@opendata-ai/openchart-core 9.7.1 → 9.8.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.
- package/dist/index.d.ts +27 -16
- package/dist/index.js +33 -23
- package/dist/index.js.map +1 -1
- package/dist/styles.css.map +1 -1
- package/package.json +1 -1
- package/schema/chart.schema.json +4 -0
- package/schema/table.schema.json +4 -0
- package/schema/vizspec.schema.json +4 -0
package/dist/index.d.ts
CHANGED
|
@@ -326,6 +326,8 @@ interface ThemeColors {
|
|
|
326
326
|
hairline: string;
|
|
327
327
|
/** Sequential palettes keyed by name. Each is an array of color stops from light to dark. */
|
|
328
328
|
sequential: Record<string, string[]>;
|
|
329
|
+
/** Default sequential ramp key; resolved to the first ramp when omitted or unknown. */
|
|
330
|
+
defaultSequential?: string;
|
|
329
331
|
/** Diverging palettes keyed by name. Each is an array of color stops with a neutral midpoint. */
|
|
330
332
|
diverging: Record<string, string[]>;
|
|
331
333
|
/** Background color for the visualization container. */
|
|
@@ -376,6 +378,8 @@ interface ThemeColors {
|
|
|
376
378
|
* neutral ramp derived from the theme's own text/background pair.
|
|
377
379
|
*/
|
|
378
380
|
interface ResolvedThemeColors extends ThemeColors {
|
|
381
|
+
/** Key of the default sequential ramp in the merged palette record. */
|
|
382
|
+
defaultSequential: string;
|
|
379
383
|
/** Grays derived by mixing `text` toward `background`. */
|
|
380
384
|
neutral: NeutralRamp;
|
|
381
385
|
}
|
|
@@ -4479,6 +4483,8 @@ interface ThemeConfig {
|
|
|
4479
4483
|
hairline?: TokenValue;
|
|
4480
4484
|
/** Sequential palettes keyed by name. Each is an array of color stops. */
|
|
4481
4485
|
sequential?: Record<string, TokenValue[]>;
|
|
4486
|
+
/** Default sequential ramp key. Unknown or omitted names use the first merged ramp. */
|
|
4487
|
+
defaultSequential?: string;
|
|
4482
4488
|
/** Diverging palettes keyed by name. Each is an array of color stops with a neutral midpoint. */
|
|
4483
4489
|
diverging?: Record<string, TokenValue[]>;
|
|
4484
4490
|
/** Background color. Accepts a TokenValue for light/dark pairs. */
|
|
@@ -7485,7 +7491,7 @@ interface ReaderSliceIndexOptions {
|
|
|
7485
7491
|
/**
|
|
7486
7492
|
* Color blindness simulation and palette distinguishability checks.
|
|
7487
7493
|
*
|
|
7488
|
-
* Uses
|
|
7494
|
+
* Uses Machado, Oliveira & Fernandes (2009), severity 1.0, for
|
|
7489
7495
|
* protanopia, deuteranopia, and tritanopia.
|
|
7490
7496
|
*
|
|
7491
7497
|
* These are approximations suitable for checking palette accessibility,
|
|
@@ -7495,15 +7501,19 @@ interface ReaderSliceIndexOptions {
|
|
|
7495
7501
|
type ColorBlindnessType = 'protanopia' | 'deuteranopia' | 'tritanopia' | 'achromatopsia';
|
|
7496
7502
|
/**
|
|
7497
7503
|
* Simulate how a color appears under a given color blindness type.
|
|
7498
|
-
* Returns a hex color string.
|
|
7504
|
+
* Returns a clamped sRGB hex color string. Unresolvable colors (including
|
|
7505
|
+
* transparent) and unsupported types return the input color unchanged.
|
|
7499
7506
|
*/
|
|
7500
7507
|
declare function simulateColorBlindness(color: string, type: ColorBlindnessType): string;
|
|
7501
7508
|
/**
|
|
7502
7509
|
* Check if colors in a palette are distinguishable under a given
|
|
7503
7510
|
* color blindness type.
|
|
7504
7511
|
*
|
|
7505
|
-
* Uses
|
|
7506
|
-
*
|
|
7512
|
+
* Uses CIE76 distance in d3-color's D50 CIELAB after simulation, with a
|
|
7513
|
+
* default minDistance of 15 delta E units as a screening heuristic.
|
|
7514
|
+
* Returns true if every pair has distance >= minDistance (also for empty or
|
|
7515
|
+
* single-color palettes). Unresolvable colors/palettes and unsupported types
|
|
7516
|
+
* return false. Non-finite or negative thresholds fall back to 15.
|
|
7507
7517
|
*/
|
|
7508
7518
|
declare function checkPaletteDistinguishability(colors: string[], type: ColorBlindnessType, minDistance?: number): boolean;
|
|
7509
7519
|
|
|
@@ -7595,9 +7605,8 @@ declare const ACHROMATIC_RAMP: {
|
|
|
7595
7605
|
* Construction rules (the contract; the hexes below are output, not input):
|
|
7596
7606
|
* - Hue order cyan 216 -> ochre 70 -> blue 262 -> rose 350 -> green 155 ->
|
|
7597
7607
|
* violet 300, so every adjacent pair including the wrap is >= 80° apart.
|
|
7598
|
-
* - Lightness varies rather than matching: colour-vision deficiency
|
|
7599
|
-
*
|
|
7600
|
-
* fails the repo's own Brettel simulator on ochre/rose and blue/violet.
|
|
7608
|
+
* - Lightness varies rather than matching: colour-vision deficiency can
|
|
7609
|
+
* reduce hue separation, while differences in lightness can survive.
|
|
7601
7610
|
* - Fills use equal or lower chroma and equal or higher lightness than
|
|
7602
7611
|
* strokes (within sRGB rounding), while clearing 3:1 on near-white.
|
|
7603
7612
|
* Cyan uses reduced chroma to remain in gamut at its darker lightness.
|
|
@@ -7608,9 +7617,11 @@ declare const ACHROMATIC_RAMP: {
|
|
|
7608
7617
|
* the dark-mode adapter's hsl-based binary search). Each entry carries its
|
|
7609
7618
|
* *measured* OKLCH so the ramp can be regenerated; do not edit hexes directly.
|
|
7610
7619
|
*
|
|
7611
|
-
*
|
|
7612
|
-
*
|
|
7613
|
-
*
|
|
7620
|
+
* With Machado simulation and the heuristic CIE76 threshold of 15, light
|
|
7621
|
+
* strokes pass deuteranopia and dark strokes pass tritanopia; the other
|
|
7622
|
+
* array/deficiency combinations fail. The colors are kept for compatibility.
|
|
7623
|
+
* See docs/design-system.md for every nearest pair and measured distance,
|
|
7624
|
+
* and `colors/__tests__/palette-a11y.test.ts` for the regression checks.
|
|
7614
7625
|
*/
|
|
7615
7626
|
declare const CATEGORICAL_PALETTE: readonly ["#0a879e", "#bf7e1f", "#4170cb", "#b2417f", "#3ca368", "#9c7bd2"];
|
|
7616
7627
|
/**
|
|
@@ -7740,9 +7751,9 @@ declare const wire: ThemeConfig;
|
|
|
7740
7751
|
* Broadsheet preset: newspaper editorial. Warm paper, a red masthead rule and
|
|
7741
7752
|
* eyebrow, a bold 24px title, and a quiet palette built around one loud hue.
|
|
7742
7753
|
*
|
|
7743
|
-
* Palette (measured OKLCH
|
|
7744
|
-
*
|
|
7745
|
-
*
|
|
7754
|
+
* Palette (measured OKLCH). Machado severity 1.0, CIE76 threshold 15:
|
|
7755
|
+
* light strokes fail deuteranopia (nearest green/gray, 5.75) and protanopia
|
|
7756
|
+
* (green/gray, 8.44); light fills also fail both (5.80 and 7.74).
|
|
7746
7757
|
* 1 #1d5f8a oklch(0.466 0.095 242) ink blue
|
|
7747
7758
|
* 2 #e3120b oklch(0.580 0.232 29) house red — the one loud hue
|
|
7748
7759
|
* 3 #7fb0d3 oklch(0.735 0.073 240) pale blue
|
|
@@ -7753,9 +7764,9 @@ declare const wire: ThemeConfig;
|
|
|
7753
7764
|
*
|
|
7754
7765
|
* Dark mode is the same page after nightfall: the newsprint gives way to an
|
|
7755
7766
|
* ink-blue ground, with the same hues lifted to hold their contrast on it.
|
|
7756
|
-
*
|
|
7757
|
-
*
|
|
7758
|
-
*
|
|
7767
|
+
* Dark strokes fail deuteranopia (nearest green/gray, 8.55) and pass
|
|
7768
|
+
* protanopia (green/gray, 15.26). Dark fills fail both (nearest green/gray,
|
|
7769
|
+
* 9.22 under deuteranopia; pale blue/gray, 13.98 under protanopia).
|
|
7759
7770
|
* 1 #5e9fd6 ink blue, lifted 2 #f4655a house red, lifted
|
|
7760
7771
|
* 3 #93c2e2 pale blue 4 #e0b267 ochre
|
|
7761
7772
|
* 5 #4fb093 green 6 #9aa1a8 gray, cooled
|
package/dist/index.js
CHANGED
|
@@ -521,21 +521,21 @@ var MARK_DISPLAY_NAMES = {
|
|
|
521
521
|
};
|
|
522
522
|
|
|
523
523
|
// src/colors/colorblind.ts
|
|
524
|
-
import { rgb } from "d3-color";
|
|
524
|
+
import { lab, rgb } from "d3-color";
|
|
525
525
|
var PROTAN_MATRIX = [
|
|
526
|
-
[0.
|
|
527
|
-
[0.
|
|
528
|
-
[
|
|
526
|
+
[0.152286, 1.052583, -0.204868],
|
|
527
|
+
[0.114503, 0.786281, 0.099216],
|
|
528
|
+
[-3882e-6, -0.048116, 1.051998]
|
|
529
529
|
];
|
|
530
530
|
var DEUTAN_MATRIX = [
|
|
531
|
-
[0.
|
|
532
|
-
[0.
|
|
533
|
-
[0, 0.
|
|
531
|
+
[0.367322, 0.860646, -0.227968],
|
|
532
|
+
[0.280085, 0.672501, 0.047413],
|
|
533
|
+
[-0.01182, 0.04294, 0.968881]
|
|
534
534
|
];
|
|
535
535
|
var TRITAN_MATRIX = [
|
|
536
|
-
[
|
|
537
|
-
[0, 0.
|
|
538
|
-
[
|
|
536
|
+
[1.255528, -0.076749, -0.178779],
|
|
537
|
+
[-0.078411, 0.930809, 0.147602],
|
|
538
|
+
[4733e-6, 0.691367, 0.3039]
|
|
539
539
|
];
|
|
540
540
|
var ACHROMAT_MATRIX = [
|
|
541
541
|
[0.2126, 0.7152, 0.0722],
|
|
@@ -557,8 +557,9 @@ function delinearize(v) {
|
|
|
557
557
|
return Math.round(Math.max(0, Math.min(255, s * 255)));
|
|
558
558
|
}
|
|
559
559
|
function simulateColorBlindness(color, type) {
|
|
560
|
+
if (typeof color !== "string" || !Object.hasOwn(MATRICES, type)) return color;
|
|
560
561
|
const c = rgb(color);
|
|
561
|
-
if (c
|
|
562
|
+
if (![c.r, c.g, c.b].every(Number.isFinite)) return color;
|
|
562
563
|
const lin = [linearize(c.r), linearize(c.g), linearize(c.b)];
|
|
563
564
|
const m = MATRICES[type];
|
|
564
565
|
const r = m[0][0] * lin[0] + m[0][1] * lin[1] + m[0][2] * lin[2];
|
|
@@ -566,18 +567,23 @@ function simulateColorBlindness(color, type) {
|
|
|
566
567
|
const b = m[2][0] * lin[0] + m[2][1] * lin[1] + m[2][2] * lin[2];
|
|
567
568
|
return rgb(delinearize(r), delinearize(g), delinearize(b)).formatHex();
|
|
568
569
|
}
|
|
569
|
-
function checkPaletteDistinguishability(colors, type, minDistance =
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
570
|
+
function checkPaletteDistinguishability(colors, type, minDistance = 15) {
|
|
571
|
+
if (!Array.isArray(colors) || !Object.hasOwn(MATRICES, type)) return false;
|
|
572
|
+
const threshold = Number.isFinite(minDistance) && minDistance >= 0 ? minDistance : 15;
|
|
573
|
+
const simulated = [];
|
|
574
|
+
for (const color of colors) {
|
|
575
|
+
if (typeof color !== "string") return false;
|
|
576
|
+
const s = lab(simulateColorBlindness(color, type));
|
|
577
|
+
if (![s.l, s.a, s.b].every(Number.isFinite)) return false;
|
|
578
|
+
simulated.push(s);
|
|
579
|
+
}
|
|
574
580
|
for (let i = 0; i < simulated.length; i++) {
|
|
575
581
|
for (let j = i + 1; j < simulated.length; j++) {
|
|
576
|
-
const
|
|
577
|
-
const
|
|
578
|
-
const db = simulated[i]
|
|
579
|
-
const dist = Math.
|
|
580
|
-
if (dist <
|
|
582
|
+
const dl = simulated[i].l - simulated[j].l;
|
|
583
|
+
const da = simulated[i].a - simulated[j].a;
|
|
584
|
+
const db = simulated[i].b - simulated[j].b;
|
|
585
|
+
const dist = Math.hypot(dl, da, db);
|
|
586
|
+
if (dist < threshold) return false;
|
|
581
587
|
}
|
|
582
588
|
}
|
|
583
589
|
return true;
|
|
@@ -2280,7 +2286,7 @@ var wire = {
|
|
|
2280
2286
|
},
|
|
2281
2287
|
fonts: {
|
|
2282
2288
|
family: '"JetBrains Mono", "Fira Code", "Cascadia Code", monospace',
|
|
2283
|
-
sizes: { title: 16, subtitle: 12, body: 11, small: 10, axisTick:
|
|
2289
|
+
sizes: { title: 16, subtitle: 12, body: 11, small: 10, axisTick: 12 },
|
|
2284
2290
|
weights: { normal: 400, medium: 500, semibold: 600, bold: 700 }
|
|
2285
2291
|
},
|
|
2286
2292
|
spacing: {
|
|
@@ -2358,7 +2364,7 @@ var terminal = /* @__PURE__ */ (() => ({
|
|
|
2358
2364
|
fonts: {
|
|
2359
2365
|
family: '"Inter Variable", Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',
|
|
2360
2366
|
mono: '"JetBrains Mono", "Fira Code", "Cascadia Code", monospace',
|
|
2361
|
-
sizes: { title: 15, subtitle: 12, body: 12, small: 10, axisTick:
|
|
2367
|
+
sizes: { title: 15, subtitle: 12, body: 12, small: 10, axisTick: 12 }
|
|
2362
2368
|
},
|
|
2363
2369
|
spacing: {
|
|
2364
2370
|
padding: 12,
|
|
@@ -2454,6 +2460,8 @@ function themeConfigToPartial(config, base2) {
|
|
|
2454
2460
|
if (Array.isArray(config.colors)) {
|
|
2455
2461
|
colors.categorical = config.colors;
|
|
2456
2462
|
} else {
|
|
2463
|
+
const { defaultSequential } = config.colors;
|
|
2464
|
+
if (typeof defaultSequential === "string") colors.defaultSequential = defaultSequential;
|
|
2457
2465
|
if (config.colors.categorical)
|
|
2458
2466
|
colors.categorical = config.colors.categorical.map(resolveTokenLight);
|
|
2459
2467
|
if (config.colors.categoricalFill)
|
|
@@ -2742,12 +2750,14 @@ function resolveTheme(userTheme, base2 = DEFAULT_THEME) {
|
|
|
2742
2750
|
const neutral = deriveNeutralRamp(merged.colors.text, merged.colors.background, dark);
|
|
2743
2751
|
const authoredColors = userTheme?.colors && !Array.isArray(userTheme.colors) ? userTheme.colors : {};
|
|
2744
2752
|
const rampPairs = userTheme ? collectRampPairs(userTheme) : void 0;
|
|
2753
|
+
const { sequential, defaultSequential } = merged.colors;
|
|
2745
2754
|
return {
|
|
2746
2755
|
...merged,
|
|
2747
2756
|
_authored: userTheme,
|
|
2748
2757
|
colors: {
|
|
2749
2758
|
...merged.colors,
|
|
2750
2759
|
neutral,
|
|
2760
|
+
defaultSequential: typeof defaultSequential === "string" && Object.hasOwn(sequential, defaultSequential) ? defaultSequential : Object.keys(sequential)[0] ?? "",
|
|
2751
2761
|
annotationMarkerFill: authoredColors.annotationMarkerFill === void 0 ? neutral.surface : merged.colors.annotationMarkerFill,
|
|
2752
2762
|
annotationPlate: authoredColors.annotationPlate === void 0 ? neutral.surface : merged.colors.annotationPlate
|
|
2753
2763
|
},
|