@altertable/data-app-react 0.77.0 → 0.79.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,10 @@
1
- import { $ as DimensionPicker, $t as PressButton, A as LiveControl, B as isPlainKeyEvent, Bt as Sheet, E as DataAppFrame, F as MenuSeparator, Ft as TabList, G as useDeclaredResult, Gt as TooltipSurface, Ht as Tooltip, I as MenuTrigger, It as TabPanel, J as SearchTypeahead, K as FilterActions, Lt as TabPanels, M as MenuItem, N as MenuPopover, Nt as AboutData, P as MenuSection, Pt as Tab, Q as NumberRangeField, Qt as Button$1, Rt as Tabs, S as withWidgetBoundary, T as DataValue, Ut as TooltipProvider, V as createDataHooks, Vt as GradientScroll, Wt as ChartTooltip$1, X as NumberFilterPicker, Xt as AppIcon, Y as SearchField, Z as NumberField, _ as explorationMenuEvents, a as TextWidget$1, at as SelectionMark, b as useChartActions, c as DataTableEmptyRow, ct as dateTimeRangePresets, d as MetricWidget$1, dt as matchSearchText, en as classNames, et as FilterBar, f as VisualizationWidget$1, ft as searchItems, g as ExplorationActionMenu, h as ExplorationActionControl, in as injectDataAppStyles, j as Menu, jt as DataAppProvider, k as PresentStory, kt as ShimmerText, l as DataTableShare, lt as useAppFilters, n as createDataContext, nn as useDateFormatting, nt as Select, o as TableWidget$1, ot as SearchMatch, q as ControlBar, r as chartBarFill, rt as ChoicePicker, s as DataTable, st as dateTimeRangeFilter, t as SectionHeading, tt as DateTimeRangePicker, u as DataTableTimestamp, v as getPrimaryExplorationAction, x as DataWidget, xt as HelpPopover, y as openExplorationMenu, yt as DateDisplay, zt as useViewTab } from "../chunks/SectionHeading-Bz5RIXit.js";
2
- import { createDataClient } from "@altertable/data-app/client";
1
+ import { $ as ChoicePicker, A as MenuSeparator, B as useDeclaredResult, Bt as Tooltip, D as MenuItem, Dt as DataAppProvider, E as Menu, F as isPlainKeyEvent, Ft as TabPanels, G as NumberFilterPicker, H as ControlBar, Ht as ChartTooltip$1, I as createDataHooks, It as Tabs, J as DimensionPicker, Jt as AppIcon, K as NumberField, Lt as useViewTab, Mt as Tab, Nt as TabList, O as MenuPopover, Pt as TabPanel, Qt as classNames, Rt as Sheet, T as LiveControl, Tt as ShimmerText, U as SearchTypeahead, Ut as TooltipSurface, V as FilterActions, Vt as TooltipProvider, W as SearchField, X as DateTimeRangePicker, Xt as Button$1, Y as FilterBar, Z as Select, Zt as PressButton, _t as HelpPopover, a as DataTable, at as useAppFilters, b as Notice, c as DataTableTimestamp, ct as searchItems, d as explorationMenuEvents, en as useDateFormatting, f as getPrimaryExplorationAction, h as DataWidget, ht as DateDisplay, it as dateTimeRangePresets, j as MenuTrigger, k as MenuSection, kt as AboutData, l as ExplorationActionControl, m as useChartActions, n as createDataContext, nn as injectDataAppStyles, nt as SearchMatch, o as DataTableEmptyRow, p as openExplorationMenu, q as NumberRangeField, r as chartBarFill, rt as dateTimeRangeFilter, s as DataTableShare, st as matchSearchText, t as SectionHeading, tt as SelectionMark, u as ExplorationActionMenu, w as PresentStory, x as DataAppFrame, zt as GradientScroll } from "../chunks/SectionHeading-BAZB-Fnf.js";
3
2
  import { KEY_SEPARATOR, invariant, validateChoiceOptions } from "@altertable/data-app/internal";
4
- import { Children, Fragment, cloneElement, createContext, isValidElement, useCallback, useContext, useEffect, useId, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
3
+ import { Children, Fragment, cloneElement, createContext, isValidElement, memo, useCallback, useContext, useEffect, useId, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
5
4
  import { Label, Radio as Radio$1, RadioGroup as RadioGroup$1 } from "react-aria-components";
6
5
  import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
7
6
  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, useActiveTooltipLabel, useCartesianChartLayout, useIsTooltipActive, useMargin, useOffset, usePlotArea, useXAxisScale, useYAxisTicks } from "recharts";
7
+ 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, Rectangle, ReferenceArea, ReferenceDot, ReferenceLine, Scatter, Tooltip as Tooltip$1, XAxis, YAxis, ZAxis, useActiveTooltipLabel, useCartesianChartLayout, useIsTooltipActive, useMargin, useOffset, usePlotArea, useXAxisScale, useYAxisTicks } from "recharts";
9
8
  //#region src/ui/StaticDataApp.tsx
10
9
  /** Setup and static screens; fetched data uses the declared-view DataApp. */
