@opendata-ai/openchart-core 6.24.2 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opendata-ai/openchart-core",
3
- "version": "6.24.2",
3
+ "version": "6.25.1",
4
4
  "description": "Types, theme, colors, accessibility, and utilities for openchart",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Riley Hilliard",
package/src/index.ts CHANGED
@@ -77,9 +77,30 @@ export type {
77
77
  LegendPosition,
78
78
  } from './responsive/index';
79
79
  export {
80
+ AXIS_TITLE_OFFSET_COMPACT,
81
+ AXIS_TITLE_OFFSET_DEFAULT,
82
+ AXIS_TITLE_TRAILING_PAD,
83
+ BREAKPOINT_COMPACT_MAX,
84
+ BREAKPOINT_MEDIUM_MAX,
85
+ getAxisTitleOffset,
80
86
  getBreakpoint,
81
87
  getHeightClass,
82
88
  getLayoutStrategy,
89
+ HEIGHT_CRAMPED_MAX,
90
+ HEIGHT_SHORT_MAX,
91
+ HPAD_COMPACT_FRACTION,
92
+ HPAD_COMPACT_MIN,
93
+ LABEL_GAP_COMPACT,
94
+ LABEL_GAP_DEFAULT,
95
+ LABEL_GAP_NARROW_MAX,
96
+ MAX_LEFT_LABEL_FRACTION_COMPACT,
97
+ MAX_LEFT_LABEL_FRACTION_DEFAULT,
98
+ MAX_LEFT_LABEL_FRACTION_MEDIUM,
99
+ MAX_LEFT_LABEL_FRACTION_MEDIUM_MAX,
100
+ NARROW_VIEWPORT_MAX,
101
+ TICK_LABEL_OFFSET,
102
+ TOP_PAD_EXTRA_NARROW,
103
+ TOP_PAD_NARROW_MAX,
83
104
  } from './responsive/index';
84
105
 
85
106
  // ---------------------------------------------------------------------------
@@ -21,3 +21,22 @@ export {
21
21
  HEIGHT_CRAMPED_MAX,
22
22
  HEIGHT_SHORT_MAX,
23
23
  } from './breakpoints';
