/
githubmirror
/
d3
Обзор
Документация
Войти
/
githubmirror
/
d3
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
docs/components/ColorSpan.vue
30 строк
748 B
Philippe Rivière
add color (#3669)
15 июн 2023, 21:02
Не верифицирован
15 июн 2023, 21:02
5e1ef93
Код
Авторство
О чём код?
<script setup> import * as d3 from "d3"; </script> <script> export default { props: { color: true, text: {type: String}, format: {type: String, optional: true} } }; function formatColor(color, format) { switch (format) { case "rgb": color = d3.rgb(color).formatRgb(); break; case "hex": color = d3.rgb(color).formatHex(); break; case "hex8": color = d3.rgb(color).formatHex8(); break; case "hsl": color = d3.hsl(color).formatHsl(); break; default: color = String(color); break; } return color.replace(/(\d+\.\d+)/g, (d) => +(+d).toFixed(1)); } </script> <template> <em :style="{borderBottom: `solid 2px ${String(color)}`}">{{text === undefined ? formatColor(color, format) : text}}</em> </template>