@sit-onyx/chartjs-plugin 1.0.0-beta.99 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/README.md +1 -5
  2. package/package.json +14 -10
  3. package/src/index.ts +2 -2
  4. package/src/plugin.ts +4 -3
  5. package/src/stories/BarChart/BarChart.ct.tsx +1 -1
  6. package/src/stories/BarChart/BarChart.stories.ts +1 -1
  7. package/src/stories/BarChart/BarChart.vue +1 -1
  8. package/src/stories/BubbleChart/BubbleChart.ct.tsx +1 -1
  9. package/src/stories/BubbleChart/BubbleChart.stories.ts +1 -1
  10. package/src/stories/BubbleChart/BubbleChart.vue +1 -1
  11. package/src/stories/DoughnutChart/DoughnutChart.ct.tsx +1 -1
  12. package/src/stories/DoughnutChart/DoughnutChart.stories.ts +1 -1
  13. package/src/stories/DoughnutChart/DoughnutChart.vue +1 -1
  14. package/src/stories/LineChart/LineChart.ct.tsx +1 -1
  15. package/src/stories/LineChart/LineChart.stories.ts +1 -1
  16. package/src/stories/LineChart/LineChart.vue +1 -1
  17. package/src/stories/PieChart/PieChart.ct.tsx +1 -1
  18. package/src/stories/PieChart/PieChart.stories.ts +1 -1
  19. package/src/stories/PieChart/PieChart.vue +1 -1
  20. package/src/stories/PolarAreaChart/PolarAreaChart.ct.tsx +1 -1
  21. package/src/stories/PolarAreaChart/PolarAreaChart.stories.ts +1 -1
  22. package/src/stories/PolarAreaChart/PolarAreaChart.vue +1 -1
  23. package/src/stories/RadarChart/RadarChart.ct.tsx +1 -1
  24. package/src/stories/RadarChart/RadarChart.stories.ts +1 -1
  25. package/src/stories/RadarChart/RadarChart.vue +1 -1
  26. package/src/stories/ScatterChart/ScatterChart.ct.tsx +1 -1
  27. package/src/stories/ScatterChart/ScatterChart.stories.ts +1 -1
  28. package/src/stories/ScatterChart/ScatterChart.vue +1 -1
  29. package/src/utils.spec.ts +1 -1
  30. package/src/utils.ts +11 -2
package/README.md CHANGED
@@ -1,9 +1,5 @@
1
1
  <div align="center" style="text-align: center">
2
- <picture>
3
- <source media="(prefers-color-scheme: dark)" type="image/svg+xml" srcset="https://raw.githubusercontent.com/SchwarzIT/onyx/main/.github/onyx-logo-light.svg">
4
- <source media="(prefers-color-scheme: light)" type="image/svg+xml" srcset="https://raw.githubusercontent.com/SchwarzIT/onyx/main/.github/onyx-logo-dark.svg">
5
- <img alt="onyx logo" src="https://raw.githubusercontent.com/SchwarzIT/onyx/main/.github/onyx-logo-dark.svg" width="160px">
6
- </picture>
2
+ <img alt="onyx logo" src="https://raw.githubusercontent.com/SchwarzIT/onyx/main/.github/onyx-logo.svg" height="96px">
7
3
  </div>
8
4
 
9
5
  <br>
package/package.json CHANGED
@@ -1,10 +1,13 @@
1
1
  {
2
2
  "name": "@sit-onyx/chartjs-plugin",
3
3
  "description": "A Chart.js plugin for the onyx design system created by Schwarz IT",
4
- "version": "1.0.0-beta.99",
4
+ "version": "1.0.0",
5
5
  "type": "module",
6
6
  "author": "Schwarz IT KG",
7
7
  "license": "Apache-2.0",
8
+ "engines": {
9
+ "node": ">=20"
10
+ },
8
11
  "files": [
9
12
  "src"
10
13
  ],
@@ -24,20 +27,21 @@
24
27
  },
25
28
  "peerDependencies": {
26
29
  "chart.js": ">= 4.0.0",
27
- "sit-onyx": "^1.0.0-beta.99"
30
+ "sit-onyx": "^1.0.0"
28
31
  },
