@astryxdesign/lab 0.1.4-canary.39ffd21 → 0.1.4-canary.3d64ef2

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.
Files changed (143) hide show
  1. package/README.md +2 -0
  2. package/dist/CodeEditor/CodeEditor.d.ts +4 -1
  3. package/dist/CodeEditor/CodeEditor.d.ts.map +1 -1
  4. package/dist/CodeEditor/CodeEditor.js +3 -0
  5. package/dist/InfoTip/InfoTip.d.ts +58 -0
  6. package/dist/InfoTip/InfoTip.d.ts.map +1 -0
  7. package/dist/InfoTip/InfoTip.js +91 -0
  8. package/dist/InfoTip/index.d.ts +6 -0
  9. package/dist/InfoTip/index.d.ts.map +1 -0
  10. package/dist/InfoTip/index.js +8 -0
  11. package/dist/Sankey/SankeyChart.d.ts.map +1 -1
  12. package/dist/Sankey/SankeyChart.js +3 -0
  13. package/dist/Schedule/ListView.d.ts.map +1 -1
  14. package/dist/Schedule/ListView.js +7 -4
  15. package/dist/Schedule/MonthlyView.js +3 -2
  16. package/dist/Schedule/Schedule.d.ts +3 -1
  17. package/dist/Schedule/Schedule.d.ts.map +1 -1
  18. package/dist/Schedule/Schedule.js +9 -4
  19. package/dist/Schedule/TimeGridView.js +3 -2
  20. package/dist/Schedule/context.d.ts +2 -0
  21. package/dist/Schedule/context.d.ts.map +1 -1
  22. package/dist/index.d.ts +1 -1
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +5 -2
  25. package/dist/lab.css +6 -15
  26. package/package.json +2 -2
  27. package/src/CodeEditor/CodeEditor.test.tsx +21 -0
  28. package/src/CodeEditor/CodeEditor.tsx +5 -0
  29. package/src/InfoTip/InfoTip.doc.mjs +97 -0
  30. package/src/InfoTip/InfoTip.test.tsx +169 -0
  31. package/src/InfoTip/InfoTip.tsx +155 -0
  32. package/src/InfoTip/index.ts +10 -0
  33. package/src/Sankey/SankeyChart.test.tsx +77 -0
  34. package/src/Sankey/SankeyChart.tsx +3 -0
  35. package/src/Schedule/ListView.tsx +5 -2
  36. package/src/Schedule/MonthlyView.tsx +2 -2
  37. package/src/Schedule/Schedule.test.tsx +39 -0
  38. package/src/Schedule/Schedule.tsx +8 -0
  39. package/src/Schedule/TimeGridView.tsx +2 -2
  40. package/src/Schedule/context.tsx +2 -0
  41. package/src/index.ts +5 -46
  42. package/dist/ChartV2/Chart.d.ts +0 -32
  43. package/dist/ChartV2/Chart.d.ts.map +0 -1
  44. package/dist/ChartV2/Chart.js +0 -281
  45. package/dist/ChartV2/ChartAxis.d.ts +0 -36
  46. package/dist/ChartV2/ChartAxis.d.ts.map +0 -1
  47. package/dist/ChartV2/ChartAxis.js +0 -161
  48. package/dist/ChartV2/ChartGrid.d.ts +0 -20
  49. package/dist/ChartV2/ChartGrid.d.ts.map +0 -1
  50. package/dist/ChartV2/ChartGrid.js +0 -76
  51. package/dist/ChartV2/ChartLegend.d.ts +0 -14
  52. package/dist/ChartV2/ChartLegend.d.ts.map +0 -1
  53. package/dist/ChartV2/ChartLegend.js +0 -54
  54. package/dist/ChartV2/ChartSwatch.d.ts +0 -36
  55. package/dist/ChartV2/ChartSwatch.d.ts.map +0 -1
  56. package/dist/ChartV2/ChartSwatch.js +0 -82
  57. package/dist/ChartV2/ChartTooltip.d.ts +0 -46
  58. package/dist/ChartV2/ChartTooltip.d.ts.map +0 -1
  59. package/dist/ChartV2/ChartTooltip.js +0 -267
  60. package/dist/ChartV2/ChartV2Context.d.ts +0 -4
  61. package/dist/ChartV2/ChartV2Context.d.ts.map +0 -1
  62. package/dist/ChartV2/ChartV2Context.js +0 -12
  63. package/dist/ChartV2/index.d.ts +0 -13
  64. package/dist/ChartV2/index.d.ts.map +0 -1
  65. package/dist/ChartV2/index.js +0 -10
  66. package/dist/ChartV2/layout.d.ts +0 -25
  67. package/dist/ChartV2/layout.d.ts.map +0 -1
  68. package/dist/ChartV2/layout.js +0 -195
  69. package/dist/ChartV2/legend.d.ts +0 -18
  70. package/dist/ChartV2/legend.d.ts.map +0 -1
  71. package/dist/ChartV2/legend.js +0 -24
  72. package/dist/ChartV2/marks/area.d.ts +0 -19
  73. package/dist/ChartV2/marks/area.d.ts.map +0 -1
  74. package/dist/ChartV2/marks/area.js +0 -109
  75. package/dist/ChartV2/marks/band.d.ts +0 -9
  76. package/dist/ChartV2/marks/band.d.ts.map +0 -1
  77. package/dist/ChartV2/marks/band.js +0 -59
  78. package/dist/ChartV2/marks/bar.d.ts +0 -17
  79. package/dist/ChartV2/marks/bar.d.ts.map +0 -1
  80. package/dist/ChartV2/marks/bar.js +0 -120
  81. package/dist/ChartV2/marks/candlestick.d.ts +0 -15
  82. package/dist/ChartV2/marks/candlestick.d.ts.map +0 -1
  83. package/dist/ChartV2/marks/candlestick.js +0 -83
  84. package/dist/ChartV2/marks/dot.d.ts +0 -15
  85. package/dist/ChartV2/marks/dot.d.ts.map +0 -1
  86. package/dist/ChartV2/marks/dot.js +0 -65
  87. package/dist/ChartV2/marks/dotGL.d.ts +0 -16
  88. package/dist/ChartV2/marks/dotGL.d.ts.map +0 -1
  89. package/dist/ChartV2/marks/dotGL.js +0 -178
  90. package/dist/ChartV2/marks/dotGLInteractive.d.ts +0 -30
  91. package/dist/ChartV2/marks/dotGLInteractive.d.ts.map +0 -1
  92. package/dist/ChartV2/marks/dotGLInteractive.js +0 -464
  93. package/dist/ChartV2/marks/errorBar.d.ts +0 -27
  94. package/dist/ChartV2/marks/errorBar.d.ts.map +0 -1
  95. package/dist/ChartV2/marks/errorBar.js +0 -87
  96. package/dist/ChartV2/marks/heatmapGL.d.ts +0 -23
  97. package/dist/ChartV2/marks/heatmapGL.d.ts.map +0 -1
  98. package/dist/ChartV2/marks/heatmapGL.js +0 -242
  99. package/dist/ChartV2/marks/index.d.ts +0 -13
  100. package/dist/ChartV2/marks/index.d.ts.map +0 -1
  101. package/dist/ChartV2/marks/index.js +0 -14
  102. package/dist/ChartV2/marks/line.d.ts +0 -18
  103. package/dist/ChartV2/marks/line.d.ts.map +0 -1
  104. package/dist/ChartV2/marks/line.js +0 -76
  105. package/dist/ChartV2/marks/referenceLine.d.ts +0 -35
  106. package/dist/ChartV2/marks/referenceLine.d.ts.map +0 -1
  107. package/dist/ChartV2/marks/referenceLine.js +0 -186
  108. package/dist/ChartV2/marks/streamGL.d.ts +0 -36
  109. package/dist/ChartV2/marks/streamGL.d.ts.map +0 -1
  110. package/dist/ChartV2/marks/streamGL.js +0 -204
  111. package/dist/ChartV2/tooltip.d.ts +0 -38
  112. package/dist/ChartV2/tooltip.d.ts.map +0 -1
  113. package/dist/ChartV2/tooltip.js +0 -54
  114. package/dist/ChartV2/types.d.ts +0 -115
  115. package/dist/ChartV2/types.d.ts.map +0 -1
  116. package/dist/ChartV2/types.js +0 -35
  117. package/src/ChartV2/Chart.tsx +0 -348
  118. package/src/ChartV2/ChartAxis.tsx +0 -209
  119. package/src/ChartV2/ChartGrid.tsx +0 -99
  120. package/src/ChartV2/ChartLegend.tsx +0 -69
  121. package/src/ChartV2/ChartSwatch.doc.mjs +0 -17
  122. package/src/ChartV2/ChartSwatch.tsx +0 -86
  123. package/src/ChartV2/ChartTooltip.tsx +0 -382
  124. package/src/ChartV2/ChartV2.doc.mjs +0 -16
  125. package/src/ChartV2/ChartV2Context.ts +0 -15
  126. package/src/ChartV2/index.ts +0 -62
  127. package/src/ChartV2/layout.ts +0 -223
  128. package/src/ChartV2/legend.ts +0 -32
  129. package/src/ChartV2/marks/area.tsx +0 -122
  130. package/src/ChartV2/marks/band.tsx +0 -70
  131. package/src/ChartV2/marks/bar.tsx +0 -159
  132. package/src/ChartV2/marks/candlestick.tsx +0 -106
  133. package/src/ChartV2/marks/dot.tsx +0 -64
  134. package/src/ChartV2/marks/dotGL.tsx +0 -202
  135. package/src/ChartV2/marks/dotGLInteractive.tsx +0 -546
  136. package/src/ChartV2/marks/errorBar.tsx +0 -89
  137. package/src/ChartV2/marks/heatmapGL.tsx +0 -299
  138. package/src/ChartV2/marks/index.ts +0 -14
  139. package/src/ChartV2/marks/line.tsx +0 -94
  140. package/src/ChartV2/marks/referenceLine.tsx +0 -224
  141. package/src/ChartV2/marks/streamGL.tsx +0 -251
  142. package/src/ChartV2/tooltip.ts +0 -70
  143. package/src/ChartV2/types.ts +0 -129
