@altertable/data-app-react 0.75.0 → 0.76.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/ui/index.js CHANGED
@@ -1,11 +1,11 @@
1
- import { $ as DateTimeRangePicker, $t as AppIcon, A as LiveControl, B as isPlainKeyEvent, Bt as TabPanel, Ct as DateDisplay, E as DataAppFrame, F as MenuSeparator, Ft as DataAppProvider, G as FilterActions, Gt as GradientScroll, Ht as Tabs, I as MenuTrigger, J as NumberFilterPicker, Jt as TooltipSurface, K as SearchTypeahead, Kt as Tooltip, Lt as AboutData, M as MenuItem, N as MenuPopover, P as MenuSection, Q as FilterBar, Rt as Tab, S as withWidgetBoundary, T as DataValue, Tt as HelpPopover, U as useDeclaredResult, Ut as useViewTab, V as createDataHooks, Vt as TabPanels, W as VariableBar, Wt as Sheet, X as NumberRangeField, Y as NumberField, Z as DimensionPicker, _ as explorationMenuEvents, a as TextWidget$1, an as useDateFormatting, b as useChartActions, c as DataTableEmptyRow, ct as matchSearchText, d as MetricWidget$1, et as Select, f as VisualizationWidget$1, ft as dateTimeRangePresets, g as ExplorationActionMenu, gt as useAppVariables, h as ExplorationActionControl, it as ChoicePicker, j as Menu, jt as ShimmerText, k as PresentStory, l as DataTableShare, lt as searchItems, n as createDataContext, nn as PressButton, nt as Checkbox, o as TableWidget$1, ot as SearchMatch, pt as dateTimeRangeVariable, q as SearchField, qt as TooltipProvider, r as chartBarFill, rn as classNames, rt as CheckboxGroupContext, s as DataTable, sn as injectDataAppStyles, t as SectionHeading, tn as Button$1, tt as DateRangePicker, u as DataTableTimestamp, v as getPrimaryExplorationAction, x as DataWidget, y as openExplorationMenu, zt as TabList } from "../chunks/SectionHeading-CLvnHe1C.js";
1
+ import { $ as SearchField, $t as Button$1, A as LiveControl, B as isPlainKeyEvent, Bt as useViewTab, E as DataAppFrame, F as MenuSeparator, Ft as Tab, G as FilterActions, Gt as ChartTooltip$1, Ht as GradientScroll, I as MenuTrigger, It as TabList, J as dateTimeRangeVariable, Kt as TooltipSurface, Lt as TabPanel, M as MenuItem, Mt as DataAppProvider, N as MenuPopover, Ot as ShimmerText, P as MenuSection, Pt as AboutData, Q as SearchTypeahead, Rt as TabPanels, S as withWidgetBoundary, St as HelpPopover, T as DataValue, U as useDeclaredResult, Ut as Tooltip, V as createDataHooks, Vt as Sheet, W as VariableBar, Wt as TooltipProvider, Z as useAppVariables, Zt as AppIcon, _ as explorationMenuEvents, a as TextWidget$1, an as injectDataAppStyles, at as DateTimeRangePicker, b as useChartActions, bt as DateDisplay, c as DataTableEmptyRow, d as MetricWidget$1, en as PressButton, et as NumberFilterPicker, f as VisualizationWidget$1, ft as matchSearchText, g as ExplorationActionMenu, h as ExplorationActionControl, it as FilterBar, j as Menu, k as PresentStory, l as DataTableShare, lt as SelectionMark, n as createDataContext, nt as NumberRangeField, o as TableWidget$1, ot as Select, pt as searchItems, q as dateTimeRangePresets, r as chartBarFill, rn as useDateFormatting, rt as DimensionPicker, s as DataTable, st as ChoicePicker, t as SectionHeading, tn as classNames, tt as NumberField, u as DataTableTimestamp, ut as SearchMatch, v as getPrimaryExplorationAction, x as DataWidget, y as openExplorationMenu, zt as Tabs } from "../chunks/SectionHeading-DLVTKa91.js";
2
2
  import { createDataClient } from "@altertable/data-app/client";
3
3
  import { KEY_SEPARATOR, invariant, validateChoiceOptions } from "@altertable/data-app/internal";
