@altertable/data-app-react 0.76.0 → 0.77.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,15 +1,21 @@
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";
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
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, isValidElement, useCallback, useContext, useEffect, useId, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
4
+ import { Children, Fragment, cloneElement, 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, useActiveTooltipLabel, useIsTooltipActive, usePlotArea, useXAxisScale, 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, useCartesianChartLayout, useIsTooltipActive, useMargin, useOffset, 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
- function DataApp(props) {
12
- return /* @__PURE__ */ jsx(DataAppFrame, { ...props });
11
+ function DataApp({ csvExport, ...props }) {
12
+ return /* @__PURE__ */ jsx(DataAppFrame, {
13
+ ...props,
14
+ csvExport: csvExport && {
15
+ loading: false,
16
+ value: csvExport
17
+ }
18
+ });
13
19
  }
14
20
  //#endregion
15
21
  //#region src/ui/GettingStarted.tsx
@@ -17,13 +23,11 @@ const connectionContext = createDataContext({})({
17
23
  description: "Connection setup",
18
24
  glossary: {}
19
25
  });
20
- const { defineDataView } = /* @__PURE__ */ createDataHooks(/* @__PURE__ */ createDataClient());
21
- const connectionView = defineDataView({
26
+ const { defineView } = /* @__PURE__ */ createDataHooks(/* @__PURE__ */ createDataClient());
27
+ const connectionView = defineView({
22
28
  dataContext: connectionContext,
23
29
  operation: "connection",
24
- describeInput: () => "the connection",
25
- isEmpty: () => false,
26
- emptyFallback: { title: "No connection" }
30
+ describeInput: () => "the connection"
27
31
  });
28
32
  /** Query-backed connection state and next steps for a newly created app. Mount within
29
33
  * `DataAppProvider` and register `connection: connectionCheck(app.queries)` on the server. */
@@ -1049,6 +1053,62 @@ function ChartSeries({ id, children }) {
1049
1053
  });
1050
1054
  }
1051
1055
  //#endregion
1056
+ //#region src/ui/chart-legend-interaction.tsx
1057
+ function chartLegendSeriesKey(id, dataKey) {
1058
+ if (typeof id === "string" || typeof id === "number") return [
1059
+ "series",
1060
+ typeof id,
1061
+ id
1062
+ ].join(KEY_SEPARATOR);
1063
+ if (typeof dataKey === "string" || typeof dataKey === "number") return [
1064
+ "data",
1065
+ typeof dataKey,
1066
+ dataKey
1067
+ ].join(KEY_SEPARATOR);
1068
+ return null;
1069
+ }
1070
+ function reconcileLegendFocus(focused, keys) {
1071
+ if (!focused) return null;
1072
+ const available = new Set(keys);
1073
+ const next = new Set([...focused].filter((key) => available.has(key)));
1074
+ if (next.size === 0 || next.size === available.size) return null;
1075
+ return next.size === focused.size ? focused : next;
1076
+ }
1077
+ function toggleLegendFocus(focused, key, keys) {
1078
+ const current = reconcileLegendFocus(focused, keys);
1079
+ if (!current) return /* @__PURE__ */ new Set([key]);
1080
+ const next = new Set(current);
1081
+ if (next.has(key)) next.delete(key);
1082
+ else next.add(key);
1083
+ return next.size === 0 || next.size === new Set(keys).size ? null : next;
1084
+ }
1085
+ const ChartLegendInteractionContext = createContext(null);
1086
+ function useChartLegendSeries(id, dataKey) {
1087
+ const interaction = useContext(ChartLegendInteractionContext);
1088
+ const key = chartLegendSeriesKey(id, dataKey);
1089
+ return {
1090
+ inspectingLegend: !!interaction?.suppressPlotInspection,
1091
+ hidden: !!(key && interaction?.focusedKeys && !interaction.focusedKeys.has(key)),
1092
+ dimmed: !!(key && interaction?.hoveredKey && (!interaction.focusedKeys || interaction.focusedKeys.has(interaction.hoveredKey)) && interaction.hoveredKey !== key)
1093
+ };
1094
+ }
1095
+ function useChartLegendFocus(ids) {
1096
+ const [hoveredId, setHoveredId] = useState(null);
1097
+ const [storedFocusedIds, setStoredFocusedIds] = useState(null);
1098
+ const focusedIds = reconcileLegendFocus(storedFocusedIds, ids);
1099
+ function toggle(id) {
1100
+ setStoredFocusedIds((current) => toggleLegendFocus(current, id, ids));
1101
+ }
1102
+ return {
1103
+ hoveredId,
1104
+ setHoveredId,
1105
+ focusedIds,
1106
+ toggle,
1107
+ visible: (id) => !focusedIds || focusedIds.has(id),
1108
+ opacity: (id) => focusedIds && !focusedIds.has(id) ? 0 : hoveredId && (!focusedIds || focusedIds.has(hoveredId)) && hoveredId !== id ? .2 : 1
1109
+ };
1110
+ }
1111
+ //#endregion
1052
1112
  //#region src/ui/chart-value-format.ts
1053
1113
  const ChartValueFormat = createContext(void 0);
1054
1114
  /** Use one magnitude for every tick, and enough precision to distinguish them. */
@@ -1098,7 +1158,7 @@ function ChartLegendRoot({ children, layout = "horizontal", align = "start", max
1098
1158
  const container = containerRef.current;
1099
1159
  if (!container) return;
1100
1160
  function measure() {
1101
- const list = containerRef.current?.firstElementChild;
1161
+ const list = containerRef.current?.querySelector(".altertable-chart-legend");
1102
1162
  if (list) setColumns(getComputedStyle(list).gridTemplateColumns.split(" ").length);
1103
1163
  }
1104
1164
  const observer = new ResizeObserver(measure);
@@ -1243,16 +1303,18 @@ function ChartDot({ active = false, stroke = seriesColor, fill = active ? stroke
1243
1303
  function NearestChartDot({ seriesId, cx, cy, stroke }) {
1244
1304
  const interaction = useContext(ChartInteractionContext);
1245
1305
  const registerPoint = interaction?.registerPoint;
1306
+ const legend = useChartLegendSeries(seriesId, void 0);
1246
1307
  useLayoutEffect(() => {
1247
- if (cx == null || cy == null) return;
1308
+ if (legend.hidden || cx == null || cy == null) return;
1248
1309
  return registerPoint?.(seriesId, cx, cy);
1249
1310
  }, [
1250
1311
  registerPoint,
1251
1312
  seriesId,
1252
1313
  cx,
1253
- cy
1314
+ cy,
1315
+ legend.hidden
1254
1316
  ]);
1255
- return isChartSeriesActive(interaction, seriesId) ? /* @__PURE__ */ jsx(ChartDot, {
1317
+ return !legend.hidden && isChartSeriesActive(interaction, seriesId) ? /* @__PURE__ */ jsx(ChartDot, {
1256
1318
  cx,
1257
1319
  cy,
1258
1320
  stroke,
@@ -1264,6 +1326,18 @@ function NearestChartDot({ seriesId, cx, cy, stroke }) {
1264
1326
  function ChartBar(props) {
1265
1327
  useDateAxisBar(props.xAxisId);
1266
1328
  const series = useChartSeries(props.id);
1329
+ const legend = useChartLegendSeries(series.id, props.dataKey);
1330
+ const interaction = useContext(ChartLegendInteractionContext);
1331
+ const layout = useCartesianChartLayout();
1332
+ const registerBarAxis = interaction?.registerBarAxis;
1333
+ const key = chartLegendSeriesKey(series.id, props.dataKey);
1334
+ const axisId = layout === "vertical" ? props.xAxisId ?? 0 : props.yAxisId ?? 0;
1335
+ useLayoutEffect(() => key && !props.hide ? registerBarAxis?.(key, axisId) : void 0, [
1336
+ registerBarAxis,
1337
+ key,
1338
+ axisId,
1339
+ props.hide
1340
+ ]);
1267
1341
  return /* @__PURE__ */ jsx(ChartSeries, {
1268
1342
  id: series.id,
1269
1343
  children: /* @__PURE__ */ jsx(Bar, {
@@ -1278,7 +1352,13 @@ function ChartBar(props) {
1278
1352
  activeBar: series.active ? { opacity: .75 } : false,
1279
1353
  isAnimationActive: false,
1280
1354
  ...props,
1281
- id: series.id
1355
+ id: series.id,
1356
+ hide: legend.hidden || props.hide,
1357
+ opacity: legend.hidden ? 0 : legend.dimmed ? .2 : props.opacity,
1358
+ style: {
1359
+ ...props.style,
1360
+ pointerEvents: legend.hidden ? "none" : props.style?.pointerEvents
1361
+ }
1282
1362
  })
1283
1363
  });
1284
1364
  }
@@ -1286,6 +1366,7 @@ function ChartBar(props) {
1286
1366
  * activeDot independently controls the hovered point. Native dot props and renderers remain available. */
1287
1367
  function ChartLine({ stroke = seriesColor, dot = false, activeDot, ...props }) {
1288
1368
  const series = useChartSeries(props.id);
1369
+ const legend = useChartLegendSeries(series.id, props.dataKey);
1289
1370
  return /* @__PURE__ */ jsx(ChartSeries, {
1290
1371
  id: series.id,
1291
1372
  children: /* @__PURE__ */ jsx(Line, {
@@ -1294,12 +1375,12 @@ function ChartLine({ stroke = seriesColor, dot = false, activeDot, ...props }) {
1294
1375
  strokeWidth: 2,
1295
1376
  strokeLinecap: "round",
1296
1377
  strokeLinejoin: "round",
1297
- dot: dot === true ? ({ cx, cy }) => /* @__PURE__ */ jsx(ChartDot, {
1378
+ dot: legend.hidden ? false : dot === true ? ({ cx, cy }) => /* @__PURE__ */ jsx(ChartDot, {
1298
1379
  cx,
1299
1380
  cy,
1300
1381
  stroke
1301
1382
  }) : dot,
1302
- activeDot: activeDot === void 0 || activeDot === true ? ({ cx, cy }) => /* @__PURE__ */ jsx(NearestChartDot, {
1383
+ activeDot: legend.hidden || legend.inspectingLegend ? false : activeDot === void 0 || activeDot === true ? ({ cx, cy }) => /* @__PURE__ */ jsx(NearestChartDot, {
1303
1384
  seriesId: series.id,
1304
1385
  cx,
1305
1386
  cy,
@@ -1307,13 +1388,20 @@ function ChartLine({ stroke = seriesColor, dot = false, activeDot, ...props }) {
1307
1388
  }) : activeDot,
1308
1389
  isAnimationActive: false,
1309
1390
  ...props,
1310
- id: series.id
1391
+ id: series.id,
1392
+ hide: legend.hidden || props.hide,
1393
+ opacity: legend.hidden ? 0 : legend.dimmed ? .2 : props.opacity,
1394
+ style: {
1395
+ ...props.style,
1396
+ pointerEvents: legend.hidden ? "none" : props.style?.pointerEvents
1397
+ }
1311
1398
  })
1312
1399
  });
1313
1400
  }
1314
1401
  /** Filled series with the same sample-dot and activeDot options as ChartLine. */
1315
1402
  function ChartArea({ stroke = seriesColor, dot = false, activeDot, ...props }) {
1316
1403
  const series = useChartSeries(props.id);
1404
+ const legend = useChartLegendSeries(series.id, props.dataKey);
1317
1405
  return /* @__PURE__ */ jsx(ChartSeries, {
1318
1406
  id: series.id,
1319
1407
  children: /* @__PURE__ */ jsx(Area, {
@@ -1325,12 +1413,12 @@ function ChartArea({ stroke = seriesColor, dot = false, activeDot, ...props }) {
1325
1413
  strokeLinejoin: "round",
1326
1414
  fill: stroke,
1327
1415
  fillOpacity: .14,
1328
- dot: dot === true ? ({ cx, cy }) => /* @__PURE__ */ jsx(ChartDot, {
1416
+ dot: legend.hidden ? false : dot === true ? ({ cx, cy }) => /* @__PURE__ */ jsx(ChartDot, {
1329
1417
  cx,
1330
1418
  cy,
1331
1419
  stroke
1332
1420
  }) : dot,
1333
- activeDot: activeDot === void 0 || activeDot === true ? ({ cx, cy }) => /* @__PURE__ */ jsx(NearestChartDot, {
1421
+ activeDot: legend.hidden || legend.inspectingLegend ? false : activeDot === void 0 || activeDot === true ? ({ cx, cy }) => /* @__PURE__ */ jsx(NearestChartDot, {
1334
1422
  seriesId: series.id,
1335
1423
  cx,
1336
1424
  cy,
@@ -1338,19 +1426,32 @@ function ChartArea({ stroke = seriesColor, dot = false, activeDot, ...props }) {
1338
1426
  }) : activeDot,
1339
1427
  isAnimationActive: false,
1340
1428
  ...props,
1341
- id: series.id
1429
+ id: series.id,
1430
+ hide: legend.hidden || props.hide,
1431
+ opacity: legend.hidden ? 0 : legend.dimmed ? .2 : props.opacity,
1432
+ style: {
1433
+ ...props.style,
1434
+ pointerEvents: legend.hidden ? "none" : props.style?.pointerEvents
1435
+ }
1342
1436
  })
1343
1437
  });
1344
1438
  }
1345
1439
  function ChartScatter(props) {
1346
1440
  const series = useChartSeries(props.id);
1441
+ const legend = useChartLegendSeries(series.id, props.dataKey);
1347
1442
  return /* @__PURE__ */ jsx(ChartSeries, {
1348
1443
  id: series.id,
1349
1444
  children: /* @__PURE__ */ jsx(Scatter, {
1350
1445
  fill: seriesColor,
1351
1446
  isAnimationActive: false,
1352
1447
  ...props,
1353
- id: series.id
1448
+ id: series.id,
1449
+ hide: legend.hidden || props.hide,
1450
+ opacity: legend.hidden ? 0 : legend.dimmed ? .2 : props.opacity,
1451
+ style: {
1452
+ ...props.style,
1453
+ pointerEvents: legend.hidden ? "none" : props.style?.pointerEvents
1454
+ }
1354
1455
  })
1355
1456
  });
1356
1457
  }
@@ -1440,16 +1541,29 @@ function ChartTooltipContent(props) {
1440
1541
  function ChartTooltip(props) {
1441
1542
  const dateLabel = useDateAxisLabel(props.axisId);
1442
1543
  const interaction = useContext(ChartInteractionContext);
1544
+ const legendInteraction = useContext(ChartLegendInteractionContext);
1545
+ const { content: authoredContent, ...tooltipProps } = props;
1443
1546
  return /* @__PURE__ */ jsx(Tooltip$1, {
1444
1547
  labelFormatter: dateLabel,
1445
- content: (content) => /* @__PURE__ */ jsx(ChartTooltipContent, {
1446
- ...content,
1447
- payload: interaction?.isPointerInspection && interaction.seriesCount !== 1 && props.shared !== true ? content.payload.filter((entry) => entry.graphicalItemId === interaction.activeSeriesId) : content.payload
1448
- }),
1449
1548
  position: interaction?.isPointerInspection && interaction.activePoint ? { y: interaction.activePoint.y } : void 0,
1450
1549
  cursor: false,
1451
1550
  isAnimationActive: false,
1452
- ...props
1551
+ ...tooltipProps,
1552
+ content: (content) => {
1553
+ if (legendInteraction?.suppressPlotInspection) return null;
1554
+ const payload = (interaction?.isPointerInspection && interaction.seriesCount !== 1 && props.shared !== true ? content.payload.filter((entry) => entry.graphicalItemId === interaction.activeSeriesId) : content.payload).filter((entry) => {
1555
+ if (!legendInteraction?.focusedKeys) return true;
1556
+ const key = chartLegendSeriesKey(entry.graphicalItemId, entry.dataKey);
1557
+ return key == null || legendInteraction.focusedKeys.has(key);
1558
+ });
1559
+ const filtered = {
1560
+ ...content,
1561
+ payload
1562
+ };
1563
+ if (typeof authoredContent === "function") return authoredContent(filtered);
1564
+ if (isValidElement(authoredContent)) return cloneElement(authoredContent, filtered);
1565
+ return /* @__PURE__ */ jsx(ChartTooltipContent, { ...filtered });
1566
+ }
1453
1567
  });
1454
1568
  }
1455
1569
  //#endregion
@@ -2378,17 +2492,9 @@ function createLegendItemKeys() {
2378
2492
  const keys = payload.map((entry) => {
2379
2493
  const source = entry.payload;
2380
2494
  const id = source && typeof source === "object" && "id" in source ? source.id : void 0;
2381
- if (typeof id === "string" || typeof id === "number") return [
2382
- "series",
2383
- typeof id,
2384
- id
2385
- ].join(KEY_SEPARATOR);
2386
2495
  const key = entry.dataKey;
2387
- if (typeof key === "string" || typeof key === "number") return [
2388
- "data",
2389
- typeof key,
2390
- key
2391
- ].join(KEY_SEPARATOR);
2496
+ const seriesKey = chartLegendSeriesKey(id, key);
2497
+ if (seriesKey) return seriesKey;
2392
2498
  return ["object", identity(typeof key === "function" ? key : entry)].join(KEY_SEPARATOR);
2393
2499
  });
2394
2500
  const counts = /* @__PURE__ */ new Map();
@@ -2405,9 +2511,15 @@ function createLegendItemKeys() {
2405
2511
  });
2406
2512
  };
2407
2513
  }
2408
- function LegendContent({ payload = [], maxVisibleItems, formatter, layout, align, labelStyle, iconType, iconSize = 8, inactiveColor = "var(--atbl-muted)", position, verticalAlign, onClick, onMouseEnter, onMouseLeave, "aria-label": ariaLabel }) {
2514
+ function LegendContent({ payload = [], maxVisibleItems, formatter, layout, align, labelStyle, iconType, iconSize = 8, inactiveColor = "var(--atbl-muted)", position, verticalAlign, onClick, onMouseEnter, onMouseLeave, interactive = true, "aria-label": ariaLabel }) {
2409
2515
  const [getItemKeys] = useState(createLegendItemKeys);
2516
+ const interaction = useContext(ChartLegendInteractionContext);
2410
2517
  const itemKeys = getItemKeys(payload);
2518
+ const selectableKeys = itemKeys.filter((_, index) => payload[index]?.type !== "none");
2519
+ useLayoutEffect(() => {
2520
+ interaction?.reconcile(selectableKeys);
2521
+ });
2522
+ const canInteract = interactive && !onClick && interaction && (payload.filter((entry) => entry.type !== "none").length > 1 || interaction.focusedKeys !== null);
2411
2523
  if (!payload.some((entry) => entry.type !== "none")) return null;
2412
2524
  const vertical = layout === "vertical" || layout === "auto" && (position === "left" || position === "right");
2413
2525
  return /* @__PURE__ */ jsx(ChartLegend, {
@@ -2435,14 +2547,32 @@ function LegendContent({ payload = [], maxVisibleItems, formatter, layout, align
2435
2547
  })] });
2436
2548
  return /* @__PURE__ */ jsx(ChartLegend.Item, {
2437
2549
  inactive: entry.inactive,
2438
- onMouseEnter: onMouseEnter ? (event) => onMouseEnter(entry, index, event) : void 0,
2439
- onMouseLeave: onMouseLeave ? (event) => onMouseLeave(entry, index, event) : void 0,
2440
- children: onClick ? /* @__PURE__ */ jsx("button", {
2550
+ "data-legend-muted": canInteract && interaction.hoveredKey && (!interaction.focusedKeys || interaction.focusedKeys.has(interaction.hoveredKey)) && interaction.hoveredKey !== itemKeys[index] ? true : void 0,
2551
+ "data-legend-excluded": canInteract && interaction.focusedKeys && !interaction.focusedKeys.has(itemKeys[index]) ? true : void 0,
2552
+ onMouseEnter: (event) => {
2553
+ if (canInteract) interaction.hover(itemKeys[index]);
2554
+ onMouseEnter?.(entry, index, event);
2555
+ },
2556
+ onMouseLeave: (event) => {
2557
+ if (canInteract) interaction.hover(null);
2558
+ onMouseLeave?.(entry, index, event);
2559
+ },
2560
+ children: canInteract || onClick ? /* @__PURE__ */ jsx("button", {
2441
2561
  type: "button",
2442
2562
  "data-atbl-control": "action",
2443
2563
  "data-atbl-focus": "ring",
2444
2564
  className: "altertable-chart-legend-action",
2445
- onClick: (event) => onClick(entry, index, event),
2565
+ "aria-pressed": canInteract ? !!interaction.focusedKeys?.has(itemKeys[index]) : void 0,
2566
+ onFocus: () => {
2567
+ if (canInteract) interaction.hover(itemKeys[index]);
2568
+ },
2569
+ onBlur: () => {
2570
+ if (canInteract) interaction.hover(null);
2571
+ },
2572
+ onClick: (event) => {
2573
+ if (canInteract) interaction.toggle(itemKeys[index], selectableKeys);
2574
+ onClick?.(entry, index, event);
2575
+ },
2446
2576
  children: content
2447
2577
  }) : content
2448
2578
  }, itemKeys[index]);
@@ -2450,13 +2580,15 @@ function LegendContent({ payload = [], maxVisibleItems, formatter, layout, align
2450
2580
  });
2451
2581
  }
2452
2582
  /** Opt in inside ComposedChart to derive the shared legend from its displayed series.
2453
- * Give native series unique IDs when they share a data key.
2454
2583
  * Native positioning, sorting, formatters, callbacks, and custom content remain available. */
2455
- function ComposedChartLegend({ maxVisibleItems, ...props }) {
2584
+ function ComposedChartLegend({ maxVisibleItems, interactive = true, ...props }) {
2456
2585
  return /* @__PURE__ */ jsx(Legend, {
2457
2586
  iconSize: 8,
2458
2587
  inactiveColor: "var(--atbl-muted)",
2459
- content: /* @__PURE__ */ jsx(LegendContent, { maxVisibleItems }),
2588
+ content: /* @__PURE__ */ jsx(LegendContent, {
2589
+ maxVisibleItems,
2590
+ interactive
2591
+ }),
2460
2592
  ...props
2461
2593
  });
2462
2594
  }
@@ -2478,6 +2610,122 @@ function findNearestSeriesId(hoveredSeriesId, points, position) {
2478
2610
  function hasAuthoredGrid(children) {
2479
2611
  return Children.toArray(children).some((child) => isValidElement(child) && (child.type === ChartGrid || child.type === CartesianGrid || child.type === Fragment && hasAuthoredGrid(child.props.children)));
2480
2612
  }
2613
+ function countNativeSeriesKeys(children, counts = /* @__PURE__ */ new Map()) {
2614
+ Children.forEach(children, (child) => {
2615
+ if (!isValidElement(child)) return;
2616
+ if (child.type === Fragment) countNativeSeriesKeys(child.props.children, counts);
2617
+ else if (child.type === Line || child.type === Bar || child.type === Area || child.type === Scatter) {
2618
+ const props = child.props;
2619
+ const key = chartLegendSeriesKey(props.id, props.dataKey);
2620
+ if (key) counts.set(key, (counts.get(key) ?? 0) + 1);
2621
+ }
2622
+ });
2623
+ return counts;
2624
+ }
2625
+ function nativeSeriesId(props, child, index, path, keyCounts) {
2626
+ if (props.id != null) return props.id;
2627
+ const key = chartLegendSeriesKey(void 0, props.dataKey);
2628
+ return !key || (keyCounts.get(key) ?? 0) > 1 ? `atbl-native-${path}-${child.key ?? index}` : void 0;
2629
+ }
2630
+ function applyNativeLegendInteraction(children, focusedKeys, hoveredKey, suppressPlotInspection, valueAxis, visibleBarAxisIds, fullAxisSpace, yAxisSideCounts, keyCounts, path = "root") {
2631
+ return Children.map(children, (child, index) => {
2632
+ if (!isValidElement(child)) return child;
2633
+ if (child.type === Fragment) {
2634
+ const props = child.props;
2635
+ return cloneElement(child, { children: applyNativeLegendInteraction(props.children, focusedKeys, hoveredKey, suppressPlotInspection, valueAxis, visibleBarAxisIds, fullAxisSpace, yAxisSideCounts, keyCounts, `${path}-${child.key ?? index}`) });
2636
+ }
2637
+ if (child.type === ChartXAxis || child.type === XAxis) {
2638
+ const axis = child;
2639
+ if (valueAxis === "y") return cloneElement(axis, { includeHidden: axis.props.includeHidden ?? true });
2640
+ if (!focusedKeys || axis.props.domain != null || axis.props.ticks != null) return child;
2641
+ return cloneElement(axis, { domain: visibleBarAxisIds.has(axis.props.xAxisId ?? 0) ? [0, "auto"] : ["auto", "auto"] });
2642
+ }
2643
+ if (child.type === ChartYAxis || child.type === YAxis) {
2644
+ const axis = child;
2645
+ if (valueAxis === "x") return cloneElement(axis, { includeHidden: axis.props.includeHidden ?? true });
2646
+ if (!focusedKeys || axis.props.domain != null || axis.props.ticks != null) return child;
2647
+ const side = axis.props.orientation ?? "left";
2648
+ const reservedWidth = (axis.props.width === "auto" || child.type === ChartYAxis && axis.props.width == null) && yAxisSideCounts[side] === 1 ? fullAxisSpace?.[side] : void 0;
2649
+ return cloneElement(axis, {
2650
+ domain: visibleBarAxisIds.has(axis.props.yAxisId ?? 0) ? [0, "auto"] : ["auto", "auto"],
2651
+ ...reservedWidth != null && { width: reservedWidth }
2652
+ });
2653
+ }
2654
+ if (child.type !== Line && child.type !== Bar && child.type !== Area && child.type !== Scatter) return child;
2655
+ const series = child;
2656
+ const id = nativeSeriesId(series.props, child, index, path, keyCounts);
2657
+ const key = chartLegendSeriesKey(id, series.props.dataKey);
2658
+ const excluded = !!(focusedKeys && !focusedKeys.has(key));
2659
+ return cloneElement(series, {
2660
+ id,
2661
+ hide: excluded || series.props.hide,
2662
+ opacity: excluded ? 0 : hoveredKey && (!focusedKeys || focusedKeys.has(hoveredKey)) && hoveredKey !== key ? .2 : series.props.opacity,
2663
+ style: {
2664
+ ...series.props.style,
2665
+ pointerEvents: excluded ? "none" : series.props.style?.pointerEvents
2666
+ },
2667
+ ...excluded && (child.type === Line || child.type === Area) ? {
2668
+ dot: false,
2669
+ activeDot: false
2670
+ } : {},
2671
+ ...suppressPlotInspection && (child.type === Line || child.type === Area) ? { activeDot: false } : {}
2672
+ });
2673
+ });
2674
+ }
2675
+ function collectVisibleNativeBarAxisIds(children, focusedKeys, valueAxis, keyCounts, path = "root", ids = /* @__PURE__ */ new Set()) {
2676
+ Children.forEach(children, (child, index) => {
2677
+ if (!isValidElement(child)) return;
2678
+ if (child.type === Fragment) collectVisibleNativeBarAxisIds(child.props.children, focusedKeys, valueAxis, keyCounts, `${path}-${child.key ?? index}`, ids);
2679
+ else if (child.type === Bar) {
2680
+ const props = child.props;
2681
+ const key = chartLegendSeriesKey(nativeSeriesId(props, child, index, path, keyCounts), props.dataKey);
2682
+ if (!props.hide && (!focusedKeys || focusedKeys.has(key))) ids.add(valueAxis === "x" ? props.xAxisId ?? 0 : props.yAxisId ?? 0);
2683
+ }
2684
+ });
2685
+ return ids;
2686
+ }
2687
+ function inspectAxisLayout(children, layout = {
2688
+ left: 0,
2689
+ right: 0,
2690
+ autoYAxis: false,
2691
+ interactiveLegend: false
2692
+ }) {
2693
+ Children.forEach(children, (child) => {
2694
+ if (!isValidElement(child)) return;
2695
+ if (child.type === Fragment) inspectAxisLayout(child.props.children, layout);
2696
+ else if (child.type === ChartYAxis || child.type === YAxis) {
2697
+ const props = child.props;
2698
+ if (!props.hide && !props.mirror) {
2699
+ layout[props.orientation ?? "left"]++;
2700
+ if (props.width === "auto" || child.type === ChartYAxis && props.width == null) layout.autoYAxis = true;
2701
+ }
2702
+ } else if (child.type === ComposedChartLegend || child.type === Legend) {
2703
+ const props = child.props;
2704
+ if (child.type === ComposedChartLegend && props.interactive !== false) layout.interactiveLegend = true;
2705
+ const side = props.position === "left" || props.position === "right" ? props.position : props.layout === "vertical" && (props.align === "left" || props.align === "right") ? props.align : null;
2706
+ if (side) layout[side]++;
2707
+ }
2708
+ });
2709
+ return layout;
2710
+ }
2711
+ function PlotOffsets({ onChange }) {
2712
+ const offset = useOffset();
2713
+ const margin = useMargin();
2714
+ const left = offset?.left;
2715
+ const right = offset?.right;
2716
+ const marginLeft = margin?.left ?? 5;
2717
+ const marginRight = margin?.right ?? 5;
2718
+ useLayoutEffect(() => {
2719
+ if (left != null && right != null) onChange(left - marginLeft, right - marginRight);
2720
+ }, [
2721
+ left,
2722
+ right,
2723
+ marginLeft,
2724
+ marginRight,
2725
+ onChange
2726
+ ]);
2727
+ return null;
2728
+ }
2481
2729
  /** Compose Cartesian series inside VisualizationWidget. Defaults to responsive
2482
2730
  * full width and 300px height. Children retain native Recharts props and behavior,
2483
2731
  * including stacking, numeric/time axes, missing values, tooltips, and keyboard
@@ -2485,7 +2733,7 @@ function hasAuthoredGrid(children) {
2485
2733
  * for stacks. Preserve missing measures as null and choose connectNulls deliberately.
2486
2734
  * Use public chart tokens for series colors. Dataset bindings own
2487
2735
  * loading, empty results, evidence, and CSV; this primitive owns only the plot. */
2488
- function ComposedChartRoot({ data, ariaLabel, valueFormat, cursorGroup, horizontalGrid = false, children, width = "100%", height = 300, responsive = true, className, ...props }) {
2736
+ function ComposedChartRoot({ data, ariaLabel, valueFormat, cursorGroup, horizontalGrid = false, children, width = "100%", height = 300, responsive = true, layout = "horizontal", className, ...props }) {
2489
2737
  const cursor = useLinkedChartCursor(cursorGroup);
2490
2738
  const [mouseHover, setMouseHover] = useState(false);
2491
2739
  const [hasPointerFocus, setHasPointerFocus] = useState(false);
@@ -2515,6 +2763,7 @@ function ComposedChartRoot({ data, ariaLabel, valueFormat, cursorGroup, horizont
2515
2763
  resetPointerInspection();
2516
2764
  return false;
2517
2765
  }
2766
+ setSuppressPlotInspection(false);
2518
2767
  setIsPointerInspection(true);
2519
2768
  if (hoveredSeriesId != null && !points.has(hoveredSeriesId)) {
2520
2769
  latestPointerPosition.current = null;
@@ -2552,56 +2801,114 @@ function ComposedChartRoot({ data, ariaLabel, valueFormat, cursorGroup, horizont
2552
2801
  });
2553
2802
  };
2554
2803
  }, []);
2804
+ const [legendHoveredKey, setLegendHoveredKey] = useState(null);
2805
+ const [suppressPlotInspection, setSuppressPlotInspection] = useState(false);
2806
+ const [focusedLegendKeys, setFocusedLegendKeys] = useState(null);
2807
+ const [barAxisByKey, setBarAxisByKey] = useState(() => /* @__PURE__ */ new Map());
2808
+ const registerBarAxis = useCallback((key, axisId) => {
2809
+ setBarAxisByKey((current) => {
2810
+ if (current.get(key) === axisId) return current;
2811
+ return new Map(current).set(key, axisId);
2812
+ });
2813
+ return () => setBarAxisByKey((current) => {
2814
+ if (current.get(key) !== axisId) return current;
2815
+ const next = new Map(current);
2816
+ next.delete(key);
2817
+ return next;
2818
+ });
2819
+ }, []);
2820
+ const valueAxis = layout === "vertical" ? "x" : "y";
2821
+ const [fullAxisSpace, setFullAxisSpace] = useState(null);
2822
+ const trackPlotOffsets = useCallback((left, right) => {
2823
+ if (focusedLegendKeys) return;
2824
+ setFullAxisSpace((current) => current?.left === left && current.right === right ? current : {
2825
+ left,
2826
+ right
2827
+ });
2828
+ }, [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
+ const reconcileLegendKeys = useCallback((keys) => {
2834
+ setFocusedLegendKeys((current) => reconcileLegendFocus(current, keys));
2835
+ }, []);
2836
+ const toggleLegendKey = useCallback((key, keys) => {
2837
+ setSuppressPlotInspection(true);
2838
+ setFocusedLegendKeys((current) => toggleLegendFocus(current, key, keys));
2839
+ }, []);
2555
2840
  return /* @__PURE__ */ jsx(ChartCursorChartContext.Provider, {
2556
2841
  value: {
2557
2842
  cursor,
2558
2843
  mouseHover
2559
2844
  },
2560
- children: /* @__PURE__ */ jsx(ChartInteractionContext.Provider, {
2845
+ children: /* @__PURE__ */ jsx(ChartLegendInteractionContext.Provider, {
2561
2846
  value: {
2562
- isPointerInspection,
2563
- activeSeriesId,
2564
- activePoint: activeSeriesId == null ? void 0 : points.get(activeSeriesId),
2565
- registerPoint,
2566
- setHoveredSeriesId,
2567
- seriesCount: seriesIds.size,
2568
- registerSeries
2569
- },
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();
2847
+ hoveredKey: legendHoveredKey,
2848
+ focusedKeys: focusedLegendKeys,
2849
+ suppressPlotInspection,
2850
+ hover: (key) => {
2851
+ setLegendHoveredKey(key);
2852
+ if (key) setSuppressPlotInspection(true);
2581
2853
  },
2582
- onKeyDownCapture: () => {
2583
- setHasPointerFocus(false);
2584
- resetPointerInspection();
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
2585
2867
  },
2586
- onBlurCapture: (event) => {
2587
- if (!event.currentTarget.contains(event.relatedTarget)) {
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: () => {
2588
2881
  setHasPointerFocus(false);
2589
2882
  resetPointerInspection();
2590
- }
2591
- },
2592
- children: /* @__PURE__ */ jsx(ChartValueFormat.Provider, {
2593
- value: valueFormat,
2594
- children: /* @__PURE__ */ jsx(ChartDateAxes, {
2595
- data,
2596
- children: /* @__PURE__ */ jsxs(ComposedChart$1, {
2597
- "data-atbl-focus": "inset",
2598
- ...props,
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)) {
2889
+ setHasPointerFocus(false);
2890
+ resetPointerInspection();
2891
+ }
2892
+ },
2893
+ children: /* @__PURE__ */ jsx(ChartValueFormat.Provider, {
2894
+ value: valueFormat,
2895
+ children: /* @__PURE__ */ jsx(ChartDateAxes, {
2599
2896
  data,
2600
- width,
2601
- height,
2602
- responsive,
2603
- "aria-label": ariaLabel,
2604
- children: [horizontalGrid && !hasAuthoredGrid(children) && /* @__PURE__ */ jsx(ChartGrid, {}), children]
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
+ })
2605
2912
  })
2606
2913
  })
2607
2914
  })
@@ -2695,7 +3002,8 @@ function createFunnelModel(steps, series, chartId) {
2695
3002
  }
2696
3003
  /** Conversion columns with previous-step drop-off, normalized to each series' first step.
2697
3004
  * Owns series highlighting and portion-specific inspection; compose inside VisualizationWidget. */
2698
- function FunnelChart({ steps, series, unit, ariaLabel, className, formatValue = formatNumber, horizontalGrid = true }) {
3005
+ function FunnelChart({ steps, series, unit, ariaLabel, className, formatValue = formatNumber, horizontalGrid = true, interactiveLegend = true }) {
3006
+ const legendFocus = useChartLegendFocus(series.map((item) => item.id));
2699
3007
  const chartId = useSvgId();
2700
3008
  const [highlighted, setHighlighted] = useState(null);
2701
3009
  const clearTimer = useRef(null);
@@ -2733,13 +3041,36 @@ function FunnelChart({ steps, series, unit, ariaLabel, className, formatValue =
2733
3041
  layout: "single-row",
2734
3042
  children: populations.map((item) => /* @__PURE__ */ jsxs(ChartLegend.Item, {
2735
3043
  className: "altertable-funnel-summary-item",
2736
- children: [/* @__PURE__ */ jsxs("span", {
3044
+ "data-legend-muted": interactiveLegend && legendFocus.hoveredId && (!legendFocus.focusedIds || legendFocus.focusedIds.has(legendFocus.hoveredId)) && legendFocus.hoveredId !== item.id || void 0,
3045
+ "data-legend-excluded": interactiveLegend && !legendFocus.visible(item.id) || void 0,
3046
+ children: [interactiveLegend && populations.length > 1 ? /* @__PURE__ */ jsxs("button", {
3047
+ type: "button",
3048
+ "data-atbl-control": "action",
3049
+ "data-atbl-focus": "ring",
3050
+ className: "altertable-chart-legend-action altertable-funnel-legend-button",
3051
+ "aria-pressed": !!legendFocus.focusedIds?.has(item.id),
3052
+ onPointerEnter: () => legendFocus.setHoveredId(item.id),
3053
+ onPointerLeave: () => legendFocus.setHoveredId(null),
3054
+ onFocus: () => legendFocus.setHoveredId(item.id),
3055
+ onBlur: () => legendFocus.setHoveredId(null),
3056
+ onClick: () => legendFocus.toggle(item.id),
3057
+ children: [/* @__PURE__ */ jsxs("span", {
3058
+ className: "altertable-funnel-series-label",
3059
+ children: [/* @__PURE__ */ jsx(ChartLegend.Marker, {
3060
+ kind: "square",
3061
+ color: item.color
3062
+ }), /* @__PURE__ */ jsx(ChartLegend.Label, { children: item.label })]
3063
+ }), /* @__PURE__ */ jsx("strong", {
3064
+ className: "altertable-funnel-series-value",
3065
+ children: formatPercent(rows.at(-1)?.readings.get(item.id)?.conversion ?? null)
3066
+ })]
3067
+ }) : /* @__PURE__ */ jsxs("span", {
2737
3068
  className: "altertable-funnel-series-label",
2738
3069
  children: [/* @__PURE__ */ jsx(ChartLegend.Marker, {
2739
3070
  kind: "square",
2740
3071
  color: item.color
2741
3072
  }), /* @__PURE__ */ jsx(ChartLegend.Label, { children: item.label })]
2742
- }), /* @__PURE__ */ jsx("strong", {
3073
+ }), (!interactiveLegend || populations.length <= 1) && /* @__PURE__ */ jsx("strong", {
2743
3074
  className: "altertable-funnel-series-value",
2744
3075
  children: formatPercent(rows.at(-1)?.readings.get(item.id)?.conversion ?? null)
2745
3076
  })]
@@ -2806,7 +3137,8 @@ function FunnelChart({ steps, series, unit, ariaLabel, className, formatValue =
2806
3137
  maxBarSize: void 0,
2807
3138
  activeBar: false,
2808
3139
  minPointSize: 0,
2809
- opacity: !highlighted || highlighted.id === item.id ? 1 : .2,
3140
+ style: { pointerEvents: interactiveLegend && !legendFocus.visible(item.id) ? "none" : void 0 },
3141
+ opacity: interactiveLegend ? legendFocus.opacity(item.id) * (!highlighted || highlighted.id === item.id ? 1 : .2) : !highlighted || highlighted.id === item.id ? 1 : .2,
2810
3142
  onMouseEnter: (bar) => highlight(item.id, true, bar.payload.index),
2811
3143
  onMouseLeave: scheduleClear,
2812
3144
  onClick: (bar) => highlight(item.id, true, bar.payload.index)
@@ -2815,7 +3147,8 @@ function FunnelChart({ steps, series, unit, ariaLabel, className, formatValue =
2815
3147
  name: `${item.label} drop-off`,
2816
3148
  stackId: item.id,
2817
3149
  fill: `url(#${item.hatchId})`,
2818
- opacity: !highlighted || highlighted.id === item.id ? 1 : .2,
3150
+ style: { pointerEvents: interactiveLegend && !legendFocus.visible(item.id) ? "none" : void 0 },
3151
+ opacity: interactiveLegend ? legendFocus.opacity(item.id) * (!highlighted || highlighted.id === item.id ? 1 : .2) : !highlighted || highlighted.id === item.id ? 1 : .2,
2819
3152
  onMouseEnter: (bar) => highlight(item.id, false, bar.payload.index),
2820
3153
  onMouseLeave: scheduleClear,
2821
3154
  onClick: (bar) => highlight(item.id, false, bar.payload.index),
@@ -2826,7 +3159,7 @@ function FunnelChart({ steps, series, unit, ariaLabel, className, formatValue =
2826
3159
  /* @__PURE__ */ jsx(ComposedChart.Tooltip, { content: ({ active, activeIndex }) => {
2827
3160
  const row = activeIndex == null ? void 0 : rows[Number(activeIndex)];
2828
3161
  if (!active || !row) return null;
2829
- const tooltipItems = [...row.readings.values()].filter((value) => !highlighted || highlighted.step !== row.index || value.population.id === highlighted.id).flatMap((value) => {
3162
+ const tooltipItems = [...row.readings.values()].filter((value) => (!interactiveLegend || legendFocus.visible(value.population.id)) && (!highlighted || highlighted.step !== row.index || value.population.id === highlighted.id)).flatMap((value) => {
2830
3163
  const item = value.population;
2831
3164
  return (highlighted?.step === row.index ? [highlighted.conversion] : [true, false]).map((conversion) => {
2832
3165
  const key = [item.id, conversion ? "conversion" : "drop-off"].join(KEY_SEPARATOR);
@@ -2943,7 +3276,8 @@ function createRetentionModel(series, unit, formatValue) {
2943
3276
  }
2944
3277
  /** Query-defined retention curves with count inspection and dotted incomplete periods.
2945
3278
  * Rates are not recomputed from counts. Compose inside VisualizationWidget. */
2946
- function RetentionChart({ series, unit, ariaLabel, className, formatValue = formatNumber, horizontalGrid = true }) {
3279
+ function RetentionChart({ series, unit, ariaLabel, className, formatValue = formatNumber, horizontalGrid = true, interactiveLegend = true }) {
3280
+ const legendFocus = useChartLegendFocus(series.map((item) => item.id));
2947
3281
  const { rows, rowsByOffset, cohorts } = createRetentionModel(series, unit, formatValue);
2948
3282
  return /* @__PURE__ */ jsx("section", {
2949
3283
  className: classNames("altertable-retention-chart", className),
@@ -2970,11 +3304,15 @@ function RetentionChart({ series, unit, ariaLabel, className, formatValue = form
2970
3304
  dataKey: (row) => row.readings.get(item.id)?.completePercent ?? null,
2971
3305
  name: item.label,
2972
3306
  stroke: item.color,
3307
+ opacity: interactiveLegend ? legendFocus.opacity(item.id) : 1,
3308
+ style: { pointerEvents: interactiveLegend && !legendFocus.visible(item.id) ? "none" : void 0 },
2973
3309
  connectNulls: false
2974
3310
  }), /* @__PURE__ */ jsx(ComposedChart.Line, {
2975
3311
  dataKey: (row) => row.readings.get(item.id)?.incompletePercent ?? null,
2976
3312
  name: item.label,
2977
3313
  stroke: item.color,
3314
+ opacity: interactiveLegend ? legendFocus.opacity(item.id) : 1,
3315
+ style: { pointerEvents: interactiveLegend && !legendFocus.visible(item.id) ? "none" : void 0 },
2978
3316
  strokeDasharray: "3 3",
2979
3317
  dot: false,
2980
3318
  activeDot: false,
@@ -2990,7 +3328,7 @@ function RetentionChart({ series, unit, ariaLabel, className, formatValue = form
2990
3328
  role: "tooltip",
2991
3329
  children: [/* @__PURE__ */ jsx("strong", { children: row.label }), cohorts.map((item) => {
2992
3330
  const reading = row.readings.get(item.id);
2993
- if (!reading) return null;
3331
+ if (!reading || interactiveLegend && !legendFocus.visible(item.id)) return null;
2994
3332
  return /* @__PURE__ */ jsxs("span", { children: [
2995
3333
  item.label,
2996
3334
  ": ",
@@ -3004,10 +3342,29 @@ function RetentionChart({ series, unit, ariaLabel, className, formatValue = form
3004
3342
  }),
3005
3343
  /* @__PURE__ */ jsx(ChartLegend, {
3006
3344
  "aria-label": `${ariaLabel} cohorts`,
3007
- children: cohorts.map((item) => /* @__PURE__ */ jsxs(ChartLegend.Item, { children: [/* @__PURE__ */ jsx(ChartLegend.Marker, {
3008
- kind: "square",
3009
- color: item.color
3010
- }), /* @__PURE__ */ jsx(ChartLegend.Label, { children: item.label })] }, item.id))
3345
+ children: cohorts.map((item) => /* @__PURE__ */ jsx(ChartLegend.Item, {
3346
+ "data-legend-muted": interactiveLegend && legendFocus.hoveredId && (!legendFocus.focusedIds || legendFocus.focusedIds.has(legendFocus.hoveredId)) && legendFocus.hoveredId !== item.id || void 0,
3347
+ "data-legend-excluded": interactiveLegend && !legendFocus.visible(item.id) || void 0,
3348
+ children: interactiveLegend && cohorts.length > 1 ? /* @__PURE__ */ jsxs("button", {
3349
+ type: "button",
3350
+ "data-atbl-control": "action",
3351
+ "data-atbl-focus": "ring",
3352
+ className: "altertable-chart-legend-action",
3353
+ "aria-pressed": !!legendFocus.focusedIds?.has(item.id),
3354
+ onPointerEnter: () => legendFocus.setHoveredId(item.id),
3355
+ onPointerLeave: () => legendFocus.setHoveredId(null),
3356
+ onFocus: () => legendFocus.setHoveredId(item.id),
3357
+ onBlur: () => legendFocus.setHoveredId(null),
3358
+ onClick: () => legendFocus.toggle(item.id),
3359
+ children: [/* @__PURE__ */ jsx(ChartLegend.Marker, {
3360
+ kind: "square",
3361
+ color: item.color
3362
+ }), /* @__PURE__ */ jsx(ChartLegend.Label, { children: item.label })]
3363
+ }) : /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(ChartLegend.Marker, {
3364
+ kind: "square",
3365
+ color: item.color
3366
+ }), /* @__PURE__ */ jsx(ChartLegend.Label, { children: item.label })] })
3367
+ }, item.id))
3011
3368
  }),
3012
3369
  /* @__PURE__ */ jsx("ul", {
3013
3370
  className: "altertable-sr-only",
@@ -3348,6 +3705,6 @@ const VisualizationWidget = withWidgetBoundary(VisualizationWidget$1);
3348
3705
  const TableWidget = withWidgetBoundary(TableWidget$1);
3349
3706
  const MetricWidget = withWidgetBoundary(MetricWidget$1);
3350
3707
  //#endregion
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 };
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 };
3352
3709
 
3353
3710
  //# sourceMappingURL=index.js.map