@opendata-ai/openchart-core 6.24.0 → 6.24.1
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 +7 -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/spec.ts +8 -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.
|
|
@@ -629,13 +631,15 @@ interface RangeAnnotation extends AnnotationBase {
|
|
|
629
631
|
* Useful for baselines (zero), targets, or thresholds.
|
|
630
632
|
*/
|
|
631
633
|
interface RefLineAnnotation extends AnnotationBase {
|
|
632
|
-
type: 'refline';
|
|
634
|
+
type: 'refline' | 'rule';
|
|
633
635
|
/** X-axis value for a vertical reference line. */
|
|
634
636
|
x?: string | number;
|
|
635
637
|
/** Y-axis value for a horizontal reference line. */
|
|
636
638
|
y?: string | number;
|
|
637
639
|
/** Line style. */
|
|
638
640
|
style?: 'solid' | 'dashed' | 'dotted';
|
|
641
|
+
/** Raw SVG dash pattern override, e.g. [4, 4]. Takes precedence over style. */
|
|
642
|
+
strokeDash?: number[];
|
|
639
643
|
/** Line width in pixels. */
|
|
640
644
|
strokeWidth?: number;
|
|
641
645
|
/** Pixel offset for the reference line label. */
|
|
@@ -736,6 +740,8 @@ interface LegendConfig {
|
|
|
736
740
|
symbolLimit?: number;
|
|
737
741
|
/** Maximum number of rows for top-positioned legends before truncation. Defaults to 2. */
|
|
738
742
|
maxRows?: number;
|
|
743
|
+
/** Series names to exclude from the legend. Excluded series still render in the chart. */
|
|
744
|
+
exclude?: string[];
|
|
739
745
|
}
|
|
740
746
|
/** Data row: a plain object with string keys. */
|
|
741
747
|
type DataRow = Record<string, unknown>;
|
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
|