4
- import { Children, Fragment, createContext, useCallback, useContext, useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from "react";
4
+ import { Children, Fragment, createContext, isValidElement, useCallback, useContext, useEffect, useId, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
5
5
  import { Label, Radio as Radio$1, RadioGroup as RadioGroup$1 } from "react-aria-components";
6
6
  import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
7
7
  import { formatDate, formatDateTime, formatMetric, formatNumber, formatPercent, parseDateTime } from "@altertable/data-app/format";
8
- import { Area, AreaChart as AreaChart$1, Bar, BarChart as BarChart$1, Brush, CartesianGrid, Cell, ComposedChart as ComposedChart$1, DefaultTooltipContent, Dot, ErrorBar, Label as Label$1, LabelList, Legend, Line, LineChart as LineChart$1, ReferenceArea, ReferenceDot, ReferenceLine, Scatter, Tooltip as Tooltip$1, XAxis, YAxis, ZAxis, usePlotArea, useYAxisTicks } from "recharts";
8
+ import { Area, AreaChart as AreaChart$1, Bar, BarChart as BarChart$1, Brush, CartesianGrid, Cell, ComposedChart as ComposedChart$1, DefaultTooltipContent, Dot, ErrorBar, Label as Label$1, LabelList, Legend, Line, LineChart as LineChart$1, ReferenceArea, ReferenceDot, ReferenceLine, Scatter, Tooltip as Tooltip$1, XAxis, YAxis, ZAxis, useActiveTooltipLabel, useIsTooltipActive, usePlotArea, useXAxisScale, useYAxisTicks } from "recharts";
9
9
  //#region src/ui/StaticDataApp.tsx
10
10
  /** Setup and static screens; fetched data uses the declared-view DataApp. */
11
11
  function DataApp(props) {
@@ -143,6 +143,39 @@ function GlossaryDefinition({ entry, children }) {
143
143
  });
144
144
  }
145
145
  //#endregion
146
+ //#region src/ui/Checkbox.tsx
147
+ const CheckboxGroupContext = createContext(null);
148
+ function Checkbox({ label, description, checked, value, onChange, disabled, className }) {
149
+ const group = useContext(CheckboxGroupContext);
150
+ const descriptionId = useId();
151
+ invariant(value === void 0 || group, "A checkbox with value must belong to a CheckboxGroup.");
152
+ const selected = value === void 0 ? checked : group.values.includes(value);
153
+ return /* @__PURE__ */ jsxs("label", {
154
+ "data-atbl-focus": "ring",
155
+ "data-atbl-control": "action",
156
+ className: classNames("altertable-checkbox", className),
157
+ children: [
158
+ /* @__PURE__ */ jsx("input", {
159
+ type: "checkbox",
160
+ value,
161
+ checked: selected,
162
+ "aria-label": label,
163
+ "aria-describedby": description ? descriptionId : void 0,
164
+ disabled: disabled || group?.disabled,
165
+ onChange: (event) => {
166
+ if (value === void 0) onChange(event.currentTarget.checked);
167
+ else group.onChange(value, event.currentTarget.checked);
168
+ }
169
+ }),
170
+ /* @__PURE__ */ jsx(SelectionMark, { selected }),
171
+ /* @__PURE__ */ jsxs("span", { children: [label, description && /* @__PURE__ */ jsx("small", {
172
+ id: descriptionId,
173
+ children: description
174
+ })] })
175
+ ]
176
+ });
177
+ }
178
+ //#endregion
146
179
  //#region src/ui/chart-data.ts
147
180
  function validateChartIds(kind, items) {
148
181
  const ids = /* @__PURE__ */ new Set();
@@ -741,6 +774,81 @@ function timeTicks(model, width) {
741
774
  };
742
775
  }
743
776
  //#endregion
777
+ //#region src/ui/use-chart-cursor-group.tsx
778
+ const groupBrand = Symbol("ChartCursorGroup");
779
+ const stores = /* @__PURE__ */ new WeakMap();
780
+ function createGroup() {
781
+ const group = { [groupBrand]: true };
782
+ let cursor = null;
783
+ const listeners = /* @__PURE__ */ new Set();
784
+ function notify() {
785
+ for (const listener of listeners) listener();
786
+ }
787
+ stores.set(group, {
788
+ snapshot: () => cursor,
789
+ subscribe: (listener) => {
790
+ listeners.add(listener);
791
+ return () => {
792
+ listeners.delete(listener);
793
+ };
794
+ },
795
+ publish: (source, time) => {
796
+ if (!Number.isFinite(time) || cursor?.source === source && cursor.time === time) return;
797
+ cursor = {
798
+ source,
799
+ time
800
+ };
801
+ notify();
802
+ },
803
+ clear: (source) => {
804
+ if (cursor?.source !== source) return;
805
+ cursor = null;
806
+ notify();
807
+ }
808
+ });
809
+ return group;
810
+ }
811
+ /** Creates a stable shared mouse-hover cursor handle. Pass it explicitly to each participating chart's cursorGroup prop.
812
+ * Peers indicate exact timestamp matches while tooltips remain local. Mouse leave clears the cursor.
813
+ * Each hook call creates an independent group; handles can be passed through component props.
814
+ * @example
815
+ * function Dashboard() {
816
+ * const operations = useChartCursorGroup();
817
+ * const samples = [{ id: 'noon', label: '12:00', time: 1767268800000, value: 42 }];
818
+ * return <>
819
+ * <BarChart cursorGroup={operations} items={samples} unit="requests" ariaLabel="Traffic" />
820
+ * <LineChart cursorGroup={operations} items={samples} unit="ms" ariaLabel="Latency" />
821
+ * </>;
822
+ * }
823
+ */
824
+ function useChartCursorGroup() {
825
+ const [group] = useState(createGroup);
826
+ return group;
827
+ }
828
+ function emptySnapshot() {
829
+ return null;
830
+ }
831
+ function emptySubscribe() {
832
+ return () => {};
833
+ }
834
+ function useLinkedChartCursor(group) {
835
+ const store = group == null ? void 0 : stores.get(group);
836
+ const cursor = useSyncExternalStore(store?.subscribe ?? emptySubscribe, store?.snapshot ?? emptySnapshot, emptySnapshot);
837
+ const id = useId();
838
+ const setTime = useCallback((time) => {
839
+ if (time != null) store?.publish(id, time);
840
+ else store?.clear(id);
841
+ }, [store, id]);
842
+ const reset = useCallback(() => store?.clear(id), [store, id]);
843
+ useEffect(() => reset, [reset]);
844
+ return {
845
+ time: cursor?.source !== id ? cursor?.time : void 0,
846
+ setTime,
847
+ reset
848
+ };
849
+ }
850
+ const ChartCursorChartContext = createContext(null);
851
+ //#endregion
744
852
  //#region src/ui/chart-date-axis.tsx
745
853
  const ChartDateAxesContext = createContext(null);
746
854
  function ChartDateAxes({ data, children }) {
@@ -795,6 +903,45 @@ const xAxisDefaults = {
795
903
  axisLine: { stroke: "var(--atbl-border)" },
796
904
  tick: { fontSize: "var(--atbl-type-meta-size)" }
797
905
  };
906
+ function LinkedTimeCursor({ times, axisId }) {
907
+ const context = useContext(ChartCursorChartContext);
908
+ const label = useActiveTooltipLabel();
909
+ const active = useIsTooltipActive();
910
+ const scale = useXAxisScale(axisId);
911
+ const plot = usePlotArea();
912
+ const mouseHover = context?.mouseHover;
913
+ const setTime = context?.cursor.setTime;
914
+ const reset = context?.cursor.reset;
915
+ useEffect(() => {
916
+ if (!mouseHover || !active) reset?.();
917
+ else {
918
+ const time = chartTimestamp(label, true);
919
+ if (time != null && times.includes(time)) setTime?.(time);
920
+ }
921
+ }, [
922
+ mouseHover,
923
+ active,
924
+ label,
925
+ times,
926
+ setTime,
927
+ reset
928
+ ]);
929
+ const time = context?.cursor.time;
930
+ if (time == null || !times.includes(time)) return null;
931
+ const x = scale?.(time);
932
+ if (!plot || x == null || !Number.isFinite(x) || x < plot.x || x > plot.x + plot.width) return null;
933
+ return /* @__PURE__ */ jsx("line", {
934
+ "aria-hidden": "true",
935
+ x1: x,
936
+ x2: x,
937
+ y1: plot.y,
938
+ y2: plot.y + plot.height,
939
+ stroke: "var(--atbl-muted)",
940
+ strokeOpacity: .3,
941
+ pointerEvents: "none",
942
+ "data-atbl-internal-linked-cursor": "true"
943
+ });
944
+ }
798
945
  /**
799
946
  * Infers temporal input from ISO dates, zoned ISO timestamps, and Date values.
800
947
  * Use scale="utc" for epoch milliseconds or type="category" for date-like categories.
@@ -816,6 +963,16 @@ function ChartXAxis(props) {
816
963
  enabled,
817
964
  numeric
818
965
  ]);
966
+ const cursorModel = useMemo(() => {
967
+ if (!data?.length || dataKey == null || props.type === "category") return null;
968
+ if (props.scale !== "utc" && props.scale !== "time") return null;
969
+ return timeModel(data.map((row) => typeof dataKey === "function" ? dataKey(row) : field(row, dataKey)), props.scale === "utc" || props.scale === "time");
970
+ }, [
971
+ data,
972
+ dataKey,
973
+ props.type,
974
+ props.scale
975
+ ]);
819
976
  const register = context?.register;
820
977
  const id = props.xAxisId ?? 0;
821
978
  useEffect(() => model ? register?.(id, model.tooltip) : void 0, [
@@ -823,12 +980,15 @@ function ChartXAxis(props) {
823
980
  id,
824
981
  model
825
982
  ]);
826
- if (!model || dataKey == null) return /* @__PURE__ */ jsx(XAxis, {
983
+ if (!model || dataKey == null) return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(XAxis, {
827
984
  ...xAxisDefaults,
828
985
  ...props
829
- });
986
+ }), cursorModel && /* @__PURE__ */ jsx(LinkedTimeCursor, {
987
+ times: cursorModel.times,
988
+ axisId: id
989
+ })] });
830
990
  const automaticTicks = props.ticks == null && props.tickFormatter == null ? timeTicks(model, plot?.width ?? 400) : null;
