@opendata-ai/openchart-core 6.7.1 → 6.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 +23 -3
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/layout/__tests__/chrome.test.ts +35 -0
- package/src/layout/chrome.ts +11 -0
- package/src/types/spec.ts +23 -3
package/dist/index.d.ts
CHANGED
|
@@ -547,9 +547,17 @@ interface RefLineAnnotation extends AnnotationBase {
|
|
|
547
547
|
type Annotation = TextAnnotation | RangeAnnotation | RefLineAnnotation;
|
|
548
548
|
/**
|
|
549
549
|
* Dark mode behavior.
|
|
550
|
-
*
|
|
551
|
-
* - "
|
|
552
|
-
* -
|
|
550
|
+
*
|
|
551
|
+
* - `"auto"` - Checks the `prefers-color-scheme` media query to detect the
|
|
552
|
+
* user's system-level preference. This does NOT detect class-based dark mode
|
|
553
|
+
* toggles (e.g. `document.documentElement.classList.toggle('dark')`). If your
|
|
554
|
+
* app uses class-based dark mode, use VizThemeProvider with `"force"` or
|
|
555
|
+
* `"off"` instead of `"auto"` and toggle based on your app's state.
|
|
556
|
+
* - `"force"` - Always render in dark mode regardless of system preference.
|
|
557
|
+
* - `"off"` - Always render in light mode (default).
|
|
558
|
+
*
|
|
559
|
+
* All components (Chart, Sankey, Graph) inherit darkMode from VizThemeProvider
|
|
560
|
+
* when no explicit prop is passed.
|
|
553
561
|
*/
|
|
554
562
|
type DarkMode = 'auto' | 'force' | 'off';
|
|
555
563
|
/**
|
|
@@ -626,6 +634,8 @@ interface LegendConfig {
|
|
|
626
634
|
columns?: number;
|
|
627
635
|
/** Max number of legend entries before truncation. Remaining entries show as "+N more". */
|
|
628
636
|
symbolLimit?: number;
|
|
637
|
+
/** Maximum number of rows for top-positioned legends before truncation. Defaults to 2. */
|
|
638
|
+
maxRows?: number;
|
|
629
639
|
}
|
|
630
640
|
/** Data row: a plain object with string keys. */
|
|
631
641
|
type DataRow = Record<string, unknown>;
|
|
@@ -931,6 +941,8 @@ interface SankeySpec {
|
|
|
931
941
|
iterations?: number;
|
|
932
942
|
/** Link coloring strategy. Defaults to 'gradient'. */
|
|
933
943
|
linkStyle?: SankeyLinkColor;
|
|
944
|
+
/** Link fill opacity (0-1). Defaults to 0.5 in light mode, 0.75 in dark mode. */
|
|
945
|
+
linkOpacity?: number;
|
|
934
946
|
/** Editorial chrome (title, subtitle, source, byline, footer). */
|
|
935
947
|
chrome?: Chrome;
|
|
936
948
|
/** Legend display configuration. */
|
|
@@ -941,6 +953,14 @@ interface SankeySpec {
|
|
|
941
953
|
darkMode?: DarkMode;
|
|
942
954
|
/** Animation configuration for entrance animations. */
|
|
943
955
|
animation?: AnimationSpec;
|
|
956
|
+
/**
|
|
957
|
+
* d3-format string applied to flow values in tooltips and ARIA labels.
|
|
958
|
+
* Uses the literal suffix extension: ".0f%" appends "%" to the formatted
|
|
959
|
+
* number (data value 28 renders as "28%"). For currency: "$,.0f" or "$~s".
|
|
960
|
+
* For SI suffixes: "~s" (renders 1000 as "1k"). When not set, values use
|
|
961
|
+
* the default number formatter.
|
|
962
|
+
*/
|
|
963
|
+
valueFormat?: string;
|
|
944
964
|
}
|
|
945
965
|
/**
|
|
946
966
|
* Top-level visualization spec: union discriminated by structural shape.
|
package/dist/index.js
CHANGED
|
@@ -1077,6 +1077,12 @@ function buildTextStyle(defaults, fontFamily, textColor, width, overrides) {
|
|
|
1077
1077
|
}
|
|
1078
1078
|
function estimateLineCount(text, style, maxWidth, _measureText) {
|
|
1079
1079
|
if (maxWidth <= 0) return 1;
|
|
1080
|
+
const segments = text.split("\n");
|
|
1081
|
+
if (segments.length > 1) {
|
|
1082
|
+
return segments.reduce((total, segment) => {
|
|
1083
|
+
return total + (segment.length === 0 ? 1 : estimateLineCount(segment, style, maxWidth, _measureText));
|
|
1084
|
+
}, 0);
|
|
1085
|
+
}
|
|
1080
1086
|
const charWidth = estimateCharWidth(style.fontSize, style.fontWeight);
|
|
1081
1087
|
const maxChars = Math.floor(maxWidth / charWidth);
|
|
1082
1088
|
if (text.length <= maxChars) return 1;
|