@opendata-ai/openchart-core 6.23.1 → 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 +17 -4
- package/dist/index.js +27 -17
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/colors/contrast.ts +35 -23
- package/src/index.ts +1 -0
- package/src/layout/chrome.ts +6 -2
- package/src/layout/index.ts +1 -0
- package/src/layout/text-measure.ts +10 -0
- package/src/layout/text-wrap.ts +2 -2
- package/src/types/layout.ts +2 -0
- 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>;
|
|
@@ -2536,6 +2542,8 @@ interface SankeyLayout {
|
|
|
2536
2542
|
animation?: ResolvedAnimation;
|
|
2537
2543
|
/** Whether the tryOpenData.ai watermark is enabled. */
|
|
2538
2544
|
watermark: boolean;
|
|
2545
|
+
/** Real text measurement function from the adapter (for accurate SVG text wrapping). */
|
|
2546
|
+
measureText?: MeasureTextFn;
|
|
2539
2547
|
}
|
|
2540
2548
|
/** Function signature for text measurement provided by adapters. */
|
|
2541
2549
|
type MeasureTextFn = (text: string, fontSize: number, fontWeight?: number) => {
|
|
@@ -2784,6 +2792,11 @@ declare const BRAND_RESERVE_WIDTH = 130;
|
|
|
2784
2792
|
declare const BRAND_FONT_SIZE = 12;
|
|
2785
2793
|
/** Minimum chart width to render the brand watermark (px). */
|
|
2786
2794
|
declare const BRAND_MIN_WIDTH = 120;
|
|
2795
|
+
/**
|
|
2796
|
+
* Width threshold below which layout tightens spacing (legend gaps, chrome
|
|
2797
|
+
* padding, label gaps) to maximize data area on small screens.
|
|
2798
|
+
*/
|
|
2799
|
+
declare const COMPACT_WIDTH = 420;
|
|
2787
2800
|
|
|
2788
2801
|
/**
|
|
2789
2802
|
* Word-wrap a text string into lines that fit within a max width.
|
|
@@ -2793,8 +2806,8 @@ declare const BRAND_MIN_WIDTH = 120;
|
|
|
2793
2806
|
* accurate wrapping. Otherwise falls back to a character-width
|
|
2794
2807
|
* heuristic driven by `estimateCharWidth` from text-measure.ts.
|
|
2795
2808
|
*
|
|
2796
|
-
*
|
|
2797
|
-
* the
|
|
2809
|
+
* Non-browser callers (SSR, tests) omit the measureText argument to
|
|
2810
|
+
* use the heuristic fallback. Do not change the signature without
|
|
2798
2811
|
* re-verifying visual baselines for every caller.
|
|
2799
2812
|
*/
|
|
2800
2813
|
|
|
@@ -3134,4 +3147,4 @@ declare function scatterChart(data: DataRow[], x: FieldRef, y: FieldRef, options
|
|
|
3134
3147
|
*/
|
|
3135
3148
|
declare function dataTable(data: DataRow[], options?: TableBuilderOptions): TableSpec;
|
|
3136
3149
|
|
|
3137
|
-
export { type A11yMetadata, type AggregateOp, type AggregateTransform, type AnimationConfig, type AnimationEase, type AnimationPhaseConfig, type AnimationSpec, type AnimationStagger, type Annotation, type AnnotationAnchor, type AnnotationOffset, type AnnotationPosition, type ArcMark, type AreaMark, type AxisConfig, type AxisLabelDensity, type AxisLayout, type AxisTick, BRAND_FONT_SIZE, BRAND_MIN_WIDTH, BRAND_RESERVE_WIDTH, type BarColumnConfig, type BarTableCell, type BinParams, type BinTransform, type Breakpoint, CATEGORICAL_PALETTE, CHART_ENCODING_RULES, CHART_TYPES, type CalculateExpression, type CalculateTransform, type CategoricalPalette, type CategoryColorsConfig, type CategoryTableCell, type CellStyle, type ChannelRule, type ChartBuilderOptions, type ChartEventHandlers, type ChartLayout, type ChartSpec, type ChartSpecOverride, type ChartSpecWithoutData, type ChartType, type Chrome, type ChromeDefaults, type ChromeKey, type ChromeMode, type ChromeText, type ChromeTextStyle, type ColorBlindnessType, type ColumnConfig, type CompileOptions, type CompileTableOptions, type Condition, type ConditionalValueDef, DEFAULT_THEME, DIVERGING_PALETTES, type DarkMode, type DataRow, type DateGranularity, type DivergingPalette, EXTENDED_OFFSET_STRATEGIES, type ElementEdit, type ElementRef, type Encoding, type EncodingChannel, type EncodingRule, type FieldPredicate, type FieldRef, type FieldType, type FilterPredicate, type FilterTransform, type FlagTableCell, type FoldTransform, GRAPH_ENCODING_RULES, type GradientDef, type GradientStop, type GraphChannelRule, type GraphEdge, type GraphEdgeLayout, type GraphEncoding, type GraphEncodingChannel, type GraphLayout, type GraphLayoutConfig, type GraphNode, type GraphNodeLayout, type GraphSpec, type GraphSpecWithoutData, type Gridline, type HeatmapColumnConfig, type HeatmapTableCell, type HeightClass, type ImageColumnConfig, type ImageTableCell, type LabelCandidate, type LabelConfig, type LabelDensity, type LabelMode, type LabelPriority, type LayerSpec, type LayoutStrategy, type LegendConfig, type LegendEntry, type LegendLayout, type LegendPosition, type LineMark, type LinearGradient, type LogicalAnd, type LogicalNot, type LogicalOr, MARK_DISPLAY_NAMES, MARK_ENCODING_RULES, MARK_TYPES, type Margins, type Mark, type MarkAria, type MarkDef, type MarkEvent, type MarkType, type MeasureTextFn, type NodeOverride, OFFSET_STRATEGIES, type OffsetStrategy, type PaginationState, type Point, type PointMark, type RadialGradient, type RangeAnnotation, type Rect, type RectMark, type RefLineAnnotation, type ResolveConfig, type ResolveMode, type ResolvedAnimation, type ResolvedAnnotation, type ResolvedChrome, type ResolvedChromeElement, type ResolvedColumn, type ResolvedLabel, type ResolvedTheme, type RuleMarkLayout, SEQUENTIAL_PALETTES, type SankeyEncoding, type SankeyLayout, type SankeyLinkColor, type SankeyLinkMark, type SankeyNodeAlign, type SankeyNodeMark, type SankeySpec, type SankeySpecWithoutData, type ScaleConfig, type ScaleType, type SequentialPalette, type SeriesStyle, type SortState, type SparklineColumnConfig, type SparklineData, type SparklineTableCell, type StoredVizSpec, type TableBuilderOptions, type TableCell, type TableCellBase, type TableLayout, type TableRow, type TableSpec, type TableSpecWithoutData, type TextAnnotation, type TextMarkLayout, type TextStyle, type TextTableCell, type Theme, type ThemeChromeDefaults, type ThemeColors, type ThemeConfig, type ThemeFontSizes, type ThemeFontWeights, type ThemeFonts, type ThemeSpacing, type TickMarkLayout, type TimeUnit, type TimeUnitTransform, type TooltipContent, type TooltipField, type Transform, type VizSpec, abbreviateNumber, adaptColorForDarkMode, adaptTheme, areaChart, barChart, buildD3Formatter, buildTemporalFormatter, checkPaletteDistinguishability, columnChart, computeChrome, computeLabelBounds, contrastRatio, dataTable, detectCollision, donutChart, dotChart, elementRef, estimateTextWidth, findAccessibleColor, formatDate, formatNumber, generateAltText, generateAriaLabels, generateDataTable, getBreakpoint, getHeightClass, getLayoutStrategy, getRepresentativeColor, inferFieldType, isChartSpec, isConditionalDef, isEncodingChannel, isGradientDef, isGraphSpec, isLayerSpec, isRangeAnnotation, isRefLineAnnotation, isSankeySpec, isTableSpec, isTextAnnotation, lineChart, meetsAA, pieChart, resolveCollisions, resolveMarkDef, resolveMarkType, resolveTheme, scatterChart, simulateColorBlindness, wrapText };
|
|
3150
|
+
export { type A11yMetadata, type AggregateOp, type AggregateTransform, type AnimationConfig, type AnimationEase, type AnimationPhaseConfig, type AnimationSpec, type AnimationStagger, type Annotation, type AnnotationAnchor, type AnnotationOffset, type AnnotationPosition, type ArcMark, type AreaMark, type AxisConfig, type AxisLabelDensity, type AxisLayout, type AxisTick, BRAND_FONT_SIZE, BRAND_MIN_WIDTH, BRAND_RESERVE_WIDTH, type BarColumnConfig, type BarTableCell, type BinParams, type BinTransform, type Breakpoint, CATEGORICAL_PALETTE, CHART_ENCODING_RULES, CHART_TYPES, COMPACT_WIDTH, type CalculateExpression, type CalculateTransform, type CategoricalPalette, type CategoryColorsConfig, type CategoryTableCell, type CellStyle, type ChannelRule, type ChartBuilderOptions, type ChartEventHandlers, type ChartLayout, type ChartSpec, type ChartSpecOverride, type ChartSpecWithoutData, type ChartType, type Chrome, type ChromeDefaults, type ChromeKey, type ChromeMode, type ChromeText, type ChromeTextStyle, type ColorBlindnessType, type ColumnConfig, type CompileOptions, type CompileTableOptions, type Condition, type ConditionalValueDef, DEFAULT_THEME, DIVERGING_PALETTES, type DarkMode, type DataRow, type DateGranularity, type DivergingPalette, EXTENDED_OFFSET_STRATEGIES, type ElementEdit, type ElementRef, type Encoding, type EncodingChannel, type EncodingRule, type FieldPredicate, type FieldRef, type FieldType, type FilterPredicate, type FilterTransform, type FlagTableCell, type FoldTransform, GRAPH_ENCODING_RULES, type GradientDef, type GradientStop, type GraphChannelRule, type GraphEdge, type GraphEdgeLayout, type GraphEncoding, type GraphEncodingChannel, type GraphLayout, type GraphLayoutConfig, type GraphNode, type GraphNodeLayout, type GraphSpec, type GraphSpecWithoutData, type Gridline, type HeatmapColumnConfig, type HeatmapTableCell, type HeightClass, type ImageColumnConfig, type ImageTableCell, type LabelCandidate, type LabelConfig, type LabelDensity, type LabelMode, type LabelPriority, type LayerSpec, type LayoutStrategy, type LegendConfig, type LegendEntry, type LegendLayout, type LegendPosition, type LineMark, type LinearGradient, type LogicalAnd, type LogicalNot, type LogicalOr, MARK_DISPLAY_NAMES, MARK_ENCODING_RULES, MARK_TYPES, type Margins, type Mark, type MarkAria, type MarkDef, type MarkEvent, type MarkType, type MeasureTextFn, type NodeOverride, OFFSET_STRATEGIES, type OffsetStrategy, type PaginationState, type Point, type PointMark, type RadialGradient, type RangeAnnotation, type Rect, type RectMark, type RefLineAnnotation, type ResolveConfig, type ResolveMode, type ResolvedAnimation, type ResolvedAnnotation, type ResolvedChrome, type ResolvedChromeElement, type ResolvedColumn, type ResolvedLabel, type ResolvedTheme, type RuleMarkLayout, SEQUENTIAL_PALETTES, type SankeyEncoding, type SankeyLayout, type SankeyLinkColor, type SankeyLinkMark, type SankeyNodeAlign, type SankeyNodeMark, type SankeySpec, type SankeySpecWithoutData, type ScaleConfig, type ScaleType, type SequentialPalette, type SeriesStyle, type SortState, type SparklineColumnConfig, type SparklineData, type SparklineTableCell, type StoredVizSpec, type TableBuilderOptions, type TableCell, type TableCellBase, type TableLayout, type TableRow, type TableSpec, type TableSpecWithoutData, type TextAnnotation, type TextMarkLayout, type TextStyle, type TextTableCell, type Theme, type ThemeChromeDefaults, type ThemeColors, type ThemeConfig, type ThemeFontSizes, type ThemeFontWeights, type ThemeFonts, type ThemeSpacing, type TickMarkLayout, type TimeUnit, type TimeUnitTransform, type TooltipContent, type TooltipField, type Transform, type VizSpec, abbreviateNumber, adaptColorForDarkMode, adaptTheme, areaChart, barChart, buildD3Formatter, buildTemporalFormatter, checkPaletteDistinguishability, columnChart, computeChrome, computeLabelBounds, contrastRatio, dataTable, detectCollision, donutChart, dotChart, elementRef, estimateTextWidth, findAccessibleColor, formatDate, formatNumber, generateAltText, generateAriaLabels, generateDataTable, getBreakpoint, getHeightClass, getLayoutStrategy, getRepresentativeColor, inferFieldType, isChartSpec, isConditionalDef, isEncodingChannel, isGradientDef, isGraphSpec, isLayerSpec, isRangeAnnotation, isRefLineAnnotation, isSankeySpec, isTableSpec, isTextAnnotation, lineChart, meetsAA, pieChart, resolveCollisions, resolveMarkDef, resolveMarkType, resolveTheme, scatterChart, simulateColorBlindness, wrapText };
|
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
|
|
@@ -1061,6 +1068,7 @@ function estimateTextWidth(text, fontSize, fontWeight = 400) {
|
|
|
1061
1068
|
var BRAND_RESERVE_WIDTH = 130;
|
|
1062
1069
|
var BRAND_FONT_SIZE = 12;
|
|
1063
1070
|
var BRAND_MIN_WIDTH = 120;
|
|
1071
|
+
var COMPACT_WIDTH = 420;
|
|
1064
1072
|
function estimateTextHeight(fontSize, lineCount = 1, lineHeight = 1.3) {
|
|
1065
1073
|
return fontSize * lineHeight * lineCount;
|
|
1066
1074
|
}
|
|
@@ -1186,7 +1194,8 @@ function computeChrome(chrome, theme, width, measureText, chromeMode = "full", p
|
|
|
1186
1194
|
topY += estimateTextHeight(style.fontSize, lineCount, style.lineHeight) + chromeGap;
|
|
1187
1195
|
}
|
|
1188
1196
|
const hasTopChrome = titleNorm || subtitleNorm;
|
|
1189
|
-
const
|
|
1197
|
+
const chromeToChart = width < COMPACT_WIDTH ? Math.min(theme.spacing.chromeToChart, 2) : theme.spacing.chromeToChart;
|
|
1198
|
+
const topHeight = hasTopChrome ? topY - pad2 + chromeToChart - chromeGap : 0;
|
|
1190
1199
|
if (chromeMode === "compact") {
|
|
1191
1200
|
let compactBottom = 0;
|
|
1192
1201
|
if (watermark && width >= BRAND_MIN_WIDTH) {
|
|
@@ -2833,6 +2842,7 @@ export {
|
|
|
2833
2842
|
CATEGORICAL_PALETTE,
|
|
2834
2843
|
CHART_ENCODING_RULES,
|
|
2835
2844
|
CHART_TYPES,
|
|
2845
|
+
COMPACT_WIDTH,
|
|
2836
2846
|
DEFAULT_THEME,
|
|
2837
2847
|
DIVERGING_PALETTES,
|
|
2838
2848
|
EXTENDED_OFFSET_STRATEGIES,
|