@opendata-ai/openchart-core 7.2.1 → 7.2.3

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
@@ -774,10 +774,24 @@ interface RangeAnnotation extends AnnotationBase {
774
774
  y1?: string | number;
775
775
  /** End of the range on the y-axis. */
776
776
  y2?: string | number;
777
+ /**
778
+ * For band/point (ordinal) x or y scales, whether the range extends from the
779
+ * data point's center out to the band/step edge. Default `true`: a range on a
780
+ * bar chart spans full columns, and a range on a line chart extends half a step
781
+ * past the first/last point so the band reaches the plot edge. Set `false` to
782
+ * anchor the range exactly at the data point centers instead — useful when you
783
+ * want the band inset from the axis (e.g. starting at the first data point
784
+ * rather than flush against the y-axis guide). No effect on linear/time scales.
785
+ */
786
+ extendToEdges?: boolean;
777
787
  /** Pixel offset for the range label. */
778
788
  labelOffset?: AnnotationOffset;
779
789
  /** Anchor direction for the range label. */
780
790
  labelAnchor?: AnnotationAnchor;
791
+ /** Font size override for the range label (px). Default: 11. */
792
+ fontSize?: number;
793
+ /** Font weight override for the range label. Default: 500. */
794
+ fontWeight?: number;
781
795
  }
782
796
  /**
783
797
  * Reference line annotation: a horizontal or vertical line at a data value.
@@ -799,6 +813,10 @@ interface RefLineAnnotation extends AnnotationBase {
799
813
  labelOffset?: AnnotationOffset;
800
814
  /** Anchor direction for the reference line label. */
801
815
  labelAnchor?: AnnotationAnchor;
816
+ /** Label font size in pixels. Default: 11. */
817
+ fontSize?: number;
818
+ /** Label font weight. Default: 400. */
819
+ fontWeight?: number;
802
820
  }
803
821
  /** Discriminated union of all annotation types. */
804
822
  type Annotation = TextAnnotation | RangeAnnotation | RefLineAnnotation;
@@ -861,6 +879,10 @@ interface ThemeConfig {
861
879
  small?: number;
862
880
  /** Axis tick labels. Default: 11. */
863
881
  axisTick?: number;
882
+ /** KPI metric uppercase label. Default: 10. */
883
+ metricLabel?: number;
884
+ /** KPI metric primary value. Default: 22. Delta/secondary derive from this. */
885
+ metricValue?: number;
864
886
  };
865
887
  };
866
888
  /** Spacing overrides in pixels. */
@@ -2208,6 +2230,11 @@ interface ThemeFontSizes {
2208
2230
  small: number;
2209
2231
  /** Axis tick label font size in pixels. */
2210
2232
  axisTick: number;
2233
+ /** KPI metric uppercase label font size in pixels. */
2234
+ metricLabel: number;
2235
+ /** KPI metric primary value font size in pixels. The delta and secondary
2236
+ * values derive from this (each ~0.55x), so scaling this scales the whole cell. */
2237
+ metricValue: number;
2211
2238
  }
2212
2239
  /** Font weight presets. */
