@sit-onyx/chartjs-plugin 1.0.0-alpha.63 → 1.0.0-alpha.64
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.
- package/package.json +1 -1
- package/src/plugin.ts +4 -12
- package/src/utils.ts +6 -3
package/package.json
CHANGED
package/src/plugin.ts
CHANGED
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
type ScaleOptionsByType,
|
|
11
11
|
type ScaleTypeRegistry,
|
|
12
12
|
} from "chart.js";
|
|
13
|
-
import { getCSSVariableValue, hexToRgb } from "./utils";
|
|
13
|
+
import { QUANTITATIVE_COLOR_STEPS, getCSSVariableValue, hexToRgb } from "./utils";
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* Registers the onyx Chart.js plugin and updates the default styles (colors, fonts etc.) to match
|
|
@@ -207,17 +207,9 @@ const colorizeDataset = (dataset: ChartDataset, offset = 0, allData = false) =>
|
|
|
207
207
|
/**
|
|
208
208
|
* Available colors to choose from for default dataset styles.
|
|
209
209
|
*/
|
|
210
|
-
const COLORS =
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
"--onyx-color-base-quantitatives-300",
|
|
214
|
-
"--onyx-color-base-quantitatives-400",
|
|
215
|
-
"--onyx-color-base-quantitatives-500",
|
|
216
|
-
"--onyx-color-base-quantitatives-600",
|
|
217
|
-
"--onyx-color-base-quantitatives-700",
|
|
218
|
-
"--onyx-color-base-quantitatives-800",
|
|
219
|
-
"--onyx-color-base-quantitatives-900",
|
|
220
|
-
] as const;
|
|
210
|
+
const COLORS = QUANTITATIVE_COLOR_STEPS.map(
|
|
211
|
+
(step) => `--onyx-color-base-quantitatives-${step}` as const,
|
|
212
|
+
);
|
|
221
213
|
|
|
222
214
|
/**
|
|
223
215
|
* Gets a border color.
|
package/src/utils.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import type { OnyxColor } from "sit-onyx/types";
|
|
2
2
|
|
|
3
|
+
export const QUANTITATIVE_COLOR_STEPS = [
|
|
4
|
+
100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200,
|
|
5
|
+
] as const;
|
|
6
|
+
export type QuantitativeColorStep = (typeof QUANTITATIVE_COLOR_STEPS)[number];
|
|
7
|
+
|
|
3
8
|
/**
|
|
4
9
|
* Utility for easily styling a Chart.js dataset with a specific onyx color.
|
|
5
10
|
* Will be updated automatically when switching between light/dark mode.
|
|
@@ -18,9 +23,7 @@ import type { OnyxColor } from "sit-onyx/types";
|
|
|
18
23
|
* };
|
|
19
24
|
* ```
|
|
20
25
|
*/
|
|
21
|
-
export const getDatasetColors = (
|
|
22
|
-
color: OnyxColor | `quantitatives-${100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900}`,
|
|
23
|
-
) => {
|
|
26
|
+
export const getDatasetColors = (color: OnyxColor | `quantitatives-${QuantitativeColorStep}`) => {
|
|
24
27
|
const cssVariable = `--onyx-color-base-${color.startsWith("quantitatives-") ? color : `${color}-500`}`;
|
|
25
28
|
// we use arrow functions here so the value is updated / re-evaluated when
|
|
26
29
|
// switched between light and dark mode
|