@astryxdesign/lab 0.1.4-canary.c679f18 → 0.1.4-canary.cb964b6

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 (142) hide show
  1. package/dist/ChartV2/Chart.d.ts +32 -0
  2. package/dist/ChartV2/Chart.d.ts.map +1 -0
  3. package/dist/ChartV2/Chart.js +281 -0
  4. package/dist/ChartV2/ChartAxis.d.ts +36 -0
  5. package/dist/ChartV2/ChartAxis.d.ts.map +1 -0
  6. package/dist/ChartV2/ChartAxis.js +161 -0
  7. package/dist/ChartV2/ChartGrid.d.ts +20 -0
  8. package/dist/ChartV2/ChartGrid.d.ts.map +1 -0
  9. package/dist/ChartV2/ChartGrid.js +76 -0
  10. package/dist/ChartV2/ChartLegend.d.ts +14 -0
  11. package/dist/ChartV2/ChartLegend.d.ts.map +1 -0
  12. package/dist/ChartV2/ChartLegend.js +54 -0
  13. package/dist/ChartV2/ChartSwatch.d.ts +36 -0
  14. package/dist/ChartV2/ChartSwatch.d.ts.map +1 -0
  15. package/dist/ChartV2/ChartSwatch.js +82 -0
  16. package/dist/ChartV2/ChartTooltip.d.ts +46 -0
  17. package/dist/ChartV2/ChartTooltip.d.ts.map +1 -0
  18. package/dist/ChartV2/ChartTooltip.js +267 -0
  19. package/dist/ChartV2/ChartV2Context.d.ts +4 -0
  20. package/dist/ChartV2/ChartV2Context.d.ts.map +1 -0
  21. package/dist/ChartV2/ChartV2Context.js +12 -0
  22. package/dist/ChartV2/index.d.ts +13 -0
  23. package/dist/ChartV2/index.d.ts.map +1 -0
  24. package/dist/ChartV2/index.js +10 -0
  25. package/dist/ChartV2/layout.d.ts +25 -0
  26. package/dist/ChartV2/layout.d.ts.map +1 -0
  27. package/dist/ChartV2/layout.js +195 -0
  28. package/dist/ChartV2/legend.d.ts +18 -0
  29. package/dist/ChartV2/legend.d.ts.map +1 -0
  30. package/dist/ChartV2/legend.js +24 -0
  31. package/dist/ChartV2/marks/area.d.ts +19 -0
  32. package/dist/ChartV2/marks/area.d.ts.map +1 -0
  33. package/dist/ChartV2/marks/area.js +109 -0
  34. package/dist/ChartV2/marks/band.d.ts +9 -0
  35. package/dist/ChartV2/marks/band.d.ts.map +1 -0
  36. package/dist/ChartV2/marks/band.js +59 -0
  37. package/dist/ChartV2/marks/bar.d.ts +17 -0
  38. package/dist/ChartV2/marks/bar.d.ts.map +1 -0
  39. package/dist/ChartV2/marks/bar.js +120 -0
  40. package/dist/ChartV2/marks/candlestick.d.ts +15 -0
  41. package/dist/ChartV2/marks/candlestick.d.ts.map +1 -0
  42. package/dist/ChartV2/marks/candlestick.js +83 -0
  43. package/dist/ChartV2/marks/dot.d.ts +15 -0
  44. package/dist/ChartV2/marks/dot.d.ts.map +1 -0
  45. package/dist/ChartV2/marks/dot.js +65 -0
  46. package/dist/ChartV2/marks/dotGL.d.ts +16 -0
  47. package/dist/ChartV2/marks/dotGL.d.ts.map +1 -0
  48. package/dist/ChartV2/marks/dotGL.js +178 -0
  49. package/dist/ChartV2/marks/dotGLInteractive.d.ts +30 -0
  50. package/dist/ChartV2/marks/dotGLInteractive.d.ts.map +1 -0
  51. package/dist/ChartV2/marks/dotGLInteractive.js +464 -0
  52. package/dist/ChartV2/marks/errorBar.d.ts +27 -0
  53. package/dist/ChartV2/marks/errorBar.d.ts.map +1 -0
  54. package/dist/ChartV2/marks/errorBar.js +87 -0
  55. package/dist/ChartV2/marks/heatmapGL.d.ts +23 -0
  56. package/dist/ChartV2/marks/heatmapGL.d.ts.map +1 -0
  57. package/dist/ChartV2/marks/heatmapGL.js +242 -0
  58. package/dist/ChartV2/marks/index.d.ts +13 -0
  59. package/dist/ChartV2/marks/index.d.ts.map +1 -0
  60. package/dist/ChartV2/marks/index.js +14 -0
  61. package/dist/ChartV2/marks/line.d.ts +18 -0
  62. package/dist/ChartV2/marks/line.d.ts.map +1 -0
  63. package/dist/ChartV2/marks/line.js +76 -0
  64. package/dist/ChartV2/marks/referenceLine.d.ts +35 -0
  65. package/dist/ChartV2/marks/referenceLine.d.ts.map +1 -0
  66. package/dist/ChartV2/marks/referenceLine.js +186 -0
  67. package/dist/ChartV2/marks/streamGL.d.ts +36 -0
  68. package/dist/ChartV2/marks/streamGL.d.ts.map +1 -0
  69. package/dist/ChartV2/marks/streamGL.js +204 -0
  70. package/dist/ChartV2/tooltip.d.ts +38 -0
  71. package/dist/ChartV2/tooltip.d.ts.map +1 -0
  72. package/dist/ChartV2/tooltip.js +54 -0
  73. package/dist/ChartV2/types.d.ts +115 -0
  74. package/dist/ChartV2/types.d.ts.map +1 -0
  75. package/dist/ChartV2/types.js +35 -0
  76. package/dist/CodeEditor/CodeEditor.d.ts +1 -4
  77. package/dist/CodeEditor/CodeEditor.d.ts.map +1 -1
  78. package/dist/CodeEditor/CodeEditor.js +0 -3
  79. package/dist/Sankey/SankeyChart.d.ts.map +1 -1
  80. package/dist/Sankey/SankeyChart.js +0 -3
  81. package/dist/Schedule/ListView.d.ts.map +1 -1
  82. package/dist/Schedule/ListView.js +4 -7
  83. package/dist/Schedule/MonthlyView.js +2 -3
  84. package/dist/Schedule/Schedule.d.ts +1 -3
  85. package/dist/Schedule/Schedule.d.ts.map +1 -1
  86. package/dist/Schedule/Schedule.js +4 -9
  87. package/dist/Schedule/TimeGridView.js +2 -3
  88. package/dist/Schedule/context.d.ts +0 -2
  89. package/dist/Schedule/context.d.ts.map +1 -1
  90. package/dist/index.d.ts +1 -1
  91. package/dist/index.d.ts.map +1 -1
  92. package/dist/index.js +2 -5
  93. package/dist/lab.css +15 -6
  94. package/package.json +2 -2
  95. package/src/ChartV2/Chart.tsx +348 -0
  96. package/src/ChartV2/ChartAxis.tsx +209 -0
  97. package/src/ChartV2/ChartGrid.tsx +99 -0
  98. package/src/ChartV2/ChartLegend.tsx +69 -0
  99. package/src/ChartV2/ChartSwatch.doc.mjs +17 -0
  100. package/src/ChartV2/ChartSwatch.tsx +86 -0
  101. package/src/ChartV2/ChartTooltip.tsx +382 -0
  102. package/src/ChartV2/ChartV2.doc.mjs +16 -0
  103. package/src/ChartV2/ChartV2Context.ts +15 -0
  104. package/src/ChartV2/index.ts +62 -0
  105. package/src/ChartV2/layout.ts +223 -0
  106. package/src/ChartV2/legend.ts +32 -0
  107. package/src/ChartV2/marks/area.tsx +122 -0
  108. package/src/ChartV2/marks/band.tsx +70 -0
  109. package/src/ChartV2/marks/bar.tsx +159 -0
  110. package/src/ChartV2/marks/candlestick.tsx +106 -0
  111. package/src/ChartV2/marks/dot.tsx +64 -0
  112. package/src/ChartV2/marks/dotGL.tsx +202 -0
  113. package/src/ChartV2/marks/dotGLInteractive.tsx +546 -0
  114. package/src/ChartV2/marks/errorBar.tsx +89 -0
  115. package/src/ChartV2/marks/heatmapGL.tsx +299 -0
  116. package/src/ChartV2/marks/index.ts +14 -0
  117. package/src/ChartV2/marks/line.tsx +94 -0
  118. package/src/ChartV2/marks/referenceLine.tsx +224 -0
  119. package/src/ChartV2/marks/streamGL.tsx +251 -0
  120. package/src/ChartV2/tooltip.ts +70 -0
  121. package/src/ChartV2/types.ts +129 -0
  122. package/src/CodeEditor/CodeEditor.tsx +0 -5
  123. package/src/Sankey/SankeyChart.tsx +0 -3
  124. package/src/Schedule/ListView.tsx +2 -5
  125. package/src/Schedule/MonthlyView.tsx +2 -2
  126. package/src/Schedule/Schedule.test.tsx +0 -39
  127. package/src/Schedule/Schedule.tsx +0 -8
  128. package/src/Schedule/TimeGridView.tsx +2 -2
  129. package/src/Schedule/context.tsx +0 -2
  130. package/src/index.ts +46 -5
  131. package/dist/InfoTip/InfoTip.d.ts +0 -58
  132. package/dist/InfoTip/InfoTip.d.ts.map +0 -1
  133. package/dist/InfoTip/InfoTip.js +0 -91
  134. package/dist/InfoTip/index.d.ts +0 -6
  135. package/dist/InfoTip/index.d.ts.map +0 -1
  136. package/dist/InfoTip/index.js +0 -8
  137. package/src/CodeEditor/CodeEditor.test.tsx +0 -21
  138. package/src/InfoTip/InfoTip.doc.mjs +0 -97
  139. package/src/InfoTip/InfoTip.test.tsx +0 -169
  140. package/src/InfoTip/InfoTip.tsx +0 -155
  141. package/src/InfoTip/index.ts +0 -10
  142. package/src/Sankey/SankeyChart.test.tsx +0 -77
