@opendata-ai/openchart-core 6.25.0 → 6.25.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 CHANGED
@@ -13,12 +13,18 @@
13
13
  */
14
14
  /** Responsive breakpoint based on container width. */
15
15
  type Breakpoint = 'compact' | 'medium' | 'full';
16
+ /** Breakpoint thresholds in pixels. */
17
+ declare const BREAKPOINT_COMPACT_MAX = 400;
18
+ declare const BREAKPOINT_MEDIUM_MAX = 700;
16
19
  /**
17
20
  * Determine the breakpoint for a given container width.
18
21
  */
19
22
  declare function getBreakpoint(width: number): Breakpoint;
20
23
  /** Height classification based on container height. */
21
24
  type HeightClass = 'cramped' | 'short' | 'normal';
25
+ /** Height class thresholds in pixels. */
26
+ declare const HEIGHT_CRAMPED_MAX = 200;
27
+ declare const HEIGHT_SHORT_MAX = 350;
22
28
  /**
23
29
  * Determine the height class for a given container height.
24
30
  */
@@ -2849,6 +2855,68 @@ declare const COMPACT_WIDTH = 420;
2849
2855
  */
2850
2856
  declare function wrapText(text: string, fontSize: number, fontWeight: number, maxWidth: number, measureText?: MeasureTextFn): string[];
2851
2857
 
2858
+ /**
2859
+ * Pixel-level responsive metrics for chart layout.
2860
+ *
2861
+ * These are the numeric tuning values that correspond to the semantic decisions
2862
+ * in LayoutStrategy. Centralizing them here ensures the engine and renderer
2863
+ * always agree on the same thresholds and offsets without duplicating raw numbers.
2864
+ *
2865
+ * LayoutStrategy is semantic (what to show), this module is metric (how much space).
2866
+ */
2867
+ /** Distance from the chart edge to the rotated y-axis title center (compact viewports). */
2868
+ declare const AXIS_TITLE_OFFSET_COMPACT = 35;
2869
+ /** Distance from the chart edge to the rotated y-axis title center (standard viewports). */
2870
+ declare const AXIS_TITLE_OFFSET_DEFAULT = 45;
2871
+ /** Returns the y-axis title offset appropriate for the given container width. */
2872
+ declare function getAxisTitleOffset(width: number): number;
2873
+ /**
2874
+ * On compact viewports axis titles and tick labels tolerate closer container edges
2875
+ * than chrome text (title, subtitle). Reduce horizontal padding to reclaim space.
2876
+ */
2877
+ declare const HPAD_COMPACT_FRACTION = 0.5;
2878
+ /** Minimum horizontal padding regardless of scaling. */
2879
+ declare const HPAD_COMPACT_MIN = 4;
2880
+ /**
2881
+ * Horizontal gap between the chart edge and the near edge of y-axis tick labels.
2882
+ * The engine uses this to reserve right-axis margin; the renderer uses it to position labels.
2883
+ * Both must agree on this value — do not change one without the other.
2884
+ */
2885
+ declare const TICK_LABEL_OFFSET = 6;
2886
+ /**
2887
+ * Extra padding beyond half-glyph height added to the rotated axis title margin on
2888
+ * standard (non-compact) viewports. Omitted on compact viewports to save space.
2889
+ */
2890
+ declare const AXIS_TITLE_TRAILING_PAD = 4;
2891
+ /**
2892
+ * Width below which "narrow" adjustments apply: extra iOS Safari top padding and
2893
+ * tighter category label gaps. Sits between compact (< 400) and medium (400–700).
2894
+ * Not a semantic breakpoint — a layout heuristic for narrow-but-not-compact containers.
2895
+ */
2896
+ declare const NARROW_VIEWPORT_MAX = 500;
2897
+ /** Extra top padding added below NARROW_VIEWPORT_MAX to clear iOS Safari browser chrome. */
2898
+ declare const TOP_PAD_EXTRA_NARROW = 10;
2899
+ /** @deprecated Use NARROW_VIEWPORT_MAX instead. */
2900
+ declare const TOP_PAD_NARROW_MAX = 500;
2901
+ /** Gap between category label text and chart edge on narrow viewports (< NARROW_VIEWPORT_MAX). */
2902
+ declare const LABEL_GAP_COMPACT = 8;
2903
+ /** Gap between category label text and chart edge on standard viewports. */
2904
+ declare const LABEL_GAP_DEFAULT = 12;
2905
+ /** @deprecated Use NARROW_VIEWPORT_MAX instead. */
2906
+ declare const LABEL_GAP_NARROW_MAX = 500;
2907
+ /**
2908
+ * Width threshold for the medium left-label fraction cap.
2909
+ * Sits between medium (400-700) and full (> 700) to prevent wide category labels
2910
+ * from consuming too much horizontal space at mid-range widths.
2911
+ */
2912
+ declare const MAX_LEFT_LABEL_FRACTION_MEDIUM_MAX = 600;
2913
+ /** Max fraction of container width reservable for left category labels (compact). */
2914
+ declare const MAX_LEFT_LABEL_FRACTION_COMPACT = 0.45;
2915
+ /** Max fraction of container width reservable for left category labels (mid-range). */
2916
+ declare const MAX_LEFT_LABEL_FRACTION_MEDIUM = 0.55;
2917
+ /** Max fraction of container width reservable for left category labels (standard). */
2918
+ declare const MAX_LEFT_LABEL_FRACTION_DEFAULT = 1;
2919
+
2852
2920
  /**
2853
2921
  * Label collision detection and resolution.
2854
2922
  *
@@ -3171,4 +3239,4 @@ declare function scatterChart(data: DataRow[], x: FieldRef, y: FieldRef, options
3171
3239
  */
