@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/dist/index.d.ts
CHANGED
|
@@ -567,6 +567,8 @@ interface AnnotationBase {
|
|
|
567
567
|
opacity?: number;
|
|
568
568
|
/** Z-index for render ordering. Higher values render on top. */
|
|
569
569
|
zIndex?: number;
|
|
570
|
+
/** When false, the annotation is always shown even at compact breakpoints. Default true. */
|
|
571
|
+
responsive?: boolean;
|
|
570
572
|
}
|
|
571
573
|
/**
|
|
572
574
|
* Text annotation positioned at a data coordinate.
|
|
@@ -604,6 +606,8 @@ interface TextAnnotation extends AnnotationBase {
|
|
|
604
606
|
};
|
|
605
607
|
/** Background color behind the text. Useful for readability over chart lines. */
|
|
606
608
|
background?: string;
|
|
609
|
+
/** Whether to show the paint-order stroke halo behind text. Default true. Set false for white text on colored backgrounds. */
|
|
610
|
+
halo?: boolean;
|
|
607
611
|
}
|
|
608
612
|
/**
|
|
609
613
|
* Range annotation highlighting a region of the chart.
|
|
@@ -629,13 +633,15 @@ interface RangeAnnotation extends AnnotationBase {
|
|
|
629
633
|
* Useful for baselines (zero), targets, or thresholds.
|
|
630
634
|
*/
|
|
631
635
|
interface RefLineAnnotation extends AnnotationBase {
|
|
632
|
-
type: 'refline';
|
|
636
|
+
type: 'refline' | 'rule';
|
|
633
637
|
/** X-axis value for a vertical reference line. */
|
|
634
638
|
x?: string | number;
|
|
635
639
|
/** Y-axis value for a horizontal reference line. */
|
|
636
640
|
y?: string | number;
|
|
637
641
|
/** Line style. */
|
|
638
642
|
style?: 'solid' | 'dashed' | 'dotted';
|
|
643
|
+
/** Raw SVG dash pattern override, e.g. [4, 4]. Takes precedence over style. */
|
|
644
|
+
strokeDash?: number[];
|
|
639
645
|
/** Line width in pixels. */
|
|
640
646
|
strokeWidth?: number;
|
|
641
647
|
/** Pixel offset for the reference line label. */
|
|
@@ -736,6 +742,8 @@ interface LegendConfig {
|
|
|
736
742
|
symbolLimit?: number;
|
|
737
743
|
/** Maximum number of rows for top-positioned legends before truncation. Defaults to 2. */
|
|
738
744
|
maxRows?: number;
|
|
745
|
+
/** Series names to exclude from the legend. Excluded series still render in the chart. */
|
|
746
|
+
exclude?: string[];
|
|
739
747
|
}
|
|
740
748
|
/** Data row: a plain object with string keys. */
|
|
741
749
|
type DataRow = Record<string, unknown>;
|
|
@@ -2061,6 +2069,8 @@ interface ResolvedLabel {
|
|
|
2061
2069
|
};
|
|
2062
2070
|
/** Background color behind the label text. */
|
|
2063
2071
|
background?: string;
|
|
2072
|
+
/** Whether to show the paint-order stroke halo. Default true. */
|
|
2073
|
+
halo?: boolean;
|
|
2064
2074
|
}
|
|
2065
2075
|
/** A resolved annotation with computed pixel positions. */
|
|
2066
2076
|
interface ResolvedAnnotation {
|
package/dist/index.js
CHANGED
|
@@ -219,7 +219,7 @@ function isRangeAnnotation(annotation) {
|
|
|
219
219
|
return annotation.type === "range";
|
|
220
220
|
}
|
|
221
221
|
function isRefLineAnnotation(annotation) {
|
|
222
|
-
return annotation.type === "refline";
|
|
222
|
+
return annotation.type === "refline" || annotation.type === "rule";
|
|
223
223
|
}
|
|
224
224
|
var MARK_DISPLAY_NAMES = {
|
|
225
225
|
bar: "Bar chart",
|
|
@@ -666,23 +666,30 @@ function findAccessibleColor(baseColor, bg, targetRatio = 4.5) {
|
|
|
666
666
|
const c = rgb(baseColor);
|
|
667
667
|
if (c == null) return baseColor;
|
|
668
668
|
const bgLum = relativeLuminance(bg);
|
|
669
|
-
const
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
669
|
+
const baseLum = relativeLuminance(baseColor);
|
|
670
|
+
const preferDarken = bgLum > 0.5;
|
|
671
|
+
const directions = preferDarken ? [true, false] : [false, true];
|
|
672
|
+
for (const darken of directions) {
|
|
673
|
+
if (!darken && baseLum > 0.95) continue;
|
|
674
|
+
if (darken && baseLum < 0.05) continue;
|
|
675
|
+
let lo = 0;
|
|
676
|
+
let hi = 1;
|
|
677
|
+
let best = null;
|
|
678
|
+
for (let i = 0; i < 20; i++) {
|
|
679
|
+
const mid = (lo + hi) / 2;
|
|
680
|
+
const adjusted = darken ? rgb(c.r * (1 - mid), c.g * (1 - mid), c.b * (1 - mid)) : rgb(c.r + (255 - c.r) * mid, c.g + (255 - c.g) * mid, c.b + (255 - c.b) * mid);
|
|
681
|
+
const hex2 = adjusted.formatHex();
|
|
682
|
+
const ratio = contrastRatio(hex2, bg);
|
|
683
|
+
if (ratio >= targetRatio) {
|
|
684
|
+
best = hex2;
|
|
685
|
+
hi = mid;
|
|
686
|
+
} else {
|
|
687
|
+
lo = mid;
|
|
688
|
+
}
|
|
683
689
|
}
|
|
690
|
+
if (best) return best;
|
|
684
691
|
}
|
|
685
|
-
return
|
|
692
|
+
return baseColor;
|
|
686
693
|
}
|
|
687
694
|
|
|
688
695
|
// src/colors/palettes.ts
|