@opendata-ai/openchart-core 6.24.0 → 6.24.2
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 +11 -1
- package/dist/index.js +23 -16
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/colors/contrast.ts +35 -23
- package/src/types/layout.ts +2 -0
- package/src/types/spec.ts +10 -2
package/package.json
CHANGED
package/src/colors/contrast.ts
CHANGED
|
@@ -65,30 +65,42 @@ export function findAccessibleColor(baseColor: string, bg: string, targetRatio =
|
|
|
65
65
|
if (c == null) return baseColor;
|
|
66
66
|
|
|
67
67
|
const bgLum = relativeLuminance(bg);
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
//
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
for (
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
68
|
+
const baseLum = relativeLuminance(baseColor);
|
|
69
|
+
|
|
70
|
+
// Try both directions: prefer the one matching bg luminance, but fall back
|
|
71
|
+
// to the other if the base color is already at the extreme (e.g. white on
|
|
72
|
+
// a medium-luminance background can't be lightened, so darken instead).
|
|
73
|
+
const preferDarken = bgLum > 0.5;
|
|
74
|
+
const directions = preferDarken ? [true, false] : [false, true];
|
|
75
|
+
|
|
76
|
+
for (const darken of directions) {
|
|
77
|
+
// Skip impossible directions: can't lighten white or darken black.
|
|
78
|
+
if (!darken && baseLum > 0.95) continue;
|
|
79
|
+
if (darken && baseLum < 0.05) continue;
|
|
80
|
+
|
|
81
|
+
let lo = 0;
|
|
82
|
+
let hi = 1;
|
|
83
|
+
let best: string | null = null;
|
|
84
|
+
|
|
85
|
+
for (let i = 0; i < 20; i++) {
|
|
86
|
+
const mid = (lo + hi) / 2;
|
|
87
|
+
const adjusted = darken
|
|
88
|
+
? rgb(c.r * (1 - mid), c.g * (1 - mid), c.b * (1 - mid))
|
|
89
|
+
: rgb(c.r + (255 - c.r) * mid, c.g + (255 - c.g) * mid, c.b + (255 - c.b) * mid);
|
|
90
|
+
|
|
91
|
+
const hex = adjusted.formatHex();
|
|
92
|
+
const ratio = contrastRatio(hex, bg);
|
|
93
|
+
|
|
94
|
+
if (ratio >= targetRatio) {
|
|
95
|
+
best = hex;
|
|
96
|
+
hi = mid;
|
|
97
|
+
} else {
|
|
98
|
+
lo = mid;
|
|
99
|
+
}
|
|
90
100
|
}
|
|
101
|
+
|
|
102
|
+
if (best) return best;
|
|
91
103
|
}
|
|
92
104
|
|
|
93
|
-
return
|
|
105
|
+
return baseColor;
|
|
94
106
|
}
|
package/src/types/layout.ts
CHANGED
|
@@ -505,6 +505,8 @@ export interface ResolvedLabel {
|
|
|
505
505
|
};
|
|
506
506
|
/** Background color behind the label text. */
|
|
507
507
|
background?: string;
|
|
508
|
+
/** Whether to show the paint-order stroke halo. Default true. */
|
|
509
|
+
halo?: boolean;
|
|
508
510
|
}
|
|
509
511
|
|
|
510
512
|
// ---------------------------------------------------------------------------
|
package/src/types/spec.ts
CHANGED
|
@@ -523,6 +523,8 @@ interface AnnotationBase {
|
|
|
523
523
|
opacity?: number;
|
|
524
524
|
/** Z-index for render ordering. Higher values render on top. */
|
|
525
525
|
zIndex?: number;
|
|
526
|
+
/** When false, the annotation is always shown even at compact breakpoints. Default true. */
|
|
527
|
+
responsive?: boolean;
|
|
526
528
|
}
|
|
527
529
|
|
|
528
530
|
/**
|
|
@@ -561,6 +563,8 @@ export interface TextAnnotation extends AnnotationBase {
|
|
|
561
563
|
};
|
|
562
564
|
/** Background color behind the text. Useful for readability over chart lines. */
|
|
563
565
|
background?: string;
|
|
566
|
+
/** Whether to show the paint-order stroke halo behind text. Default true. Set false for white text on colored backgrounds. */
|
|
567
|
+
halo?: boolean;
|
|
564
568
|
}
|
|
565
569
|
|
|
566
570
|
/**
|
|
@@ -588,13 +592,15 @@ export interface RangeAnnotation extends AnnotationBase {
|
|
|
588
592
|
* Useful for baselines (zero), targets, or thresholds.
|
|
589
593
|
*/
|
|
590
594
|
export interface RefLineAnnotation extends AnnotationBase {
|
|
591
|
-
type: 'refline';
|
|
595
|
+
type: 'refline' | 'rule';
|
|
592
596
|
/** X-axis value for a vertical reference line. */
|
|
593
597
|
x?: string | number;
|
|
594
598
|
/** Y-axis value for a horizontal reference line. */
|
|
595
599
|
y?: string | number;
|
|
596
600
|
/** Line style. */
|
|
597
601
|
style?: 'solid' | 'dashed' | 'dotted';
|
|
602
|
+
/** Raw SVG dash pattern override, e.g. [4, 4]. Takes precedence over style. */
|
|
603
|
+
strokeDash?: number[];
|
|
598
604
|
/** Line width in pixels. */
|
|
599
605
|
strokeWidth?: number;
|
|
600
606
|
/** Pixel offset for the reference line label. */
|
|
@@ -715,6 +721,8 @@ export interface LegendConfig {
|
|
|
715
721
|
symbolLimit?: number;
|
|
716
722
|
/** Maximum number of rows for top-positioned legends before truncation. Defaults to 2. */
|
|
717
723
|
maxRows?: number;
|
|
724
|
+
/** Series names to exclude from the legend. Excluded series still render in the chart. */
|
|
725
|
+
exclude?: string[];
|
|
718
726
|
}
|
|
719
727
|
|
|
720
728
|
// ---------------------------------------------------------------------------
|
|
@@ -1408,7 +1416,7 @@ export function isRangeAnnotation(annotation: Annotation): annotation is RangeAn
|
|
|
1408
1416
|
|
|
1409
1417
|
/** Check if an annotation is a RefLineAnnotation. */
|
|
1410
1418
|
export function isRefLineAnnotation(annotation: Annotation): annotation is RefLineAnnotation {
|
|
1411
|
-
return annotation.type === 'refline';
|
|
1419
|
+
return annotation.type === 'refline' || annotation.type === 'rule';
|
|
1412
1420
|
}
|
|
1413
1421
|
|
|
1414
1422
|
// ---------------------------------------------------------------------------
|