24
+ export {
25
+ AXIS_TITLE_OFFSET_COMPACT,
26
+ AXIS_TITLE_OFFSET_DEFAULT,
27
+ AXIS_TITLE_TRAILING_PAD,
28
+ getAxisTitleOffset,
29
+ HPAD_COMPACT_FRACTION,
30
+ HPAD_COMPACT_MIN,
31
+ LABEL_GAP_COMPACT,
32
+ LABEL_GAP_DEFAULT,
33
+ LABEL_GAP_NARROW_MAX,
34
+ MAX_LEFT_LABEL_FRACTION_COMPACT,
35
+ MAX_LEFT_LABEL_FRACTION_DEFAULT,
36
+ MAX_LEFT_LABEL_FRACTION_MEDIUM,
37
+ MAX_LEFT_LABEL_FRACTION_MEDIUM_MAX,
38
+ NARROW_VIEWPORT_MAX,
39
+ TICK_LABEL_OFFSET,
40
+ TOP_PAD_EXTRA_NARROW,
41
+ TOP_PAD_NARROW_MAX,
42
+ } from './metrics';
@@ -0,0 +1,114 @@
1
+ /**
2
+ * Pixel-level responsive metrics for chart layout.
3
+ *
4
+ * These are the numeric tuning values that correspond to the semantic decisions
5
+ * in LayoutStrategy. Centralizing them here ensures the engine and renderer
6
+ * always agree on the same thresholds and offsets without duplicating raw numbers.
7
+ *
8
+ * LayoutStrategy is semantic (what to show), this module is metric (how much space).
9
+ */
10
+
11
+ import { BREAKPOINT_COMPACT_MAX } from './breakpoints';
12
+
13
+ // ---------------------------------------------------------------------------
14
+ // Y-axis title offsets
15
+ // ---------------------------------------------------------------------------
16
+
17
+ /** Distance from the chart edge to the rotated y-axis title center (compact viewports). */
18
+ export const AXIS_TITLE_OFFSET_COMPACT = 35;
19
+
20
+ /** Distance from the chart edge to the rotated y-axis title center (standard viewports). */
21
+ export const AXIS_TITLE_OFFSET_DEFAULT = 45;
22
+
23
+ /** Returns the y-axis title offset appropriate for the given container width. */
24
+ export function getAxisTitleOffset(width: number): number {
25
+ return width < BREAKPOINT_COMPACT_MAX ? AXIS_TITLE_OFFSET_COMPACT : AXIS_TITLE_OFFSET_DEFAULT;
26
+ }
27
+
28
+ // ---------------------------------------------------------------------------
29
+ // Horizontal padding
30
+ // ---------------------------------------------------------------------------
31
+
32
+ /**
33
+ * On compact viewports axis titles and tick labels tolerate closer container edges
34
+ * than chrome text (title, subtitle). Reduce horizontal padding to reclaim space.
35
+ */
36
+ export const HPAD_COMPACT_FRACTION = 0.5;
37
+
38
+ /** Minimum horizontal padding regardless of scaling. */
39
+ export const HPAD_COMPACT_MIN = 4;
40
+
41
+ // ---------------------------------------------------------------------------
42
+ // Tick label offset
43
+ // ---------------------------------------------------------------------------
44
+
45
+ /**
46
+ * Horizontal gap between the chart edge and the near edge of y-axis tick labels.
47
+ * The engine uses this to reserve right-axis margin; the renderer uses it to position labels.
48
+ * Both must agree on this value — do not change one without the other.
49
+ */
50
+ export const TICK_LABEL_OFFSET = 6;
51
+
52
+ // ---------------------------------------------------------------------------
53
+ // Axis title trailing padding
54
+ // ---------------------------------------------------------------------------
55
+
56
+ /**
57
+ * Extra padding beyond half-glyph height added to the rotated axis title margin on
58
+ * standard (non-compact) viewports. Omitted on compact viewports to save space.
59
+ */
60
+ export const AXIS_TITLE_TRAILING_PAD = 4;
61
+
62
+ // ---------------------------------------------------------------------------
63
+ // Narrow viewport threshold (between compact and medium)
64
+ // ---------------------------------------------------------------------------
65
+
66
+ /**
67
+ * Width below which "narrow" adjustments apply: extra iOS Safari top padding and
68
+ * tighter category label gaps. Sits between compact (< 400) and medium (400–700).
69
+ * Not a semantic breakpoint — a layout heuristic for narrow-but-not-compact containers.
70
+ */
71
+ export const NARROW_VIEWPORT_MAX = 500;
72
+
73
+ // ---------------------------------------------------------------------------
74
+ // Top padding (iOS Safari address bar / notch clearance)
75
+ // ---------------------------------------------------------------------------
76
+
77
+ /** Extra top padding added below NARROW_VIEWPORT_MAX to clear iOS Safari browser chrome. */
78
+ export const TOP_PAD_EXTRA_NARROW = 10;
79
+
80
+ /** @deprecated Use NARROW_VIEWPORT_MAX instead. */
81
+ export const TOP_PAD_NARROW_MAX = NARROW_VIEWPORT_MAX;
82
+
83
+ // ---------------------------------------------------------------------------
84
+ // Category label gaps (left-axis bar/dot charts)
85
+ // ---------------------------------------------------------------------------
86
+
87
+ /** Gap between category label text and chart edge on narrow viewports (< NARROW_VIEWPORT_MAX). */
88
+ export const LABEL_GAP_COMPACT = 8;
89
+
90
+ /** Gap between category label text and chart edge on standard viewports. */
91
+ export const LABEL_GAP_DEFAULT = 12;
92
+
93
+ /** @deprecated Use NARROW_VIEWPORT_MAX instead. */
94
+ export const LABEL_GAP_NARROW_MAX = NARROW_VIEWPORT_MAX;
95
+
96
+ // ---------------------------------------------------------------------------
97
+ // Max left-axis label fraction
98
+ // ---------------------------------------------------------------------------
99
+
100
+ /**
101
+ * Width threshold for the medium left-label fraction cap.
102
+ * Sits between medium (400-700) and full (> 700) to prevent wide category labels
103
+ * from consuming too much horizontal space at mid-range widths.
104
+ */
105
+ export const MAX_LEFT_LABEL_FRACTION_MEDIUM_MAX = 600;
106
+
107
+ /** Max fraction of container width reservable for left category labels (compact). */
108
+ export const MAX_LEFT_LABEL_FRACTION_COMPACT = 0.45;
109
+
110
+ /** Max fraction of container width reservable for left category labels (mid-range). */
111
+ export const MAX_LEFT_LABEL_FRACTION_MEDIUM = 0.55;
112
+
113
+ /** Max fraction of container width reservable for left category labels (standard). */
114
+ export const MAX_LEFT_LABEL_FRACTION_DEFAULT = 1;
@@ -220,6 +220,8 @@ export interface LineMark {
220
220
  aria: MarkAria;
221
221
  /** Index for stagger animation ordering. */
222
222
  animationIndex?: number;
223
+ /** Which y-scale produced this mark ('y' = left, 'y2' = right). */
224
+ yScale?: 'y' | 'y2';
223
225
  }