11
10
  function DataApp({ csvExport, ...props }) {
@@ -23,15 +22,14 @@ const connectionContext = createDataContext({})({
23
22
  description: "Connection setup",
24
23
  glossary: {}
25
24
  });
26
- const { defineView } = /* @__PURE__ */ createDataHooks(/* @__PURE__ */ createDataClient());
27
- const connectionView = defineView({
28
- dataContext: connectionContext,
29
- operation: "connection",
30
- describeInput: () => "the connection"
31
- });
32
25
  /** Query-backed connection state and next steps for a newly created app. Mount within
33
- * `DataAppProvider` and register `connection: connectionCheck(app.queries)` on the server. */
34
- function GettingStarted({ dataContext }) {
26
+ * `DataAppProvider` and supply the app's registered connection operation. */
27
+ function GettingStarted({ dataContext, client }) {
28
+ const connectionView = useMemo(() => createDataHooks(client).defineView({
29
+ dataContext: connectionContext,
30
+ operation: "connection",
31
+ describeInput: () => "the connection"
32
+ }), [client]);
35
33
  const connection = useDeclaredResult(connectionView);
36
34
  const state = connection.view.kind === "error" || connection.view.kind === "stale-error" ? "error" : connection.refreshing || !connection.snapshot ? "checking" : "connected";
37
35
  return /* @__PURE__ */ jsxs(DataApp, {
@@ -181,6 +179,12 @@ function Checkbox({ label, description, checked, value, onChange, disabled, clas
181
179
  }
182
180
  //#endregion
183
181
  //#region src/ui/chart-data.ts
182
+ /** Match Recharts data keys, including nested paths and literal dotted keys. */
183
+ function chartField(row, key) {
184
+ if (row == null || typeof row !== "object") return void 0;
185
+ if (key in row) return row[key];
186
+ return String(key).replace(/\[(\d+)\]/g, ".$1").split(".").reduce((value, part) => value != null && typeof value === "object" ? value[part] : void 0, row);
187
+ }
184
188
  function validateChartIds(kind, items) {
185
189
  const ids = /* @__PURE__ */ new Set();
186
190
  for (const item of items) {
@@ -201,6 +205,37 @@ function validateScatterChartItems(items) {
201
205
  for (const item of items) invariant(Number.isFinite(item.x) && Number.isFinite(item.y), `scatter chart "${item.id}" requires finite values for x and y.`);
202
206
  }
203
207
  //#endregion
208
+ //#region src/ui/chart-interaction.tsx
209
+ function chartAxisKey(axis, id) {
210
+ return `${axis}:${typeof id}:${id}`;
211
+ }
212
+ const ChartInteractionContext = createContext(null);
213
+ const ChartActiveSampleContext = createContext(null);
214
+ const ChartRegistrationContext = createContext(null);
215
+ function isChartSeriesActive(interaction, seriesId) {
216
+ return !interaction?.isPointerInspection || interaction.seriesCount === 1 || interaction.activeSeriesId === seriesId;
217
+ }
218
+ function useChartSeries(id) {
219
+ const generatedId = useId();
220
+ const interaction = useContext(ChartInteractionContext);
221
+ const registration = useContext(ChartRegistrationContext);
222
+ const seriesId = id ?? generatedId;
223
+ const registerSeries = registration?.registerSeries;
224
+ useEffect(() => registerSeries?.(seriesId), [registerSeries, seriesId]);
225
+ return {
226
+ id: seriesId,
227
+ active: isChartSeriesActive(interaction, seriesId)
228
+ };
229
+ }
230
+ function ChartSeries({ id, children }) {
231
+ const registration = useContext(ChartRegistrationContext);
232
+ return /* @__PURE__ */ jsx("g", {
233
+ onPointerOver: () => registration?.setHoveredSeriesId(id),
234
+ onPointerDown: () => registration?.setHoveredSeriesId(id),
235
+ children
236
+ });
237
+ }
238
+ //#endregion
204
239
  //#region src/ui/time-interval.ts
205
240
  /*!
206
241
  * TypeScript port of d3-time 3.1.0 (ISC), https://github.com/d3/d3-time/tree/v3.1.0
@@ -829,27 +864,37 @@ function useChartCursorGroup() {
829
864
  const [group] = useState(createGroup);
830
865
  return group;
831
866
  }
832
- function emptySnapshot() {
833
- return null;
834
- }
835
867
  function emptySubscribe() {
836
868
  return () => {};
837
869
  }
870
+ const noLinkedChartCursor = {
871
+ setTime: () => {},
872
+ reset: () => {},
873
+ subscribe: emptySubscribe,
874
+ peerTime: () => void 0
875
+ };
838
876
  function useLinkedChartCursor(group) {
839
877
  const store = group == null ? void 0 : stores.get(group);
840
- const cursor = useSyncExternalStore(store?.subscribe ?? emptySubscribe, store?.snapshot ?? emptySnapshot, emptySnapshot);
841
878
  const id = useId();
842
- const setTime = useCallback((time) => {
843
- if (time != null) store?.publish(id, time);
844
- else store?.clear(id);
845
- }, [store, id]);
846
- const reset = useCallback(() => store?.clear(id), [store, id]);
847
- useEffect(() => reset, [reset]);
848
- return {
849
- time: cursor?.source !== id ? cursor?.time : void 0,
850
- setTime,
851
- reset
852
- };
879
+ const cursor = useMemo(() => store ? {
880
+ setTime: (time) => {
881
+ if (time != null) store.publish(id, time);
882
+ else store.clear(id);
883
+ },
884
+ reset: () => store.clear(id),
885
+ subscribe: store.subscribe,
886
+ peerTime: () => {
887
+ const current = store.snapshot();
888
+ return current?.source !== id ? current?.time : void 0;
889
+ }
890
+ } : noLinkedChartCursor, [store, id]);
891
+ useEffect(() => cursor.reset, [cursor]);
892
+ return cursor;
893
+ }
894
+ /** Subscribes to a derived peer cursor value. Return a primitive so only the
895
+ * marks whose value changes re-render while the pointer moves. */
896
+ function useLinkedCursorValue(cursor, select) {
897
+ return useSyncExternalStore(cursor.subscribe, () => select(cursor.peerTime()), () => select(void 0));
853
898
  }
854
899
  const ChartCursorChartContext = createContext(null);
855
900
  //#endregion
@@ -876,7 +921,7 @@ function ChartDateAxes({ data, children }) {
876
921
  return next;
877
922
  });
878
923
  }, []);
879
- return /* @__PURE__ */ jsx(ChartDateAxesContext.Provider, {
924
+ return /* @__PURE__ */ jsx(ChartDateAxesContext, {
880
925
  value: {
881
926
  data,
882
927
  formatters,
@@ -894,11 +939,6 @@ function useDateAxisBar(id = 0) {
894
939
  function useDateAxisLabel(id = 0) {
895
940
  return useContext(ChartDateAxesContext)?.formatters.get(id);
896
941
  }
897
- function field(row, key) {
898
- if (row == null || typeof row !== "object") return void 0;
899
- if (key in row) return row[key];
900
- return String(key).replace(/\[(\d+)\]/g, ".$1").split(".").reduce((value, part) => value != null && typeof value === "object" ? value[part] : void 0, row);
901
- }
902
942
  const xAxisDefaults = {
903
943
  interval: "preserveStartEnd",
904
944
  stroke: "var(--atbl-muted)",
@@ -914,24 +954,25 @@ function LinkedTimeCursor({ times, axisId }) {
914
954
  const scale = useXAxisScale(axisId);
915
955
  const plot = usePlotArea();
916
956
  const mouseHover = context?.mouseHover;
917
- const setTime = context?.cursor.setTime;
918
- const reset = context?.cursor.reset;
957
+ const cursor = context?.cursor ?? noLinkedChartCursor;
958
+ const { setTime, reset } = cursor;
959
+ const timeSet = useMemo(() => new Set(times), [times]);
919
960
  useEffect(() => {
920
- if (!mouseHover || !active) reset?.();
961
+ if (!mouseHover || !active) reset();
921
962
  else {
922
963
  const time = chartTimestamp(label, true);
923
- if (time != null && times.includes(time)) setTime?.(time);
964
+ if (time != null && timeSet.has(time)) setTime(time);
924
965
  }
925
966
  }, [
926
967
  mouseHover,
927
968
  active,
928
969
  label,
929
- times,
970
+ timeSet,
930
971
  setTime,
931
972
  reset
932
973
  ]);
933
- const time = context?.cursor.time;
934
- if (time == null || !times.includes(time)) return null;
974
+ const time = useLinkedCursorValue(cursor, (peerTime) => peerTime != null && timeSet.has(peerTime) ? peerTime : void 0);
975
+ if (time == null) return null;
935
976
  const x = scale?.(time);
936
977
  if (!plot || x == null || !Number.isFinite(x) || x < plot.x || x > plot.x + plot.width) return null;
937
978
  return /* @__PURE__ */ jsx("line", {
@@ -949,7 +990,8 @@ function LinkedTimeCursor({ times, axisId }) {
949
990
  /**
950
991
  * Infers temporal input from ISO dates, zoned ISO timestamps, and Date values.
951
992
  * Use scale="utc" for epoch milliseconds or type="category" for date-like categories.
952
- * Explicit tick formatters and tick lists retain authored axis behavior.
993
+ * Explicit tick formatters and tick lists retain authored axis behavior while
994
+ * date-like values still receive readable tooltip labels.
953
995
  */
954
996
  function ChartXAxis(props) {
955
997
  const context = useContext(ChartDateAxesContext);
@@ -958,31 +1000,34 @@ function ChartXAxis(props) {
958
1000
  const { dataKey, ...axisProps } = props;
959
1001
  const numeric = props.scale === "utc";
960
1002
  const enabled = numeric || props.type == null && props.scale == null && props.tickFormatter == null && props.ticks == null;
961
- const model = useMemo(() => {
962
- if (!enabled || !data?.length || dataKey == null) return null;
963
- return timeModel(data.map((row) => typeof dataKey === "function" ? dataKey(row) : field(row, dataKey)), numeric);
964
- }, [
965
- data,
966
- dataKey,
967
- enabled,
968
- numeric
969
- ]);
970
- const cursorModel = useMemo(() => {
971
- if (!data?.length || dataKey == null || props.type === "category") return null;
972
- if (props.scale !== "utc" && props.scale !== "time") return null;
973
- return timeModel(data.map((row) => typeof dataKey === "function" ? dataKey(row) : field(row, dataKey)), props.scale === "utc" || props.scale === "time");
1003
+ const dateLabelModel = useMemo(() => {
1004
+ if (!data?.length || dataKey == null) return null;
1005
+ if (props.type === "category" && props.scale !== "utc") return null;
1006
+ if (props.type === "number" && props.scale !== "utc" && props.scale !== "time") return null;
1007
+ return timeModel(data.map((row) => typeof dataKey === "function" ? dataKey(row) : chartField(row, dataKey)), props.scale === "utc" || props.scale === "time");
974
1008
  }, [
975
1009
  data,
976
1010
  dataKey,
977
1011
  props.type,
978
1012
  props.scale
979
1013
  ]);
1014
+ const model = enabled ? dateLabelModel : null;
1015
+ const cursorModel = props.type !== "category" && (props.scale === "utc" || props.scale === "time") ? dateLabelModel : null;
980
1016
  const register = context?.register;
981
1017
  const id = props.xAxisId ?? 0;
982
- useEffect(() => model ? register?.(id, model.tooltip) : void 0, [
1018
+ const registerCategoryAxis = useContext(ChartRegistrationContext)?.registerCategoryAxis;
1019
+ useLayoutEffect(() => {
1020
+ if (dataKey == null) return;
1021
+ return registerCategoryAxis?.("x", id, dataKey);
1022
+ }, [
1023
+ registerCategoryAxis,
1024
+ id,
1025
+ dataKey
1026
+ ]);
1027
+ useEffect(() => dateLabelModel ? register?.(id, dateLabelModel.tooltip) : void 0, [
983
1028
  register,
984
1029
  id,
985
- model
1030
+ dateLabelModel
986
1031
  ]);
987
1032
  if (!model || dataKey == null) return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(XAxis, {
988
1033
  ...xAxisDefaults,
@@ -1021,38 +1066,13 @@ function ChartXAxis(props) {
1021
1066
  } : xAxisDefaults.tick,
1022
1067
  ...axisProps,
1023
1068
  type: "number",
1024
- dataKey: (row) => chartTimestamp(typeof dataKey === "function" ? dataKey(row) : field(row, dataKey), numeric)
1069
+ dataKey: (row) => chartTimestamp(typeof dataKey === "function" ? dataKey(row) : chartField(row, dataKey), numeric)
1025
1070
  }), /* @__PURE__ */ jsx(LinkedTimeCursor, {
1026
1071
  times: model.times,
1027
1072
  axisId: id
1028
1073
  })] });
1029
1074
  }
1030
1075
  //#endregion
1031
- //#region src/ui/chart-interaction.tsx
1032
- const ChartInteractionContext = createContext(null);
1033
- function isChartSeriesActive(interaction, seriesId) {
1034
- return !interaction?.isPointerInspection || interaction.seriesCount === 1 || interaction.activeSeriesId === seriesId;
1035
- }
1036
- function useChartSeries(id) {
1037
- const generatedId = useId();
1038
- const interaction = useContext(ChartInteractionContext);
1039
- const seriesId = id ?? generatedId;
1040
- const registerSeries = interaction?.registerSeries;
1041
- useEffect(() => registerSeries?.(seriesId), [registerSeries, seriesId]);
1042
- return {
1043
- id: seriesId,
1044
- active: isChartSeriesActive(interaction, seriesId)
1045
- };
1046
- }
1047
- function ChartSeries({ id, children }) {
1048
- const interaction = useContext(ChartInteractionContext);
1049
- return /* @__PURE__ */ jsx("g", {
1050
- onPointerOver: () => interaction?.setHoveredSeriesId(id),
1051
- onPointerDown: () => interaction?.setHoveredSeriesId(id),
1052
- children
1053
- });
1054
- }
1055
- //#endregion
1056
1076
  //#region src/ui/chart-legend-interaction.tsx
1057
1077
  function chartLegendSeriesKey(id, dataKey) {
1058
1078
  if (typeof id === "string" || typeof id === "number") return [
@@ -1302,7 +1322,7 @@ function ChartDot({ active = false, stroke = seriesColor, fill = active ? stroke
1302
1322
  }
1303
1323
  function NearestChartDot({ seriesId, cx, cy, stroke }) {
1304
1324
  const interaction = useContext(ChartInteractionContext);
1305
- const registerPoint = interaction?.registerPoint;
1325
+ const registerPoint = useContext(ChartRegistrationContext)?.registerPoint;
1306
1326
  const legend = useChartLegendSeries(seriesId, void 0);
1307
1327
  useLayoutEffect(() => {
1308
1328
  if (legend.hidden || cx == null || cy == null) return;
@@ -1322,7 +1342,73 @@ function NearestChartDot({ seriesId, cx, cy, stroke }) {
1322
1342
  style: { pointerEvents: "none" }
1323
1343
  }) : null;
1324
1344
  }
1345
+ /** Recharts does not export its bar-shape dispatcher; keep this adapter isolated. */
1346
+ function renderBarShape(option, props) {
1347
+ if (isValidElement(option)) return cloneElement(option, {
1348
+ ...props,
1349
+ ...option.props
1350
+ });
1351
+ if (option === Rectangle) return /* @__PURE__ */ jsx(Rectangle, { ...props });
1352
+ if (typeof option === "function") return option(props, props.index);
1353
+ if (option && typeof option === "object") return /* @__PURE__ */ jsx(Rectangle, {
1354
+ ...props,
1355
+ ...option
1356
+ });
1357
+ return /* @__PURE__ */ jsx(Rectangle, { ...props });
1358
+ }
1359
+ function InspectedBarVisual(inspected) {
1360
+ const interaction = useContext(ChartInteractionContext);
1361
+ const activeBar = useContext(ChartActiveSampleContext)?.activeBar;
1362
+ const selected = Boolean(interaction?.isPointerInspection && activeBar?.seriesId === inspected.seriesId && activeBar.index === inspected.originalDataIndex);
1363
+ return useMemo(() => {
1364
+ const { seriesId: _, shape, activeShape, dimmed, ...props } = inspected;
1365
+ const renderedProps = {
1366
+ ...props,
1367
+ isActive: selected || Boolean(props.isActive),
1368
+ opacity: dimmed ? void 0 : selected ? .75 : props.opacity
1369
+ };
1370
+ const rendered = renderBarShape(selected && activeShape && activeShape !== true ? activeShape : shape, renderedProps);
1371
+ return dimmed ? /* @__PURE__ */ jsx("g", {
1372
+ opacity: .2,
1373
+ children: rendered
1374
+ }) : rendered;
1375
+ }, [inspected, selected]);
1376
+ }
1325
1377
  /** Shared series defaults; native props override every authored choice. */
1378
+ function InspectedBarShape({ seriesId, shape, activeShape, dimmed, ...props }) {
1379
+ const registerBar = useContext(ChartRegistrationContext)?.registerBar;
1380
+ const { x, y, width, height, originalDataIndex, value, payload } = props;
1381
+ const reading = Array.isArray(value) ? value[1] - value[0] : value;
1382
+ useLayoutEffect(() => {
1383
+ if (reading === 0 || width <= 0 || height <= 0) return;
1384
+ return registerBar?.({
1385
+ seriesId,
1386
+ index: originalDataIndex,
1387
+ x,
1388
+ y,
1389
+ width,
1390
+ height,
1391
+ payload
1392
+ });
1393
+ }, [
1394
+ registerBar,
1395
+ seriesId,
1396
+ originalDataIndex,
1397
+ x,
1398
+ y,
1399
+ width,
1400
+ height,
1401
+ reading,
1402
+ payload
1403
+ ]);
1404
+ return /* @__PURE__ */ jsx(InspectedBarVisual, {
1405
+ ...props,
1406
+ seriesId,
1407
+ shape,
1408
+ activeShape,
1409
+ dimmed
1410
+ });
1411
+ }
1326
1412
  function ChartBar(props) {
1327
1413
  useDateAxisBar(props.xAxisId);
1328
1414
  const series = useChartSeries(props.id);
@@ -1332,6 +1418,19 @@ function ChartBar(props) {
1332
1418
  const registerBarAxis = interaction?.registerBarAxis;
1333
1419
  const key = chartLegendSeriesKey(series.id, props.dataKey);
1334
1420
  const axisId = layout === "vertical" ? props.xAxisId ?? 0 : props.yAxisId ?? 0;
1421
+ const inspectStack = props.stackId != null;
1422
+ const inspectedShape = useCallback((shapeProps) => /* @__PURE__ */ jsx(InspectedBarShape, {
1423
+ ...shapeProps,
1424
+ seriesId: series.id,
1425
+ shape: props.shape,
1426
+ activeShape: props.activeBar,
1427
+ dimmed: legend.dimmed
1428
+ }), [
1429
+ series.id,
1430
+ props.shape,
1431
+ props.activeBar,
1432
+ legend.dimmed
1433
+ ]);
1335
1434
  useLayoutEffect(() => key && !props.hide ? registerBarAxis?.(key, axisId) : void 0, [
1336
1435
  registerBarAxis,
1337
1436
  key,
@@ -1349,9 +1448,10 @@ function ChartBar(props) {
1349
1448
  0
1350
1449
  ] : 0,
1351
1450
  maxBarSize: 30,
1352
- activeBar: series.active ? { opacity: .75 } : false,
1353
1451
  isAnimationActive: false,
1354
1452
  ...props,
1453
+ activeBar: inspectStack ? false : props.activeBar ?? (series.active ? { opacity: .75 } : false),
1454
+ shape: inspectStack ? inspectedShape : props.shape,
1355
1455
  id: series.id,
1356
1456
  hide: legend.hidden || props.hide,
1357
1457
  opacity: legend.hidden ? 0 : legend.dimmed ? .2 : props.opacity,
@@ -1456,6 +1556,16 @@ function ChartScatter(props) {
1456
1556
  });
1457
1557
  }
1458
1558
  function ChartYAxis(props) {
1559
+ const registerCategoryAxis = useContext(ChartRegistrationContext)?.registerCategoryAxis;
1560
+ const id = props.yAxisId ?? 0;
1561
+ useLayoutEffect(() => {
1562
+ if (props.dataKey == null) return;
1563
+ return registerCategoryAxis?.("y", id, props.dataKey);
1564
+ }, [
1565
+ registerCategoryAxis,
1566
+ id,
1567
+ props.dataKey
1568
+ ]);
1459
1569
  const format = useContext(ChartValueFormat);
1460
1570
  const formatter = axisValueFormatter((useYAxisTicks(props.yAxisId) ?? []).map((tick) => tick.value).filter((value) => typeof value === "number"), format);
1461
1571
  return /* @__PURE__ */ jsx(YAxis, {
@@ -1469,11 +1579,21 @@ function ChartYAxis(props) {
1469
1579
  });
1470
1580
  }
1471
1581
  function ChartGrid(props) {
1472
- return /* @__PURE__ */ jsx(CartesianGrid, {
1582
+ const vertical = useCartesianChartLayout() === "vertical";
1583
+ const showZero = vertical ? props.vertical === true : props.horizontal === void 0 || props.horizontal === true;
1584
+ return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(CartesianGrid, {
1473
1585
  stroke: "var(--atbl-border)",
1474
1586
  vertical: false,
1475
1587
  ...props
1476
- });
1588
+ }), showZero && /* @__PURE__ */ jsx(ReferenceLine, {
1589
+ ...vertical ? { x: 0 } : { y: 0 },
1590
+ xAxisId: props.xAxisId,
1591
+ yAxisId: props.yAxisId,
1592
+ ifOverflow: "discard",
1593
+ stroke: props.stroke ?? "var(--atbl-muted)",
1594
+ strokeOpacity: props.strokeOpacity ?? .55,
1595
+ strokeWidth: props.strokeWidth ?? 1.5
1596
+ })] });
1477
1597
  }
1478
1598
  function ChartTooltipContent(props) {
1479
1599
  const valueFormat = useContext(ChartValueFormat);
@@ -1537,68 +1657,312 @@ function ChartTooltipContent(props) {
1537
1657
  })
1538
1658
  });
1539
1659
  }
1660
+ function MeasuredTooltipContent({ children, onMeasure }) {
1661
+ const ref = useRef(null);
1662
+ useLayoutEffect(() => {
1663
+ const element = ref.current;
1664
+ if (!element) return;
1665
+ const target = element;
1666
+ function measure() {
1667
+ onMeasure(target.offsetWidth, target.offsetHeight);
1668
+ }
1669
+ measure();
1670
+ if (typeof ResizeObserver === "undefined") return;
1671
+ const observer = new ResizeObserver(measure);
1672
+ observer.observe(element);
1673
+ return () => observer.disconnect();
1674
+ }, [onMeasure]);
1675
+ return /* @__PURE__ */ jsx("span", {
1676
+ ref,
1677
+ style: { display: "block" },
1678
+ children
1679
+ });
1680
+ }
1681
+ function barTooltipPosition(bar, plot, size) {
1682
+ const gap = 10;
1683
+ const right = bar.x + bar.width + gap;
1684
+ const left = bar.x - size.width - gap;
1685
+ const plotRight = plot.x + plot.width;
1686
+ const x = right + size.width <= plotRight ? right : left >= plot.x ? left : Math.max(plot.x, Math.min(right, plotRight - size.width));
1687
+ const edgeInset = Math.min(8, Math.max(0, (plot.height - size.height) / 2));
1688
+ return {
1689
+ x,
1690
+ y: Math.max(plot.y + edgeInset, Math.min(bar.y + bar.height / 2 - size.height / 2, plot.y + plot.height - size.height - edgeInset))
1691
+ };
1692
+ }
1540
1693
  /** Uses the same surface as single-series inspection; Recharts owns interaction. */
1541
1694
  function ChartTooltip(props) {
1542
1695
  const dateLabel = useDateAxisLabel(props.axisId);
1543
1696
  const interaction = useContext(ChartInteractionContext);
1697
+ const sample = useContext(ChartActiveSampleContext);
1544
1698
  const legendInteraction = useContext(ChartLegendInteractionContext);
1699
+ const plot = usePlotArea();
1700
+ const [tooltipSize, setTooltipSize] = useState({
1701
+ width: 0,
1702
+ height: 0
1703
+ });
1704
+ const measureTooltip = useCallback((width, height) => {
1705
+ setTooltipSize((current) => current.width === width && current.height === height ? current : {
1706
+ width,
1707
+ height
1708
+ });
1709
+ }, []);
1545
1710
  const { content: authoredContent, ...tooltipProps } = props;
1711
+ const activeBar = interaction?.isPointerInspection ? sample?.activeBar ?? null : null;
1712
+ const position = activeBar && plot && tooltipSize.width && tooltipSize.height ? barTooltipPosition(activeBar, plot, tooltipSize) : interaction?.isPointerInspection && sample?.activePoint ? { y: sample.activePoint.y } : void 0;
1546
1713
  return /* @__PURE__ */ jsx(Tooltip$1, {
1547
1714
  labelFormatter: dateLabel,
1548
- position: interaction?.isPointerInspection && interaction.activePoint ? { y: interaction.activePoint.y } : void 0,
1715
+ position,
1549
1716
  cursor: false,
1550
1717
  isAnimationActive: false,
1551
1718
  ...tooltipProps,
1719
+ filterNull: activeBar ? false : props.filterNull,
1552
1720
  content: (content) => {
1553
1721
  if (legendInteraction?.suppressPlotInspection) return null;
1722
+ const selectedRow = activeBar?.payload;
1554
1723
  const payload = (interaction?.isPointerInspection && interaction.seriesCount !== 1 && props.shared !== true ? content.payload.filter((entry) => entry.graphicalItemId === interaction.activeSeriesId) : content.payload).filter((entry) => {
1555
1724
  if (!legendInteraction?.focusedKeys) return true;
1556
1725
  const key = chartLegendSeriesKey(entry.graphicalItemId, entry.dataKey);
1557
1726
  return key == null || legendInteraction.focusedKeys.has(key);
1558
1727
  });
1728
+ const selectedPayload = selectedRow == null ? payload : payload.map((entry) => {
1729
+ const key = entry.dataKey;
1730
+ const value = typeof key === "function" ? key(selectedRow) : key == null ? entry.value : chartField(selectedRow, key);
1731
+ return {
1732
+ ...entry,
1733
+ payload: selectedRow,
1734
+ value
1735
+ };
1736
+ });
1737
+ const categoryKey = interaction?.getCategoryDataKey(props.axisId ?? 0);
1738
+ const label = selectedRow == null || categoryKey == null ? content.label : typeof categoryKey === "function" ? categoryKey(selectedRow) : chartField(selectedRow, categoryKey);
1559
1739
  const filtered = {
1560
1740
  ...content,
1561
- payload
1741
+ payload: selectedPayload,
1742
+ label
1562
1743
  };
1563
- if (typeof authoredContent === "function") return authoredContent(filtered);
1564
- if (isValidElement(authoredContent)) return cloneElement(authoredContent, filtered);
1565
- return /* @__PURE__ */ jsx(ChartTooltipContent, { ...filtered });
1744
+ const rendered = typeof authoredContent === "function" ? authoredContent(filtered) : isValidElement(authoredContent) ? cloneElement(authoredContent, filtered) : /* @__PURE__ */ jsx(ChartTooltipContent, { ...filtered });
1745
+ return /* @__PURE__ */ jsx(MeasuredTooltipContent, {
1746
+ onMeasure: measureTooltip,
1747
+ children: rendered
1748
+ });
1566
1749
  }
1567
1750
  });
1568
1751
  }
1569
1752
  //#endregion
1570
1753
  //#region src/ui/use-chart-scroll-to-end.ts
1571
1754
  /** Keep the latest supplied samples visible when the displayed items change. */
1572
- function useChartScrollToEnd(items) {
1755
+ function useChartScrollToEnd(items, enabled = true) {
1573
1756
  const scrollport = useRef(null);
1574
1757
  useLayoutEffect(() => {
1575
1758
  const element = scrollport.current;
1576
- if (element) element.scrollLeft = element.scrollWidth - element.clientWidth;
1577
- }, [items]);
1759
+ if (element && enabled) element.scrollLeft = element.scrollWidth - element.clientWidth;
1760
+ }, [items, enabled]);
1578
1761
  return scrollport;
1579
1762
  }
1580
1763
  //#endregion
1581
1764
  //#region src/ui/TrendChart.tsx
1765
+ const HighlightedSampleContext = createContext(void 0);
1766
+ /** Reads the highlighted index itself, so moving between samples skips the plot. */
1767
+ function TrendSample({ index, cx, cy }) {
1768
+ const highlighted = useContext(HighlightedSampleContext) === index;
1769
+ return /* @__PURE__ */ jsx("g", {
1770
+ "data-atbl-internal-sample": index,
1771
+ transform: `translate(${cx}, ${cy})`,
1772
+ children: highlighted && /* @__PURE__ */ jsx(ChartDot, {
1773
+ cx: 0,
1774
+ cy: 0,
1775
+ active: true
1776
+ })
1777
+ });
1778
+ }
1779
+ function LinkedTrendCursor({ cursor, items }) {
1780
+ const id = useLinkedCursorValue(cursor, (time) => time == null ? void 0 : items.find((item) => item.time === time)?.id);
1781
+ return id == null ? null : /* @__PURE__ */ jsx(ReferenceLine, {
1782
+ x: id,
1783
+ stroke: "var(--atbl-muted)",
1784
+ strokeOpacity: .3,
1785
+ pointerEvents: "none",
1786
+ "data-atbl-internal-linked-cursor": "true"
1787
+ });
1788
+ }
1789
+ /** Hit targets and tooltips stay mounted while the pointer moves between samples. */
1790
+ const TrendChartItems = memo(function TrendChartItems({ items, unit, formatValue, itemActions, actions: chartActions, setActiveIndex, onInspectAction, "aria-describedby": describedBy }) {
1791
+ const menuTriggers = useRef(/* @__PURE__ */ new Map());
1792
+ return /* @__PURE__ */ jsx("div", {
1793
+ className: "altertable-trend-points",
1794
+ "aria-describedby": describedBy,
1795
+ onClickCapture: onInspectAction,
1796
+ onContextMenuCapture: onInspectAction,
1797
+ children: items.map((item, index) => {
1798
+ const declaredActions = itemActions?.(item) ?? [];
1799
+ const actions = chartActions(declaredActions, item.label, `${formatValue(item.value)} ${unit}`);
1800
+ const action = getPrimaryExplorationAction(actions);
1801
+ const menuTrigger = { get current() {
1802
+ return menuTriggers.current.get(item.id) ?? null;
1803
+ } };
1804
+ return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsxs("div", {
1805
+ className: "altertable-chart-item-actions",
1806
+ children: [/* @__PURE__ */ jsx(ChartTooltip$1, {
1807
+ variant: "chart",
1808
+ mouseHover: false,
1809
+ followCursor: false,
1810
+ onOpenChange: (open) => setActiveIndex((current) => open ? index : current === index ? void 0 : current),
1811
+ content: /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("strong", { children: item.label }), /* @__PURE__ */ jsxs("span", { children: [
1812
+ formatValue(item.value),
1813
+ " ",
1814
+ unit
1815
+ ] })] }),
1816
+ className: "altertable-chart-column",
1817
+ children: action ? /* @__PURE__ */ jsxs("button", {
1818
+ "data-atbl-focus": "ring",
1819
+ "data-atbl-control": "action",
1820
+ type: "button",
1821
+ className: "altertable-trend-point",
1822
+ "aria-label": `${item.label}: ${formatValue(item.value)} ${unit}. ${action.label}`,
1823
+ ...explorationMenuEvents(menuTrigger),
1824
+ onClick: (event) => action.onSelect(event.currentTarget),
1825
+ children: [/* @__PURE__ */ jsx("span", { className: "altertable-trend-hit" }), /* @__PURE__ */ jsx("span", {
1826
+ className: "altertable-trend-label",
1827
+ children: item.label
1828
+ })]
1829
+ }) : actions.length > 1 ? /* @__PURE__ */ jsxs(MenuTrigger, { children: [/* @__PURE__ */ jsxs(PressButton, {
1830
+ ...explorationMenuEvents(menuTrigger),
1831
+ ref: (element) => {
1832
+ if (element) menuTriggers.current.set(item.id, element);
1833
+ else menuTriggers.current.delete(item.id);
1834
+ },
1835
+ className: "altertable-trend-point",
1836
+ "aria-label": `${item.label}: ${formatValue(item.value)} ${unit}. Actions`,
1837
+ children: [/* @__PURE__ */ jsx("span", { className: "altertable-trend-hit" }), /* @__PURE__ */ jsx("span", {
1838
+ className: "altertable-trend-label",
1839
+ children: item.label
1840
+ })]
1841
+ }), /* @__PURE__ */ jsx(ExplorationActionMenu, {
1842
+ actions,
1843
+ ariaLabel: `${item.label} actions`,
1844
+ triggerRef: menuTrigger
1845
+ })] }) : /* @__PURE__ */ jsxs("button", {
1846
+ "data-atbl-focus": "ring",
1847
+ "data-atbl-control": "default",
1848
+ type: "button",
1849
+ tabIndex: -1,
1850
+ className: "altertable-trend-point",
1851
+ "aria-label": `${item.label}: ${formatValue(item.value)} ${unit}`,
1852
+ children: [/* @__PURE__ */ jsx("span", { className: "altertable-trend-hit" }), /* @__PURE__ */ jsx("span", {
1853
+ className: "altertable-trend-label",
1854
+ children: item.label
1855
+ })]
1856
+ })
1857
+ }), action && /* @__PURE__ */ jsx(ExplorationActionControl, {
1858
+ contextOnly: declaredActions.length === 1,
1859
+ indicator: "chevron",
1860
+ ref: (element) => {
1861
+ if (element) menuTriggers.current.set(item.id, element);
1862
+ else menuTriggers.current.delete(item.id);
1863
+ },
1864
+ actions,
1865
+ ariaLabel: `${item.label} actions`,
1866
+ hidePrimary: Boolean(action)
1867
+ })]
1868
+ }) }, item.id);
1869
+ })
1870
+ });
1871
+ });
1582
1872
  /** Ordered, equally spaced samples; negative values share an explicit zero baseline. */
1583
- function TrendChart({ items, unit, ariaLabel, formatValue = formatNumber, kind, itemActions, cursorGroup, horizontalGrid = false }) {
1873
+ function TrendChart({ items, unit, ariaLabel, formatValue = formatNumber, kind, itemActions, cursorGroup, horizontalGrid = true }) {
1584
1874
  validateValueChartItems(kind, items);
1585
1875
  const Plot = kind === "area" ? AreaChart$1 : LineChart$1;
1586
1876
  const chartActions = useChartActions();
1587
1877
  const cursor = useLinkedChartCursor(cursorGroup);
1588
- const linkedItem = items.find((item) => item.time === cursor.time && cursor.time != null);
1589
1878
  const [activeIndex, setActiveIndex] = useState();
1590
1879
  const [nearestIndex, setNearestIndex] = useState();
1591
1880
  const [mouseVisible, setMouseVisible] = useState(false);
1881
+ const mouseVisibleRef = useRef(false);
1592
1882
  const nearest = useRef(void 0);
1593
1883
  const points = useRef(/* @__PURE__ */ new Map());
1594
1884
  const plotRef = useRef(null);
1595
1885
  const canvasRef = useRef(null);
1596
1886
  const highlightedIndex = mouseVisible ? nearestIndex : activeIndex;
1597
1887
  const scrollport = useChartScrollToEnd(items);
1598
- const menuTriggers = useRef(/* @__PURE__ */ new Map());
1599
- const magnitude = items.reduce((max, item) => Math.max(max, Math.abs(item.value)), 1);
1600
- const low = items.reduce((min, item) => Math.min(min, item.value / magnitude), 0);
1601
- const high = items.reduce((max, item) => Math.max(max, item.value / magnitude), 0);
1888
+ const { data, low, high } = useMemo(() => {
1889
+ const magnitude = items.reduce((max, item) => Math.max(max, Math.abs(item.value)), 1);
1890
+ return {
1891
+ data: items.map((item) => ({
1892
+ ...item,
1893
+ plotValue: item.value / magnitude
1894
+ })),
1895
+ low: items.reduce((min, item) => Math.min(min, item.value / magnitude), 0),
1896
+ high: items.reduce((max, item) => Math.max(max, item.value / magnitude), 0)
1897
+ };
1898
+ }, [items]);
1899
+ const renderSample = useCallback(({ cx, cy, index }) => {
1900
+ if (index != null && cx != null && cy != null) points.current.set(index, {
1901
+ x: cx,
1902
+ y: cy
1903
+ });
1904
+ return /* @__PURE__ */ jsx(TrendSample, {
1905
+ index,
1906
+ cx,
1907
+ cy
1908
+ });
1909
+ }, []);
1910
+ const plot = useMemo(() => /* @__PURE__ */ jsxs(Plot, {
1911
+ data,
1912
+ responsive: true,
1913
+ width: "100%",
1914
+ height: 220,
1915
+ margin: {
1916
+ top: 12,
1917
+ right: 0,
1918
+ bottom: 12,
1919
+ left: 0
1920
+ },
1921
+ accessibilityLayer: false,
1922
+ tabIndex: -1,
1923
+ children: [
1924
+ /* @__PURE__ */ jsx(ChartXAxis, {
1925
+ hide: true,
1926
+ dataKey: "id",
1927
+ scale: "band"
1928
+ }),
1929
+ /* @__PURE__ */ jsx(ChartYAxis, {
1930
+ hide: true,
1931
+ domain: [low, high === low ? low + 1 : high]
1932
+ }),
1933
+ /* @__PURE__ */ jsx(ReferenceLine, {
1934
+ y: 0,
1935
+ stroke: "var(--atbl-border)"
1936
+ }),
1937
+ horizontalGrid && /* @__PURE__ */ jsx(ChartGrid, {}),
1938
+ kind === "area" && /* @__PURE__ */ jsx(ChartArea, {
1939
+ dataKey: "plotValue",
1940
+ stroke: "none",
1941
+ fill: "var(--atbl-chart-1)",
1942
+ dot: false,
1943
+ activeDot: false
1944
+ }),
1945
+ /* @__PURE__ */ jsx(ChartLine, {
1946
+ dataKey: "plotValue",
1947
+ dot: renderSample,
1948
+ activeDot: false
1949
+ }),
1950
+ /* @__PURE__ */ jsx(LinkedTrendCursor, {
1951
+ cursor,
1952
+ items
1953
+ })
1954
+ ]
1955
+ }), [
1956
+ Plot,
1957
+ data,
1958
+ low,
1959
+ high,
1960
+ horizontalGrid,
1961
+ kind,
1962
+ renderSample,
1963
+ cursor,
1964
+ items
1965
+ ]);
1602
1966
  function screenPoint(index) {
1603
1967
  if (index == null) return null;
1604
1968
  const point = points.current.get(index);
@@ -1628,8 +1992,8 @@ function TrendChart({ items, unit, ariaLabel, formatValue = formatNumber, kind,
1628
1992
  setNearestIndex(selected);
1629
1993
  cursor.setTime(selected == null ? void 0 : items[selected]?.time);
1630
1994
  }
1631
- function inspectAction(event) {
1632
- if (!mouseVisible || nearest.current == null || !(event.target instanceof Element)) return;
1995
+ const inspectAction = useCallback((event) => {
1996
+ if (!mouseVisibleRef.current || nearest.current == null || !(event.target instanceof Element)) return;
1633
1997
  if (event.clientY >= (plotRef.current?.getBoundingClientRect().top ?? 0) + 220) return;
1634
1998
  if (event.type === "click" && event.detail === 0) return;
1635
1999
  if (event.type === "contextmenu" && event.clientX === 0 && event.clientY === 0) return;
@@ -1646,7 +2010,7 @@ function TrendChart({ items, unit, ariaLabel, formatValue = formatNumber, kind,
1646
2010
  clientX: event.clientX,
1647
2011
  clientY: event.clientY
1648
2012
  }));
1649
- }
2013
+ }, []);
1650
2014
  return /* @__PURE__ */ jsxs("section", {
1651
2015
  className: "altertable-trend-chart",
1652
2016
  "aria-label": ariaLabel,
@@ -1668,71 +2032,9 @@ function TrendChart({ items, unit, ariaLabel, formatValue = formatNumber, kind,
1668
2032
  className: "altertable-chart-canvas",
1669
2033
  "aria-hidden": "true",
1670
2034
  ref: canvasRef,
1671
- children: /* @__PURE__ */ jsxs(Plot, {
1672
- data: items.map((item) => ({
1673
- ...item,
1674
- plotValue: item.value / magnitude
1675
- })),
1676
- responsive: true,
1677
- width: "100%",
1678
- height: 220,
1679
- margin: {
1680
- top: 12,
1681
- right: 0,
1682
- bottom: 12,
1683
- left: 0
1684
- },
1685
- accessibilityLayer: false,
1686
- tabIndex: -1,
1687
- children: [
1688
- /* @__PURE__ */ jsx(ChartXAxis, {
1689
- hide: true,
1690
- dataKey: "id",
1691
- scale: "band"
1692
- }),
1693
- /* @__PURE__ */ jsx(ChartYAxis, {
1694
- hide: true,
1695
- domain: [low, high === low ? low + 1 : high]
1696
- }),
1697
- /* @__PURE__ */ jsx(ReferenceLine, {
1698
- y: 0,
1699
- stroke: "var(--atbl-border)"
1700
- }),
1701
- horizontalGrid && /* @__PURE__ */ jsx(ChartGrid, {}),
1702
- kind === "area" && /* @__PURE__ */ jsx(ChartArea, {
1703
- dataKey: "plotValue",
1704
- stroke: "none",
1705
- fill: "var(--atbl-chart-1)",
1706
- dot: false,
1707
- activeDot: false
1708
- }),
1709
- /* @__PURE__ */ jsx(ChartLine, {
1710
- dataKey: "plotValue",
1711
- dot: ({ cx, cy, index }) => {
1712
- if (index != null && cx != null && cy != null) points.current.set(index, {
1713
- x: cx,
1714
- y: cy
1715
- });
1716
- return /* @__PURE__ */ jsx("g", {
1717
- "data-atbl-internal-sample": index,
1718
- transform: `translate(${cx}, ${cy})`,
1719
- children: index === highlightedIndex && /* @__PURE__ */ jsx(ChartDot, {
1720
- cx: 0,
1721
- cy: 0,
1722
- active: true
1723
- })
1724
- });
1725
- },
1726
- activeDot: false
1727
- }),
1728
- linkedItem && /* @__PURE__ */ jsx(ReferenceLine, {
1729
- x: linkedItem.id,
1730
- stroke: "var(--atbl-muted)",
1731
- strokeOpacity: .3,
1732
- pointerEvents: "none",
1733
- "data-atbl-internal-linked-cursor": "true"
1734
- })
1735
- ]
2035
+ children: /* @__PURE__ */ jsx(HighlightedSampleContext, {
2036
+ value: highlightedIndex,
2037
+ children: plot
1736
2038
  })
1737
2039
  }), /* @__PURE__ */ jsx(ChartTooltip$1, {
1738
2040
  variant: "chart",
@@ -1741,7 +2043,10 @@ function TrendChart({ items, unit, ariaLabel, formatValue = formatNumber, kind,
1741
2043
  onPointerEnter: inspectNearest,
1742
2044
  onPointerMove: inspectNearest,
1743
2045
  onPointerLeave: cursor.reset,
1744
- onOpenChange: setMouseVisible,
2046
+ onOpenChange: (open) => {
2047
+ mouseVisibleRef.current = open;
2048
+ setMouseVisible(open);
2049
+ },
1745
2050
  anchorRect: () => {
1746
2051
  const point = screenPoint(nearest.current);
1747
2052
  return point ? new DOMRect(point.x, point.y, 0, 0) : null;
@@ -1751,83 +2056,14 @@ function TrendChart({ items, unit, ariaLabel, formatValue = formatNumber, kind,
1751
2056
  " ",
1752
2057
  unit
1753
2058
  ] })] }),
1754
- children: /* @__PURE__ */ jsx("div", {
1755
- className: "altertable-trend-points",
1756
- onClickCapture: inspectAction,
1757
- onContextMenuCapture: inspectAction,
1758
- children: items.map((item, index) => {
1759
- const declaredActions = itemActions?.(item) ?? [];
1760
- const actions = chartActions.actions(declaredActions, item.label, `${formatValue(item.value)} ${unit}`);
1761
- const action = getPrimaryExplorationAction(actions);
1762
- const menuTrigger = { get current() {
1763
- return menuTriggers.current.get(item.id) ?? null;
1764
- } };
1765
- return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsxs("div", {
1766
- className: "altertable-chart-item-actions",
1767
- children: [/* @__PURE__ */ jsx(ChartTooltip$1, {
1768
- variant: "chart",
1769
- mouseHover: false,
1770
- followCursor: false,
1771
- onOpenChange: (open) => setActiveIndex((current) => open ? index : current === index ? void 0 : current),
1772
- content: /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("strong", { children: item.label }), /* @__PURE__ */ jsxs("span", { children: [
1773
- formatValue(item.value),
1774
- " ",
1775
- unit
1776
- ] })] }),
1777
- className: "altertable-chart-column",
1778
- children: action ? /* @__PURE__ */ jsxs("button", {
1779
- "data-atbl-focus": "ring",
1780
- "data-atbl-control": "action",
1781
- type: "button",
1782
- className: "altertable-trend-point",
1783
- "aria-label": `${item.label}: ${formatValue(item.value)} ${unit}. ${action.label}`,
1784
- ...explorationMenuEvents(menuTrigger),
1785
- onClick: (event) => action.onSelect(event.currentTarget),
1786
- children: [/* @__PURE__ */ jsx("span", { className: "altertable-trend-hit" }), /* @__PURE__ */ jsx("span", {
1787
- className: "altertable-trend-label",
1788
- children: item.label
1789
- })]
1790
- }) : actions.length > 1 ? /* @__PURE__ */ jsxs(MenuTrigger, { children: [/* @__PURE__ */ jsxs(PressButton, {
1791
- ...explorationMenuEvents(menuTrigger),
1792
- ref: (element) => {
1793
- if (element) menuTriggers.current.set(item.id, element);
1794
- else menuTriggers.current.delete(item.id);
1795
- },
1796
- className: "altertable-trend-point",
1797
- "aria-label": `${item.label}: ${formatValue(item.value)} ${unit}. Actions`,
1798
- children: [/* @__PURE__ */ jsx("span", { className: "altertable-trend-hit" }), /* @__PURE__ */ jsx("span", {
1799
- className: "altertable-trend-label",
1800
- children: item.label
1801
- })]
1802
- }), /* @__PURE__ */ jsx(ExplorationActionMenu, {
1803
- actions,
1804
- ariaLabel: `${item.label} actions`,
1805
- triggerRef: menuTrigger
1806
- })] }) : /* @__PURE__ */ jsxs("button", {
1807
- "data-atbl-focus": "ring",
1808
- "data-atbl-control": "default",
1809
- type: "button",
1810
- tabIndex: -1,
1811
- className: "altertable-trend-point",
1812
- "aria-label": `${item.label}: ${formatValue(item.value)} ${unit}`,
1813
- children: [/* @__PURE__ */ jsx("span", { className: "altertable-trend-hit" }), /* @__PURE__ */ jsx("span", {
1814
- className: "altertable-trend-label",
1815
- children: item.label
1816
- })]
1817
- })
1818
- }), action && /* @__PURE__ */ jsx(ExplorationActionControl, {
1819
- contextOnly: declaredActions.length === 1,
1820
- indicator: "chevron",
1821
- ref: (element) => {
1822
- if (element) menuTriggers.current.set(item.id, element);
1823
- else menuTriggers.current.delete(item.id);
1824
- },
1825
- actions,
1826
- ariaLabel: `${item.label} actions`,
1827
- hidePrimary: Boolean(action)
1828
- })]
1829
- }) }, item.id);
1830
- })
2059
+ children: /* @__PURE__ */ jsx(TrendChartItems, {
2060
+ items,
2061
+ unit,
2062
+ formatValue,
2063
+ itemActions,
2064
+ actions: chartActions.actions,
2065
+ setActiveIndex,
2066
+ onInspectAction: inspectAction
1831
2067
  })
1832
2068
  })]
1833
2069
  })
@@ -1864,7 +2100,7 @@ function AreaChart(props) {
1864
2100
  * Include Other to represent the whole. Zero values remain in the legend; all-zero
1865
2101
  * data shows an empty circle. Colors follow item order. Compose inside VisualizationWidget;
1866
2102
  * hover/touch tooltips coordinate slice and legend emphasis without caller state. */
1867
- function PieChart({ items, unit, ariaLabel, showLegend = true, formatValue = (value) => new Intl.NumberFormat().format(value), itemActions }) {
2103
+ function PieChart({ items, unit, ariaLabel, showLegend = true, formatValue = formatNumber, itemActions }) {
1868
2104
  validateValueChartItems("pie", items);
1869
2105
  const chartActions = useChartActions();
1870
2106
  const [previewId, setPreviewId] = useState(null);
@@ -2206,29 +2442,250 @@ function timeTickIndices(items, width) {
2206
2442
  for (let tick = 0; tick < count; tick++) indices.add(start + tick * stride);
2207
2443
  return indices;
2208
2444
  }
2445
+ function PlotBoundsObserver({ overlayRef }) {
2446
+ const plot = usePlotArea();
2447
+ const left = plot?.x;
2448
+ const width = plot?.width;
2449
+ useLayoutEffect(() => {
2450
+ if (left === void 0 || width === void 0 || !Number.isFinite(left) || !Number.isFinite(width) || !overlayRef.current) return;
2451
+ const overlay = overlayRef.current;
2452
+ overlay.style.marginLeft = `${left}px`;
2453
+ overlay.style.width = `${width}px`;
2454
+ return () => {
2455
+ overlay.style.marginLeft = "";
2456
+ overlay.style.width = "";
2457
+ };
2458
+ }, [
2459
+ overlayRef,
2460
+ left,
2461
+ width
2462
+ ]);
2463
+ return null;
2464
+ }
2465
+ const ActiveBarIdContext = createContext(void 0);
2466
+ /** Reads the hovered id itself, so moving between bars redraws two bars, not the plot. */
2467
+ function HighlightedBar(props) {
2468
+ const id = props["data-atbl-internal-bar-id"];
2469
+ const active = useContext(ActiveBarIdContext) === id;
2470
+ return useMemo(() => /* @__PURE__ */ jsx(Rectangle, {
2471
+ ...props,
2472
+ opacity: active ? .75 : 1
2473
+ }), [props, active]);
2474
+ }
2475
+ function renderHighlightedBar(props) {
2476
+ return /* @__PURE__ */ jsx(HighlightedBar, { ...props });
2477
+ }
2478
+ function minimumBarSize(value) {
2479
+ return (value ?? 0) > 0 ? 7 : 0;
2480
+ }
2481
+ /** Subscribes per bar, so a peer cursor repaints two backgrounds instead of the chart. */
2482
+ function LinkedBarBackground({ cursor, time, x, y, width, height }) {
2483
+ const linked = useLinkedCursorValue(cursor, (peerTime) => time != null && peerTime === time);
2484
+ return /* @__PURE__ */ jsx("g", { children: linked && /* @__PURE__ */ jsx("rect", {
2485
+ x,
2486
+ y,
2487
+ width,
2488
+ height,
2489
+ fill: "var(--atbl-muted)",
2490
+ fillOpacity: .14,
2491
+ pointerEvents: "none",
2492
+ "aria-hidden": "true",
2493
+ "data-atbl-internal-linked-cursor": "true"
2494
+ }) });
2495
+ }
2496
+ /** Hit targets and tooltips stay mounted while the plot highlights a bar. */
2497
+ const BarChartItems = memo(function BarChartItems({ items, unit, formatValue, itemActions, actions: chartActions, cursor, ticks, setActiveId, plotRef, canvasRef, scrollport }) {
2498
+ const menuTriggers = useRef(/* @__PURE__ */ new Map());
2499
+ return items.map((item, index) => {
2500
+ const actions = chartActions(itemActions?.(item) ?? [], item.label, `${formatValue(item.value)} ${unit}`);
2501
+ const action = getPrimaryExplorationAction(actions);
2502
+ const menuTrigger = { get current() {
2503
+ return menuTriggers.current.get(item.id) ?? null;
2504
+ } };
2505
+ return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsxs("div", {
2506
+ className: "altertable-chart-item-actions",
2507
+ onPointerMove: (event) => {
2508
+ if (event.pointerType === "mouse") cursor.setTime(item.time);
2509
+ },
2510
+ children: [/* @__PURE__ */ jsx(ChartTooltip$1, {
2511
+ variant: "chart",
2512
+ followCursor: false,
2513
+ boundaryRefs: [canvasRef, scrollport],
2514
+ anchorRect: (trigger) => {
2515
+ const bar = plotRef.current?.querySelector(`[data-atbl-internal-bar-id="${CSS.escape(item.id)}"]`);
2516
+ const bounds = bar?.getBoundingClientRect() ?? trigger?.getBoundingClientRect();
2517
+ if (!bounds) return null;
2518
+ const top = bar ? bounds.top : bounds.top + 220;
2519
+ return new DOMRect(bounds.left + bounds.width / 2, top, 0, 0);
2520
+ },
2521
+ onOpenChange: (open) => setActiveId((current) => open ? item.id : current === item.id ? void 0 : current),
2522
+ content: /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("strong", { children: item.label }), /* @__PURE__ */ jsxs("span", { children: [
2523
+ formatValue(item.value),
2524
+ " ",
2525
+ unit
2526
+ ] })] }),
2527
+ className: "altertable-chart-column",
2528
+ children: action ? /* @__PURE__ */ jsx("button", {
2529
+ "data-atbl-focus": "ring",
2530
+ "data-atbl-control": "action",
2531
+ type: "button",
2532
+ className: "altertable-selectable-bars-item",
2533
+ "aria-label": `${item.label}: ${formatValue(item.value)} ${unit}. ${action.label}`,
2534
+ ...explorationMenuEvents(menuTrigger),
2535
+ onClick: (event) => action.onSelect(event.currentTarget),
2536
+ children: /* @__PURE__ */ jsx("span", { className: "altertable-selectable-bars-area" })
2537
+ }) : actions.length ? /* @__PURE__ */ jsx("button", {
2538
+ type: "button",
2539
+ "data-atbl-focus": "ring",
2540
+ "data-atbl-control": "action",
2541
+ className: "altertable-selectable-bars-item",
2542
+ "aria-label": `${item.label}: ${formatValue(item.value)} ${unit}. Actions`,
2543
+ ...explorationMenuEvents(menuTrigger),
2544
+ onClick: (event) => openExplorationMenu(menuTrigger, event),
2545
+ children: /* @__PURE__ */ jsx("span", { className: "altertable-selectable-bars-area" })
2546
+ }) : /* @__PURE__ */ jsx("button", {
2547
+ "data-atbl-focus": "ring",
2548
+ "data-atbl-control": "default",
2549
+ type: "button",
2550
+ tabIndex: -1,
2551
+ className: "altertable-selectable-bars-item",
2552
+ "aria-label": `${item.label}: ${formatValue(item.value)} ${unit}`,
2553
+ children: /* @__PURE__ */ jsx("span", { className: "altertable-selectable-bars-area" })
2554
+ })
2555
+ }), /* @__PURE__ */ jsx("div", {
2556
+ className: "altertable-chart-item-label-row",
2557
+ "data-time-tick": ticks?.has(index) || void 0,
2558
+ children: actions.length ? /* @__PURE__ */ jsxs(MenuTrigger, { children: [/* @__PURE__ */ jsxs(PressButton, {
2559
+ className: "altertable-selectable-bars-label",
2560
+ variant: "ghost",
2561
+ size: "compact",
2562
+ ...explorationMenuEvents(menuTrigger),
2563
+ ref: (element) => {
2564
+ if (element) menuTriggers.current.set(item.id, element);
2565
+ else menuTriggers.current.delete(item.id);
2566
+ },
2567
+ "aria-label": `${item.label}: Actions`,
2568
+ children: [/* @__PURE__ */ jsx("span", {
2569
+ title: item.label,
2570
+ children: item.label
2571
+ }), /* @__PURE__ */ jsx(AppIcon, {
2572
+ name: "disclosure",
2573
+ size: 12
2574
+ })]
2575
+ }), /* @__PURE__ */ jsx(ExplorationActionMenu, {
2576
+ actions,
2577
+ ariaLabel: item.label,
2578
+ triggerRef: menuTrigger,
2579
+ placement: "bottom"
2580
+ })] }) : /* @__PURE__ */ jsx("span", {
2581
+ className: "altertable-selectable-bars-label",
2582
+ children: /* @__PURE__ */ jsx("span", {
2583
+ title: item.label,
2584
+ children: item.label
2585
+ })
2586
+ })
2587
+ })]
2588
+ }) }, item.id);
2589
+ });
2590
+ });
2209
2591
  /** Nonnegative category values. Compose inside VisualizationWidget for a titled panel.
2210
2592
  * Owns hover/touch tooltips; no selection state or keyboard navigation. */
2211
- function BarChart({ items, unit, ariaLabel, formatValue = formatNumber, itemActions, cursorGroup, horizontalGrid = false }) {
2593
+ function BarChart({ items, unit, ariaLabel, formatValue: authoredFormatValue, itemActions, cursorGroup, horizontalGrid = true, showYAxis = false, scrollToEnd = true, valueFormat }) {
2594
+ const formatValue = useMemo(() => authoredFormatValue ?? (valueFormat ? (value) => formatMetric(value, valueFormat) : formatNumber), [authoredFormatValue, valueFormat]);
2595
+ const axisLabelSpace = showYAxis ? 10 : 0;
2212
2596
  validateValueChartItems("bar", items);
2213
2597
  const chartActions = useChartActions();
2214
2598
  const cursor = useLinkedChartCursor(cursorGroup);
2215
- const linkedItem = items.find((item) => item.time === cursor.time && cursor.time != null);
2216
2599
  const [activeId, setActiveId] = useState();
2217
2600
  const [viewportWidth, setViewportWidth] = useState(0);
2218
- const scrollport = useChartScrollToEnd(items);
2219
2601
  const plotRef = useRef(null);
2220
2602
  const canvasRef = useRef(null);
2221
- const menuTriggers = useRef(/* @__PURE__ */ new Map());
2222
- const maximum = items.reduce((max, item) => Math.max(max, item.value), 1);
2223
- 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;
2224
- const minimumSlotWidth = compactTimeAxis ? 3.5 : 45;
2603
+ const itemOverlayRef = useRef(null);
2604
+ const data = useMemo(() => {
2605
+ if (showYAxis) return items;
2606
+ const maximum = items.reduce((max, item) => Math.max(max, item.value), 0) || 1;
2607
+ return items.map((item) => ({
2608
+ ...item,
2609
+ plotValue: item.value / maximum
2610
+ }));
2611
+ }, [items, showYAxis]);
2612
+ const hasTimeAxis = items.length > 0 && items.every((item, index) => typeof item.time === "number" && Number.isFinite(item.time) && (index === 0 || item.time > items[index - 1].time));
2613
+ const scrollport = useChartScrollToEnd(items, scrollToEnd);
2614
+ const compactTimeAxis = hasTimeAxis && !itemActions;
2615
+ const minimumSlotWidth = compactTimeAxis ? 3.5 : 120;
2225
2616
  const plotWidth = Math.max(viewportWidth, items.length * minimumSlotWidth);
2226
- const ticks = compactTimeAxis ? timeTickIndices(items, plotWidth) : null;
2617
+ const ticks = useMemo(() => compactTimeAxis ? timeTickIndices(items, plotWidth) : null, [
2618
+ compactTimeAxis,
2619
+ items,
2620
+ plotWidth
2621
+ ]);
2622
+ const linkedBackground = useCallback(({ originalDataIndex, x, y, width, height }) => /* @__PURE__ */ jsx(LinkedBarBackground, {
2623
+ cursor,
2624
+ time: items[originalDataIndex]?.time,
2625
+ x,
2626
+ y,
2627
+ width,
2628
+ height
2629
+ }), [cursor, items]);
2630
+ const linked = cursorGroup != null;
2631
+ const plot = useMemo(() => /* @__PURE__ */ jsx(ChartValueFormat, {
2632
+ value: valueFormat,
2633
+ children: /* @__PURE__ */ jsxs(BarChart$1, {
2634
+ data,
2635
+ responsive: true,
2636
+ width: "100%",
2637
+ height: 220 + axisLabelSpace,
2638
+ margin: {
2639
+ top: 0,
2640
+ right: 0,
2641
+ bottom: axisLabelSpace,
2642
+ left: 0
2643
+ },
2644
+ accessibilityLayer: false,
2645
+ tabIndex: -1,
2646
+ barCategoryGap: "24%",
2647
+ children: [
2648
+ showYAxis && /* @__PURE__ */ jsx(PlotBoundsObserver, { overlayRef: itemOverlayRef }),
2649
+ /* @__PURE__ */ jsx(ChartXAxis, {
2650
+ hide: true,
2651
+ dataKey: "id",
2652
+ scale: "band"
2653
+ }),
2654
+ showYAxis ? /* @__PURE__ */ jsx(ChartYAxis, { domain: [0, "auto"] }) : /* @__PURE__ */ jsx(ChartYAxis, {
2655
+ hide: true,
2656
+ domain: [0, 1],
2657
+ allowDataOverflow: true
2658
+ }),
2659
+ horizontalGrid && /* @__PURE__ */ jsx(ChartGrid, {}),
2660
+ /* @__PURE__ */ jsx(ChartBar, {
2661
+ dataKey: showYAxis ? "value" : "plotValue",
2662
+ minPointSize: minimumBarSize,
2663
+ background: linked ? linkedBackground : false,
2664
+ shape: renderHighlightedBar,
2665
+ children: items.map((item) => /* @__PURE__ */ jsx(Cell, {
2666
+ fill: chartBarFill,
2667
+ "data-atbl-internal-bar-id": item.id
2668
+ }, item.id))
2669
+ })
2670
+ ]
2671
+ })
2672
+ }), [
2673
+ valueFormat,
2674
+ data,
2675
+ axisLabelSpace,
2676
+ showYAxis,
2677
+ horizontalGrid,
2678
+ linked,
2679
+ linkedBackground,
2680
+ items
2681
+ ]);
2227
2682
  useLayoutEffect(() => {
2228
2683
  const element = scrollport.current;
2229
2684
  if (!element) return;
2230
2685
  function updateWidth() {
2231
- setViewportWidth(Math.floor(element.getBoundingClientRect().width));
2686
+ const style = getComputedStyle(element);
2687
+ const padding = parseFloat(style.paddingLeft) + parseFloat(style.paddingRight);
2688
+ setViewportWidth(Math.floor(element.getBoundingClientRect().width - padding));
2232
2689
  }
2233
2690
  updateWidth();
2234
2691
  const observer = new ResizeObserver(updateWidth);
@@ -2257,149 +2714,25 @@ function BarChart({ items, unit, ariaLabel, formatValue = formatNumber, itemActi
2257
2714
  className: "altertable-chart-canvas",
2258
2715
  "aria-hidden": "true",
2259
2716
  ref: canvasRef,
2260
- children: /* @__PURE__ */ jsxs(BarChart$1, {
2261
- data: items.map((item) => ({
2262
- ...item,
2263
- plotValue: item.value / maximum
2264
- })),
2265
- responsive: true,
2266
- width: "100%",
2267
- height: 220,
2268
- margin: {
2269
- top: 0,
2270
- right: 0,
2271
- bottom: 0,
2272
- left: 0
2273
- },
2274
- accessibilityLayer: false,
2275
- tabIndex: -1,
2276
- barCategoryGap: "24%",
2277
- children: [
2278
- /* @__PURE__ */ jsx(ChartXAxis, {
2279
- hide: true,
2280
- dataKey: "id",
2281
- scale: "band"
2282
- }),
2283
- /* @__PURE__ */ jsx(ChartYAxis, {
2284
- hide: true,
2285
- domain: [0, 1],
2286
- allowDataOverflow: true
2287
- }),
2288
- horizontalGrid && /* @__PURE__ */ jsx(ChartGrid, {}),
2289
- /* @__PURE__ */ jsx(ChartBar, {
2290
- dataKey: "plotValue",
2291
- minPointSize: (value) => (value ?? 0) > 0 ? 7 : 0,
2292
- background: linkedItem ? ({ index, x, y, width, height }) => /* @__PURE__ */ jsx("g", { children: items[index]?.id === linkedItem.id && /* @__PURE__ */ jsx("rect", {
2293
- x,
2294
- y,
2295
- width,
2296
- height,
2297
- fill: "var(--atbl-muted)",
2298
- fillOpacity: .14,
2299
- pointerEvents: "none",
2300
- "aria-hidden": "true",
2301
- "data-atbl-internal-linked-cursor": "true"
2302
- }) }) : false,
2303
- children: items.map((item) => /* @__PURE__ */ jsx(Cell, {
2304
- fill: chartBarFill,
2305
- opacity: activeId === item.id ? .75 : 1,
2306
- "data-atbl-internal-bar-id": item.id
2307
- }, item.id))
2308
- })
2309
- ]
2717
+ children: /* @__PURE__ */ jsx(ActiveBarIdContext, {
2718
+ value: activeId,
2719
+ children: plot
2310
2720
  })
2311
2721
  }), /* @__PURE__ */ jsx("div", {
2312
2722
  className: "altertable-selectable-bars-items",
2313
- children: items.map((item, index) => {
2314
- const actions = chartActions.actions(itemActions?.(item) ?? [], item.label, `${formatValue(item.value)} ${unit}`);
2315
- const action = getPrimaryExplorationAction(actions);
2316
- const menuTrigger = { get current() {
2317
- return menuTriggers.current.get(item.id) ?? null;
2318
- } };
2319
- return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsxs("div", {
2320
- className: "altertable-chart-item-actions",
2321
- onPointerMove: (event) => {
2322
- if (event.pointerType === "mouse") cursor.setTime(item.time);
2323
- },
2324
- children: [/* @__PURE__ */ jsx(ChartTooltip$1, {
2325
- variant: "chart",
2326
- followCursor: false,
2327
- boundaryRefs: [canvasRef, scrollport],
2328
- anchorRect: (trigger) => {
2329
- const bar = plotRef.current?.querySelector(`[data-atbl-internal-bar-id="${CSS.escape(item.id)}"]`);
2330
- const bounds = bar?.getBoundingClientRect() ?? trigger?.getBoundingClientRect();
2331
- if (!bounds) return null;
2332
- const top = bar ? bounds.top : bounds.top + 220;
2333
- return new DOMRect(bounds.left + bounds.width / 2, top, 0, 0);
2334
- },
2335
- onOpenChange: (open) => setActiveId((current) => open ? item.id : current === item.id ? void 0 : current),
2336
- content: /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("strong", { children: item.label }), /* @__PURE__ */ jsxs("span", { children: [
2337
- formatValue(item.value),
2338
- " ",
2339
- unit
2340
- ] })] }),
2341
- className: "altertable-chart-column",
2342
- children: action ? /* @__PURE__ */ jsx("button", {
2343
- "data-atbl-focus": "ring",
2344
- "data-atbl-control": "action",
2345
- type: "button",
2346
- className: "altertable-selectable-bars-item",
2347
- "aria-label": `${item.label}: ${formatValue(item.value)} ${unit}. ${action.label}`,
2348
- ...explorationMenuEvents(menuTrigger),
2349
- onClick: (event) => action.onSelect(event.currentTarget),
2350
- children: /* @__PURE__ */ jsx("span", { className: "altertable-selectable-bars-area" })
2351
- }) : actions.length ? /* @__PURE__ */ jsx("button", {
2352
- type: "button",
2353
- "data-atbl-focus": "ring",
2354
- "data-atbl-control": "action",
2355
- className: "altertable-selectable-bars-item",
2356
- "aria-label": `${item.label}: ${formatValue(item.value)} ${unit}. Actions`,
2357
- ...explorationMenuEvents(menuTrigger),
2358
- onClick: (event) => openExplorationMenu(menuTrigger, event),
2359
- children: /* @__PURE__ */ jsx("span", { className: "altertable-selectable-bars-area" })
2360
- }) : /* @__PURE__ */ jsx("button", {
2361
- "data-atbl-focus": "ring",
2362
- "data-atbl-control": "default",
2363
- type: "button",
2364
- tabIndex: -1,
2365
- className: "altertable-selectable-bars-item",
2366
- "aria-label": `${item.label}: ${formatValue(item.value)} ${unit}`,
2367
- children: /* @__PURE__ */ jsx("span", { className: "altertable-selectable-bars-area" })
2368
- })
2369
- }), /* @__PURE__ */ jsx("div", {
2370
- className: "altertable-chart-item-label-row",
2371
- "data-time-tick": ticks?.has(index) || void 0,
2372
- children: actions.length ? /* @__PURE__ */ jsxs(MenuTrigger, { children: [/* @__PURE__ */ jsxs(PressButton, {
2373
- className: "altertable-selectable-bars-label",
2374
- variant: "ghost",
2375
- size: "compact",
2376
- ...explorationMenuEvents(menuTrigger),
2377
- ref: (element) => {
2378
- if (element) menuTriggers.current.set(item.id, element);
2379
- else menuTriggers.current.delete(item.id);
2380
- },
2381
- "aria-label": `${item.label}: Actions`,
2382
- children: [/* @__PURE__ */ jsx("span", {
2383
- title: item.label,
2384
- children: item.label
2385
- }), /* @__PURE__ */ jsx(AppIcon, {
2386
- name: "disclosure",
2387
- size: 12
2388
- })]
2389
- }), /* @__PURE__ */ jsx(ExplorationActionMenu, {
2390
- actions,
2391
- ariaLabel: item.label,
2392
- triggerRef: menuTrigger,
2393
- placement: "bottom"
2394
- })] }) : /* @__PURE__ */ jsx("span", {
2395
- className: "altertable-selectable-bars-label",
2396
- children: /* @__PURE__ */ jsx("span", {
2397
- title: item.label,
2398
- children: item.label
2399
- })
2400
- })
2401
- })]
2402
- }) }, item.id);
2723
+ ref: itemOverlayRef,
2724
+ children: /* @__PURE__ */ jsx(BarChartItems, {
2725
+ items,
2726
+ unit,
2727
+ formatValue,
2728
+ itemActions,
2729
+ actions: chartActions.actions,
2730
+ cursor,
2731
+ ticks,
2732
+ setActiveId,
2733
+ plotRef,
2734
+ canvasRef,
2735
+ scrollport
2403
2736
  })
2404
2737
  })]
2405
2738
  })
@@ -2422,9 +2755,9 @@ function RadioGroup({ label, className, children, ...props }) {
2422
2755
  }
2423
2756
  function Radio({ className, children, ...props }) {
2424
2757
  return /* @__PURE__ */ jsx(Radio$1, {
2758
+ "data-atbl-focus": "ring",
2425
2759
  ...props,
2426
2760
  "data-atbl-control": "action",
2427
- "data-atbl-focus": "ring",
2428
2761
  className: classNames("altertable-radio", className),
2429
2762
  children: (state) => /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("span", {
2430
2763
  className: "altertable-radio-mark",
@@ -2444,6 +2777,7 @@ function SegmentedControl({ options, className, ...props }) {
2444
2777
  children: options.map((option) => /* @__PURE__ */ jsx(Radio, {
2445
2778
  value: option.id,
2446
2779
  "data-atbl-internal-surface": "option",
2780
+ "data-atbl-focus": "inset",
2447
2781
  children: option.label
2448
2782
  }, option.id))
2449
2783
  })
@@ -2607,6 +2941,44 @@ function findNearestSeriesId(hoveredSeriesId, points, position) {
2607
2941
  }
2608
2942
  return selected;
2609
2943
  }
2944
+ function findNearestBar(bars, position, layout) {
2945
+ if (!position) return null;
2946
+ let nearest = null;
2947
+ let categoryDistance = Infinity;
2948
+ let valueDistance = Infinity;
2949
+ for (const bar of bars.values()) {
2950
+ const category = layout === "horizontal" ? Math.abs(position.x - (bar.x + bar.width / 2)) : Math.abs(position.y - (bar.y + bar.height / 2));
2951
+ const value = layout === "horizontal" ? Math.max(bar.y - position.y, 0, position.y - bar.y - bar.height) : Math.max(bar.x - position.x, 0, position.x - bar.x - bar.width);
2952
+ if (category < categoryDistance || category === categoryDistance && value < valueDistance) {
2953
+ nearest = bar;
2954
+ categoryDistance = category;
2955
+ valueDistance = value;
2956
+ }
2957
+ }
2958
+ return nearest;
2959
+ }
2960
+ function barCloserThanPoints(bar, points, position) {
2961
+ if (!bar || !position) return false;
2962
+ const dx = Math.max(bar.x - position.x, 0, position.x - bar.x - bar.width);
2963
+ const dy = Math.max(bar.y - position.y, 0, position.y - bar.y - bar.height);
2964
+ const barDistance = Math.hypot(dx, dy);
2965
+ let pointDistance = Infinity;
2966
+ for (const point of points.values()) pointDistance = Math.min(pointDistance, Math.hypot(point.x - position.x, point.y - position.y));
2967
+ return barDistance <= pointDistance;
2968
+ }
2969
+ function categoryDataKey(children, layout, axisId) {
2970
+ for (const child of Children.toArray(children)) {
2971
+ if (!isValidElement(child)) continue;
2972
+ if (child.type === Fragment) {
2973
+ const nested = categoryDataKey(child.props.children, layout, axisId);
2974
+ if (nested != null) return nested;
2975
+ }
2976
+ if (child.type !== (layout === "horizontal" ? ChartXAxis : ChartYAxis) && child.type !== (layout === "horizontal" ? XAxis : YAxis)) continue;
2977
+ if (((layout === "horizontal" ? child.props.xAxisId : child.props.yAxisId) ?? 0) !== axisId) continue;
2978
+ const key = child.props.dataKey;
2979
+ if (typeof key === "string" || typeof key === "number" || typeof key === "function") return key;
2980
+ }
2981
+ }
2610
2982
  function hasAuthoredGrid(children) {
2611
2983
  return Children.toArray(children).some((child) => isValidElement(child) && (child.type === ChartGrid || child.type === CartesianGrid || child.type === Fragment && hasAuthoredGrid(child.props.children)));
2612
2984
  }
@@ -2726,6 +3098,40 @@ function PlotOffsets({ onChange }) {
2726
3098
  ]);
2727
3099
  return null;
2728
3100
  }
3101
+ /** Pointer inspection reaches marks through context, so the Recharts tree
3102
+ * re-renders only for new chart props or legend state. */
3103
+ const ComposedChartPlot = memo(function ComposedChartPlot({ chartProps, registration, focusedLegendKeys, legendHoveredKey, suppressPlotInspection, barAxisByKey, fullAxisSpace, trackPlotOffsets }) {
3104
+ const { data, ariaLabel, valueFormat, cursorGroup: _cursorGroup, horizontalGrid = true, children, width = "100%", height = 300, responsive = true, layout = "horizontal", className: _className, ...rechartsProps } = chartProps;
3105
+ const valueAxis = layout === "vertical" ? "x" : "y";
3106
+ const axisLayout = inspectAxisLayout(children);
3107
+ const nativeKeyCounts = countNativeSeriesKeys(children);
3108
+ const visibleBarAxisIds = collectVisibleNativeBarAxisIds(children, focusedLegendKeys, valueAxis, nativeKeyCounts);
3109
+ for (const [key, axisId] of barAxisByKey) if (!focusedLegendKeys || focusedLegendKeys.has(key)) visibleBarAxisIds.add(axisId);
3110
+ return /* @__PURE__ */ jsx(ChartValueFormat, {
3111
+ value: valueFormat,
3112
+ children: /* @__PURE__ */ jsx(ChartDateAxes, {
3113
+ data,
3114
+ children: /* @__PURE__ */ jsx(ChartRegistrationContext, {
3115
+ value: registration,
3116
+ children: /* @__PURE__ */ jsxs(ComposedChart$1, {
3117
+ "data-atbl-focus": "inset",
3118
+ ...rechartsProps,
3119
+ data,
3120
+ width,
3121
+ height,
3122
+ responsive,
3123
+ layout,
3124
+ "aria-label": ariaLabel,
3125
+ children: [
3126
+ valueAxis === "y" && axisLayout.autoYAxis && axisLayout.interactiveLegend && /* @__PURE__ */ jsx(PlotOffsets, { onChange: trackPlotOffsets }),
3127
+ horizontalGrid && !hasAuthoredGrid(children) && /* @__PURE__ */ jsx(ChartGrid, {}),
3128
+ applyNativeLegendInteraction(children, focusedLegendKeys, legendHoveredKey, suppressPlotInspection, valueAxis, visibleBarAxisIds, fullAxisSpace, axisLayout, nativeKeyCounts)
3129
+ ]
3130
+ })
3131
+ })
3132
+ })
3133
+ });
3134
+ });
2729
3135
  /** Compose Cartesian series inside VisualizationWidget. Defaults to responsive
2730
3136
  * full width and 300px height. Children retain native Recharts props and behavior,
2731
3137
  * including stacking, numeric/time axes, missing values, tooltips, and keyboard
@@ -2733,15 +3139,42 @@ function PlotOffsets({ onChange }) {
2733
3139
  * for stacks. Preserve missing measures as null and choose connectNulls deliberately.
2734
3140
  * Use public chart tokens for series colors. Dataset bindings own
2735
3141
  * loading, empty results, evidence, and CSV; this primitive owns only the plot. */
2736
- function ComposedChartRoot({ data, ariaLabel, valueFormat, cursorGroup, horizontalGrid = false, children, width = "100%", height = 300, responsive = true, layout = "horizontal", className, ...props }) {
3142
+ function ComposedChartRoot(props) {
3143
+ const { ariaLabel, cursorGroup, children, layout = "horizontal", className } = props;
2737
3144
  const cursor = useLinkedChartCursor(cursorGroup);
2738
3145
  const [mouseHover, setMouseHover] = useState(false);
2739
3146
  const [hasPointerFocus, setHasPointerFocus] = useState(false);
2740
3147
  const [isPointerInspection, setIsPointerInspection] = useState(false);
2741
3148
  const [hoveredSeriesId, setHoveredSeriesId] = useState(null);
2742
3149
  const [pointerPosition, setPointerPosition] = useState(null);
3150
+ const [nearestBar, setNearestBar] = useState(null);
2743
3151
  const latestPointerPosition = useRef(null);
2744
3152
  const [points, setPoints] = useState(() => /* @__PURE__ */ new Map());
3153
+ const bars = useRef(/* @__PURE__ */ new Map());
3154
+ const barRefreshFrame = useRef(null);
3155
+ const refreshNearestBar = useCallback(() => {
3156
+ if (barRefreshFrame.current != null || !latestPointerPosition.current) return;
3157
+ barRefreshFrame.current = requestAnimationFrame(() => {
3158
+ barRefreshFrame.current = null;
3159
+ const selected = findNearestBar(bars.current, latestPointerPosition.current, layout);
3160
+ setNearestBar(selected);
3161
+ setPointerPosition(latestPointerPosition.current);
3162
+ });
3163
+ }, [layout]);
3164
+ useEffect(() => () => {
3165
+ if (barRefreshFrame.current != null) cancelAnimationFrame(barRefreshFrame.current);
3166
+ }, []);
3167
+ const registerBar = useCallback((bar) => {
3168
+ const key = `${bar.seriesId}:${bar.index}`;
3169
+ bars.current.set(key, bar);
3170
+ refreshNearestBar();
3171
+ return () => {
3172
+ if (bars.current.get(key) === bar) {
3173
+ bars.current.delete(key);
3174
+ refreshNearestBar();
3175
+ }
3176
+ };
3177
+ }, [refreshNearestBar]);
2745
3178
  const registerPoint = useCallback((id, x, y) => {
2746
3179
  setPoints((current) => new Map(current).set(id, {
2747
3180
  x,
@@ -2753,6 +3186,17 @@ function ComposedChartRoot({ data, ariaLabel, valueFormat, cursorGroup, horizont
2753
3186
  return next;
2754
3187
  });
2755
3188
  }, []);
3189
+ const [categoryAxisKeys, setCategoryAxisKeys] = useState(() => /* @__PURE__ */ new Map());
3190
+ const registerCategoryAxis = useCallback((axis, id, dataKey) => {
3191
+ const key = chartAxisKey(axis, id);
3192
+ setCategoryAxisKeys((current) => current.get(key) === dataKey ? current : new Map(current).set(key, dataKey));
3193
+ return () => setCategoryAxisKeys((current) => {
3194
+ if (current.get(key) !== dataKey) return current;
3195
+ const next = new Map(current);
3196
+ next.delete(key);
3197
+ return next;
3198
+ });
3199
+ }, []);
2756
3200
  useEffect(() => {
2757
3201
  setPointerPosition(latestPointerPosition.current);
2758
3202
  }, [points]);
@@ -2765,9 +3209,10 @@ function ComposedChartRoot({ data, ariaLabel, valueFormat, cursorGroup, horizont
2765
3209
  }
2766
3210
  setSuppressPlotInspection(false);
2767
3211
  setIsPointerInspection(true);
2768
- if (hoveredSeriesId != null && !points.has(hoveredSeriesId)) {
3212
+ if (bars.current.size === 0 && hoveredSeriesId != null && !points.has(hoveredSeriesId)) {
2769
3213
  latestPointerPosition.current = null;
2770
3214
  setPointerPosition(null);
3215
+ setNearestBar(null);
2771
3216
  return true;
2772
3217
  }
2773
3218
  const matrix = svg.getScreenCTM();
@@ -2778,7 +3223,12 @@ function ComposedChartRoot({ data, ariaLabel, valueFormat, cursorGroup, horizont
2778
3223
  y: point.y
2779
3224
  };
2780
3225
  latestPointerPosition.current = nextPosition;
2781
- setPointerPosition((current) => findNearestSeriesId(hoveredSeriesId, points, current) === findNearestSeriesId(hoveredSeriesId, points, nextPosition) ? current : nextPosition);
3226
+ const selected = findNearestBar(bars.current, nextPosition, layout);
3227
+ setNearestBar(selected);
3228
+ setPointerPosition((current) => {
3229
+ const currentBar = findNearestBar(bars.current, current, layout);
3230
+ return (barCloserThanPoints(currentBar, points, current) ? currentBar : findNearestSeriesId(hoveredSeriesId, points, current)) === (barCloserThanPoints(selected, points, nextPosition) ? selected : findNearestSeriesId(hoveredSeriesId, points, nextPosition)) ? current : nextPosition;
3231
+ });
2782
3232
  return true;
2783
3233
  }
2784
3234
  function resetPointerInspection() {
@@ -2788,8 +3238,10 @@ function ComposedChartRoot({ data, ariaLabel, valueFormat, cursorGroup, horizont
2788
3238
  setHoveredSeriesId(null);
2789
3239
  latestPointerPosition.current = null;
2790
3240
  setPointerPosition(null);
3241
+ setNearestBar(null);
2791
3242
  }
2792
- const activeSeriesId = findNearestSeriesId(hoveredSeriesId, points, pointerPosition);
3243
+ const activeBar = barCloserThanPoints(nearestBar, points, pointerPosition) ? nearestBar : null;
3244
+ const activeSeriesId = activeBar?.seriesId ?? findNearestSeriesId(hoveredSeriesId, points, pointerPosition);
2793
3245
  const [seriesIds, setSeriesIds] = useState(() => /* @__PURE__ */ new Set());
2794
3246
  const registerSeries = useCallback((id) => {
2795
3247
  setSeriesIds((current) => new Set(current).add(id));
@@ -2817,7 +3269,6 @@ function ComposedChartRoot({ data, ariaLabel, valueFormat, cursorGroup, horizont
2817
3269
  return next;
2818
3270
  });
2819
3271
  }, []);
2820
- const valueAxis = layout === "vertical" ? "x" : "y";
2821
3272
  const [fullAxisSpace, setFullAxisSpace] = useState(null);
2822
3273
  const trackPlotOffsets = useCallback((left, right) => {
2823
3274
  if (focusedLegendKeys) return;
@@ -2826,10 +3277,6 @@ function ComposedChartRoot({ data, ariaLabel, valueFormat, cursorGroup, horizont
2826
3277
  right
2827
3278
  });
2828
3279
  }, [focusedLegendKeys]);
2829
- const axisLayout = inspectAxisLayout(children);
2830
- const nativeKeyCounts = countNativeSeriesKeys(children);
2831
- const visibleBarAxisIds = collectVisibleNativeBarAxisIds(children, focusedLegendKeys, valueAxis, nativeKeyCounts);
2832
- for (const [key, axisId] of barAxisByKey) if (!focusedLegendKeys || focusedLegendKeys.has(key)) visibleBarAxisIds.add(axisId);
2833
3280
  const reconcileLegendKeys = useCallback((keys) => {
2834
3281
  setFocusedLegendKeys((current) => reconcileLegendFocus(current, keys));
2835
3282
  }, []);
@@ -2837,78 +3284,107 @@ function ComposedChartRoot({ data, ariaLabel, valueFormat, cursorGroup, horizont
2837
3284
  setSuppressPlotInspection(true);
2838
3285
  setFocusedLegendKeys((current) => toggleLegendFocus(current, key, keys));
2839
3286
  }, []);
2840
- return /* @__PURE__ */ jsx(ChartCursorChartContext.Provider, {
2841
- value: {
2842
- cursor,
2843
- mouseHover
2844
- },
2845
- children: /* @__PURE__ */ jsx(ChartLegendInteractionContext.Provider, {
2846
- value: {
2847
- hoveredKey: legendHoveredKey,
2848
- focusedKeys: focusedLegendKeys,
2849
- suppressPlotInspection,
2850
- hover: (key) => {
2851
- setLegendHoveredKey(key);
2852
- if (key) setSuppressPlotInspection(true);
2853
- },
2854
- toggle: toggleLegendKey,
2855
- reconcile: reconcileLegendKeys,
2856
- registerBarAxis
2857
- },
2858
- children: /* @__PURE__ */ jsx(ChartInteractionContext.Provider, {
2859
- value: {
2860
- isPointerInspection,
2861
- activeSeriesId,
2862
- activePoint: activeSeriesId == null ? void 0 : points.get(activeSeriesId),
2863
- registerPoint,
2864
- setHoveredSeriesId,
2865
- seriesCount: seriesIds.size,
2866
- registerSeries
2867
- },
2868
- children: /* @__PURE__ */ jsx("section", {
2869
- className: classNames("altertable-composed-chart", className),
2870
- "aria-label": ariaLabel,
2871
- "data-atbl-internal-pointer-focus": hasPointerFocus || void 0,
2872
- onPointerDownCapture: (event) => {
2873
- setHasPointerFocus(trackPointer(event));
2874
- },
2875
- onPointerOverCapture: trackPointer,
2876
- onPointerMoveCapture: trackPointer,
2877
- onPointerLeave: (event) => {
2878
- if (event.pointerType !== "touch") resetPointerInspection();
2879
- },
2880
- onKeyDownCapture: () => {
2881
- setHasPointerFocus(false);
2882
- resetPointerInspection();
2883
- },
2884
- onFocusCapture: (event) => {
2885
- if (event.currentTarget.querySelector("svg[role=\"application\"]")?.contains(event.target)) setSuppressPlotInspection(false);
2886
- },
2887
- onBlurCapture: (event) => {
2888
- if (!event.currentTarget.contains(event.relatedTarget)) {
3287
+ const registration = useMemo(() => ({
3288
+ registerPoint,
3289
+ registerBar,
3290
+ registerSeries,
3291
+ registerCategoryAxis,
3292
+ setHoveredSeriesId
3293
+ }), [
3294
+ registerPoint,
3295
+ registerBar,
3296
+ registerSeries,
3297
+ registerCategoryAxis
3298
+ ]);
3299
+ const cursorContext = useMemo(() => ({
3300
+ cursor,
3301
+ mouseHover
3302
+ }), [cursor, mouseHover]);
3303
+ const hoverLegendKey = useCallback((key) => {
3304
+ setLegendHoveredKey(key);
3305
+ if (key) setSuppressPlotInspection(true);
3306
+ }, []);
3307
+ const legendContext = useMemo(() => ({
3308
+ hoveredKey: legendHoveredKey,
3309
+ focusedKeys: focusedLegendKeys,
3310
+ suppressPlotInspection,
3311
+ hover: hoverLegendKey,
3312
+ toggle: toggleLegendKey,
3313
+ reconcile: reconcileLegendKeys,
3314
+ registerBarAxis
3315
+ }), [
3316
+ legendHoveredKey,
3317
+ focusedLegendKeys,
3318
+ suppressPlotInspection,
3319
+ hoverLegendKey,
3320
+ toggleLegendKey,
3321
+ reconcileLegendKeys,
3322
+ registerBarAxis
3323
+ ]);
3324
+ const getCategoryDataKey = useCallback((axisId) => categoryAxisKeys.get(chartAxisKey(layout === "horizontal" ? "x" : "y", axisId)) ?? categoryDataKey(children, layout, axisId), [
3325
+ categoryAxisKeys,
3326
+ layout,
3327
+ children
3328
+ ]);
3329
+ const seriesCount = seriesIds.size;
3330
+ const interactionContext = useMemo(() => ({
3331
+ isPointerInspection,
3332
+ activeSeriesId,
3333
+ getCategoryDataKey,
3334
+ seriesCount
3335
+ }), [
3336
+ isPointerInspection,
3337
+ activeSeriesId,
3338
+ getCategoryDataKey,
3339
+ seriesCount
3340
+ ]);
3341
+ const activePoint = activeSeriesId == null ? void 0 : points.get(activeSeriesId);
3342
+ const activeSampleContext = useMemo(() => ({
3343
+ activePoint,
3344
+ activeBar
3345
+ }), [activePoint, activeBar]);
3346
+ return /* @__PURE__ */ jsx(ChartCursorChartContext, {
3347
+ value: cursorContext,
3348
+ children: /* @__PURE__ */ jsx(ChartLegendInteractionContext, {
3349
+ value: legendContext,
3350
+ children: /* @__PURE__ */ jsx(ChartInteractionContext, {
3351
+ value: interactionContext,
3352
+ children: /* @__PURE__ */ jsx(ChartActiveSampleContext, {
3353
+ value: activeSampleContext,
3354
+ children: /* @__PURE__ */ jsx("section", {
3355
+ className: classNames("altertable-composed-chart", className),
3356
+ "aria-label": ariaLabel,
3357
+ "data-atbl-internal-pointer-focus": hasPointerFocus || void 0,
3358
+ onPointerDownCapture: (event) => {
3359
+ setHasPointerFocus(trackPointer(event));
3360
+ },
3361
+ onPointerOverCapture: trackPointer,
3362
+ onPointerMoveCapture: trackPointer,
3363
+ onPointerLeave: (event) => {
3364
+ if (event.pointerType !== "touch") resetPointerInspection();
3365
+ },
3366
+ onKeyDownCapture: () => {
2889
3367
  setHasPointerFocus(false);
2890
3368
  resetPointerInspection();
2891
- }
2892
- },
2893
- children: /* @__PURE__ */ jsx(ChartValueFormat.Provider, {
2894
- value: valueFormat,
2895
- children: /* @__PURE__ */ jsx(ChartDateAxes, {
2896
- data,
2897
- children: /* @__PURE__ */ jsxs(ComposedChart$1, {
2898
- "data-atbl-focus": "inset",
2899
- ...props,
2900
- data,
2901
- width,
2902
- height,
2903
- responsive,
2904
- layout,
2905
- "aria-label": ariaLabel,
2906
- children: [
2907
- valueAxis === "y" && axisLayout.autoYAxis && axisLayout.interactiveLegend && /* @__PURE__ */ jsx(PlotOffsets, { onChange: trackPlotOffsets }),
2908
- horizontalGrid && !hasAuthoredGrid(children) && /* @__PURE__ */ jsx(ChartGrid, {}),
2909
- applyNativeLegendInteraction(children, focusedLegendKeys, legendHoveredKey, suppressPlotInspection, valueAxis, visibleBarAxisIds, fullAxisSpace, axisLayout, nativeKeyCounts)
2910
- ]
2911
- })
3369
+ },
3370
+ onFocusCapture: (event) => {
3371
+ if (event.currentTarget.querySelector("svg[role=\"application\"]")?.contains(event.target)) setSuppressPlotInspection(false);
3372
+ },
3373
+ onBlurCapture: (event) => {
3374
+ if (!event.currentTarget.contains(event.relatedTarget)) {
3375
+ setHasPointerFocus(false);
3376
+ resetPointerInspection();
3377
+ }
3378
+ },
3379
+ children: /* @__PURE__ */ jsx(ComposedChartPlot, {
3380
+ chartProps: props,
3381
+ registration,
3382
+ focusedLegendKeys,
3383
+ legendHoveredKey,
3384
+ suppressPlotInspection,
3385
+ barAxisByKey,
3386
+ fullAxisSpace,
3387
+ trackPlotOffsets
2912
3388
  })
2913
3389
  })
2914
3390
  })
@@ -3091,6 +3567,7 @@ function FunnelChart({ steps, series, unit, ariaLabel, className, formatValue =
3091
3567
  children: /* @__PURE__ */ jsxs(ComposedChart, {
3092
3568
  data: rows,
3093
3569
  ariaLabel: `${ariaLabel} plot`,
3570
+ horizontalGrid,
3094
3571
  height: 300,
3095
3572
  barCategoryGap: "4%",
3096
3573
  barGap: 1,
@@ -3286,6 +3763,7 @@ function RetentionChart({ series, unit, ariaLabel, className, formatValue = form
3286
3763
  /* @__PURE__ */ jsxs(ComposedChart, {
3287
3764
  data: rows,
3288
3765
  ariaLabel: `${ariaLabel} plot`,
3766
+ horizontalGrid,
3289
3767
  children: [
3290
3768
  horizontalGrid && /* @__PURE__ */ jsx(ComposedChart.CartesianGrid, {}),
3291
3769
  /* @__PURE__ */ jsx(ComposedChart.XAxis, {
@@ -3697,14 +4175,6 @@ function JourneyFlow({ paths, unit, formatValue }) {
3697
4175
  });
3698
4176
  }
3699
4177
  //#endregion
3700
- //#region src/ui/index.ts
3701
- /** Direct UI composition and static screens. Requests use declared views from /react. */
3702
- const TextWidget = withWidgetBoundary(TextWidget$1);
3703
- /** Compose an unframed visual with the shared heading and inspection. */
3704
- const VisualizationWidget = withWidgetBoundary(VisualizationWidget$1);
3705
- const TableWidget = withWidgetBoundary(TableWidget$1);
3706
- const MetricWidget = withWidgetBoundary(MetricWidget$1);
3707
- //#endregion
3708
- export { AboutData, AppIcon, AreaChart, BarChart, ChartLegend, Checkbox, CheckboxGroup, ChoicePicker, ComposedChart, ControlBar, 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, VisualizationWidget, dateTimeRangeFilter, dateTimeRangePresets, injectDataAppStyles, isPlainKeyEvent, matchSearchText, searchItems, useAppFilters, useChartCursorGroup, useDateFormatting, useSvgId, useViewTab };
4178
+ export { AboutData, AppIcon, AreaChart, BarChart, ChartLegend, Checkbox, CheckboxGroup, ChoicePicker, ComposedChart, ControlBar, DataAppProvider, DataTable, DataTableEmptyRow, DataTableShare, DataTableTimestamp, 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, Notice, NumberField, NumberFilterPicker, NumberRangeField, PieChart, PresentStory, Radio, RadioGroup, RetentionChart, ScatterChart, SearchField, SearchMatch, SearchTypeahead, SectionHeading, SegmentedControl, Select, Sheet, ShimmerText, Tab, TabList, TabPanel, TabPanels, Tabs, Tooltip, TooltipProvider, dateTimeRangeFilter, dateTimeRangePresets, injectDataAppStyles, isPlainKeyEvent, matchSearchText, searchItems, useAppFilters, useChartCursorGroup, useDateFormatting, useSvgId, useViewTab };
3709
4179
 
3710
4180
  //# sourceMappingURL=index.js.map