2213
2240
  interface ThemeFontWeights {
@@ -3890,15 +3917,32 @@ declare const TICK_LABEL_OFFSET = 6;
3890
3917
  */
3891
3918
  declare const AXIS_TITLE_TRAILING_PAD = 4;
3892
3919
  /**
3893
- * Breathing room between the widest tick label's far edge and the rotated
3894
- * y-axis title center. The title glyph extends ~halfGlyph (ceil(bodyFontSize/2))
3895
- * from its center toward the tick labels, so visible clearance is
3896
- * AXIS_TITLE_GAP - halfGlyph (~7px at default body size 13).
3920
+ * Visible breathing room between the widest tick label's far edge and the
3921
+ * rotated y-axis title's near edge.
3922
+ *
3923
+ * The title is rotated -90deg and anchored at its center, so its glyph box
3924
+ * extends half the title font size toward the tick labels. To keep the gap
3925
+ * constant regardless of title font size, callers add that half-glyph on top
3926
+ * of this value (see axisTitleOffset() below). At the old fixed gap of 14 the
3927
+ * clearance silently shrank as the font grew (14 - 11 = 3px at body size 21),
3928
+ * which let large-font titles collide with the tick labels.
3897
3929
  *
3898
3930
  * Used in both the engine (dimensions.ts margin reservation) and the renderer
3899
- * (axes.ts title placement). Both must agree on this value.
3931
+ * (axes.ts title placement) via axisTitleOffset(). Both must agree on this value.
3932
+ */
3933
+ declare const AXIS_TITLE_GAP = 7;
3934
+ /**
3935
+ * Computes the distance from the chart edge to the rotated y-axis title's center.
3936
+ *
3937
+ * The title center must sit far enough left that, after accounting for the
3938
+ * widest tick label and the title's own half-glyph height, AXIS_TITLE_GAP of
3939
+ * visible clearance remains. Falls back to the viewport-minimum offset when the
3940
+ * dynamic value would be smaller (short tick labels on wide containers).
3941
+ *
3942
+ * Shared by the engine (margin reservation) and the renderer (title placement)
3943
+ * so the reserved space always matches where the title is drawn.
3900
3944
  */
3901
- declare const AXIS_TITLE_GAP = 14;
3945
+ declare function axisTitleOffset(maxTickLabelWidth: number, titleFontSize: number, width: number): number;
3902
3946
  /**
3903
3947
  * Width below which "narrow" adjustments apply: extra iOS Safari top padding and
3904
3948
  * tighter category label gaps. Sits between compact (< 400) and medium (400–700).
@@ -4285,4 +4329,4 @@ interface TileMapBuilderOptions {
4285
4329
  */
4286
4330
  declare function tileMap(data: Record<string, number | null> | DataRow[], options?: TileMapBuilderOptions): TileMapSpec;
4287
4331
 
4288
- export { type A11yMetadata, AXIS_TITLE_GAP, 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 ArcEncoding, type ArcMark, type AreaEncoding, 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 BarEncoding, type BarListEncoding, type BarListLayout, type BarListRowMark, type BarListSpec, type BarListSpecWithoutData, type BarTableCell, type BaseLegendLayout, type BinParams, type BinTransform, type Breakpoint, CATEGORICAL_PALETTE, CHART_ENCODING_RULES, CHART_TYPES, COMPACT_WIDTH, type CalculateExpression, type CalculateTransform, type CategoricalLegendLayout, 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 CircleEncoding, type ColorBlindnessType, type ColumnConfig, type CompileOptions, type CompileTableOptions, type Condition, type ConditionalValueDef, DEFAULT_THEME, DIVERGING_PALETTES, type DarkMode, type DataRow, type DateGranularity, type Display, type DivergingPalette, EXTENDED_OFFSET_STRATEGIES, type ElementEdit, type ElementRef, type Encoding, type EncodingChannel, type EncodingRule, type EndpointLabelEntry, type EndpointLabelsConfig, type EndpointLabelsLayout, type FieldPredicate, type FieldRef, type FieldType, type FilterPredicate, type FilterTransform, type FlagTableCell, type FoldTransform, GRAPH_ENCODING_RULES, type GradientColorStop, type GradientDef, type GradientLegendLayout, 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 LabelSpec, type LayerSpec, type LayoutStrategy, type LegendConfig, type LegendEntry, type LegendLayout, type LegendPosition, type LineEncoding, type LineMark, type LinearGradient, type LogicalAnd, type LogicalNot, type LogicalOr, type LollipopEncoding, 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, type Metric, NARROW_VIEWPORT_MAX, type NodeOverride, OFFSET_STRATEGIES, type OffsetStrategy, type PaginationState, type Point, type PointEncoding, type PointMark, type RadialGradient, type RangeAnnotation, type Rect, type RectEncoding, type RectMark, type RefLineAnnotation, type RelativeTimeRef, type ResolveConfig, type ResolveMode, type ResolvedAnimation, type ResolvedAnnotation, type ResolvedChrome, type ResolvedChromeElement, type ResolvedColumn, type ResolvedLabel, type ResolvedMetricBar, type ResolvedMetricCell, 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 TextEncoding, type TextMarkLayout, type TextStyle, type TextTableCell, type Theme, type ThemeChromeDefaults, type ThemeColors, type ThemeConfig, type ThemeFontSizes, type ThemeFontWeights, type ThemeFonts, type ThemeSpacing, type TickEncoding, type TickMarkLayout, type TileMapBuilderOptions, type TileMapEncoding, type TileMapLayout, type TileMapPalette, type TileMapSpec, type TileMapSpecWithoutData, type TileMapTileMark, type TimeUnit, type TimeUnitTransform, type TooltipContent, type TooltipField, type Transform, type VizSpec, type WindowFieldDef, type WindowOp, type WindowSortField, type WindowTransform, 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, isBarListSpec, isChartSpec, isConditionalDef, isEncodingChannel, isGradientDef, isGraphSpec, isLayerSpec, isRangeAnnotation, isRefLineAnnotation, isSankeySpec, isTableSpec, isTextAnnotation, isTileMapSpec, lineChart, meetsAA, pickLabelColor, pieChart, resolveCollisions, resolveMarkDef, resolveMarkType, resolveTheme, scatterChart, simulateColorBlindness, tileMap, wrapText };
4332
+ export { type A11yMetadata, AXIS_TITLE_GAP, 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 ArcEncoding, type ArcMark, type AreaEncoding, 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 BarEncoding, type BarListEncoding, type BarListLayout, type BarListRowMark, type BarListSpec, type BarListSpecWithoutData, type BarTableCell, type BaseLegendLayout, type BinParams, type BinTransform, type Breakpoint, CATEGORICAL_PALETTE, CHART_ENCODING_RULES, CHART_TYPES, COMPACT_WIDTH, type CalculateExpression, type CalculateTransform, type CategoricalLegendLayout, 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 CircleEncoding, type ColorBlindnessType, type ColumnConfig, type CompileOptions, type CompileTableOptions, type Condition, type ConditionalValueDef, DEFAULT_THEME, DIVERGING_PALETTES, type DarkMode, type DataRow, type DateGranularity, type Display, type DivergingPalette, EXTENDED_OFFSET_STRATEGIES, type ElementEdit, type ElementRef, type Encoding, type EncodingChannel, type EncodingRule, type EndpointLabelEntry, type EndpointLabelsConfig, type EndpointLabelsLayout, type FieldPredicate, type FieldRef, type FieldType, type FilterPredicate, type FilterTransform, type FlagTableCell, type FoldTransform, GRAPH_ENCODING_RULES, type GradientColorStop, type GradientDef, type GradientLegendLayout, 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 LabelSpec, type LayerSpec, type LayoutStrategy, type LegendConfig, type LegendEntry, type LegendLayout, type LegendPosition, type LineEncoding, type LineMark, type LinearGradient, type LogicalAnd, type LogicalNot, type LogicalOr, type LollipopEncoding, 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, type Metric, NARROW_VIEWPORT_MAX, type NodeOverride, OFFSET_STRATEGIES, type OffsetStrategy, type PaginationState, type Point, type PointEncoding, type PointMark, type RadialGradient, type RangeAnnotation, type Rect, type RectEncoding, type RectMark, type RefLineAnnotation, type RelativeTimeRef, type ResolveConfig, type ResolveMode, type ResolvedAnimation, type ResolvedAnnotation, type ResolvedChrome, type ResolvedChromeElement, type ResolvedColumn, type ResolvedLabel, type ResolvedMetricBar, type ResolvedMetricCell, 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 TextEncoding, type TextMarkLayout, type TextStyle, type TextTableCell, type Theme, type ThemeChromeDefaults, type ThemeColors, type ThemeConfig, type ThemeFontSizes, type ThemeFontWeights, type ThemeFonts, type ThemeSpacing, type TickEncoding, type TickMarkLayout, type TileMapBuilderOptions, type TileMapEncoding, type TileMapLayout, type TileMapPalette, type TileMapSpec, type TileMapSpecWithoutData, type TileMapTileMark, type TimeUnit, type TimeUnitTransform, type TooltipContent, type TooltipField, type Transform, type VizSpec, type WindowFieldDef, type WindowOp, type WindowSortField, type WindowTransform, abbreviateNumber, adaptColorForDarkMode, adaptTheme, areaChart, axisTitleOffset, 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, isBarListSpec, isChartSpec, isConditionalDef, isEncodingChannel, isGradientDef, isGraphSpec, isLayerSpec, isRangeAnnotation, isRefLineAnnotation, isSankeySpec, isTableSpec, isTextAnnotation, isTileMapSpec, lineChart, meetsAA, pickLabelColor, pieChart, resolveCollisions, resolveMarkDef, resolveMarkType, resolveTheme, scatterChart, simulateColorBlindness, tileMap, wrapText };
package/dist/index.js CHANGED
@@ -839,7 +839,9 @@ var DEFAULT_THEME = {
839
839
  subtitle: 14,
840
840
  body: 13,
841
841
  small: 11,
842
- axisTick: 11
842
+ axisTick: 11,
843
+ metricLabel: 10,
844
+ metricValue: 22
843
845
  },
844
846
  weights: {
845
847
  normal: 450,
@@ -855,7 +857,10 @@ var DEFAULT_THEME = {
855
857
  chartToFooter: 8,
856
858
  axisMargin: 6,
857
859
  xAxisHeight: 26,
858
- xAxisLabelPadding: 14
860
+ // Gap (px) between the x-axis line and the TOP of the tick labels. The
861
+ // renderer anchors x-tick labels at their top edge (hanging baseline), so
862
+ // this is a literal top gap that holds regardless of font size.
863
+ xAxisLabelPadding: 4
859
864
  },
860
865
  borderRadius: 2,
861
866
  chrome: {
@@ -1578,7 +1583,12 @@ var HPAD_COMPACT_FRACTION = 0.5;
1578
1583
  var HPAD_COMPACT_MIN = 4;
1579
1584
  var TICK_LABEL_OFFSET = 6;
1580
1585
  var AXIS_TITLE_TRAILING_PAD = 4;
1581
- var AXIS_TITLE_GAP = 14;
1586
+ var AXIS_TITLE_GAP = 7;
1587
+ function axisTitleOffset(maxTickLabelWidth, titleFontSize, width) {
1588
+ const halfTitleGlyph = Math.ceil(titleFontSize / 2);
1589
+ const dynamic = TICK_LABEL_OFFSET + maxTickLabelWidth + AXIS_TITLE_GAP + halfTitleGlyph;
1590
+ return Math.max(dynamic, getAxisTitleOffset(width));
1591
+ }
1582
1592
  var NARROW_VIEWPORT_MAX = 500;
1583
1593
  var TOP_PAD_EXTRA_NARROW = 10;
1584
1594
  var TOP_PAD_NARROW_MAX = NARROW_VIEWPORT_MAX;
@@ -3087,6 +3097,7 @@ export {
3087
3097
  adaptColorForDarkMode,
3088
3098
  adaptTheme,
3089
3099
  areaChart,
3100
+ axisTitleOffset,
3090
3101
  barChart,
3091
3102
  buildD3Formatter,
3092
3103
  buildTemporalFormatter,