From 5ec399ef2a821ec00c5f715e0c2318d10ac543aa Mon Sep 17 00:00:00 2001 From: zernonia Date: Fri, 26 Apr 2024 11:57:07 +0800 Subject: [PATCH] refactor: change color var --- apps/www/.vitepress/theme/style.css | 6 ++++- apps/www/src/content/docs/charts/guide.md | 24 +++++++++---------- .../default/ui/chart-area/AreaChart.vue | 6 ++--- .../default/ui/chart-bar/BarChart.vue | 4 ++-- .../default/ui/chart-line/LineChart.vue | 6 ++--- .../lib/registry/default/ui/chart/index.ts | 2 +- .../new-york/ui/chart-area/AreaChart.vue | 6 ++--- .../new-york/ui/chart-bar/BarChart.vue | 4 ++-- .../new-york/ui/chart-line/LineChart.vue | 6 ++--- .../lib/registry/new-york/ui/chart/index.ts | 2 +- .../registry/styles/default/chart-area.json | 2 +- .../registry/styles/default/chart-bar.json | 2 +- .../registry/styles/default/chart-line.json | 2 +- .../public/registry/styles/default/chart.json | 2 +- .../registry/styles/new-york/chart-area.json | 2 +- .../registry/styles/new-york/chart-bar.json | 2 +- .../registry/styles/new-york/chart-line.json | 2 +- .../registry/styles/new-york/chart.json | 2 +- 18 files changed, 43 insertions(+), 39 deletions(-) diff --git a/apps/www/.vitepress/theme/style.css b/apps/www/.vitepress/theme/style.css index 71dad42e..9c4ed1c4 100644 --- a/apps/www/.vitepress/theme/style.css +++ b/apps/www/.vitepress/theme/style.css @@ -28,7 +28,11 @@ --ring: 240 5% 64.9%; --radius: 0.5rem; - --vis-secondary-color: 160 81% 40%; + --vis-primary-color: var(--primary); + --vis-secondary-color: 160 81% 40%; + --vis-text-color: var(--muted-foreground); + + --vis-font-family: inherit !important; --vis-area-stroke-width: 2px !important; --vis-donut-central-label-text-color: hsl(var(--muted-foreground)) !important; diff --git a/apps/www/src/content/docs/charts/guide.md b/apps/www/src/content/docs/charts/guide.md index 98f90cbd..82b0e4e9 100644 --- a/apps/www/src/content/docs/charts/guide.md +++ b/apps/www/src/content/docs/charts/guide.md @@ -4,22 +4,16 @@ description: A simple guide to help setup chart components. label: Alpha --- -`Charts` components were built on top of [Unovis](https://unovis.dev/) (a modular data visualization framework), and inspired by [tremor](https://www.tremor.so). - -## Installation - Only works with Vue >3.3 +`Charts` components were built on top of [Unovis](https://unovis.dev/) (a modular data visualization framework), and inspired by [tremor](https://www.tremor.so). + +## Installation + -### Run the following command - -```bash -npx shadcn-vue@latest add chart -``` - ### Update `css` Add the following tooltip styling to your `tailwind.css` file: @@ -35,11 +29,17 @@ Add the following tooltip styling to your `tailwind.css` file: --vis-tooltip-backdrop-filter: none !important; --vis-tooltip-padding: none !important; - /* secondary color, change to any hsl value you want */ + --vis-primary-color: var(--primary); + /* change to any hsl value you want */ --vis-secondary-color: 160 81% 40%; + --vis-text-color: var(--muted-foreground); } ``` +If you are not using `css-variables` for your component, you need to update the `--vis-primary-color` and `--vis-text-color` to your desired hsl value. + +You may use [this tool](https://redpixelthemes.com/blog/tailwindcss-colors-different-formats/) to help you find the hsl value for your primary color and text color. Be sure to provide `dark` mode styling as well. + ## Colors @@ -62,7 +62,7 @@ However, you can always pass in the desired `color` into each chart. If you want to customize the `Tooltip` for the chart, you can pass `customTooltip` prop with a custom Vue component. The custom component would receive `title` and `data` props, check out [ChartTooltip.vue component](https://github.com/radix-vue/shadcn-vue/tree/dev/apps/www/src/lib/registry/default/ui/chart/ChartTooltip.vue) for example. -The expecting prop definition would be +The expected prop definition would be: ```ts defineProps<{ diff --git a/apps/www/src/lib/registry/default/ui/chart-area/AreaChart.vue b/apps/www/src/lib/registry/default/ui/chart-area/AreaChart.vue index 6333b286..5d3bf2ae 100644 --- a/apps/www/src/lib/registry/default/ui/chart-area/AreaChart.vue +++ b/apps/www/src/lib/registry/default/ui/chart-area/AreaChart.vue @@ -22,7 +22,7 @@ const props = withDefaults(defineProps & { */ showGradiant?: boolean }>(), { - curveType: CurveType.Basis, + curveType: CurveType.MonotoneX, filterOpacity: 0.2, margin: () => ({ top: 0, bottom: 0, left: 0, right: 0 }), showXAxis: true, @@ -112,7 +112,7 @@ function handleLegendItemClick(d: BulletLegendItemInterface, i: number) { :tick-format="xFormatter ?? ((v: number) => data[v]?.[index])" :grid-line="false" :tick-line="false" - tick-text-color="hsl(var(--muted-foreground))" + tick-text-color="hsl(var(--vis-text-color))" /> diff --git a/apps/www/src/lib/registry/default/ui/chart-bar/BarChart.vue b/apps/www/src/lib/registry/default/ui/chart-bar/BarChart.vue index ba1c7d95..a5d5cdfb 100644 --- a/apps/www/src/lib/registry/default/ui/chart-bar/BarChart.vue +++ b/apps/www/src/lib/registry/default/ui/chart-bar/BarChart.vue @@ -92,7 +92,7 @@ const selectorsBar = computed(() => props.type === 'grouped' ? GroupedBar.select :tick-format="xFormatter ?? ((v: number) => data[v]?.[index])" :grid-line="false" :tick-line="false" - tick-text-color="hsl(var(--muted-foreground))" + tick-text-color="hsl(var(--vis-text-color))" /> props.type === 'grouped' ? GroupedBar.select class: 'text-muted', }, }" - tick-text-color="hsl(var(--muted-foreground))" + tick-text-color="hsl(var(--vis-text-color))" /> diff --git a/apps/www/src/lib/registry/default/ui/chart-line/LineChart.vue b/apps/www/src/lib/registry/default/ui/chart-line/LineChart.vue index 02d9a00e..05025f49 100644 --- a/apps/www/src/lib/registry/default/ui/chart-line/LineChart.vue +++ b/apps/www/src/lib/registry/default/ui/chart-line/LineChart.vue @@ -17,7 +17,7 @@ const props = withDefaults(defineProps & { */ curveType?: CurveType }>(), { - curveType: CurveType.Basis, + curveType: CurveType.MonotoneX, filterOpacity: 0.2, margin: () => ({ top: 0, bottom: 0, left: 0, right: 0 }), showXAxis: true, @@ -81,7 +81,7 @@ function handleLegendItemClick(d: BulletLegendItemInterface, i: number) { :tick-format="xFormatter ?? ((v: number) => data[v]?.[index])" :grid-line="false" :tick-line="false" - tick-text-color="hsl(var(--muted-foreground))" + tick-text-color="hsl(var(--vis-text-color))" /> diff --git a/apps/www/src/lib/registry/default/ui/chart/index.ts b/apps/www/src/lib/registry/default/ui/chart/index.ts index af10d249..e2d64c17 100644 --- a/apps/www/src/lib/registry/default/ui/chart/index.ts +++ b/apps/www/src/lib/registry/default/ui/chart/index.ts @@ -10,7 +10,7 @@ export function defaultColors(count: number = 3) { const primaryCount = quotient + remainder const secondaryCount = quotient return [ - ...Array.from(Array(primaryCount).keys()).map(i => `hsl(var(--primary) / ${1 - (1 / primaryCount) * i})`), + ...Array.from(Array(primaryCount).keys()).map(i => `hsl(var(--vis-primary-color) / ${1 - (1 / primaryCount) * i})`), ...Array.from(Array(secondaryCount).keys()).map(i => `hsl(var(--vis-secondary-color) / ${1 - (1 / secondaryCount) * i})`), ] } diff --git a/apps/www/src/lib/registry/new-york/ui/chart-area/AreaChart.vue b/apps/www/src/lib/registry/new-york/ui/chart-area/AreaChart.vue index 160b82c6..2f45162f 100644 --- a/apps/www/src/lib/registry/new-york/ui/chart-area/AreaChart.vue +++ b/apps/www/src/lib/registry/new-york/ui/chart-area/AreaChart.vue @@ -22,7 +22,7 @@ const props = withDefaults(defineProps & { */ showGradiant?: boolean }>(), { - curveType: CurveType.Basis, + curveType: CurveType.MonotoneX, filterOpacity: 0.2, margin: () => ({ top: 0, bottom: 0, left: 0, right: 0 }), showXAxis: true, @@ -112,7 +112,7 @@ function handleLegendItemClick(d: BulletLegendItemInterface, i: number) { :tick-format="xFormatter ?? ((v: number) => data[v]?.[index])" :grid-line="false" :tick-line="false" - tick-text-color="hsl(var(--muted-foreground))" + tick-text-color="hsl(var(--vis-text-color))" /> diff --git a/apps/www/src/lib/registry/new-york/ui/chart-bar/BarChart.vue b/apps/www/src/lib/registry/new-york/ui/chart-bar/BarChart.vue index b6d539a8..0803142f 100644 --- a/apps/www/src/lib/registry/new-york/ui/chart-bar/BarChart.vue +++ b/apps/www/src/lib/registry/new-york/ui/chart-bar/BarChart.vue @@ -92,7 +92,7 @@ const selectorsBar = computed(() => props.type === 'grouped' ? GroupedBar.select :tick-format="xFormatter ?? ((v: number) => data[v]?.[index])" :grid-line="false" :tick-line="false" - tick-text-color="hsl(var(--muted-foreground))" + tick-text-color="hsl(var(--vis-text-color))" /> props.type === 'grouped' ? GroupedBar.select class: 'text-muted', }, }" - tick-text-color="hsl(var(--muted-foreground))" + tick-text-color="hsl(var(--vis-text-color))" /> diff --git a/apps/www/src/lib/registry/new-york/ui/chart-line/LineChart.vue b/apps/www/src/lib/registry/new-york/ui/chart-line/LineChart.vue index 9852fdca..e342fd3c 100644 --- a/apps/www/src/lib/registry/new-york/ui/chart-line/LineChart.vue +++ b/apps/www/src/lib/registry/new-york/ui/chart-line/LineChart.vue @@ -17,7 +17,7 @@ const props = withDefaults(defineProps & { */ curveType?: CurveType }>(), { - curveType: CurveType.Basis, + curveType: CurveType.MonotoneX, filterOpacity: 0.2, margin: () => ({ top: 0, bottom: 0, left: 0, right: 0 }), showXAxis: true, @@ -81,7 +81,7 @@ function handleLegendItemClick(d: BulletLegendItemInterface, i: number) { :tick-format="xFormatter ?? ((v: number) => data[v]?.[index])" :grid-line="false" :tick-line="false" - tick-text-color="hsl(var(--muted-foreground))" + tick-text-color="hsl(var(--vis-text-color))" /> diff --git a/apps/www/src/lib/registry/new-york/ui/chart/index.ts b/apps/www/src/lib/registry/new-york/ui/chart/index.ts index af10d249..e2d64c17 100644 --- a/apps/www/src/lib/registry/new-york/ui/chart/index.ts +++ b/apps/www/src/lib/registry/new-york/ui/chart/index.ts @@ -10,7 +10,7 @@ export function defaultColors(count: number = 3) { const primaryCount = quotient + remainder const secondaryCount = quotient return [ - ...Array.from(Array(primaryCount).keys()).map(i => `hsl(var(--primary) / ${1 - (1 / primaryCount) * i})`), + ...Array.from(Array(primaryCount).keys()).map(i => `hsl(var(--vis-primary-color) / ${1 - (1 / primaryCount) * i})`), ...Array.from(Array(secondaryCount).keys()).map(i => `hsl(var(--vis-secondary-color) / ${1 - (1 / secondaryCount) * i})`), ] } diff --git a/apps/www/src/public/registry/styles/default/chart-area.json b/apps/www/src/public/registry/styles/default/chart-area.json index a5d56936..000bdeda 100644 --- a/apps/www/src/public/registry/styles/default/chart-area.json +++ b/apps/www/src/public/registry/styles/default/chart-area.json @@ -12,7 +12,7 @@ "files": [ { "name": "AreaChart.vue", - "content": "\n\n\n" + "content": "\n\n\n" }, { "name": "index.ts", diff --git a/apps/www/src/public/registry/styles/default/chart-bar.json b/apps/www/src/public/registry/styles/default/chart-bar.json index 626d2781..aeb05dd6 100644 --- a/apps/www/src/public/registry/styles/default/chart-bar.json +++ b/apps/www/src/public/registry/styles/default/chart-bar.json @@ -12,7 +12,7 @@ "files": [ { "name": "BarChart.vue", - "content": "\n\n\n" + "content": "\n\n\n" }, { "name": "index.ts", diff --git a/apps/www/src/public/registry/styles/default/chart-line.json b/apps/www/src/public/registry/styles/default/chart-line.json index a5d71ee1..2b08ea7f 100644 --- a/apps/www/src/public/registry/styles/default/chart-line.json +++ b/apps/www/src/public/registry/styles/default/chart-line.json @@ -12,7 +12,7 @@ "files": [ { "name": "LineChart.vue", - "content": "\n\n\n" + "content": "\n\n\n" }, { "name": "index.ts", diff --git a/apps/www/src/public/registry/styles/default/chart.json b/apps/www/src/public/registry/styles/default/chart.json index 48bf6495..e8094acd 100644 --- a/apps/www/src/public/registry/styles/default/chart.json +++ b/apps/www/src/public/registry/styles/default/chart.json @@ -28,7 +28,7 @@ }, { "name": "index.ts", - "content": "export { default as ChartTooltip } from './ChartTooltip.vue'\nexport { default as ChartSingleTooltip } from './ChartSingleTooltip.vue'\nexport { default as ChartLegend } from './ChartLegend.vue'\nexport { default as ChartCrosshair } from './ChartCrosshair.vue'\n\nexport function defaultColors(count: number = 3) {\n const quotient = Math.floor(count / 2)\n const remainder = count % 2\n\n const primaryCount = quotient + remainder\n const secondaryCount = quotient\n return [\n ...Array.from(Array(primaryCount).keys()).map(i => `hsl(var(--primary) / ${1 - (1 / primaryCount) * i})`),\n ...Array.from(Array(secondaryCount).keys()).map(i => `hsl(var(--vis-secondary-color) / ${1 - (1 / secondaryCount) * i})`),\n ]\n}\n\nexport * from './interface'\n" + "content": "export { default as ChartTooltip } from './ChartTooltip.vue'\nexport { default as ChartSingleTooltip } from './ChartSingleTooltip.vue'\nexport { default as ChartLegend } from './ChartLegend.vue'\nexport { default as ChartCrosshair } from './ChartCrosshair.vue'\n\nexport function defaultColors(count: number = 3) {\n const quotient = Math.floor(count / 2)\n const remainder = count % 2\n\n const primaryCount = quotient + remainder\n const secondaryCount = quotient\n return [\n ...Array.from(Array(primaryCount).keys()).map(i => `hsl(var(--vis-primary-color) / ${1 - (1 / primaryCount) * i})`),\n ...Array.from(Array(secondaryCount).keys()).map(i => `hsl(var(--vis-secondary-color) / ${1 - (1 / secondaryCount) * i})`),\n ]\n}\n\nexport * from './interface'\n" }, { "name": "interface.ts", diff --git a/apps/www/src/public/registry/styles/new-york/chart-area.json b/apps/www/src/public/registry/styles/new-york/chart-area.json index a6f275bc..90920ca8 100644 --- a/apps/www/src/public/registry/styles/new-york/chart-area.json +++ b/apps/www/src/public/registry/styles/new-york/chart-area.json @@ -12,7 +12,7 @@ "files": [ { "name": "AreaChart.vue", - "content": "\n\n\n" + "content": "\n\n\n" }, { "name": "index.ts", diff --git a/apps/www/src/public/registry/styles/new-york/chart-bar.json b/apps/www/src/public/registry/styles/new-york/chart-bar.json index 4301adcd..a030e379 100644 --- a/apps/www/src/public/registry/styles/new-york/chart-bar.json +++ b/apps/www/src/public/registry/styles/new-york/chart-bar.json @@ -12,7 +12,7 @@ "files": [ { "name": "BarChart.vue", - "content": "\n\n\n" + "content": "\n\n\n" }, { "name": "index.ts", diff --git a/apps/www/src/public/registry/styles/new-york/chart-line.json b/apps/www/src/public/registry/styles/new-york/chart-line.json index 81726097..fdc55a8d 100644 --- a/apps/www/src/public/registry/styles/new-york/chart-line.json +++ b/apps/www/src/public/registry/styles/new-york/chart-line.json @@ -12,7 +12,7 @@ "files": [ { "name": "LineChart.vue", - "content": "\n\n\n" + "content": "\n\n\n" }, { "name": "index.ts", diff --git a/apps/www/src/public/registry/styles/new-york/chart.json b/apps/www/src/public/registry/styles/new-york/chart.json index e1ad8d3c..6195cd48 100644 --- a/apps/www/src/public/registry/styles/new-york/chart.json +++ b/apps/www/src/public/registry/styles/new-york/chart.json @@ -28,7 +28,7 @@ }, { "name": "index.ts", - "content": "export { default as ChartTooltip } from './ChartTooltip.vue'\nexport { default as ChartSingleTooltip } from './ChartSingleTooltip.vue'\nexport { default as ChartLegend } from './ChartLegend.vue'\nexport { default as ChartCrosshair } from './ChartCrosshair.vue'\n\nexport function defaultColors(count: number = 3) {\n const quotient = Math.floor(count / 2)\n const remainder = count % 2\n\n const primaryCount = quotient + remainder\n const secondaryCount = quotient\n return [\n ...Array.from(Array(primaryCount).keys()).map(i => `hsl(var(--primary) / ${1 - (1 / primaryCount) * i})`),\n ...Array.from(Array(secondaryCount).keys()).map(i => `hsl(var(--vis-secondary-color) / ${1 - (1 / secondaryCount) * i})`),\n ]\n}\n\nexport * from './interface'\n" + "content": "export { default as ChartTooltip } from './ChartTooltip.vue'\nexport { default as ChartSingleTooltip } from './ChartSingleTooltip.vue'\nexport { default as ChartLegend } from './ChartLegend.vue'\nexport { default as ChartCrosshair } from './ChartCrosshair.vue'\n\nexport function defaultColors(count: number = 3) {\n const quotient = Math.floor(count / 2)\n const remainder = count % 2\n\n const primaryCount = quotient + remainder\n const secondaryCount = quotient\n return [\n ...Array.from(Array(primaryCount).keys()).map(i => `hsl(var(--vis-primary-color) / ${1 - (1 / primaryCount) * i})`),\n ...Array.from(Array(secondaryCount).keys()).map(i => `hsl(var(--vis-secondary-color) / ${1 - (1 / secondaryCount) * i})`),\n ]\n}\n\nexport * from './interface'\n" }, { "name": "interface.ts",