@@ -0,0 +1,32 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,281 @@
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
+ }
@@ -0,0 +1,36 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,161 @@
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
+ }
@@ -0,0 +1,20 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,76 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file ChartGrid.tsx (v2)
5
+ * @output Grid lines behind chart marks
6
+ * @position Child of Chart v2; reads scales from chart context
7
+ */
8
+
9
+ import { useMemo } from 'react';
10
+ import * as stylex from '@stylexjs/stylex';
11
+ import '@astryxdesign/core/theme/tokens.stylex';
12
+ import { colorVars } from '@astryxdesign/core/theme/tokens.stylex';
13
+ import { useChart } from "../Chart/ChartContext.js";
14
+ import { isBandScale } from "../Chart/utils.js";
15
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
16
+ /**
17
+ * Grid lines behind chart marks.
18
+ *
19
+ * Pair with `<ChartAxis>` so users always see an axis line beside the
20
+ * grid — the components are designed to be used together.
21
+ *
22
+ * @example
23
+ * ```
24
+ * <ChartGrid /> // horizontal grid lines (default)
25
+ * <ChartGrid horizontal vertical />
26
+ * ```
27
+ */
28
+ export function ChartGrid({
29
+ horizontal = true,
30
+ vertical = false
31
+ }) {
32
+ const {
33
+ width,
34
+ height,
35
+ xScale,
36
+ yScale
37
+ } = useChart();
38
+
39
+ // Skip the y=0 line when emphasizing it via the axis. Without this we'd
40
+ // double-draw on top of the axis line.
41
+ const hLines = useMemo(() => {
42
+ if (!horizontal) {
43
+ return [];
44
+ }
45
+ return yScale.ticks(5).filter(tick => tick !== 0).map(tick => yScale(tick));
46
+ }, [horizontal, yScale]);
47
+ const vLines = useMemo(() => {
48
+ if (!vertical) {
49
+ return [];
50
+ }
51
+ if (isBandScale(xScale)) {
52
+ return xScale.domain().map(d => (xScale(d) ?? 0) + xScale.bandwidth() / 2);
53
+ }
54
+ const linear = xScale;
55
+ return linear.ticks(5).map(d => linear(d));
56
+ }, [vertical, xScale]);
57
+ return /*#__PURE__*/_jsxs("g", {
58
+ children: [hLines.map(y => /*#__PURE__*/_jsx("line", {
59
+ x1: 0,
60
+ x2: width,
61
+ y1: y,
62
+ y2: y,
63
+ ...{
64
+ className: "x113i6qz xnpr05h"
65
+ }
66
+ }, `h-${y}`)), vLines.map(x => /*#__PURE__*/_jsx("line", {
67
+ x1: x,
68
+ x2: x,
69
+ y1: 0,
70
+ y2: height,
71
+ ...{
72
+ className: "x113i6qz xnpr05h"
73
+ }
74
+ }, `v-${x}`))]
75
+ });
76
+ }
@@ -0,0 +1,14 @@
1
+ import type { LegendItem } from './legend';
2
+ export type { LegendItem };
3
+ export type LegendPosition = 'top' | 'bottom' | 'start' | 'end';
4
+ export type LegendAlignment = 'start' | 'center' | 'end';
5
+ export interface ChartLegendProps {
6
+ /** Legend items to display */
7
+ items?: LegendItem[];
8
+ /** Position of the legend relative to the chart. Default: 'bottom' */
9
+ position?: LegendPosition;
10
+ /** Alignment of the legend within its position. Default: 'start' */
11
+ alignment?: LegendAlignment;
12
+ }
13
+ export declare function ChartLegend({ items, position, alignment, }: ChartLegendProps): import("react").JSX.Element | null;
14
+ //# sourceMappingURL=ChartLegend.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChartLegend.d.ts","sourceRoot":"","sources":["../../src/ChartV2/ChartLegend.tsx"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,UAAU,CAAC;AAEzC,YAAY,EAAC,UAAU,EAAC,CAAC;AAEzB,MAAM,MAAM,cAAc,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,GAAG,KAAK,CAAC;AAChE,MAAM,MAAM,eAAe,GAAG,OAAO,GAAG,QAAQ,GAAG,KAAK,CAAC;AAEzD,MAAM,WAAW,gBAAgB;IAC/B,8BAA8B;IAC9B,KAAK,CAAC,EAAE,UAAU,EAAE,CAAC;IACrB,sEAAsE;IACtE,QAAQ,CAAC,EAAE,cAAc,CAAC;IAC1B,oEAAoE;IACpE,SAAS,CAAC,EAAE,eAAe,CAAC;CAC7B;AAED,wBAAgB,WAAW,CAAC,EAC1B,KAAU,EACV,QAAmB,EACnB,SAAmB,GACpB,EAAE,gBAAgB,sCA8BlB"}