29
32
  "devDependencies": {
30
- "@vue/compiler-dom": "3.5.13",
31
- "chart.js": "^4.4.5",
32
- "vue": "3.5.13",
33
+ "@playwright/experimental-ct-vue": "1.55.0",
34
+ "@playwright/test": "1.55.0",
35
+ "@vue/compiler-dom": "3.5.21",
36
+ "chart.js": "4.5.0",
37
+ "vue": "3.5.21",
33
38
  "vue-chartjs": "^5.3.2",
34
- "@sit-onyx/shared": "^0.0.1-beta.0",
35
- "@sit-onyx/storybook-utils": "^1.0.0-beta.75",
36
- "sit-onyx": "^1.0.0-beta.99"
39
+ "@sit-onyx/shared": "^0.1.0",
40
+ "@sit-onyx/storybook-utils": "^1.0.0",
41
+ "sit-onyx": "^1.0.0"
37
42
  },
38
43
  "scripts": {
39
- "dev": "turbo run turbo:dev --filter=.",
40
- "turbo:dev": "storybook dev -p 6006 --no-open",
44
+ "dev": "storybook dev -p 6006 --no-open",
41
45
  "build": "vue-tsc --noEmit",
42
46
  "test": "vitest",
43
47
  "test:coverage": "vitest run --coverage",
package/src/index.ts CHANGED
@@ -1,2 +1,2 @@
1
- export * from "./plugin";
2
- export * from "./utils";
1
+ export * from "./plugin.js";
2
+ export * from "./utils.js";
package/src/plugin.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import {
2
- Chart,
3
2
  DoughnutController,
4
3
  PieController,
5
4
  PolarAreaController,
5
+ type Chart,
6
6
  type ChartDataset,
7
7
  type ChartType,
8
8
  type Color,
@@ -10,7 +10,7 @@ import {
10
10
  type ScaleOptionsByType,
11
11
  type ScaleTypeRegistry,
12
12
  } from "chart.js";
13
- import { QUANTITATIVE_COLOR_STEPS, getCSSVariableValue, hexToRgb } from "./utils";
13
+ import { QUANTITATIVE_COLOR_STEPS, getCSSVariableValue, hexToRgb } from "./utils.js";
14
14
 
15
15
  /**
16
16
  * Registers the onyx Chart.js plugin and updates the default styles (colors, fonts etc.) to match
@@ -146,6 +146,7 @@ const plugin: Plugin<ChartType, undefined> = {
146
146
  */
147
147
  afterInit: (chart) => {
148
148
  const darkModeObserver = new MutationObserver((mutations) => {
149
+ if (!mutations[0]) return;
149
150
  const oldClasses = mutations[0].oldValue ?? "";
150
151
  const newClasses = (mutations[0].target as HTMLElement).className;
151
152
 
@@ -214,7 +215,7 @@ const COLORS = QUANTITATIVE_COLOR_STEPS.map(
214
215
  /**
215
216
  * Gets a border color.
216
217
  */
217
- const getBorderColor = (i: number) => getCSSVariableValue(COLORS[i % COLORS.length]);
218
+ const getBorderColor = (i: number) => getCSSVariableValue(COLORS[i % COLORS.length]!);
218
219
 
219
220
  /**
220
221
  * Gets a background color (same as border color + 30% transparency).
@@ -1,5 +1,5 @@
1
1
  import { test } from "@playwright/experimental-ct-vue";
2
- import { executeChartScreenshotTest } from "../playwright-utils";
2
+ import { executeChartScreenshotTest } from "../playwright-utils.js";
3
3
  import BarChart from "./BarChart.vue";
4
4
 
5
5
  test("should render bar chart", async ({ mount, page }) => {
@@ -1,4 +1,4 @@
1
- import type { Meta, StoryObj } from "@storybook/vue3";
1
+ import type { Meta, StoryObj } from "@storybook/vue3-vite";
2
2
  import BarChart from "./BarChart.vue";
3
3
 
4
4
  const meta: Meta<typeof BarChart> = {
@@ -1,7 +1,7 @@
1
1
  <script lang="ts" setup>
2
2
  import type { ChartData } from "chart.js";
3
3
  import { Bar } from "vue-chartjs";
4
- import { chartOptions } from "../data";
4
+ import { chartOptions } from "../data.js";
5
5
 
6
6
  const labels = ["01.01.2024", "01.02.2024", "01.03.2024", "01.04.2024", "01.05.2024"];
7
7
 
@@ -1,5 +1,5 @@
1
1
  import { test } from "@playwright/experimental-ct-vue";
2
- import { executeChartScreenshotTest } from "../playwright-utils";
2
+ import { executeChartScreenshotTest } from "../playwright-utils.js";
3
3
  import BubbleChart from "./BubbleChart.vue";
4
4
 
5
5
  test("should render bubble chart", async ({ mount, page }) => {
@@ -1,4 +1,4 @@
1
- import type { Meta, StoryObj } from "@storybook/vue3";
1
+ import type { Meta, StoryObj } from "@storybook/vue3-vite";
2
2
  import BubbleChart from "./BubbleChart.vue";
3
3
 
4
4
  const meta: Meta<typeof BubbleChart> = {
@@ -1,7 +1,7 @@
1
1
  <script lang="ts" setup>
2
2
  import type { ChartData } from "chart.js";
3
3
  import { Bubble } from "vue-chartjs";
4
- import { chartOptions } from "../data";
4
+ import { chartOptions } from "../data.js";
5
5
 
6
6
  const chartData: ChartData<"bubble"> = {
7
7
  datasets: [
@@ -1,5 +1,5 @@
1
1
  import { test } from "@playwright/experimental-ct-vue";
2
- import { executeChartScreenshotTest } from "../playwright-utils";
2
+ import { executeChartScreenshotTest } from "../playwright-utils.js";
3
3
  import DoughnutChart from "./DoughnutChart.vue";
4
4
 
5
5
  test("should render doughnut chart", async ({ mount, page }) => {
@@ -1,4 +1,4 @@
1
- import type { Meta, StoryObj } from "@storybook/vue3";
1
+ import type { Meta, StoryObj } from "@storybook/vue3-vite";
2
2
  import DoughnutChart from "./DoughnutChart.vue";
3
3
 
4
4
  const meta: Meta<typeof DoughnutChart> = {
@@ -1,7 +1,7 @@
1
1
  <script lang="ts" setup>
2
2
  import type { ChartData } from "chart.js";
3
3
  import { Doughnut } from "vue-chartjs";
4
- import { chartOptions } from "../data";
4
+ import { chartOptions } from "../data.js";
5
5
 
6
6
  const chartData: ChartData<"doughnut"> = {
7
7
  labels: ["Label 1", "Label 2", "Label 3", "Label 4"],
@@ -1,5 +1,5 @@
1
1
  import { test } from "@playwright/experimental-ct-vue";
2
- import { executeChartScreenshotTest } from "../playwright-utils";
2
+ import { executeChartScreenshotTest } from "../playwright-utils.js";
3
3
  import LineChart from "./LineChart.vue";
4
4
 
5
5
  test("should render line chart", async ({ mount, page }) => {
@@ -1,4 +1,4 @@
1
- import type { Meta, StoryObj } from "@storybook/vue3";
1
+ import type { Meta, StoryObj } from "@storybook/vue3-vite";
2
2
  import LineChart from "./LineChart.vue";
3
3
 
4
4
  const meta: Meta<typeof LineChart> = {
@@ -1,7 +1,7 @@
1
1
  <script lang="ts" setup>
2
2
  import type { ChartData } from "chart.js";
3
3
  import { Line } from "vue-chartjs";
4
- import { chartOptions } from "../data";
4
+ import { chartOptions } from "../data.js";
5
5
 
6
6
  const labels = ["01.01.2024", "01.02.2024", "01.03.2024", "01.04.2024", "01.05.2024"];
7
7
 
@@ -1,5 +1,5 @@
1
1
  import { test } from "@playwright/experimental-ct-vue";
2
- import { executeChartScreenshotTest } from "../playwright-utils";
2
+ import { executeChartScreenshotTest } from "../playwright-utils.js";
3
3
  import PieChart from "./PieChart.vue";
4
4
 
5
5
  test("should render pie chart", async ({ mount, page }) => {
@@ -1,4 +1,4 @@
1
- import type { Meta, StoryObj } from "@storybook/vue3";
1
+ import type { Meta, StoryObj } from "@storybook/vue3-vite";
2
2
  import PieChart from "./PieChart.vue";
3
3
 
4
4
  const meta: Meta<typeof PieChart> = {
@@ -1,7 +1,7 @@
1
1
  <script lang="ts" setup>
2
2
  import type { ChartData } from "chart.js";
3
3
  import { Pie } from "vue-chartjs";
4
- import { chartOptions } from "../data";
4
+ import { chartOptions } from "../data.js";
5
5
 
6
6
  const chartData: ChartData<"pie"> = {
7
7
  labels: ["Label 1", "Label 2", "Label 3", "Label 4"],
@@ -1,5 +1,5 @@
1
1
  import { test } from "@playwright/experimental-ct-vue";
2
- import { executeChartScreenshotTest } from "../playwright-utils";
2
+ import { executeChartScreenshotTest } from "../playwright-utils.js";
3
3
  import PolarAreaChart from "./PolarAreaChart.vue";
4
4
 
5
5
  test("should render polar area chart", async ({ mount, page }) => {
@@ -1,4 +1,4 @@
1
- import type { Meta, StoryObj } from "@storybook/vue3";
1
+ import type { Meta, StoryObj } from "@storybook/vue3-vite";
2
2
  import PolarAreaChart from "./PolarAreaChart.vue";
3
3
 
4
4
  const meta: Meta<typeof PolarAreaChart> = {
@@ -1,7 +1,7 @@
1
1
  <script lang="ts" setup>
2
2
  import type { ChartData } from "chart.js";
3
3
  import { PolarArea } from "vue-chartjs";
4
- import { chartOptionsWithoutScales } from "../data";
4
+ import { chartOptionsWithoutScales } from "../data.js";
5
5
 
6
6
  const chartData: ChartData<"polarArea"> = {
7
7
  labels: ["Label 1", "Label 2", "Label 3", "Label 4", "Label 5", "Label 6", "Label 7"],
@@ -1,5 +1,5 @@
1
1
  import { test } from "@playwright/experimental-ct-vue";
2
- import { executeChartScreenshotTest } from "../playwright-utils";
2
+ import { executeChartScreenshotTest } from "../playwright-utils.js";
3
3
  import RadarChart from "./RadarChart.vue";
4
4
 
5
5
  test("should render radar chart", async ({ mount, page }) => {
@@ -1,4 +1,4 @@
1
- import type { Meta, StoryObj } from "@storybook/vue3";
1
+ import type { Meta, StoryObj } from "@storybook/vue3-vite";
2
2
  import RadarChart from "./RadarChart.vue";
3
3
 
4
4
  const meta: Meta<typeof RadarChart> = {
@@ -1,7 +1,7 @@
1
1
  <script lang="ts" setup>
2
2
  import type { ChartData } from "chart.js";
3
3
  import { Radar } from "vue-chartjs";
4
- import { chartOptionsWithoutScales } from "../data";
4
+ import { chartOptionsWithoutScales } from "../data.js";
5
5
 
6
6
  const chartData: ChartData<"radar"> = {
7
7
  labels: ["Eating", "Drinking", "Sleeping", "Designing", "Coding", "Cycling", "Running"],
@@ -1,5 +1,5 @@
1
1
  import { test } from "@playwright/experimental-ct-vue";
2
- import { executeChartScreenshotTest } from "../playwright-utils";
2
+ import { executeChartScreenshotTest } from "../playwright-utils.js";
3
3
  import ScatterChart from "./ScatterChart.vue";
4
4
 
5
5
  test("should render scatter chart", async ({ mount, page }) => {
@@ -1,4 +1,4 @@
1
- import type { Meta, StoryObj } from "@storybook/vue3";
1
+ import type { Meta, StoryObj } from "@storybook/vue3-vite";
2
2
  import ScatterChart from "./ScatterChart.vue";
3
3
 
4
4
  const meta: Meta<typeof ScatterChart> = {
@@ -1,7 +1,7 @@
1
1
  <script lang="ts" setup>
2
2
  import type { ChartData } from "chart.js";
3
3
  import { Scatter } from "vue-chartjs";
4
- import { chartOptions } from "../data";
4
+ import { chartOptions } from "../data.js";
5
5
 
6
6
  const chartData: ChartData<"scatter"> = {
7
7
  datasets: [
package/src/utils.spec.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { describe, expect, test } from "vitest";
2
- import { hexToRgb } from "./utils";
2
+ import { hexToRgb } from "./utils.js";
3
3
 
4
4
  describe("utils.ts", () => {
5
5
  test("should convert hex to rgb", () => {
package/src/utils.ts CHANGED
@@ -39,8 +39,17 @@ export const getDatasetColors = (color: OnyxColor | `quantitatives-${Quantitativ
39
39
  * Gets the current value of the given CSS variable.
40
40
  * @param CSS variable name, e.g. `--onyx-color-base-primary-500`
41
41
  */
42
- export const getCSSVariableValue = (variableName: string) => {
43
- return getComputedStyle(document.body).getPropertyValue(variableName);
42
+
43
+ export const getCSSVariableValue = (variableName: string): string => {
44
+ const isDark = getComputedStyle(document.body).colorScheme === "dark";
45
+ const computedValue = getComputedStyle(document.body).getPropertyValue(variableName).trim();
46
+ const lightDarkMatch = /^light-dark\(([^,]+),\s*([^)]+)\)$/.exec(computedValue);
47
+
48
+ if (lightDarkMatch) {
49
+ return lightDarkMatch[isDark ? 2 : 1]!.trim();
50
+ } else {
51
+ return computedValue;
52
+ }
44
53
  };
45
54
 
46
55
  /**