224
226
 
225
227
  /**
@@ -262,6 +264,8 @@ export interface AreaMark {
262
264
  aria: MarkAria;
263
265
  /** Index for stagger animation ordering. */
264
266
  animationIndex?: number;
267
+ /** Which y-scale produced this mark ('y' = left, 'y2' = right). */
268
+ yScale?: 'y' | 'y2';
265
269
  }
266
270
 
267
271
  /**
@@ -300,6 +304,8 @@ export interface RectMark {
300
304
  stackGroup?: string;
301
305
  /** Position of this segment within its stack group (0, 1, 2...). Set by engine for stacked bars. */
302
306
  stackPos?: number;
307
+ /** Which y-scale produced this mark ('y' = left, 'y2' = right). */
308
+ yScale?: 'y' | 'y2';
303
309
  }
304
310
 
305
311
  /**
@@ -366,6 +372,8 @@ export interface PointMark {
366
372
  aria: MarkAria;
367
373
  /** Index for stagger animation ordering. */
368
374
  animationIndex?: number;
375
+ /** Which y-scale produced this mark ('y' = left, 'y2' = right). */
376
+ yScale?: 'y' | 'y2';
369
377
  }
370
378
 
371
379
  /**
@@ -400,6 +408,8 @@ export interface TextMarkLayout {
400
408
  aria: MarkAria;
401
409
  /** Index for stagger animation ordering. */
402
410
  animationIndex?: number;
411
+ /** Which y-scale produced this mark ('y' = left, 'y2' = right). */
412
+ yScale?: 'y' | 'y2';
403
413
  }
404
414
 
405
415
  /**
@@ -430,6 +440,8 @@ export interface RuleMarkLayout {
430
440
  aria: MarkAria;
431
441
  /** Index for stagger animation ordering. */
432
442
  animationIndex?: number;
443
+ /** Which y-scale produced this mark ('y' = left, 'y2' = right). */
444
+ yScale?: 'y' | 'y2';
433
445
  }
434
446
 
435
447
  /**
@@ -458,6 +470,8 @@ export interface TickMarkLayout {
458
470
  aria: MarkAria;
459
471
  /** Index for stagger animation ordering. */
460
472
  animationIndex?: number;
473
+ /** Which y-scale produced this mark ('y' = left, 'y2' = right). */
474
+ yScale?: 'y' | 'y2';
461
475
  }
462
476
 
463
477
  /** Discriminated union of all mark types. */
@@ -654,6 +668,8 @@ export interface ChartLayout {
654
668
  axes: {
655
669
  x?: AxisLayout;
656
670
  y?: AxisLayout;
671
+ /** Right-side y-axis for independent-scale layers (dual-axis charts). */
672
+ y2?: AxisLayout;
657
673
  };
658
674
  /** Data marks: the visual representation of data points. */
659
675
  marks: Mark[];
@@ -1076,6 +1092,8 @@ export interface CompileOptions {
1076
1092
  * If not provided, the engine falls back to heuristic estimation.
1077
1093
  */
1078
1094
  measureText?: MeasureTextFn;
1095
+ /** Extra pixels to reserve on the right margin for a secondary y-axis. Set by compileLayer when resolve.scale.y is 'independent'. */
1096
+ rightAxisReserve?: number;
1079
1097
  }
1080
1098
 
1081
1099
  /** Extended compile options for table visualizations. */
package/src/types/spec.ts CHANGED
@@ -238,6 +238,8 @@ export interface AxisConfig {
238
238
  titlePadding?: number;
239
239
  /** Padding between tick labels and axis. */
240
240
  labelPadding?: number;
241
+ /** Color override for axis tick labels and title. Useful in dual-axis charts to match axis color to its series. */
242
+ labelColor?: string;
241
243
  }
242
244
 
243
245
  /** Scale configuration for an encoding channel. */