@astryxdesign/lab 0.1.4-canary.37c19d3 → 0.1.4-canary.39ffd21

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,54 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file ChartLegend.tsx
5
+ * @output Standalone chart legend component
6
+ * @position Can be used inside Chart via the `legend` prop, or independently
7
+ *
8
+ * @example
9
+ * // Via Chart
10
+ * <Chart legend={{position: 'top', alignment: 'start'}} ... />
11
+ *
12
+ * // Standalone
13
+ * <ChartLegend items={[{label: 'Revenue', color: '#3b82f6'}]} />
14
+ */
15
+
16
+ import { Text } from '@astryxdesign/core';
17
+ import { VStack, HStack } from '@astryxdesign/core';
18
+ import { ChartSwatch, swatchVariantForType } from "./ChartSwatch.js";
19
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
20
+ export function ChartLegend({
21
+ items = [],
22
+ position = 'bottom',
23
+ alignment = 'start'
24
+ }) {
25
+ if (items.length === 0) {
26
+ return null;
27
+ }
28
+ const isVertical = position === 'start' || position === 'end';
29
+ const legendItems = items.map(item => /*#__PURE__*/_jsxs(HStack, {
30
+ gap: 2,
31
+ vAlign: "center",
32
+ children: [/*#__PURE__*/_jsx(ChartSwatch, {
33
+ color: item.color,
34
+ variant: swatchVariantForType(item.type)
35
+ }), /*#__PURE__*/_jsx(Text, {
36
+ type: "supporting",
37
+ children: item.label
38
+ })]
39
+ }, item.label));
40
+ if (isVertical) {
41
+ return /*#__PURE__*/_jsx(VStack, {
42
+ gap: 2,
43
+ hAlign: alignment,
44
+ children: legendItems
45
+ });
46
+ }
47
+ return /*#__PURE__*/_jsx(HStack, {
48
+ gap: 4,
49
+ justify: alignment,
50
+ vAlign: "center",
51
+ wrap: "wrap",
52
+ children: legendItems
53
+ });
54
+ }
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Visual variant — drives shape.
3
+ * - `'square'` — square chip (bar series)
4
+ * - `'line'` — short stroke (line, dot, area, and other non-bar series)
5
+ */
6
+ export type ChartSwatchVariant = 'square' | 'line';
7
+ export interface ChartSwatchProps {
8
+ /** Fill color — typically a series color token */
9
+ color: string;
10
+ /** Visual variant. Default: `'square'`. */
11
+ variant?: ChartSwatchVariant;
12
+ }
13
+ /**
14
+ * Color swatch primitive.
15
+ *
16
+ * Used by ChartLegend (and ChartTooltip) to render the colored
17
+ * indicator next to a series label. Exported as a primitive so consumers
18
+ * can build their own custom legend/tooltip layouts while keeping visuals
19
+ * consistent.
20
+ */
21
+ declare function ChartSwatchImpl({ color, variant }: ChartSwatchProps): import("react").JSX.Element;
22
+ /**
23
+ * Memoized — swatches are static for a given (color, variant) tuple
24
+ * and can render many times in a tooltip/legend with several series.
25
+ */
26
+ export declare const ChartSwatch: import("react").MemoExoticComponent<typeof ChartSwatchImpl>;
27
+ /**
28
+ * Map a SeriesDef.type string to its swatch variant.
29
+ *
30
+ * Bar series get a square chip; everything else (line, dot, area, and any
31
+ * other non-bar mark) gets a short stroke. Centralized so legend, tooltip,
32
+ * and any custom chrome stay consistent.
33
+ */
34
+ export declare function swatchVariantForType(type: string | undefined): ChartSwatchVariant;
35
+ export {};
36
+ //# sourceMappingURL=ChartSwatch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChartSwatch.d.ts","sourceRoot":"","sources":["../../src/ChartV2/ChartSwatch.tsx"],"names":[],"mappings":"AAmBA;;;;GAIG;AACH,MAAM,MAAM,kBAAkB,GAAG,QAAQ,GAAG,MAAM,CAAC;AAEnD,MAAM,WAAW,gBAAgB;IAC/B,kDAAkD;IAClD,KAAK,EAAE,MAAM,CAAC;IACd,2CAA2C;IAC3C,OAAO,CAAC,EAAE,kBAAkB,CAAC;CAC9B;AAmBD;;;;;;;GAOG;AACH,iBAAS,eAAe,CAAC,EAAC,KAAK,EAAE,OAAkB,EAAC,EAAE,gBAAgB,+BAQrE;AAED;;;GAGG;AACH,eAAO,MAAM,WAAW,6DAAwB,CAAC;AAEjD;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,MAAM,GAAG,SAAS,GACvB,kBAAkB,CAEpB"}
@@ -0,0 +1,82 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file ChartSwatch.tsx
5
+ * @output Color swatch primitive for legends, tooltips, and standalone use
6
+ * @position Composable primitive — used by ChartLegend (and future
7
+ * ChartTooltip), or independently anywhere a series indicator
8
+ * is needed.
9
+ *
10
+ * @example
11
+ * ```
12
+ * <ChartSwatch color="#3b82f6" variant="square" />
13
+ * <ChartSwatch color="#f59e0b" variant="line" />
14
+ * ```
15
+ */
16
+
17
+ import { memo } from 'react';
18
+ import * as stylex from '@stylexjs/stylex';
19
+
20
+ /**
21
+ * Visual variant — drives shape.
22
+ * - `'square'` — square chip (bar series)
23
+ * - `'line'` — short stroke (line, dot, area, and other non-bar series)
24
+ */
25
+ import { jsx as _jsx } from "react/jsx-runtime";
26
+ const styles = {
27
+ base: {
28
+ kmuXW: "x2lah0s",
29
+ $$css: true
30
+ },
31
+ square: {
32
+ kzqmXN: "x1xc55vz",
33
+ kZKoxP: "xdk7pt",
34
+ kaIpWk: "x1cum3z5",
35
+ kUOVxO: "xckhbgb",
36
+ $$css: true
37
+ },
38
+ line: {
39
+ kzqmXN: "x1fsd2vl",
40
+ kZKoxP: "xuoj239",
41
+ kaIpWk: "xbvija",
42
+ $$css: true
43
+ }
44
+ };
45
+
46
+ /**
47
+ * Color swatch primitive.
48
+ *
49
+ * Used by ChartLegend (and ChartTooltip) to render the colored
50
+ * indicator next to a series label. Exported as a primitive so consumers
51
+ * can build their own custom legend/tooltip layouts while keeping visuals
52
+ * consistent.
53
+ */
54
+ function ChartSwatchImpl({
55
+ color,
56
+ variant = 'square'
57
+ }) {
58
+ return /*#__PURE__*/_jsx("div", {
59
+ "aria-hidden": true,
60
+ ...stylex.props(styles.base, styles[variant]),
61
+ style: {
62
+ backgroundColor: color
63
+ }
64
+ });
65
+ }
66
+
67
+ /**
68
+ * Memoized — swatches are static for a given (color, variant) tuple
69
+ * and can render many times in a tooltip/legend with several series.
70
+ */
71
+ export const ChartSwatch = /*#__PURE__*/memo(ChartSwatchImpl);
72
+
73
+ /**
74
+ * Map a SeriesDef.type string to its swatch variant.
75
+ *
76
+ * Bar series get a square chip; everything else (line, dot, area, and any
77
+ * other non-bar mark) gets a short stroke. Centralized so legend, tooltip,
78
+ * and any custom chrome stay consistent.
79
+ */
80
+ export function swatchVariantForType(type) {
81
+ return type === 'bar' ? 'square' : 'line';
82
+ }
@@ -0,0 +1,46 @@
1
+ import { type ReactNode } from 'react';
2
+ import { type TooltipSeriesValue } from './tooltip';
3
+ import type { SeriesDef } from './types';
4
+ export type ChartTooltipPlacement = 'auto' | 'right' | 'left' | 'top';
5
+ export interface ChartTooltipProps {
6
+ /**
7
+ * Series definitions — used to map the hovered datum to per-series rows.
8
+ * When rendered via `<Chart tooltip />`, Chart injects this automatically.
9
+ * When composing directly, pass the same `series` array you gave Chart.
10
+ */
11
+ series?: readonly SeriesDef[];
12
+ /**
13
+ * Custom render function. Receives the x-value and one row per visible series.
14
+ * Returning `null` hides the card while still rendering the band highlight + dots.
15
+ */
16
+ render?: (xValue: unknown, seriesValues: TooltipSeriesValue[]) => ReactNode;
17
+ /**
18
+ * Whether to draw a hover indicator at the focused x-position.
19
+ * Picks the right shape automatically:
20
+ * - **band-highlight rect** when the chart includes bar series on a band scale
21
+ * - **vertical crosshair line** for line / area / dot charts
22
+ *
23
+ * Default: `true`.
24
+ */
25
+ hoverIndicator?: boolean;
26
+ /**
27
+ * Whether to draw a hover dot at each series' point (skipped for bars).
28
+ * Default: `true`.
29
+ */
30
+ showHoverDots?: boolean;
31
+ /**
32
+ * Card placement relative to the hovered point:
33
+ * - `'auto'` (default): right of the point, flips to left if it would overflow
34
+ * - `'right'` / `'left'` / `'top'`: pinned position
35
+ */
36
+ placement?: ChartTooltipPlacement;
37
+ }
38
+ /**
39
+ * Composable grouped tooltip for Chart.
40
+ *
41
+ * Subscribes to the chart's pointer event stream and only re-renders when the
42
+ * hovered data index changes (not on every pointer move). Card position is
43
+ * updated imperatively via a ref to keep pointer-move cost ~free.
44
+ */
45
+ export declare function ChartTooltip({ series, render, hoverIndicator, showHoverDots, placement, }: ChartTooltipProps): import("react").JSX.Element;
46
+ //# sourceMappingURL=ChartTooltip.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChartTooltip.d.ts","sourceRoot":"","sources":["../../src/ChartV2/ChartTooltip.tsx"],"names":[],"mappings":"AA0BA,OAAO,EAOL,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAaf,OAAO,EAGL,KAAK,kBAAkB,EACxB,MAAM,WAAW,CAAC;AACnB,OAAO,KAAK,EAAC,SAAS,EAAoB,MAAM,SAAS,CAAC;AAG1D,MAAM,MAAM,qBAAqB,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,KAAK,CAAC;AAEtE,MAAM,WAAW,iBAAiB;IAChC;;;;OAIG;IACH,MAAM,CAAC,EAAE,SAAS,SAAS,EAAE,CAAC;IAC9B;;;OAGG;IACH,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,KAAK,SAAS,CAAC;IAC5E;;;;;;;OAOG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;;OAGG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;;;;OAIG;IACH,SAAS,CAAC,EAAE,qBAAqB,CAAC;CACnC;AA2DD;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,EAC3B,MAAW,EACX,MAAM,EACN,cAAqB,EACrB,aAAoB,EACpB,SAAkB,GACnB,EAAE,iBAAiB,+BA4NnB"}
@@ -0,0 +1,267 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file ChartTooltip.tsx
5
+ * @output Grouped chart tooltip — shows all series values at the hovered x-position.
6
+ * Composable: drop into `<Chart tooltip>` or render directly inside a chart
7
+ * to take full control of props.
8
+ * @position Reads from ChartV2Context — must render inside an <Chart>.
9
+ *
10
+ * @example
11
+ * ```
12
+ * // Default — declarative on Chart
13
+ * <Chart tooltip />
14
+ *
15
+ * // Custom render function via Chart prop
16
+ * <Chart tooltip={{render: (x, rows) => <MyCard x={x} rows={rows} />}} />
17
+ *
18
+ * // Composable — drop into the chart's children for full control
19
+ * <Chart>
20
+ * <ChartTooltip hoverIndicator={false} placement="top" />
21
+ * </Chart>
22
+ * ```
23
+ */
24
+
25
+ 'use client';
26
+
27
+ import { memo, useState, useEffect, useMemo, useRef, useCallback } from 'react';
28
+ import { createPortal } from 'react-dom';
29
+ import * as stylex from '@stylexjs/stylex';
30
+ import '@astryxdesign/core/theme/tokens.stylex';
31
+ import { colorVars, radiusVars, shadowVars, spacingVars } from '@astryxdesign/core/theme/tokens.stylex';
32
+ import { Text } from '@astryxdesign/core';
33
+ import { VStack, HStack } from '@astryxdesign/core';
34
+ import { useChartV2 } from "./ChartV2Context.js";
35
+ import { ChartSwatch, swatchVariantForType } from "./ChartSwatch.js";
36
+ import { deriveTooltipSeriesValues, shouldRenderHoverDot } from "./tooltip.js";
37
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
38
+ /** Default tooltip body — used when `render` is not provided. */
39
+ const DefaultTooltipContent = /*#__PURE__*/memo(function DefaultTooltipContent({
40
+ xValue,
41
+ rows
42
+ }) {
43
+ return /*#__PURE__*/_jsxs(VStack, {
44
+ gap: 1,
45
+ children: [/*#__PURE__*/_jsx(Text, {
46
+ type: "body",
47
+ weight: "semibold",
48
+ children: String(xValue)
49
+ }), rows.length === 1 ? /*#__PURE__*/_jsx(Text, {
50
+ type: "supporting",
51
+ children: String(rows[0].value)
52
+ }) : /*#__PURE__*/_jsx(VStack, {
53
+ gap: 1,
54
+ children: rows.map(row => /*#__PURE__*/_jsxs(HStack, {
55
+ gap: 2,
56
+ vAlign: "center",
57
+ children: [/*#__PURE__*/_jsx(ChartSwatch, {
58
+ color: row.color,
59
+ variant: swatchVariantForType(row.type)
60
+ }), /*#__PURE__*/_jsx(Text, {
61
+ type: "supporting",
62
+ children: row.label
63
+ }), /*#__PURE__*/_jsx(Text, {
64
+ type: "supporting",
65
+ weight: "semibold",
66
+ children: String(row.value)
67
+ })]
68
+ }, row.key))
69
+ })]
70
+ });
71
+ });
72
+
73
+ /**
74
+ * Composable grouped tooltip for Chart.
75
+ *
76
+ * Subscribes to the chart's pointer event stream and only re-renders when the
77
+ * hovered data index changes (not on every pointer move). Card position is
78
+ * updated imperatively via a ref to keep pointer-move cost ~free.
79
+ */
80
+ export function ChartTooltip({
81
+ series = [],
82
+ render,
83
+ hoverIndicator = true,
84
+ showHoverDots = true,
85
+ placement = 'auto'
86
+ }) {
87
+ const {
88
+ data,
89
+ xKey,
90
+ resolved,
91
+ onPointer,
92
+ svgRef,
93
+ margin,
94
+ xScale,
95
+ width,
96
+ height
97
+ } = useChartV2();
98
+ const [hoveredIndex, setHoveredIndex] = useState(null);
99
+ const cardRef = useRef(null);
100
+
101
+ // Stable Set of resolved series keys — used by deriveTooltipSeriesValues.
102
+ // Recomputed only when the resolved map identity changes (per layout pass).
103
+ const resolvedKeys = useMemo(() => new Set(resolved.keys()), [resolved]);
104
+
105
+ // ─── Card positioning ──────────────────────────────────────────────────
106
+ // Imperative — the card is portaled, and we don't want pointer-move to
107
+ // trigger React renders.
108
+ const positionCard = useCallback(e => {
109
+ const card = cardRef.current;
110
+ const svg = svgRef.current;
111
+ if (!card) {
112
+ return;
113
+ }
114
+ if (!svg || !e.nearest) {
115
+ card.style.display = 'none';
116
+ return;
117
+ }
118
+ const svgRect = svg.getBoundingClientRect();
119
+ const screenX = svgRect.left + margin.left + e.nearest.px;
120
+ const screenY = svgRect.top + margin.top;
121
+ const cardWidth = card.offsetWidth;
122
+ const cardHeight = card.offsetHeight;
123
+ const viewportWidth = window.innerWidth;
124
+ const gap = 8;
125
+ let x;
126
+ let y = screenY;
127
+ switch (placement) {
128
+ case 'left':
129
+ x = screenX - cardWidth - gap;
130
+ break;
131
+ case 'right':
132
+ x = screenX + gap;
133
+ break;
134
+ case 'top':
135
+ x = screenX - cardWidth / 2;
136
+ y = screenY - cardHeight - gap;
137
+ break;
138
+ case 'auto':
139
+ default:
140
+ {
141
+ const rightX = screenX + gap;
142
+ x = rightX + cardWidth > viewportWidth ? screenX - cardWidth - gap : rightX;
143
+ }
144
+ }
145
+ card.style.left = `${x}px`;
146
+ card.style.top = `${y}px`;
147
+ card.style.display = 'block';
148
+ }, [svgRef, margin, placement]);
149
+
150
+ // ─── Subscribe to pointer events ───────────────────────────────────────
151
+ useEffect(() => {
152
+ let currentIndex = null;
153
+ const unsub = onPointer(e => {
154
+ const newIndex = e.nearest?.dataIndex ?? null;
155
+ if (newIndex !== currentIndex) {
156
+ currentIndex = newIndex;
157
+ setHoveredIndex(newIndex);
158
+ }
159
+ positionCard(e);
160
+ });
161
+ return unsub;
162
+ }, [onPointer, positionCard]);
163
+
164
+ // ─── Derived data ──────────────────────────────────────────────────────
165
+ const datum = hoveredIndex != null ? data[hoveredIndex] : undefined;
166
+ const xValue = datum?.[xKey];
167
+ const seriesValues = useMemo(() => deriveTooltipSeriesValues(series, datum, resolvedKeys), [series, datum, resolvedKeys]);
168
+
169
+ // Hover dots — read from the resolved map at the hovered index.
170
+ const dots = useMemo(() => {
171
+ if (!showHoverDots || hoveredIndex == null) {
172
+ return null;
173
+ }
174
+ const elements = [];
175
+ for (const s of series) {
176
+ if (!shouldRenderHoverDot(s.type)) {
177
+ continue;
178
+ }
179
+ const points = resolved.get(s.key);
180
+ const point = points?.find(p => p.dataIndex === hoveredIndex);
181
+ if (!point) {
182
+ continue;
183
+ }
184
+ elements.push(/*#__PURE__*/_jsx("circle", {
185
+ cx: point.px,
186
+ cy: point.py,
187
+ r: 4,
188
+ fill: "var(--color-background-surface)",
189
+ stroke: s.color ?? 'var(--color-border-emphasized)',
190
+ strokeWidth: 2,
191
+ pointerEvents: "none"
192
+ }, s.key));
193
+ }
194
+ return elements;
195
+ }, [showHoverDots, hoveredIndex, series, resolved]);
196
+
197
+ // Hover indicator — band-highlight rect for bar charts, vertical crosshair
198
+ // line for line/area charts. Same source-of-truth (hoveredIndex), distinct
199
+ // visual idioms picked automatically based on the series mix.
200
+ const hoverIndicatorElement = useMemo(() => {
201
+ if (!hoverIndicator || hoveredIndex == null) {
202
+ return null;
203
+ }
204
+ const xv = data[hoveredIndex]?.[xKey];
205
+ if (xv == null) {
206
+ return null;
207
+ }
208
+ const isBandScale = 'bandwidth' in xScale;
209
+ const hasBars = series.some(s => s.type === 'bar');
210
+
211
+ // Bar charts on a band scale → soft column highlight.
212
+ if (hasBars && isBandScale) {
213
+ const bandScale = xScale;
214
+ const x = bandScale(String(xv)) ?? 0;
215
+ const bw = bandScale.bandwidth();
216
+ const pad = 8;
217
+ const rectX = Math.max(0, x - pad);
218
+ const rectRight = Math.min(width, x + bw + pad);
219
+ const rectWidth = rectRight - rectX;
220
+ const topPad = Math.min(pad, margin.top);
221
+ return /*#__PURE__*/_jsx("rect", {
222
+ x: rectX,
223
+ y: -topPad,
224
+ width: rectWidth,
225
+ height: height + topPad,
226
+ fill: "currentColor",
227
+ opacity: 0.06,
228
+ rx: 4,
229
+ pointerEvents: "none"
230
+ });
231
+ }
232
+
233
+ // Line / area / dot charts → vertical crosshair through the point.
234
+ const px = isBandScale ? (xScale(String(xv)) ?? 0) + xScale.bandwidth() / 2 : xScale(xv);
235
+ return /*#__PURE__*/_jsx("line", {
236
+ x1: px,
237
+ x2: px,
238
+ y1: 0,
239
+ y2: height,
240
+ ...{
241
+ className: "x1lo1t26 xnpr05h"
242
+ },
243
+ pointerEvents: "none"
244
+ });
245
+ }, [hoverIndicator, hoveredIndex, series, xScale, data, xKey, width, height, margin.top]);
246
+
247
+ // ─── Render ────────────────────────────────────────────────────────────
248
+ if (typeof document === 'undefined') {
249
+ // SSR: no DOM portal target; band highlight + dots still render in SVG.
250
+ return /*#__PURE__*/_jsxs(_Fragment, {
251
+ children: [hoverIndicatorElement, dots]
252
+ });
253
+ }
254
+ const cardContent = hoveredIndex == null ? null : render ? render(xValue, seriesValues) : /*#__PURE__*/_jsx(DefaultTooltipContent, {
255
+ xValue: xValue,
256
+ rows: seriesValues
257
+ });
258
+ return /*#__PURE__*/_jsxs(_Fragment, {
259
+ children: [hoverIndicatorElement, dots, /*#__PURE__*/createPortal(/*#__PURE__*/_jsx("div", {
260
+ ref: cardRef,
261
+ ...{
262
+ className: "xixxii4 x1prclbq x1hviunn xce4md1 xrrkdod x14hfi27 x47corl xuxw1ft x1q2oy4v x1s85apg"
263
+ },
264
+ children: cardContent
265
+ }), document.body)]
266
+ });
267
+ }
@@ -0,0 +1,4 @@
1
+ import type { ChartV2Context } from './types';
2
+ export declare const ChartV2Provider: import("react").Provider<ChartV2Context | null>;
3
+ export declare function useChartV2(): ChartV2Context;
4
+ //# sourceMappingURL=ChartV2Context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChartV2Context.d.ts","sourceRoot":"","sources":["../../src/ChartV2/ChartV2Context.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,SAAS,CAAC;AAG5C,eAAO,MAAM,eAAe,iDAAe,CAAC;AAE5C,wBAAgB,UAAU,IAAI,cAAc,CAM3C"}
@@ -0,0 +1,12 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ import { createContext, useContext } from 'react';
4
+ const Ctx = /*#__PURE__*/createContext(null);
5
+ export const ChartV2Provider = Ctx.Provider;
6
+ export function useChartV2() {
7
+ const ctx = useContext(Ctx);
8
+ if (!ctx) {
9
+ throw new Error('Must be used inside <Chart>');
10
+ }
11
+ return ctx;
12
+ }
@@ -0,0 +1,13 @@
1
+ export { Chart, type ChartProps } from './Chart';
2
+ export { ChartAxis, type ChartAxisProps } from './ChartAxis';
3
+ export { ChartGrid, type ChartGridProps } from './ChartGrid';
4
+ export { ChartLegend, type ChartLegendProps, type LegendPosition, type LegendAlignment, } from './ChartLegend';
5
+ export { type LegendItem } from './legend';
6
+ export { ChartSwatch, swatchVariantForType, type ChartSwatchProps, type ChartSwatchVariant, } from './ChartSwatch';
7
+ export { ChartTooltip, type ChartTooltipProps, type ChartTooltipPlacement, } from './ChartTooltip';
8
+ export { type TooltipSeriesValue } from './tooltip';
9
+ export { bar, line, dot, area, band, candlestick, errorBar, referenceLine, dotGL, dotGLInteractive, heatmapGL, streamGL, } from './marks';
10
+ export type { BarOptions, LineOptions, DotOptions, AreaOptions, BandOptions, CandlestickOptions, ErrorBarOptions, ReferenceLineOptions, DotGLOptions, DotGLInteractiveOptions, HeatmapGLOptions, StreamGLOptions, StreamGLHandle, } from './marks';
11
+ export { useChartV2 } from './ChartV2Context';
12
+ export type { SeriesDef, ChartV2Context, ChartPointerEvent, ResolvedPoint, ResolvedPositions, SeriesContext, } from './types';
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ChartV2/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,KAAK,EAAE,KAAK,UAAU,EAAC,MAAM,SAAS,CAAC;AAC/C,OAAO,EAAC,SAAS,EAAE,KAAK,cAAc,EAAC,MAAM,aAAa,CAAC;AAC3D,OAAO,EAAC,SAAS,EAAE,KAAK,cAAc,EAAC,MAAM,aAAa,CAAC;AAC3D,OAAO,EACL,WAAW,EACX,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,eAAe,GACrB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAC,KAAK,UAAU,EAAC,MAAM,UAAU,CAAC;AACzC,OAAO,EACL,WAAW,EACX,oBAAoB,EACpB,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,GACxB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,YAAY,EACZ,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,GAC3B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAC,KAAK,kBAAkB,EAAC,MAAM,WAAW,CAAC;AAClD,OAAO,EACL,GAAG,EACH,IAAI,EACJ,GAAG,EACH,IAAI,EACJ,IAAI,EACJ,WAAW,EACX,QAAQ,EACR,aAAa,EACb,KAAK,EACL,gBAAgB,EAChB,SAAS,EACT,QAAQ,GACT,MAAM,SAAS,CAAC;AACjB,YAAY,EACV,UAAU,EACV,WAAW,EACX,UAAU,EACV,WAAW,EACX,WAAW,EACX,kBAAkB,EAClB,eAAe,EACf,oBAAoB,EACpB,YAAY,EACZ,uBAAuB,EACvB,gBAAgB,EAChB,eAAe,EACf,cAAc,GACf,MAAM,SAAS,CAAC;AACjB,OAAO,EAAC,UAAU,EAAC,MAAM,kBAAkB,CAAC;AAC5C,YAAY,EACV,SAAS,EACT,cAAc,EACd,iBAAiB,EACjB,aAAa,EACb,iBAAiB,EACjB,aAAa,GACd,MAAM,SAAS,CAAC"}
@@ -0,0 +1,10 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ export { Chart } from "./Chart.js";
4
+ export { ChartAxis } from "./ChartAxis.js";
5
+ export { ChartGrid } from "./ChartGrid.js";
6
+ export { ChartLegend } from "./ChartLegend.js";
7
+ export { ChartSwatch, swatchVariantForType } from "./ChartSwatch.js";
8
+ export { ChartTooltip } from "./ChartTooltip.js";
9
+ export { bar, line, dot, area, band, candlestick, errorBar, referenceLine, dotGL, dotGLInteractive, heatmapGL, streamGL } from "./marks/index.js";
10
+ export { useChartV2 } from "./ChartV2Context.js";
@@ -0,0 +1,25 @@
1
+ /**
2
+ * @file layout.ts
3
+ * @output Computes scales, stacking, grouping, then delegates to each series.resolve()
4
+ * @position Called by Chart root — the single layout pass
5
+ *
6
+ * The layout engine does NOT know about specific mark types.
7
+ * It handles cross-series coordination (scales, stacking, grouping)
8
+ * then calls each series' own resolve() method.
9
+ */
10
+ import { scaleLinear } from 'd3-scale';
11
+ import type { SeriesDef, ChartScale, ResolvedPoint } from './types';
12
+ export interface LayoutInput {
13
+ data: Record<string, unknown>[];
14
+ xKey: string;
15
+ series: SeriesDef[];
16
+ width: number;
17
+ height: number;
18
+ }
19
+ export interface LayoutResult {
20
+ xScale: ChartScale;
21
+ yScale: ReturnType<typeof scaleLinear<number, number>>;
22
+ resolved: Map<string, ResolvedPoint[]>;
23
+ }
24
+ export declare function computeLayout({ data, xKey, series, width, height, }: LayoutInput): LayoutResult;
25
+ //# sourceMappingURL=layout.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"layout.d.ts","sourceRoot":"","sources":["../../src/ChartV2/layout.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AAEH,OAAO,EAAC,WAAW,EAAY,MAAM,UAAU,CAAC;AAEhD,OAAO,KAAK,EACV,SAAS,EACT,UAAU,EACV,aAAa,EAEd,MAAM,SAAS,CAAC;AAEjB,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,SAAS,EAAE,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,UAAU,CAAC;IACnB,MAAM,EAAE,UAAU,CAAC,OAAO,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACvD,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,aAAa,EAAE,CAAC,CAAC;CACxC;AAED,wBAAgB,aAAa,CAAC,EAC5B,IAAI,EACJ,IAAI,EACJ,MAAM,EACN,KAAK,EACL,MAAM,GACP,EAAE,WAAW,GAAG,YAAY,CAqL5B"}