3172
3240
  declare function dataTable(data: DataRow[], options?: TableBuilderOptions): TableSpec;
3173
3241
 
3174
- 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 };
3242
+ export { type A11yMetadata, AXIS_TITLE_OFFSET_COMPACT, AXIS_TITLE_OFFSET_DEFAULT, AXIS_TITLE_TRAILING_PAD, 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, BREAKPOINT_COMPACT_MAX, BREAKPOINT_MEDIUM_MAX, 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, HEIGHT_CRAMPED_MAX, HEIGHT_SHORT_MAX, HPAD_COMPACT_FRACTION, HPAD_COMPACT_MIN, type HeatmapColumnConfig, type HeatmapTableCell, type HeightClass, type ImageColumnConfig, type ImageTableCell, LABEL_GAP_COMPACT, LABEL_GAP_DEFAULT, LABEL_GAP_NARROW_MAX, 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, MAX_LEFT_LABEL_FRACTION_COMPACT, MAX_LEFT_LABEL_FRACTION_DEFAULT, MAX_LEFT_LABEL_FRACTION_MEDIUM, MAX_LEFT_LABEL_FRACTION_MEDIUM_MAX, type Margins, type Mark, type MarkAria, type MarkDef, type MarkEvent, type MarkType, type MeasureTextFn, NARROW_VIEWPORT_MAX, 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, TICK_LABEL_OFFSET, TOP_PAD_EXTRA_NARROW, TOP_PAD_NARROW_MAX, 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, getAxisTitleOffset, 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
@@ -1395,6 +1395,27 @@ function getLayoutStrategy(breakpoint, heightClass = "normal") {
1395
1395
  return applyHeightConstraints(base, heightClass);
1396
1396
  }
1397
1397
 
1398
+ // src/responsive/metrics.ts
1399
+ var AXIS_TITLE_OFFSET_COMPACT = 35;
1400
+ var AXIS_TITLE_OFFSET_DEFAULT = 45;
1401
+ function getAxisTitleOffset(width) {
1402
+ return width < BREAKPOINT_COMPACT_MAX ? AXIS_TITLE_OFFSET_COMPACT : AXIS_TITLE_OFFSET_DEFAULT;
1403
+ }
1404
+ var HPAD_COMPACT_FRACTION = 0.5;
1405
+ var HPAD_COMPACT_MIN = 4;
1406
+ var TICK_LABEL_OFFSET = 6;
1407
+ var AXIS_TITLE_TRAILING_PAD = 4;
1408
+ var NARROW_VIEWPORT_MAX = 500;
1409
+ var TOP_PAD_EXTRA_NARROW = 10;
1410
+ var TOP_PAD_NARROW_MAX = NARROW_VIEWPORT_MAX;
1411
+ var LABEL_GAP_COMPACT = 8;
1412
+ var LABEL_GAP_DEFAULT = 12;
1413
+ var LABEL_GAP_NARROW_MAX = NARROW_VIEWPORT_MAX;
1414
+ var MAX_LEFT_LABEL_FRACTION_MEDIUM_MAX = 600;
1415
+ var MAX_LEFT_LABEL_FRACTION_COMPACT = 0.45;
1416
+ var MAX_LEFT_LABEL_FRACTION_MEDIUM = 0.55;
1417
+ var MAX_LEFT_LABEL_FRACTION_DEFAULT = 1;
1418
+
1398
1419
  // src/labels/collision.ts
1399
1420
  var PRIORITY_ORDER = {
1400
1421
  data: 0,
@@ -2836,9 +2857,14 @@ function dataTable(data, options) {
2836
2857
  return spec;
2837
2858
  }
2838
2859
  export {
2860
+ AXIS_TITLE_OFFSET_COMPACT,
2861
+ AXIS_TITLE_OFFSET_DEFAULT,
2862
+ AXIS_TITLE_TRAILING_PAD,
2839
2863
  BRAND_FONT_SIZE,
2840
2864
  BRAND_MIN_WIDTH,
2841
2865
  BRAND_RESERVE_WIDTH,
2866
+ BREAKPOINT_COMPACT_MAX,
2867
+ BREAKPOINT_MEDIUM_MAX,
2842
2868
  CATEGORICAL_PALETTE,
2843
2869
  CHART_ENCODING_RULES,
2844
2870
  CHART_TYPES,
@@ -2847,11 +2873,26 @@ export {
2847
2873
  DIVERGING_PALETTES,
2848
2874
  EXTENDED_OFFSET_STRATEGIES,
2849
2875
  GRAPH_ENCODING_RULES,
2876
+ HEIGHT_CRAMPED_MAX,
2877
+ HEIGHT_SHORT_MAX,
2878
+ HPAD_COMPACT_FRACTION,
2879
+ HPAD_COMPACT_MIN,
2880
+ LABEL_GAP_COMPACT,
2881
+ LABEL_GAP_DEFAULT,
2882
+ LABEL_GAP_NARROW_MAX,
2850
2883
  MARK_DISPLAY_NAMES,
2851
2884
  MARK_ENCODING_RULES,
2852
2885
  MARK_TYPES,
2886
+ MAX_LEFT_LABEL_FRACTION_COMPACT,
2887
+ MAX_LEFT_LABEL_FRACTION_DEFAULT,
2888
+ MAX_LEFT_LABEL_FRACTION_MEDIUM,
2889
+ MAX_LEFT_LABEL_FRACTION_MEDIUM_MAX,
2890
+ NARROW_VIEWPORT_MAX,
2853
2891
  OFFSET_STRATEGIES,
2854
2892
  SEQUENTIAL_PALETTES,
2893
+ TICK_LABEL_OFFSET,
2894
+ TOP_PAD_EXTRA_NARROW,
2895
+ TOP_PAD_NARROW_MAX,
2855
2896
  abbreviateNumber,
2856
2897
  adaptColorForDarkMode,
2857
2898
  adaptTheme,
@@ -2876,6 +2917,7 @@ export {
2876
2917
  generateAltText,
2877
2918
  generateAriaLabels,
2878
2919
  generateDataTable,
2920
+ getAxisTitleOffset,
2879
2921
  getBreakpoint,
2880
2922
  getHeightClass,
2881
2923
  getLayoutStrategy,