@@ -56,6 +56,8 @@ export interface ScheduleProps<
56
56
  timezoneID?: string;
57
57
  /** Header/rendering plugins. Defaults to pagination controls. */
58
58
  plugins?: ReadonlyArray<SchedulePlugin>;
59
+ /** Heading level for sub-headings (day labels, weekday headers) within the schedule. @default 3 */
60
+ headingLevel?: 2 | 3 | 4 | 5 | 6;
59
61
  }
60
62
 
61
63
  interface EventRecord {
@@ -158,6 +160,7 @@ function ScheduleViewContent<Options extends ScheduleViewOptions>({
158
160
  onNextDate,
159
161
  nextDateLabel,
160
162
  plugins,
163
+ headingLevel,
161
164
  }: {
162
165
  view: ScheduleView<Options>;
163
166
  eventSource: ScheduleEventSource;
@@ -171,6 +174,7 @@ function ScheduleViewContent<Options extends ScheduleViewOptions>({
171
174
  onNextDate: () => void;
172
175
  nextDateLabel: string;
173
176
  plugins: ReadonlyArray<SchedulePlugin>;
177
+ headingLevel: 2 | 3 | 4 | 5 | 6;
174
178
  }) {
175
179
  const Component = view.component;
176
180
  const range = getRange(view, date);
@@ -195,6 +199,7 @@ function ScheduleViewContent<Options extends ScheduleViewOptions>({
195
199
  nextDateLabel,
196
200
  view,
197
201
  plugins,
202
+ headingLevel,
198
203
  }}>
199
204
  <Component options={view.options} />
200
205
  </ScheduleContext.Provider>
@@ -210,6 +215,7 @@ export function Schedule({
210
215
  onChangeDate,
211
216
  timezoneID: timezoneIDProp,
212
217
  plugins = defaultSchedulePlugins,
218
+ headingLevel = 3,
213
219
  xstyle,
214
220
  className,
215
221
  style,
@@ -285,6 +291,7 @@ export function Schedule({
285
291
  onNextDate={onNextDate}
286
292
  nextDateLabel={nextDateRange.label}
287
293
  plugins={plugins}
294
+ headingLevel={headingLevel}
288
295
  />
289
296
  }>
290
297
  <ScheduleViewContent
@@ -300,6 +307,7 @@ export function Schedule({
300
307
  onNextDate={onNextDate}
301
308
  nextDateLabel={nextDateRange.label}
302
309
  plugins={plugins}
310
+ headingLevel={headingLevel}
303
311
  />
304
312
  </Suspense>
305
313
  </div>
@@ -65,7 +65,7 @@ export function TimeGridView({
65
65
  maxHour: number;
66
66
  hourHeight: number;
67
67
  }) {
68
- const {categories} = useScheduleContext();
68
+ const {categories, headingLevel} = useScheduleContext();
69
69
  const normalizedMinHour = Math.max(0, Math.min(23, Math.floor(minHour)));
70
70
  const normalizedMaxHour = Math.max(
71
71
  normalizedMinHour + 1,
@@ -114,7 +114,7 @@ export function TimeGridView({
114
114
  index === days.length - 1 && styles.timeGridHeaderCellLast,
115
115
  )}>
116
116
  <Heading
117
- level={4}
117
+ level={headingLevel}
118
118
  color="secondary"
119
119
  display="block"
120
120
  xstyle={styles.timeGridHeaderHeading}>
@@ -34,6 +34,8 @@ export interface ScheduleContextValue {
34
34
  nextDateLabel: string;
35
35
  view: ScheduleViewBase;
36
36
  plugins: ReadonlyArray<SchedulePlugin>;
37
+ /** Heading level used for sub-headings within the schedule (day labels, weekday headers). */
38
+ headingLevel: 2 | 3 | 4 | 5 | 6;
37
39
  }
38
40
 
39
41
  export const ScheduleContext = createContext<ScheduleContextValue | null>(
package/src/index.ts CHANGED
@@ -22,6 +22,9 @@ export {
22
22
  type SyntaxToken,
23
23
  } from '@astryxdesign/core/CodeBlock';
24
24
 
25
+ // InfoTip — accessible info-icon help affordance (RFC facebook/astryx#3349)
26
+ export {InfoTip, type InfoTipProps, type InfoTipSize} from './InfoTip';
27
+
25
28
  // Chat — experimental reasoning display
26
29
  export {
27
30
  ChatReasoning,
@@ -200,51 +203,7 @@ export {
200
203
  type SankeyContext,
201
204
  } from './Sankey';
202
205
 
203
- // Chart v2 — config model
204
- export {
205
- Chart as ChartV2,
206
- type ChartProps as ChartV2Props,
207
- ChartLegend as ChartV2Legend,
208
- type ChartLegendProps as ChartV2LegendProps,
209
- type LegendItem as ChartV2LegendItem,
210
- ChartAxis as ChartV2Axis,
211
- type ChartAxisProps as ChartV2AxisProps,
212
- ChartGrid as ChartV2Grid,
213
- type ChartGridProps as ChartV2GridProps,
214
- ChartSwatch as ChartV2Swatch,
215
- swatchVariantForType as xdsChartV2SwatchVariantForType,
216
- type ChartSwatchProps as ChartV2SwatchProps,
217
- type ChartSwatchVariant as ChartV2SwatchVariant,
218
- ChartTooltip as ChartV2Tooltip,
219
- type ChartTooltipProps as ChartV2TooltipProps,
220
- type ChartTooltipPlacement as ChartV2TooltipPlacement,
221
- type TooltipSeriesValue as ChartV2TooltipSeriesValue,
222
- bar,
223
- line,
224
- dot,
225
- area,
226
- band,
227
- candlestick,
228
- errorBar,
229
- referenceLine,
230
- dotGL,
231
- dotGLInteractive,
232
- heatmapGL,
233
- streamGL,
234
- useChartV2,
235
- type SeriesDef,
236
- type ChartV2Context,
237
- type ChartPointerEvent,
238
- type ResolvedPoint,
239
- type ResolvedPositions,
240
- type SeriesContext,
241
- type ErrorBarOptions,
242
- type ReferenceLineOptions,
243
- type DotGLOptions,
244
- type DotGLInteractiveOptions,
245
- type HeatmapGLOptions,
246
- type StreamGLOptions,
247
- type StreamGLHandle,
248
- } from './ChartV2';
206
+ // Chart v2 (config model) moved to its own package: @astryxdesign/charts.
207
+ // It is no longer re-exported from @astryxdesign/lab.
249
208
  export * from './Stepper';
250
209
  export * from './CircularProgress';
@@ -1,32 +0,0 @@
1
- /**
2
- * @file Chart.tsx (v2)
3
- * @output Root chart — coordinates layout, rendering, and events
4
- * @position Top-level; delegates everything to series configs and interaction slots
5
- *
6
- * The chart root has ZERO knowledge of mark types. It:
7
- * 1. Runs the layout engine (scales + stacking + grouping)
8
- * 2. Calls each series' resolve() and render() methods
9
- * 3. Provides a single event layer for interaction children
10
- */
11
- import { type ReactNode } from 'react';
12
- import type { SeriesDef } from './types';
13
- import type { ChartMargin } from './types';
14
- import { type ChartLegendProps } from './ChartLegend';
15
- import { type ChartTooltipProps } from './ChartTooltip';
16
- export interface ChartProps {
17
- data: Record<string, unknown>[];
18
- xKey: string;
19
- series: SeriesDef[];
20
- height?: number;
21
- margin?: Partial<ChartMargin>;
22
- grid?: ReactNode;
23
- axes?: ReactNode;
24
- legend?: boolean | ChartLegendProps;
25
- tooltip?: boolean | Omit<ChartTooltipProps, 'series'>;
26
- interactions?: ReactNode;
27
- children?: ReactNode;
28
- title?: string;
29
- subtitle?: string;
30
- }
31
- export declare function Chart({ data, xKey, series, height, margin: marginOverride, grid, axes, legend, tooltip, interactions, children, title, subtitle, }: ChartProps): import("react").JSX.Element;
32
- //# sourceMappingURL=Chart.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Chart.d.ts","sourceRoot":"","sources":["../../src/ChartV2/Chart.tsx"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AAEH,OAAO,EACL,KAAK,SAAS,EAOf,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,SAAS,CAAC;AACvC,OAAO,KAAK,EAAiB,WAAW,EAAoB,MAAM,SAAS,CAAC;AAO5E,OAAO,EAAc,KAAK,gBAAgB,EAAC,MAAM,eAAe,CAAC;AAEjE,OAAO,EAAe,KAAK,iBAAiB,EAAC,MAAM,gBAAgB,CAAC;AAEpE,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,SAAS,EAAE,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;IAC9B,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,MAAM,CAAC,EAAE,OAAO,GAAG,gBAAgB,CAAC;IACpC,OAAO,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC,iBAAiB,EAAE,QAAQ,CAAC,CAAC;IACtD,YAAY,CAAC,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAkBD,wBAAgB,KAAK,CAAC,EACpB,IAAI,EACJ,IAAI,EACJ,MAAM,EACN,MAAY,EACZ,MAAM,EAAE,cAAc,EACtB,IAAI,EACJ,IAAI,EACJ,MAAM,EACN,OAAO,EACP,YAAY,EACZ,QAAQ,EACR,KAAK,EACL,QAAQ,GACT,EAAE,UAAU,+BA2QZ"}
@@ -1,281 +0,0 @@
1
- // Copyright (c) Meta Platforms, Inc. and affiliates.
2
-
3
- /**
4
- * @file Chart.tsx (v2)
5
- * @output Root chart — coordinates layout, rendering, and events
6
- * @position Top-level; delegates everything to series configs and interaction slots
7
- *
8
- * The chart root has ZERO knowledge of mark types. It:
9
- * 1. Runs the layout engine (scales + stacking + grouping)
10
- * 2. Calls each series' resolve() and render() methods
11
- * 3. Provides a single event layer for interaction children
12
- */
13
-
14
- import { useId, useMemo, useRef, useState, useCallback, useLayoutEffect } from 'react';
15
- import { computeLayout } from "./layout.js";
16
- import { ChartV2Provider } from "./ChartV2Context.js";
17
- import { ChartProvider } from "../Chart/ChartContext.js";
18
- import { Text } from '@astryxdesign/core';
19
- import { VStack, HStack } from '@astryxdesign/core';
20
- import * as stylex from '@stylexjs/stylex';
21
- import { ChartLegend } from "./ChartLegend.js";
22
- import { deriveLegendItems } from "./legend.js";
23
- import { ChartTooltip } from "./ChartTooltip.js";
24
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
25
- const DEFAULT_MARGIN = {
26
- top: 24,
27
- right: 24,
28
- bottom: 32,
29
- left: 48
30
- };
31
- export function Chart({
32
- data,
33
- xKey,
34
- series,
35
- height = 300,
36
- margin: marginOverride,
37
- grid,
38
- axes,
39
- legend,
40
- tooltip,
41
- interactions,
42
- children,
43
- title,
44
- subtitle
45
- }) {
46
- const chartId = useId();
47
- const descId = `${chartId}-desc`;
48
- const containerRef = useRef(null);
49
- const svgRef = useRef(null);
50
- const [containerWidth, setContainerWidth] = useState(0);
51
- const pointerHandlers = useRef(new Set());
52
- useLayoutEffect(() => {
53
- if (!containerRef.current) {
54
- return;
55
- }
56
- const observer = new ResizeObserver(entries => {
57
- const entry = entries[0];
58
- if (entry) {
59
- setContainerWidth(entry.contentRect.width);
60
- }
61
- });
62
- observer.observe(containerRef.current);
63
- return () => observer.disconnect();
64
- }, []);
65
- const margin = useMemo(() => ({
66
- ...DEFAULT_MARGIN,
67
- ...marginOverride
68
- }), [marginOverride]);
69
- const innerWidth = Math.max(0, containerWidth - margin.left - margin.right);
70
- const innerHeight = Math.max(0, height - margin.top - margin.bottom);
71
-
72
- // ─── Layout pass ──────────────────────────────────────────────────────
73
- const layout = useMemo(() => computeLayout({
74
- data,
75
- xKey,
76
- series,
77
- width: innerWidth,
78
- height: innerHeight
79
- }), [data, xKey, series, innerWidth, innerHeight]);
80
- const seriesCtx = useMemo(() => ({
81
- data,
82
- xKey,
83
- xScale: layout.xScale,
84
- yScale: layout.yScale,
85
- width: innerWidth,
86
- height: innerHeight
87
- }), [data, xKey, layout, innerWidth, innerHeight]);
88
-
89
- // ─── Event dispatch ───────────────────────────────────────────────────
90
- const onPointer = useCallback(handler => {
91
- pointerHandlers.current.add(handler);
92
- return () => {
93
- pointerHandlers.current.delete(handler);
94
- };
95
- }, []);
96
- const dispatch = useCallback(e => {
97
- for (const handler of pointerHandlers.current) {
98
- handler(e);
99
- }
100
- }, []);
101
- const handlePointerMove = useCallback(e => {
102
- const svg = svgRef.current;
103
- if (!svg) {
104
- return;
105
- }
106
- const point = svg.createSVGPoint();
107
- point.x = e.clientX;
108
- point.y = e.clientY;
109
- const ctm = e.currentTarget.getScreenCTM()?.inverse();
110
- if (!ctm) {
111
- return;
112
- }
113
- const cursor = point.matrixTransform(ctm);
114
-
115
- // Find nearest point by x-distance only (full vertical column is the hover zone)
116
- let nearest = null;
117
- let bestXDist = Infinity;
118
- for (const [seriesKey, points] of layout.resolved) {
119
- for (const p of points) {
120
- const xDist = Math.abs(p.px - cursor.x);
121
- if (xDist < bestXDist) {
122
- bestXDist = xDist;
123
- nearest = {
124
- ...p,
125
- seriesKey
126
- };
127
- }
128
- }
129
- }
130
- dispatch({
131
- x: cursor.x,
132
- y: cursor.y,
133
- nearest,
134
- active: e.buttons > 0
135
- });
136
- }, [layout.resolved, dispatch]);
137
- const handlePointerLeave = useCallback(() => {
138
- dispatch({
139
- x: -1,
140
- y: -1,
141
- nearest: null,
142
- active: false
143
- });
144
- }, [dispatch]);
145
-
146
- // ─── Context for interactions + v1 chrome ─────────────────────────────
147
- const ctx = useMemo(() => ({
148
- width: innerWidth,
149
- height: innerHeight,
150
- margin,
151
- data,
152
- xKey,
153
- xScale: layout.xScale,
154
- yScale: layout.yScale,
155
- resolved: layout.resolved,
156
- onPointer,
157
- svgRef
158
- }), [innerWidth, innerHeight, margin, data, xKey, layout, onPointer]);
159
-
160
- // Bridge v1 context for ChartGrid/Axis compatibility
161
- const v1Ctx = useMemo(() => ({
162
- width: innerWidth,
163
- height: innerHeight,
164
- margin,
165
- xKey,
166
- data,
167
- xScale: layout.xScale,
168
- yScale: layout.yScale,
169
- svgRef,
170
- pointerToData: () => ({
171
- x: null,
172
- y: 0,
173
- px: 0,
174
- py: 0
175
- }),
176
- pixelToData: (px, py) => ({
177
- x: null,
178
- y: 0,
179
- px,
180
- py
181
- })
182
- }), [innerWidth, innerHeight, margin, xKey, data, layout, svgRef]);
183
-
184
- // ─── Legend ────────────────────────────────────────────────────────────
185
- const legendConfig = legend === true ? {} : legend || null;
186
- const legendElement = legendConfig ? /*#__PURE__*/_jsx(ChartLegend, {
187
- items: legendConfig.items ?? deriveLegendItems(series),
188
- position: legendConfig.position,
189
- alignment: legendConfig.alignment
190
- }) : null;
191
- const legendPosition = legendConfig?.position ?? 'bottom';
192
- const isLegendHorizontal = legendPosition === 'start' || legendPosition === 'end';
193
-
194
- // ─── Render ───────────────────────────────────────────────────────────
195
- if (containerWidth === 0) {
196
- return /*#__PURE__*/_jsx("div", {
197
- ref: containerRef,
198
- ...{
199
- className: "xh8yej3"
200
- },
201
- style: {
202
- height
203
- }
204
- });
205
- }
206
- return /*#__PURE__*/_jsxs("div", {
207
- ref: containerRef,
208
- ...{
209
- className: "xh8yej3"
210
- },
211
- children: [(title || subtitle) && /*#__PURE__*/_jsxs("div", {
212
- ...{
213
- className: "x1yztbdb"
214
- },
215
- children: [title && /*#__PURE__*/_jsx(Text, {
216
- type: "body",
217
- weight: "semibold",
218
- display: "block",
219
- children: title
220
- }), subtitle && /*#__PURE__*/_jsx(Text, {
221
- type: "supporting",
222
- display: "block",
223
- children: subtitle
224
- })]
225
- }), /*#__PURE__*/_jsx(ChartV2Provider, {
226
- value: ctx,
227
- children: /*#__PURE__*/_jsx(ChartProvider, {
228
- value: v1Ctx,
229
- children: legendConfig == null ? renderSvg() : isLegendHorizontal ? /*#__PURE__*/_jsxs(HStack, {
230
- gap: 4,
231
- children: [legendPosition === 'start' && legendElement, /*#__PURE__*/_jsx("div", {
232
- ...{
233
- className: "x98rzlu xeuugli xb3r6kr"
234
- },
235
- children: renderSvg()
236
- }), legendPosition === 'end' && legendElement]
237
- }) : /*#__PURE__*/_jsxs(VStack, {
238
- gap: 4,
239
- children: [legendPosition === 'top' && legendElement, renderSvg(), legendPosition === 'bottom' && legendElement]
240
- })
241
- })
242
- })]
243
- });
244
- function renderSvg() {
245
- return /*#__PURE__*/_jsxs("svg", {
246
- ref: svgRef,
247
- width: "100%",
248
- height: height,
249
- "aria-label": title ?? undefined,
250
- "aria-describedby": subtitle ? descId : undefined,
251
- children: [title && /*#__PURE__*/_jsx("title", {
252
- children: title
253
- }), subtitle && /*#__PURE__*/_jsx("desc", {
254
- id: descId,
255
- children: subtitle
256
- }), /*#__PURE__*/_jsxs("g", {
257
- transform: `translate(${margin.left},${margin.top})`,
258
- children: [grid, series.map(s => {
259
- const resolved = layout.resolved.get(s.key);
260
- if (!resolved) {
261
- return null;
262
- }
263
- return /*#__PURE__*/_jsx("g", {
264
- children: s.render(resolved, seriesCtx)
265
- }, s.key);
266
- }), axes, /*#__PURE__*/_jsx("rect", {
267
- x: 0,
268
- y: 0,
269
- width: innerWidth,
270
- height: innerHeight,
271
- fill: "transparent",
272
- onPointerMove: handlePointerMove,
273
- onPointerLeave: handlePointerLeave
274
- }), interactions, tooltip && /*#__PURE__*/_jsx(ChartTooltip, {
275
- series: series,
276
- ...(tooltip === true ? {} : tooltip)
277
- }), children]
278
- })]
279
- });
280
- }
281
- }
@@ -1,36 +0,0 @@
1
- export interface ChartAxisProps {
2
- /** Which edge to render the axis on */
3
- position: 'top' | 'right' | 'bottom' | 'left';
4
- /** Number of ticks (approximate — d3 decides final count) */
5
- tickCount?: number;
6
- /** Maximum number of tick labels to show. Labels are evenly skipped when exceeded. */
7
- maxTicks?: number;
8
- /** Custom tick formatter */
9
- tickFormat?: (value: unknown) => string;
10
- /** Truncate labels to this many characters (appends "\u2026"). */
11
- truncate?: number;
12
- /** Enable smooth transitions for streaming (default: true) */
13
- animated?: boolean;
14
- /**
15
- * Show the axis edge line. Defaults to `true` for `position="bottom"`,
16
- * `false` otherwise. Forced to `true` when `showTicks` is enabled.
17
- * Pair with `<ChartGrid vertical />` and pass `showAxisLine` on the
18
- * corresponding side axis to keep the visual edge grounded.
19
- */
20
- showAxisLine?: boolean;
21
- /** Show perpendicular tick marks at each tick label. Default: `false`. */
22
- showTicks?: boolean;
23
- }
24
- /**
25
- * Chart axis. Always draws tick labels; the axis edge line and tick marks
26
- * are independently toggleable. Pair with `<ChartGrid>` for grid lines.
27
- *
28
- * @example
29
- * ```
30
- * <ChartAxis position="bottom" /> // edge line + labels
31
- * <ChartAxis position="left" /> // labels only (no edge line)
32
- * <ChartAxis position="left" showAxisLine showTicks />
33
- * ```
34
- */
35
- export declare function ChartAxis({ position, tickCount, maxTicks, tickFormat, truncate, animated, showAxisLine, showTicks, }: ChartAxisProps): import("react").JSX.Element;
36
- //# sourceMappingURL=ChartAxis.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ChartAxis.d.ts","sourceRoot":"","sources":["../../src/ChartV2/ChartAxis.tsx"],"names":[],"mappings":"AAsBA,MAAM,WAAW,cAAc;IAC7B,uCAAuC;IACvC,QAAQ,EAAE,KAAK,GAAG,OAAO,GAAG,QAAQ,GAAG,MAAM,CAAC;IAC9C,6DAA6D;IAC7D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,sFAAsF;IACtF,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,4BAA4B;IAC5B,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,MAAM,CAAC;IACxC,kEAAkE;IAClE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,8DAA8D;IAC9D,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;;;OAKG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,0EAA0E;IAC1E,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAeD;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,CAAC,EACxB,QAAQ,EACR,SAAa,EACb,QAAQ,EACR,UAAU,EACV,QAAQ,EACR,QAAe,EACf,YAAoC,EACpC,SAAiB,GAClB,EAAE,cAAc,+BAiIhB"}
@@ -1,161 +0,0 @@
1
- // Copyright (c) Meta Platforms, Inc. and affiliates.
2
-
3
- /**
4
- * @file ChartAxis.tsx (v2)
5
- * @output Renders an axis (top, right, bottom, left) using the chart's scales
6
- * @position Child of Chart v2; reads scales from chart context
7
- *
8
- * The axis edge line and tick marks are independently toggleable so callers
9
- * can compose: line-only, line + ticks, or line + ticks + grid (paired with
10
- * `<ChartGrid>`). To stay consistent with most charts, the bottom axis
11
- * draws its edge line by default and other positions don't.
12
- *
13
- * Ticks use CSS transitions for smooth sliding during streaming updates.
14
- */
15
-
16
- import { useMemo } from 'react';
17
- import * as stylex from '@stylexjs/stylex';
18
- import '@astryxdesign/core/theme/tokens.stylex';
19
- import { colorVars } from '@astryxdesign/core/theme/tokens.stylex';
20
- import { useChart } from "../Chart/ChartContext.js";
21
- import { isBandScale } from "../Chart/utils.js";
22
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
23
- const TICK_SIZE = 6;
24
-
25
- /**
26
- * Chart axis. Always draws tick labels; the axis edge line and tick marks
27
- * are independently toggleable. Pair with `<ChartGrid>` for grid lines.
28
- *
29
- * @example
30
- * ```
31
- * <ChartAxis position="bottom" /> // edge line + labels
32
- * <ChartAxis position="left" /> // labels only (no edge line)
33
- * <ChartAxis position="left" showAxisLine showTicks />
34
- * ```
35
- */
36
- export function ChartAxis({
37
- position,
38
- tickCount = 5,
39
- maxTicks,
40
- tickFormat,
41
- truncate,
42
- animated = true,
43
- showAxisLine = position === 'bottom',
44
- showTicks = false
45
- }) {
46
- // Tick marks need an axis line to anchor against; force it on when ticks
47
- // are enabled so the two visuals stay coherent.
48
- const renderAxisLine = showAxisLine || showTicks;
49
- const {
50
- width,
51
- height,
52
- xScale,
53
- yScale
54
- } = useChart();
55
- const isHorizontal = position === 'top' || position === 'bottom';
56
- const scale = isHorizontal ? xScale : yScale;
57
- const ticks = useMemo(() => {
58
- let allTicks;
59
- if (isBandScale(scale)) {
60
- allTicks = scale.domain().map(d => ({
61
- value: d,
62
- offset: (scale(d) ?? 0) + scale.bandwidth() / 2
63
- }));
64
- } else {
65
- const linearScale = scale;
66
- allTicks = linearScale.ticks(tickCount).map(d => ({
67
- value: d,
68
- offset: linearScale(d)
69
- }));
70
- }
71
-
72
- // Auto-skip: show every Nth label if maxTicks is exceeded
73
- if (maxTicks && allTicks.length > maxTicks) {
74
- const step = Math.ceil(allTicks.length / maxTicks);
75
- allTicks = allTicks.filter((_, i) => i % step === 0);
76
- }
77
- return allTicks;
78
- }, [scale, tickCount, maxTicks]);
79
- const transform = position === 'bottom' ? `translate(0,${height})` : position === 'right' ? `translate(${width},0)` : undefined;
80
-
81
- // For the bottom axis, draw the axis line at y=0 when the domain spans
82
- // negative values (so the axis line still represents zero, not the chart edge).
83
- const axisLineY = (() => {
84
- if (position !== 'bottom') {
85
- return 0;
86
- }
87
- const domain = yScale.domain();
88
- if (domain[0] < 0 && domain[1] > 0) {
89
- return yScale(0) - height;
90
- }
91
- return 0;
92
- })();
93
- const baseFormat = tickFormat ?? String;
94
- const format = truncate ? value => {
95
- const str = baseFormat(value);
96
- return str.length > truncate ? str.slice(0, truncate) + '\u2026' : str;
97
- } : baseFormat;
98
- const tickTransition = animated ? 'transform 150ms linear, opacity 150ms ease' : undefined;
99
- return /*#__PURE__*/_jsxs("g", {
100
- transform: transform,
101
- children: [renderAxisLine && /*#__PURE__*/_jsx("line", {
102
- x1: 0,
103
- x2: isHorizontal ? width : 0,
104
- y1: isHorizontal ? axisLineY : 0,
105
- y2: isHorizontal ? axisLineY : height,
106
- ...{
107
- className: "x1lo1t26 xnpr05h"
108
- }
109
- }), ticks.map(({
110
- value,
111
- offset
112
- }) => {
113
- const label = format(value);
114
- const isVisible = isHorizontal ? offset >= -10 && offset <= width + 10 : offset >= -10 && offset <= height + 10;
115
- if (isHorizontal) {
116
- const y = position === 'bottom' ? TICK_SIZE : -TICK_SIZE;
117
- return /*#__PURE__*/_jsxs("g", {
118
- style: {
119
- transform: `translateX(${offset}px)`,
120
- transition: tickTransition,
121
- opacity: isVisible ? 1 : 0
122
- },
123
- children: [showTicks && /*#__PURE__*/_jsx("line", {
124
- y2: y,
125
- ...{
126
- className: "x1lo1t26 xnpr05h"
127
- }
128
- }), /*#__PURE__*/_jsx("text", {
129
- y: position === 'bottom' ? TICK_SIZE + 12 : -(TICK_SIZE + 4),
130
- textAnchor: "middle",
131
- fill: "var(--color-text-secondary)",
132
- fontSize: 12,
133
- children: label
134
- })]
135
- }, label);
136
- }
137
- // Vertical axis
138
- const x = position === 'left' ? -TICK_SIZE : TICK_SIZE;
139
- return /*#__PURE__*/_jsxs("g", {
140
- style: {
141
- transform: `translateY(${offset}px)`,
142
- transition: tickTransition,
143
- opacity: isVisible ? 1 : 0
144
- },
145
- children: [showTicks && /*#__PURE__*/_jsx("line", {
146
- x2: x,
147
- ...{
148
- className: "x1lo1t26 xnpr05h"
149
- }
150
- }), /*#__PURE__*/_jsx("text", {
151
- x: position === 'left' ? -(TICK_SIZE + 4) : TICK_SIZE + 4,
152
- dy: "0.32em",
153
- textAnchor: position === 'left' ? 'end' : 'start',
154
- fill: "var(--color-text-secondary)",
155
- fontSize: 12,
156
- children: label
157
- })]
158
- }, label);
159
- })]
160
- });
161
- }
@@ -1,20 +0,0 @@
1
- export interface ChartGridProps {
2
- /** Show horizontal grid lines. Default: `true`. */
3
- horizontal?: boolean;
4
- /** Show vertical grid lines. Default: `false`. */
5
- vertical?: boolean;
6
- }
7
- /**
8
- * Grid lines behind chart marks.
9
- *
10
- * Pair with `<ChartAxis>` so users always see an axis line beside the
11
- * grid — the components are designed to be used together.
12
- *
13
- * @example
14
- * ```
15
- * <ChartGrid /> // horizontal grid lines (default)
16
- * <ChartGrid horizontal vertical />
17
- * ```
18
- */
19
- export declare function ChartGrid({ horizontal, vertical, }: ChartGridProps): import("react").JSX.Element;
20
- //# sourceMappingURL=ChartGrid.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ChartGrid.d.ts","sourceRoot":"","sources":["../../src/ChartV2/ChartGrid.tsx"],"names":[],"mappings":"AAeA,MAAM,WAAW,cAAc;IAC7B,mDAAmD;IACnD,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,kDAAkD;IAClD,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AASD;;;;;;;;;;;GAWG;AACH,wBAAgB,SAAS,CAAC,EACxB,UAAiB,EACjB,QAAgB,GACjB,EAAE,cAAc,+BAsDhB"}