831
- return /* @__PURE__ */ jsx(XAxis, {
991
+ return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(XAxis, {
832
992
  ...xAxisDefaults,
833
993
  scale: "utc",
834
994
  domain: model.start === model.end || context?.barAxes.has(id) ? [model.start - model.minimumInterval / 2, model.end + model.minimumInterval / 2] : [model.start, model.end],
@@ -858,7 +1018,10 @@ function ChartXAxis(props) {
858
1018
  ...axisProps,
859
1019
  type: "number",
860
1020
  dataKey: (row) => chartTimestamp(typeof dataKey === "function" ? dataKey(row) : field(row, dataKey), numeric)
861
- });
1021
+ }), /* @__PURE__ */ jsx(LinkedTimeCursor, {
1022
+ times: model.times,
1023
+ axisId: id
1024
+ })] });
862
1025
  }
863
1026
  //#endregion
864
1027
  //#region src/ui/chart-interaction.tsx
@@ -1303,19 +1466,81 @@ function useChartScrollToEnd(items) {
1303
1466
  //#endregion
1304
1467
  //#region src/ui/TrendChart.tsx
1305
1468
  /** Ordered, equally spaced samples; negative values share an explicit zero baseline. */
1306
- function TrendChart({ items, unit, ariaLabel, formatValue = formatNumber, kind, itemActions }) {
1469
+ function TrendChart({ items, unit, ariaLabel, formatValue = formatNumber, kind, itemActions, cursorGroup, horizontalGrid = false }) {
1307
1470
  validateValueChartItems(kind, items);
1308
1471
  const Plot = kind === "area" ? AreaChart$1 : LineChart$1;
1309
1472
  const chartActions = useChartActions();
1473
+ const cursor = useLinkedChartCursor(cursorGroup);
1474
+ const linkedItem = items.find((item) => item.time === cursor.time && cursor.time != null);
1310
1475
  const [activeIndex, setActiveIndex] = useState();
1476
+ const [nearestIndex, setNearestIndex] = useState();
1477
+ const [mouseVisible, setMouseVisible] = useState(false);
1478
+ const nearest = useRef(void 0);
1479
+ const points = useRef(/* @__PURE__ */ new Map());
1480
+ const plotRef = useRef(null);
1481
+ const canvasRef = useRef(null);
1482
+ const highlightedIndex = mouseVisible ? nearestIndex : activeIndex;
1311
1483
  const scrollport = useChartScrollToEnd(items);
1312
1484
  const menuTriggers = useRef(/* @__PURE__ */ new Map());
1313
1485
  const magnitude = items.reduce((max, item) => Math.max(max, Math.abs(item.value)), 1);
1314
1486
  const low = items.reduce((min, item) => Math.min(min, item.value / magnitude), 0);
1315
1487
  const high = items.reduce((max, item) => Math.max(max, item.value / magnitude), 0);
1488
+ function screenPoint(index) {
1489
+ if (index == null) return null;
1490
+ const point = points.current.get(index);
1491
+ const matrix = plotRef.current?.querySelector("svg")?.getScreenCTM();
1492
+ return point && matrix ? new DOMPoint(point.x, point.y).matrixTransform(matrix) : null;
1493
+ }
1494
+ function inspectNearest(event) {
1495
+ if (event.pointerType !== "mouse") return;
1496
+ const matrix = plotRef.current?.querySelector("svg")?.getScreenCTM();
1497
+ if (!matrix) return;
1498
+ let distance = Infinity;
1499
+ let selected;
1500
+ const viewport = scrollport.current?.getBoundingClientRect();
1501
+ const overLabels = event.clientY >= (plotRef.current?.getBoundingClientRect().top ?? 0) + 220;
1502
+ for (let index = 0; index < items.length; index++) {
1503
+ const sample = points.current.get(index);
1504
+ if (!sample) continue;
1505
+ const point = new DOMPoint(sample.x, sample.y).matrixTransform(matrix);
1506
+ if (viewport && (point.x < viewport.left || point.x > viewport.right)) continue;
1507
+ const candidate = overLabels ? Math.abs(point.x - event.clientX) : Math.hypot(point.x - event.clientX, point.y - event.clientY);
1508
+ if (candidate < distance) {
1509
+ distance = candidate;
1510
+ selected = index;
1511
+ }
1512
+ }
1513
+ nearest.current = selected;
1514
+ setNearestIndex(selected);
1515
+ cursor.setTime(selected == null ? void 0 : items[selected]?.time);
1516
+ }
1517
+ function inspectAction(event) {
1518
+ if (!mouseVisible || nearest.current == null || !(event.target instanceof Element)) return;
1519
+ if (event.clientY >= (plotRef.current?.getBoundingClientRect().top ?? 0) + 220) return;
1520
+ if (event.type === "click" && event.detail === 0) return;
1521
+ if (event.type === "contextmenu" && event.clientX === 0 && event.clientY === 0) return;
1522
+ const target = event.target.closest(".altertable-trend-point");
1523
+ const selected = plotRef.current?.querySelectorAll(".altertable-trend-point")[nearest.current];
1524
+ if (!target || !selected || target === selected) return;
1525
+ event.preventDefault();
1526
+ event.stopPropagation();
1527
+ if (event.type === "click") selected.click();
1528
+ else selected.dispatchEvent(new MouseEvent("contextmenu", {
1529
+ bubbles: true,
1530
+ cancelable: true,
1531
+ button: 2,
1532
+ clientX: event.clientX,
1533
+ clientY: event.clientY
1534
+ }));
1535
+ }
1316
1536
  return /* @__PURE__ */ jsxs("section", {
1317
1537
  className: "altertable-trend-chart",
1318
1538
  "aria-label": ariaLabel,
1539
+ onPointerLeave: cursor.reset,
1540
+ onKeyDownCapture: cursor.reset,
1541
+ onPointerDownCapture: (event) => {
1542
+ if (event.pointerType !== "mouse") cursor.reset();
1543
+ },
1319
1544
  children: [
1320
1545
  items.length === 0 && /* @__PURE__ */ jsx("span", { children: "No data" }),
1321
1546
  items.length > 0 && /* @__PURE__ */ jsx(Fragment$1, { children: /* @__PURE__ */ jsx("div", {
@@ -1323,10 +1548,12 @@ function TrendChart({ items, unit, ariaLabel, formatValue = formatNumber, kind,
1323
1548
  ref: scrollport,
1324
1549
  children: /* @__PURE__ */ jsxs("div", {
1325
1550
  className: "altertable-trend-plot",
1551
+ ref: plotRef,
1326
1552
  style: { minWidth: items.length * 40 },
1327
1553
  children: [/* @__PURE__ */ jsx("div", {
1328
1554
  className: "altertable-chart-canvas",
1329
1555
  "aria-hidden": "true",
1556
+ ref: canvasRef,
1330
1557
  children: /* @__PURE__ */ jsxs(Plot, {
1331
1558
  data: items.map((item) => ({
1332
1559
  ...item,
@@ -1357,6 +1584,7 @@ function TrendChart({ items, unit, ariaLabel, formatValue = formatNumber, kind,
1357
1584
  y: 0,
1358
1585
  stroke: "var(--atbl-border)"
1359
1586
  }),
1587
+ horizontalGrid && /* @__PURE__ */ jsx(ChartGrid, {}),
1360
1588
  kind === "area" && /* @__PURE__ */ jsx(ChartArea, {
1361
1589
  dataKey: "plotValue",
1362
1590
  stroke: "none",
@@ -1366,87 +1594,126 @@ function TrendChart({ items, unit, ariaLabel, formatValue = formatNumber, kind,
1366
1594
  }),
1367
1595
  /* @__PURE__ */ jsx(ChartLine, {
1368
1596
  dataKey: "plotValue",
1369
- dot: ({ cx, cy, index }) => index === activeIndex ? /* @__PURE__ */ jsx(ChartDot, {
1370
- cx,
1371
- cy,
1372
- active: index === activeIndex
1373
- }) : /* @__PURE__ */ jsx("g", {}),
1597
+ dot: ({ cx, cy, index }) => {
1598
+ if (index != null && cx != null && cy != null) points.current.set(index, {
1599
+ x: cx,
1600
+ y: cy
1601
+ });
1602
+ return /* @__PURE__ */ jsx("g", {
1603
+ "data-atbl-internal-sample": index,
1604
+ transform: `translate(${cx}, ${cy})`,
1605
+ children: index === highlightedIndex && /* @__PURE__ */ jsx(ChartDot, {
1606
+ cx: 0,
1607
+ cy: 0,
1608
+ active: true
1609
+ })
1610
+ });
1611
+ },
1374
1612
  activeDot: false
1613
+ }),
1614
+ linkedItem && /* @__PURE__ */ jsx(ReferenceLine, {
1615
+ x: linkedItem.id,
1616
+ stroke: "var(--atbl-muted)",
1617
+ strokeOpacity: .3,
1618
+ pointerEvents: "none",
1619
+ "data-atbl-internal-linked-cursor": "true"
1375
1620
  })
1376
1621
  ]
1377
1622
  })
1378
- }), /* @__PURE__ */ jsx("div", {
1379
- className: "altertable-trend-points",
1380
- children: items.map((item, index) => {
1381
- const declaredActions = itemActions?.(item) ?? [];
1382
- const actions = chartActions.actions(declaredActions, item.label, `${formatValue(item.value)} ${unit}`);
1383
- const action = getPrimaryExplorationAction(actions);
1384
- const menuTrigger = { get current() {
1385
- return menuTriggers.current.get(item.id) ?? null;
1386
- } };
1387
- return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsxs("div", {
1388
- className: "altertable-chart-item-actions",
1389
- children: [/* @__PURE__ */ jsx(Tooltip, {
1390
- variant: "chart",
1391
- onOpenChange: (open) => setActiveIndex((current) => open ? index : current === index ? void 0 : current),
1392
- content: /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("strong", { children: item.label }), /* @__PURE__ */ jsxs("span", { children: [
1393
- formatValue(item.value),
1394
- " ",
1395
- unit
1396
- ] })] }),
1397
- className: "altertable-chart-column",
1398
- children: action ? /* @__PURE__ */ jsxs("button", {
1399
- "data-atbl-focus": "ring",
1400
- "data-atbl-control": "action",
1401
- type: "button",
1402
- className: "altertable-trend-point",
1403
- "aria-label": `${item.label}: ${formatValue(item.value)} ${unit}. ${action.label}`,
1404
- ...explorationMenuEvents(menuTrigger),
1405
- onClick: (event) => action.onSelect(event.currentTarget),
1406
- children: [/* @__PURE__ */ jsx("span", { className: "altertable-trend-hit" }), /* @__PURE__ */ jsx("span", {
1407
- className: "altertable-trend-label",
1408
- children: item.label
1409
- })]
1410
- }) : actions.length > 1 ? /* @__PURE__ */ jsxs(MenuTrigger, { children: [/* @__PURE__ */ jsxs(PressButton, {
1411
- ...explorationMenuEvents(menuTrigger),
1623
+ }), /* @__PURE__ */ jsx(ChartTooltip$1, {
1624
+ variant: "chart",
1625
+ touchInspection: false,
1626
+ boundaryRefs: [canvasRef, scrollport],
1627
+ onPointerEnter: inspectNearest,
1628
+ onPointerMove: inspectNearest,
1629
+ onPointerLeave: cursor.reset,
1630
+ onOpenChange: setMouseVisible,
1631
+ anchorRect: () => {
1632
+ const point = screenPoint(nearest.current);
1633
+ return point ? new DOMRect(point.x, point.y, 0, 0) : null;
1634
+ },
1635
+ content: nearestIndex == null || !items[nearestIndex] ? null : /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("strong", { children: items[nearestIndex].label }), /* @__PURE__ */ jsxs("span", { children: [
1636
+ formatValue(items[nearestIndex].value),
1637
+ " ",
1638
+ unit
1639
+ ] })] }),
1640
+ children: /* @__PURE__ */ jsx("div", {
1641
+ className: "altertable-trend-points",
1642
+ onClickCapture: inspectAction,
1643
+ onContextMenuCapture: inspectAction,
1644
+ children: items.map((item, index) => {
1645
+ const declaredActions = itemActions?.(item) ?? [];
1646
+ const actions = chartActions.actions(declaredActions, item.label, `${formatValue(item.value)} ${unit}`);
1647
+ const action = getPrimaryExplorationAction(actions);
1648
+ const menuTrigger = { get current() {
1649
+ return menuTriggers.current.get(item.id) ?? null;
1650
+ } };
1651
+ return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsxs("div", {
1652
+ className: "altertable-chart-item-actions",
1653
+ children: [/* @__PURE__ */ jsx(ChartTooltip$1, {
1654
+ variant: "chart",
1655
+ mouseHover: false,
1656
+ followCursor: false,
1657
+ onOpenChange: (open) => setActiveIndex((current) => open ? index : current === index ? void 0 : current),
1658
+ content: /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("strong", { children: item.label }), /* @__PURE__ */ jsxs("span", { children: [
1659
+ formatValue(item.value),
1660
+ " ",
1661
+ unit
1662
+ ] })] }),
1663
+ className: "altertable-chart-column",
1664
+ children: action ? /* @__PURE__ */ jsxs("button", {
1665
+ "data-atbl-focus": "ring",
1666
+ "data-atbl-control": "action",
1667
+ type: "button",
1668
+ className: "altertable-trend-point",
1669
+ "aria-label": `${item.label}: ${formatValue(item.value)} ${unit}. ${action.label}`,
1670
+ ...explorationMenuEvents(menuTrigger),
1671
+ onClick: (event) => action.onSelect(event.currentTarget),
1672
+ children: [/* @__PURE__ */ jsx("span", { className: "altertable-trend-hit" }), /* @__PURE__ */ jsx("span", {
1673
+ className: "altertable-trend-label",
1674
+ children: item.label
1675
+ })]
1676
+ }) : actions.length > 1 ? /* @__PURE__ */ jsxs(MenuTrigger, { children: [/* @__PURE__ */ jsxs(PressButton, {
1677
+ ...explorationMenuEvents(menuTrigger),
1678
+ ref: (element) => {
1679
+ if (element) menuTriggers.current.set(item.id, element);
1680
+ else menuTriggers.current.delete(item.id);
1681
+ },
1682
+ className: "altertable-trend-point",
1683
+ "aria-label": `${item.label}: ${formatValue(item.value)} ${unit}. Actions`,
1684
+ children: [/* @__PURE__ */ jsx("span", { className: "altertable-trend-hit" }), /* @__PURE__ */ jsx("span", {
1685
+ className: "altertable-trend-label",
1686
+ children: item.label
1687
+ })]
1688
+ }), /* @__PURE__ */ jsx(ExplorationActionMenu, {
1689
+ actions,
1690
+ ariaLabel: `${item.label} actions`,
1691
+ triggerRef: menuTrigger
1692
+ })] }) : /* @__PURE__ */ jsxs("button", {
1693
+ "data-atbl-focus": "ring",
1694
+ "data-atbl-control": "default",
1695
+ type: "button",
1696
+ tabIndex: -1,
1697
+ className: "altertable-trend-point",
1698
+ "aria-label": `${item.label}: ${formatValue(item.value)} ${unit}`,
1699
+ children: [/* @__PURE__ */ jsx("span", { className: "altertable-trend-hit" }), /* @__PURE__ */ jsx("span", {
1700
+ className: "altertable-trend-label",
1701
+ children: item.label
1702
+ })]
1703
+ })
1704
+ }), action && /* @__PURE__ */ jsx(ExplorationActionControl, {
1705
+ contextOnly: declaredActions.length === 1,
1706
+ indicator: "chevron",
1412
1707
  ref: (element) => {
1413
1708
  if (element) menuTriggers.current.set(item.id, element);
1414
1709
  else menuTriggers.current.delete(item.id);
1415
1710
  },
1416
- className: "altertable-trend-point",
1417
- "aria-label": `${item.label}: ${formatValue(item.value)} ${unit}. Actions`,
1418
- children: [/* @__PURE__ */ jsx("span", { className: "altertable-trend-hit" }), /* @__PURE__ */ jsx("span", {
1419
- className: "altertable-trend-label",
1420
- children: item.label
1421
- })]
1422
- }), /* @__PURE__ */ jsx(ExplorationActionMenu, {
1423
1711
  actions,
1424
1712
  ariaLabel: `${item.label} actions`,
1425
- triggerRef: menuTrigger
1426
- })] }) : /* @__PURE__ */ jsxs("button", {
1427
- "data-atbl-focus": "ring",
1428
- "data-atbl-control": "default",
1429
- type: "button",
1430
- tabIndex: -1,
1431
- className: "altertable-trend-point",
1432
- "aria-label": `${item.label}: ${formatValue(item.value)} ${unit}`,
1433
- children: [/* @__PURE__ */ jsx("span", { className: "altertable-trend-hit" }), /* @__PURE__ */ jsx("span", {
1434
- className: "altertable-trend-label",
1435
- children: item.label
1436
- })]
1437
- })
1438
- }), action && /* @__PURE__ */ jsx(ExplorationActionControl, {
1439
- contextOnly: declaredActions.length === 1,
1440
- indicator: "chevron",
1441
- ref: (element) => {
1442
- if (element) menuTriggers.current.set(item.id, element);
1443
- else menuTriggers.current.delete(item.id);
1444
- },
1445
- actions,
1446
- ariaLabel: `${item.label} actions`,
1447
- hidePrimary: Boolean(action)
1448
- })]
1449
- }) }, item.id);
1713
+ hidePrimary: Boolean(action)
1714
+ })]
1715
+ }) }, item.id);
1716
+ })
1450
1717
  })
1451
1718
  })]
1452
1719
  })
@@ -1712,7 +1979,7 @@ function scale(values) {
1712
1979
  * Negative and constant coordinates are supported. Axis labels and units describe
1713
1980
  * tooltips as well as the plot; formatX/formatY format ticks and tooltip values.
1714
1981
  * Compose inside VisualizationWidget; hover/touch tooltips need no caller state. */
1715
- function ScatterChart({ items, xLabel, yLabel, xUnit, yUnit, ariaLabel, formatX = formatNumber$1, formatY = formatNumber$1 }) {
1982
+ function ScatterChart({ items, xLabel, yLabel, xUnit, yUnit, ariaLabel, formatX = formatNumber$1, formatY = formatNumber$1, horizontalGrid = true }) {
1716
1983
  validateScatterChartItems(items);
1717
1984
  const xScale = scale(items.map((item) => item.x));
1718
1985
  const yScale = scale(items.map((item) => item.y));
@@ -1731,7 +1998,10 @@ function ScatterChart({ items, xLabel, yLabel, xUnit, yUnit, ariaLabel, formatX
1731
1998
  children: [
1732
1999
  yScale.ticks.map((value, index) => /* @__PURE__ */ jsx("div", {
1733
2000
  className: "altertable-scatter-gridline",
1734
- style: { bottom: `${index * 50}%` },
2001
+ style: {
2002
+ bottom: `${index * 50}%`,
2003
+ borderTopStyle: horizontalGrid ? void 0 : "none"
2004
+ },
1735
2005
  "aria-hidden": "true",
1736
2006
  children: /* @__PURE__ */ jsx("span", {
1737
2007
  title: formatY(value),
@@ -1792,29 +2062,87 @@ function ScatterChart({ items, xLabel, yLabel, xUnit, yUnit, ariaLabel, formatX
1792
2062
  }
1793
2063
  //#endregion
1794
2064
  //#region src/ui/BarChart.tsx
2065
+ const timeTickIntervals = [
2066
+ 6e4,
2067
+ 12e4,
2068
+ 3e5,
2069
+ 6e5,
2070
+ 9e5,
2071
+ 18e5,
2072
+ 36e5,
2073
+ 72e5,
2074
+ 216e5,
2075
+ 432e5,
2076
+ 864e5,
2077
+ 1728e5,
2078
+ 6048e5,
2079
+ 12096e5
2080
+ ];
2081
+ function timeTickIndices(items, width) {
2082
+ if (items.length === 1) return /* @__PURE__ */ new Set([0]);
2083
+ if (items.length < 2 || width <= 0) return /* @__PURE__ */ new Set();
2084
+ const slotWidth = width / items.length;
2085
+ const cadence = (items.at(-1).time - items[0].time) / (items.length - 1);
2086
+ const minimumInterval = Math.max(cadence, 100 / slotWidth * cadence);
2087
+ const interval = timeTickIntervals.find((candidate) => candidate >= minimumInterval) ?? Math.ceil(minimumInterval / timeTickIntervals.at(-1)) * timeTickIntervals.at(-1);
2088
+ const indices = /* @__PURE__ */ new Set();
2089
+ const stride = Math.max(1, Math.ceil(interval / cadence));
2090
+ const count = Math.max(1, Math.min(Math.floor((items.length - 1) / stride) + 1, Math.floor(Math.max(0, width - 60) / (stride * slotWidth)) + 1));
2091
+ const start = Math.floor((items.length - 1 - (count - 1) * stride) / 2);
2092
+ for (let tick = 0; tick < count; tick++) indices.add(start + tick * stride);
2093
+ return indices;
2094
+ }
1795
2095
  /** Nonnegative category values. Compose inside VisualizationWidget for a titled panel.
1796
2096
  * Owns hover/touch tooltips; no selection state or keyboard navigation. */
1797
- function BarChart({ items, unit, ariaLabel, formatValue = formatNumber, itemActions }) {
2097
+ function BarChart({ items, unit, ariaLabel, formatValue = formatNumber, itemActions, cursorGroup, horizontalGrid = false }) {
1798
2098
  validateValueChartItems("bar", items);
1799
2099
  const chartActions = useChartActions();
2100
+ const cursor = useLinkedChartCursor(cursorGroup);
2101
+ const linkedItem = items.find((item) => item.time === cursor.time && cursor.time != null);
1800
2102
  const [activeId, setActiveId] = useState();
2103
+ const [viewportWidth, setViewportWidth] = useState(0);
1801
2104
  const scrollport = useChartScrollToEnd(items);
2105
+ const plotRef = useRef(null);
2106
+ const canvasRef = useRef(null);
1802
2107
  const menuTriggers = useRef(/* @__PURE__ */ new Map());
1803
2108
  const maximum = items.reduce((max, item) => Math.max(max, item.value), 1);
2109
+ const compactTimeAxis = items.length > 0 && items.every((item, index) => typeof item.time === "number" && Number.isFinite(item.time) && (index === 0 || item.time > items[index - 1].time)) && !itemActions;
2110
+ const minimumSlotWidth = compactTimeAxis ? 3.5 : 45;
2111
+ const plotWidth = Math.max(viewportWidth, items.length * minimumSlotWidth);
2112
+ const ticks = compactTimeAxis ? timeTickIndices(items, plotWidth) : null;
2113
+ useLayoutEffect(() => {
2114
+ const element = scrollport.current;
2115
+ if (!element) return;
2116
+ function updateWidth() {
2117
+ setViewportWidth(Math.floor(element.getBoundingClientRect().width));
2118
+ }
2119
+ updateWidth();
2120
+ const observer = new ResizeObserver(updateWidth);
2121
+ observer.observe(element);
2122
+ return () => observer.disconnect();
2123
+ }, [scrollport]);
1804
2124
  return /* @__PURE__ */ jsxs("section", {
1805
2125
  className: "altertable-selectable-bars",
1806
2126
  "aria-label": ariaLabel,
2127
+ onPointerLeave: cursor.reset,
2128
+ onKeyDownCapture: cursor.reset,
2129
+ onPointerDownCapture: (event) => {
2130
+ if (event.pointerType !== "mouse") cursor.reset();
2131
+ },
1807
2132
  children: [
1808
2133
  items.length === 0 && /* @__PURE__ */ jsx("span", { children: "No data" }),
1809
2134
  /* @__PURE__ */ jsx("div", {
1810
2135
  className: "altertable-selectable-bars-scroll",
2136
+ "data-time-axis": compactTimeAxis || void 0,
1811
2137
  ref: scrollport,
1812
2138
  children: /* @__PURE__ */ jsxs("div", {
1813
2139
  className: "altertable-selectable-bars-plot",
1814
- style: { minWidth: items.length * 45 },
2140
+ ref: plotRef,
2141
+ style: { width: plotWidth },
1815
2142
  children: [/* @__PURE__ */ jsx("div", {
1816
2143
  className: "altertable-chart-canvas",
1817
2144
  "aria-hidden": "true",
2145
+ ref: canvasRef,
1818
2146
  children: /* @__PURE__ */ jsxs(BarChart$1, {
1819
2147
  data: items.map((item) => ({
1820
2148
  ...item,
@@ -1843,19 +2171,32 @@ function BarChart({ items, unit, ariaLabel, formatValue = formatNumber, itemActi
1843
2171
  domain: [0, 1],
1844
2172
  allowDataOverflow: true
1845
2173
  }),
2174
+ horizontalGrid && /* @__PURE__ */ jsx(ChartGrid, {}),
1846
2175
  /* @__PURE__ */ jsx(ChartBar, {
1847
2176
  dataKey: "plotValue",
1848
2177
  minPointSize: (value) => (value ?? 0) > 0 ? 7 : 0,
2178
+ background: linkedItem ? ({ index, x, y, width, height }) => /* @__PURE__ */ jsx("g", { children: items[index]?.id === linkedItem.id && /* @__PURE__ */ jsx("rect", {
2179
+ x,
2180
+ y,
2181
+ width,
2182
+ height,
2183
+ fill: "var(--atbl-muted)",
2184
+ fillOpacity: .14,
2185
+ pointerEvents: "none",
2186
+ "aria-hidden": "true",
2187
+ "data-atbl-internal-linked-cursor": "true"
2188
+ }) }) : false,
1849
2189
  children: items.map((item) => /* @__PURE__ */ jsx(Cell, {
1850
2190
  fill: chartBarFill,
1851
- opacity: activeId === item.id ? .75 : 1
2191
+ opacity: activeId === item.id ? .75 : 1,
2192
+ "data-atbl-internal-bar-id": item.id
1852
2193
  }, item.id))
1853
2194
  })
1854
2195
  ]
1855
2196
  })
1856
2197
  }), /* @__PURE__ */ jsx("div", {
1857
2198
  className: "altertable-selectable-bars-items",
1858
- children: items.map((item) => {
2199
+ children: items.map((item, index) => {
1859
2200
  const actions = chartActions.actions(itemActions?.(item) ?? [], item.label, `${formatValue(item.value)} ${unit}`);
1860
2201
  const action = getPrimaryExplorationAction(actions);
1861
2202
  const menuTrigger = { get current() {
@@ -1863,8 +2204,20 @@ function BarChart({ items, unit, ariaLabel, formatValue = formatNumber, itemActi
1863
2204
  } };
1864
2205
  return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsxs("div", {
1865
2206
  className: "altertable-chart-item-actions",
1866
- children: [/* @__PURE__ */ jsx(Tooltip, {
2207
+ onPointerMove: (event) => {
2208
+ if (event.pointerType === "mouse") cursor.setTime(item.time);
2209
+ },
2210
+ children: [/* @__PURE__ */ jsx(ChartTooltip$1, {
1867
2211
  variant: "chart",
2212
+ followCursor: false,
2213
+ boundaryRefs: [canvasRef, scrollport],
2214
+ anchorRect: (trigger) => {
2215
+ const bar = plotRef.current?.querySelector(`[data-atbl-internal-bar-id="${CSS.escape(item.id)}"]`);
2216
+ const bounds = bar?.getBoundingClientRect() ?? trigger?.getBoundingClientRect();
2217
+ if (!bounds) return null;
2218
+ const top = bar ? bounds.top : bounds.top + 220;
2219
+ return new DOMRect(bounds.left + bounds.width / 2, top, 0, 0);
2220
+ },
1868
2221
  onOpenChange: (open) => setActiveId((current) => open ? item.id : current === item.id ? void 0 : current),
1869
2222
  content: /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("strong", { children: item.label }), /* @__PURE__ */ jsxs("span", { children: [
1870
2223
  formatValue(item.value),
@@ -1901,6 +2254,7 @@ function BarChart({ items, unit, ariaLabel, formatValue = formatNumber, itemActi
1901
2254
  })
1902
2255
  }), /* @__PURE__ */ jsx("div", {
1903
2256
  className: "altertable-chart-item-label-row",
2257
+ "data-time-tick": ticks?.has(index) || void 0,
1904
2258
  children: actions.length ? /* @__PURE__ */ jsxs(MenuTrigger, { children: [/* @__PURE__ */ jsxs(PressButton, {
1905
2259
  className: "altertable-selectable-bars-label",
1906
2260
  variant: "ghost",
@@ -2121,6 +2475,9 @@ function findNearestSeriesId(hoveredSeriesId, points, position) {
2121
2475
  }
2122
2476
  return selected;
2123
2477
  }
2478
+ function hasAuthoredGrid(children) {
2479
+ return Children.toArray(children).some((child) => isValidElement(child) && (child.type === ChartGrid || child.type === CartesianGrid || child.type === Fragment && hasAuthoredGrid(child.props.children)));
2480
+ }
2124
2481
  /** Compose Cartesian series inside VisualizationWidget. Defaults to responsive
2125
2482
  * full width and 300px height. Children retain native Recharts props and behavior,
2126
2483
  * including stacking, numeric/time axes, missing values, tooltips, and keyboard
@@ -2128,11 +2485,14 @@ function findNearestSeriesId(hoveredSeriesId, points, position) {
2128
2485
  * for stacks. Preserve missing measures as null and choose connectNulls deliberately.
2129
2486
  * Use public chart tokens for series colors. Dataset bindings own
2130
2487
  * loading, empty results, evidence, and CSV; this primitive owns only the plot. */
2131
- function ComposedChartRoot({ data, ariaLabel, valueFormat, width = "100%", height = 300, responsive = true, className, ...props }) {
2488
+ function ComposedChartRoot({ data, ariaLabel, valueFormat, cursorGroup, horizontalGrid = false, children, width = "100%", height = 300, responsive = true, className, ...props }) {
2489
+ const cursor = useLinkedChartCursor(cursorGroup);
2490
+ const [mouseHover, setMouseHover] = useState(false);
2132
2491
  const [hasPointerFocus, setHasPointerFocus] = useState(false);
2133
2492
  const [isPointerInspection, setIsPointerInspection] = useState(false);
2134
2493
  const [hoveredSeriesId, setHoveredSeriesId] = useState(null);
2135
2494
  const [pointerPosition, setPointerPosition] = useState(null);
2495
+ const latestPointerPosition = useRef(null);
2136
2496
  const [points, setPoints] = useState(() => /* @__PURE__ */ new Map());
2137
2497
  const registerPoint = useCallback((id, x, y) => {
2138
2498
  setPoints((current) => new Map(current).set(id, {
@@ -2145,7 +2505,11 @@ function ComposedChartRoot({ data, ariaLabel, valueFormat, width = "100%", heigh
2145
2505
  return next;
2146
2506
  });
2147
2507
  }, []);
2508
+ useEffect(() => {
2509
+ setPointerPosition(latestPointerPosition.current);
2510
+ }, [points]);
2148
2511
  function trackPointer(event) {
2512
+ setMouseHover(event.pointerType === "mouse");
2149
2513
  const svg = event.currentTarget.querySelector("svg[role=\"application\"]");
2150
2514
  if (!(svg instanceof SVGSVGElement) || !(event.target instanceof Node) || !svg.contains(event.target)) {
2151
2515
  resetPointerInspection();
@@ -2153,21 +2517,27 @@ function ComposedChartRoot({ data, ariaLabel, valueFormat, width = "100%", heigh
2153
2517
  }
2154
2518
  setIsPointerInspection(true);
2155
2519
  if (hoveredSeriesId != null && !points.has(hoveredSeriesId)) {
2520
+ latestPointerPosition.current = null;
2156
2521
  setPointerPosition(null);
2157
2522
  return true;
2158
2523
  }
2159
2524
  const matrix = svg.getScreenCTM();
2160
2525
  if (!matrix) return true;
2161
2526
  const point = new DOMPoint(event.clientX, event.clientY).matrixTransform(matrix.inverse());
2162
- setPointerPosition({
2527
+ const nextPosition = {
2163
2528
  x: point.x,
2164
2529
  y: point.y
2165
- });
2530
+ };
2531
+ latestPointerPosition.current = nextPosition;
2532
+ setPointerPosition((current) => findNearestSeriesId(hoveredSeriesId, points, current) === findNearestSeriesId(hoveredSeriesId, points, nextPosition) ? current : nextPosition);
2166
2533
  return true;
2167
2534
  }
2168
2535
  function resetPointerInspection() {
2536
+ setMouseHover(false);
2537
+ cursor.reset();
2169
2538
  setIsPointerInspection(false);
2170
2539
  setHoveredSeriesId(null);
2540
+ latestPointerPosition.current = null;
2171
2541
  setPointerPosition(null);
2172
2542
  }
2173
2543
  const activeSeriesId = findNearestSeriesId(hoveredSeriesId, points, pointerPosition);
@@ -2182,50 +2552,57 @@ function ComposedChartRoot({ data, ariaLabel, valueFormat, width = "100%", heigh
2182
2552
  });
2183
2553
  };
2184
2554
  }, []);
2185
- return /* @__PURE__ */ jsx(ChartInteractionContext.Provider, {
2555
+ return /* @__PURE__ */ jsx(ChartCursorChartContext.Provider, {
2186
2556
  value: {
2187
- isPointerInspection,
2188
- activeSeriesId,
2189
- activePoint: activeSeriesId == null ? void 0 : points.get(activeSeriesId),
2190
- registerPoint,
2191
- setHoveredSeriesId,
2192
- seriesCount: seriesIds.size,
2193
- registerSeries
2557
+ cursor,
2558
+ mouseHover
2194
2559
  },
2195
- children: /* @__PURE__ */ jsx("section", {
2196
- className: classNames("altertable-composed-chart", className),
2197
- "aria-label": ariaLabel,
2198
- "data-atbl-internal-pointer-focus": hasPointerFocus || void 0,
2199
- onPointerDownCapture: (event) => {
2200
- setHasPointerFocus(trackPointer(event));
2201
- },
2202
- onPointerOverCapture: trackPointer,
2203
- onPointerMoveCapture: trackPointer,
2204
- onPointerLeave: (event) => {
2205
- if (event.pointerType !== "touch") resetPointerInspection();
2206
- },
2207
- onKeyDownCapture: () => {
2208
- setHasPointerFocus(false);
2209
- resetPointerInspection();
2560
+ children: /* @__PURE__ */ jsx(ChartInteractionContext.Provider, {
2561
+ value: {
2562
+ isPointerInspection,
2563
+ activeSeriesId,
2564
+ activePoint: activeSeriesId == null ? void 0 : points.get(activeSeriesId),
2565
+ registerPoint,
2566
+ setHoveredSeriesId,
2567
+ seriesCount: seriesIds.size,
2568
+ registerSeries
2210
2569
  },
2211
- onBlurCapture: (event) => {
2212
- if (!event.currentTarget.contains(event.relatedTarget)) {
2570
+ children: /* @__PURE__ */ jsx("section", {
2571
+ className: classNames("altertable-composed-chart", className),
2572
+ "aria-label": ariaLabel,
2573
+ "data-atbl-internal-pointer-focus": hasPointerFocus || void 0,
2574
+ onPointerDownCapture: (event) => {
2575
+ setHasPointerFocus(trackPointer(event));
2576
+ },
2577
+ onPointerOverCapture: trackPointer,
2578
+ onPointerMoveCapture: trackPointer,
2579
+ onPointerLeave: (event) => {
2580
+ if (event.pointerType !== "touch") resetPointerInspection();
2581
+ },
2582
+ onKeyDownCapture: () => {
2213
2583
  setHasPointerFocus(false);
2214
2584
  resetPointerInspection();
2215
- }
2216
- },
2217
- children: /* @__PURE__ */ jsx(ChartValueFormat.Provider, {
2218
- value: valueFormat,
2219
- children: /* @__PURE__ */ jsx(ChartDateAxes, {
2220
- data,
2221
- children: /* @__PURE__ */ jsx(ComposedChart$1, {
2222
- "data-atbl-focus": "inset",
2223
- ...props,
2585
+ },
2586
+ onBlurCapture: (event) => {
2587
+ if (!event.currentTarget.contains(event.relatedTarget)) {
2588
+ setHasPointerFocus(false);
2589
+ resetPointerInspection();
2590
+ }
2591
+ },
2592
+ children: /* @__PURE__ */ jsx(ChartValueFormat.Provider, {
2593
+ value: valueFormat,
2594
+ children: /* @__PURE__ */ jsx(ChartDateAxes, {
2224
2595
  data,
2225
- width,
2226
- height,
2227
- responsive,
2228
- "aria-label": ariaLabel
2596
+ children: /* @__PURE__ */ jsxs(ComposedChart$1, {
2597
+ "data-atbl-focus": "inset",
2598
+ ...props,
2599
+ data,
2600
+ width,
2601
+ height,
2602
+ responsive,
2603
+ "aria-label": ariaLabel,
2604
+ children: [horizontalGrid && !hasAuthoredGrid(children) && /* @__PURE__ */ jsx(ChartGrid, {}), children]
2605
+ })
2229
2606
  })
2230
2607
  })
2231
2608
  })
@@ -2318,7 +2695,7 @@ function createFunnelModel(steps, series, chartId) {
2318
2695
  }
2319
2696
  /** Conversion columns with previous-step drop-off, normalized to each series' first step.
2320
2697
  * Owns series highlighting and portion-specific inspection; compose inside VisualizationWidget. */
2321
- function FunnelChart({ steps, series, unit, ariaLabel, className, formatValue = formatNumber }) {
2698
+ function FunnelChart({ steps, series, unit, ariaLabel, className, formatValue = formatNumber, horizontalGrid = true }) {
2322
2699
  const chartId = useSvgId();
2323
2700
  const [highlighted, setHighlighted] = useState(null);
2324
2701
  const clearTimer = useRef(null);
@@ -2388,7 +2765,7 @@ function FunnelChart({ steps, series, unit, ariaLabel, className, formatValue =
2388
2765
  barGap: 1,
2389
2766
  onMouseLeave: clearHighlight,
2390
2767
  children: [
2391
- /* @__PURE__ */ jsx(ComposedChart.CartesianGrid, {}),
2768
+ horizontalGrid && /* @__PURE__ */ jsx(ComposedChart.CartesianGrid, {}),
2392
2769
  /* @__PURE__ */ jsx(ComposedChart.XAxis, {
2393
2770
  dataKey: "label",
2394
2771
  interval: 0,
@@ -2566,7 +2943,7 @@ function createRetentionModel(series, unit, formatValue) {
2566
2943
  }
2567
2944
  /** Query-defined retention curves with count inspection and dotted incomplete periods.
2568
2945
  * Rates are not recomputed from counts. Compose inside VisualizationWidget. */
2569
- function RetentionChart({ series, unit, ariaLabel, className, formatValue = formatNumber }) {
2946
+ function RetentionChart({ series, unit, ariaLabel, className, formatValue = formatNumber, horizontalGrid = true }) {
2570
2947
  const { rows, rowsByOffset, cohorts } = createRetentionModel(series, unit, formatValue);
2571
2948
  return /* @__PURE__ */ jsx("section", {
2572
2949
  className: classNames("altertable-retention-chart", className),
@@ -2576,7 +2953,7 @@ function RetentionChart({ series, unit, ariaLabel, className, formatValue = form
2576
2953
  data: rows,
2577
2954
  ariaLabel: `${ariaLabel} plot`,
2578
2955
  children: [
2579
- /* @__PURE__ */ jsx(ComposedChart.CartesianGrid, {}),
2956
+ horizontalGrid && /* @__PURE__ */ jsx(ComposedChart.CartesianGrid, {}),
2580
2957
  /* @__PURE__ */ jsx(ComposedChart.XAxis, {
2581
2958
  dataKey: "offset",
2582
2959
  type: "number",
@@ -2971,6 +3348,6 @@ const VisualizationWidget = withWidgetBoundary(VisualizationWidget$1);
2971
3348
  const TableWidget = withWidgetBoundary(TableWidget$1);
2972
3349
  const MetricWidget = withWidgetBoundary(MetricWidget$1);
2973
3350
  //#endregion
2974
- export { AboutData, AppIcon, AreaChart, BarChart, ChartLegend, Checkbox, CheckboxGroup, ChoicePicker, ComposedChart, DataApp, DataAppProvider, DataTable, DataTableEmptyRow, DataTableShare, DataTableTimestamp, DataValue, DataWidget, DateDisplay, DateRangePicker, DateTimeRangePicker, DimensionPicker, ExplorationActionControl, FilterActions, FilterBar, FunnelChart, GettingStarted, GlossaryDefinition, GlossaryExplanation, GradientScroll, HelpPopover, JourneyChart, LineChart, LiveControl, Menu, PressButton as MenuButton, MenuItem, MenuPopover, MenuSection, MenuSeparator, MenuTrigger, MetricWidget, NumberField, NumberFilterPicker, NumberRangeField, PieChart, PresentStory, Radio, RadioGroup, RetentionChart, ScatterChart, SearchField, SearchMatch, SearchTypeahead, SectionHeading, SegmentedControl, Select, Sheet, ShimmerText, Tab, TabList, TabPanel, TabPanels, TableWidget, Tabs, TextWidget, Tooltip, TooltipProvider, VariableBar, VisualizationWidget, dateTimeRangePresets, dateTimeRangeVariable, injectDataAppStyles, isPlainKeyEvent, matchSearchText, searchItems, useAppVariables, useDateFormatting, useSvgId, useViewTab };
3351
+ export { AboutData, AppIcon, AreaChart, BarChart, ChartLegend, Checkbox, CheckboxGroup, ChoicePicker, ComposedChart, DataApp, DataAppProvider, DataTable, DataTableEmptyRow, DataTableShare, DataTableTimestamp, DataValue, DataWidget, DateDisplay, DateTimeRangePicker, DimensionPicker, ExplorationActionControl, FilterActions, FilterBar, FunnelChart, GettingStarted, GlossaryDefinition, GlossaryExplanation, GradientScroll, HelpPopover, JourneyChart, LineChart, LiveControl, Menu, PressButton as MenuButton, MenuItem, MenuPopover, MenuSection, MenuSeparator, MenuTrigger, MetricWidget, NumberField, NumberFilterPicker, NumberRangeField, PieChart, PresentStory, Radio, RadioGroup, RetentionChart, ScatterChart, SearchField, SearchMatch, SearchTypeahead, SectionHeading, SegmentedControl, Select, Sheet, ShimmerText, Tab, TabList, TabPanel, TabPanels, TableWidget, Tabs, TextWidget, Tooltip, TooltipProvider, VariableBar, VisualizationWidget, dateTimeRangePresets, dateTimeRangeVariable, injectDataAppStyles, isPlainKeyEvent, matchSearchText, searchItems, useAppVariables, useChartCursorGroup, useDateFormatting, useSvgId, useViewTab };
2975
3352
 
2976
3353
  //# sourceMappingURL=index.js.map