@altertable/data-app 0.69.0 → 0.70.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.
Files changed (107) hide show
  1. package/AGENTS.md +4 -0
  2. package/dist/chunks/{index-m0gbxtgp.js → index-2ajhmsc4.js} +3 -3
  3. package/dist/chunks/{index-m0gbxtgp.js.map → index-2ajhmsc4.js.map} +1 -1
  4. package/dist/chunks/{index-2sbp9h2b.js → index-58kks6a8.js} +1 -1
  5. package/dist/chunks/{index-2sbp9h2b.js.map → index-58kks6a8.js.map} +2 -2
  6. package/dist/chunks/{index-ap60vggk.js → index-7q99hf1z.js} +18 -11
  7. package/dist/chunks/index-7q99hf1z.js.map +10 -0
  8. package/dist/chunks/{index-kwnqycjt.js → index-9zqbrv2z.js} +7 -3
  9. package/dist/chunks/index-9zqbrv2z.js.map +10 -0
  10. package/dist/chunks/{index-k766wwwr.js → index-q1w84fv9.js} +167 -24
  11. package/dist/chunks/index-q1w84fv9.js.map +15 -0
  12. package/dist/chunks/{index-zcqxfwdq.js → index-rew95tbg.js} +85 -10
  13. package/dist/chunks/index-rew95tbg.js.map +13 -0
  14. package/dist/chunks/{index-qhzdzca2.js → index-vtpygsbq.js} +2392 -991
  15. package/dist/chunks/index-vtpygsbq.js.map +126 -0
  16. package/dist/chunks/{index-r7b1ftwy.js → index-wjt6cavj.js} +5 -3
  17. package/dist/chunks/index-wjt6cavj.js.map +10 -0
  18. package/dist/chunks/{index-sx488hvs.js → index-xzb7sx6g.js} +3 -3
  19. package/dist/client/index.js +5 -5
  20. package/dist/core/config.js +2 -2
  21. package/dist/core/contract.js +6 -6
  22. package/dist/core/contract.js.map +1 -1
  23. package/dist/embed/index.js +5 -5
  24. package/dist/index.js +2 -2
  25. package/dist/local.js +35 -2
  26. package/dist/local.js.map +8 -6
  27. package/dist/preview.js +15 -15
  28. package/dist/preview.js.map +6 -6
  29. package/dist/react/embed/index.js +1 -1
  30. package/dist/react/index.js +273 -331
  31. package/dist/react/index.js.map +5 -8
  32. package/dist/react/ui/index.js +874 -502
  33. package/dist/react/ui/index.js.map +24 -23
  34. package/dist/server.js +35 -2
  35. package/dist/server.js.map +8 -6
  36. package/dist/types/client/data-client.d.ts +21 -10
  37. package/dist/types/core/config.d.ts +20 -17
  38. package/dist/types/core/contract.d.ts +23 -13
  39. package/dist/types/core/dimension-source.d.ts +64 -0
  40. package/dist/types/core/dimension.d.ts +31 -23
  41. package/dist/types/core/facets.d.ts +13 -0
  42. package/dist/types/core/keys.d.ts +2 -0
  43. package/dist/types/core/operation-types.d.ts +6 -5
  44. package/dist/types/core/queries.d.ts +75 -7
  45. package/dist/types/core/variables.d.ts +38 -12
  46. package/dist/types/embed/sql.d.ts +1 -1
  47. package/dist/types/index.d.ts +1 -1
  48. package/dist/types/react/actions.d.ts +53 -0
  49. package/dist/types/react/bindings.d.ts +36 -0
  50. package/dist/types/react/details.d.ts +46 -0
  51. package/dist/types/react/exploration.d.ts +44 -0
  52. package/dist/types/react/hooks.d.ts +76 -38
  53. package/dist/types/react/index.d.ts +3 -0
  54. package/dist/types/react/style-contract.d.ts +1 -1
  55. package/dist/types/react/ui/AboutData.d.ts +9 -4
  56. package/dist/types/react/ui/AreaChart.d.ts +2 -2
  57. package/dist/types/react/ui/BarChart.d.ts +2 -2
  58. package/dist/types/react/ui/Button.d.ts +2 -1
  59. package/dist/types/react/ui/ComposedChartLegend.d.ts +2 -1
  60. package/dist/types/react/ui/DataApp.d.ts +3 -0
  61. package/dist/types/react/ui/DataWidget.d.ts +3 -0
  62. package/dist/types/react/ui/DimensionPicker.d.ts +2 -2
  63. package/dist/types/react/ui/ExplorationActionControl.d.ts +60 -0
  64. package/dist/types/react/ui/InspectionProvider.d.ts +2 -2
  65. package/dist/types/react/ui/LineChart.d.ts +2 -2
  66. package/dist/types/react/ui/Menu.d.ts +3 -2
  67. package/dist/types/react/ui/MetricWidget.d.ts +2 -0
  68. package/dist/types/react/ui/PickerField.d.ts +9 -1
  69. package/dist/types/react/ui/PieChart.d.ts +2 -2
  70. package/dist/types/react/ui/Select.d.ts +5 -1
  71. package/dist/types/react/ui/Sheet.d.ts +1 -1
  72. package/dist/types/react/ui/TrendChart.d.ts +3 -3
  73. package/dist/types/react/ui/VisualizationWidget.d.ts +1 -1
  74. package/dist/types/react/ui/chart-data.d.ts +8 -6
  75. package/dist/types/react/ui/chart-date-axis.d.ts +1 -1
  76. package/dist/types/react/ui/chart-interaction.d.ts +15 -9
  77. package/dist/types/react/ui/chart-time.d.ts +8 -5
  78. package/dist/types/react/ui/icons.d.ts +2 -0
  79. package/dist/types/react/ui/index.d.ts +2 -0
  80. package/dist/types/react/ui/use-chart-scroll-to-end.d.ts +2 -0
  81. package/dist/types/react/view-control-bar.d.ts +6 -4
  82. package/dist/types/react/view-runtime.d.ts +5 -2
  83. package/dist/types/react/view.d.ts +15 -6
  84. package/dist/types/react/widgets.d.ts +22 -11
  85. package/dist/worker.js +1 -1
  86. package/docs/app-authoring.md +10 -3
  87. package/docs/client.md +5 -6
  88. package/docs/composition.md +84 -0
  89. package/docs/contract.md +41 -21
  90. package/docs/data-context.md +2 -0
  91. package/docs/server.md +1 -1
  92. package/docs/styling.md +4 -0
  93. package/docs/ui.md +12 -1
  94. package/docs/variables.md +83 -11
  95. package/docs/views.md +56 -2
  96. package/docs/widgets.md +93 -0
  97. package/examples/starter-data-app/index.tsx +10 -22
  98. package/examples/starter-local-data-app/app.ts +7 -1
  99. package/examples/starter-local-data-app/tsconfig.json +7 -1
  100. package/package.json +1 -1
  101. package/dist/chunks/index-ap60vggk.js.map +0 -10
  102. package/dist/chunks/index-k766wwwr.js.map +0 -13
  103. package/dist/chunks/index-kwnqycjt.js.map +0 -10
  104. package/dist/chunks/index-qhzdzca2.js.map +0 -118
  105. package/dist/chunks/index-r7b1ftwy.js.map +0 -10
  106. package/dist/chunks/index-zcqxfwdq.js.map +0 -13
  107. /package/dist/chunks/{index-sx488hvs.js.map → index-xzb7sx6g.js.map} +0 -0
@@ -51,6 +51,12 @@ import {
51
51
  LiveControl2,
52
52
  PresentStory2,
53
53
  DataAppFrame,
54
+ ExplorationActionControl2,
55
+ ExplorationActionMenu,
56
+ useChartActions,
57
+ openExplorationMenu,
58
+ explorationMenuEvents,
59
+ getPrimaryExplorationAction,
54
60
  DataWidget2,
55
61
  VisualizationWidget2,
56
62
  MetricWidget2,
@@ -64,7 +70,7 @@ import {
64
70
  chartBarFill,
65
71
  createDataContext2,
66
72
  SectionHeading2
67
- } from "../../chunks/index-qhzdzca2.js";
73
+ } from "../../chunks/index-vtpygsbq.js";
68
74
  import {
69
75
  formatDate2,
70
76
  parseDateTime2,
@@ -72,17 +78,19 @@ import {
72
78
  formatNumber2,
73
79
  formatPercent2
74
80
  } from "../../chunks/index-22d576sn.js";
75
- import"../../chunks/index-k766wwwr.js";
76
- import"../../chunks/index-kwnqycjt.js";
81
+ import {
82
+ KEY_SEPARATOR
83
+ } from "../../chunks/index-q1w84fv9.js";
84
+ import"../../chunks/index-9zqbrv2z.js";
77
85
  import"../../chunks/index-cv36cyna.js";
78
86
  import {
79
87
  createDataClient2
80
- } from "../../chunks/index-ap60vggk.js";
81
- import"../../chunks/index-r7b1ftwy.js";
82
- import"../../chunks/index-sx488hvs.js";
88
+ } from "../../chunks/index-7q99hf1z.js";
89
+ import"../../chunks/index-wjt6cavj.js";
90
+ import"../../chunks/index-xzb7sx6g.js";
83
91
  import {
84
92
  invariant
85
- } from "../../chunks/index-zcqxfwdq.js";
93
+ } from "../../chunks/index-rew95tbg.js";
86
94
  // src/react/ui/StaticDataApp.tsx
87
95
  import { jsx } from "react/jsx-runtime";
88
96
  function DataApp(props) {
@@ -283,8 +291,24 @@ function GlossaryDefinition({
283
291
  ]
284
292
  });
285
293
  }
294
+ // src/react/ui/use-chart-scroll-to-end.ts
295
+ import { useLayoutEffect, useRef } from "react";
296
+ function useChartScrollToEnd(items) {
297
+ const scrollport = useRef(null);
298
+ useLayoutEffect(() => {
299
+ const element = scrollport.current;
300
+ if (element)
301
+ element.scrollLeft = element.scrollWidth - element.clientWidth;
302
+ }, [items]);
303
+ return scrollport;
304
+ }
305
+
286
306
  // src/react/ui/TrendChart.tsx
287
- import { useLayoutEffect as useLayoutEffect2, useRef as useRef2, useState as useState3 } from "react";
307
+ import {
308
+ Fragment as Fragment2,
309
+ useRef as useRef3,
310
+ useState as useState3
311
+ } from "react";
288
312
  import {
289
313
  AreaChart as RechartsAreaChart,
290
314
  LineChart as RechartsLineChart,
@@ -695,7 +719,9 @@ function ticker(year, month, week, day, hour, minute) {
695
719
  return year.every(tickStep(+start / durationYear, +stop / durationYear, count));
696
720
  if (i === 0)
697
721
  return millisecond.every(Math.max(tickStep(+start, +stop, count), 1));
698
- const [t, step] = tickIntervals[target / tickIntervals[i - 1][2] < tickIntervals[i][2] / target ? i - 1 : i];
722
+ const previous = tickIntervals[i - 1];
723
+ const next = tickIntervals[i];
724
+ const [t, step] = target / previous[2] < next[2] / target ? previous : next;
699
725
  return t.every(step);
700
726
  }
701
727
  return [ticks, tickInterval];
@@ -705,8 +731,12 @@ var [timeTicks, timeTickInterval] = ticker(timeYear, timeMonth, timeSunday, time
705
731
 
706
732
  // src/react/ui/chart-time.ts
707
733
  var day = 86400000;
734
+ var calendarDatePattern = /^\d{4}-\d{2}-\d{2}$/;
735
+ function isCalendarDate(value) {
736
+ return typeof value === "string" && calendarDatePattern.test(value);
737
+ }
708
738
  function chartTimestamp(value, numeric = false) {
709
- if (typeof value === "string" && /^\d{4}-\d{2}-\d{2}$/.test(value)) {
739
+ if (isCalendarDate(value)) {
710
740
  return parseDateTime2(`${value}T00:00:00Z`)?.getTime() ?? null;
711
741
  }
712
742
  if (value instanceof Date || typeof value === "string" || numeric && typeof value === "number") {
@@ -715,19 +745,27 @@ function chartTimestamp(value, numeric = false) {
715
745
  return null;
716
746
  }
717
747
  function timeModel(values, numeric = false) {
718
- if (!values.length)
719
- return null;
720
- const parsed = values.map((value) => chartTimestamp(value, numeric));
721
- if (parsed.some((value) => value == null))
722
- return null;
723
- const times = [...new Set(parsed)].sort((a, b) => a - b);
748
+ const timestamps = new Set;
749
+ for (const value of values) {
750
+ const timestamp = chartTimestamp(value, numeric);
751
+ if (timestamp == null)
752
+ return null;
753
+ timestamps.add(timestamp);
754
+ }
755
+ const times = [...timestamps].sort((a, b) => a - b);
724
756
  const start = times[0];
725
757
  const end = times.at(-1);
726
- const gaps = times.slice(1).map((value, index) => value - times[index]);
727
- const precision = gaps.reduce((minimum, gap) => Math.min(minimum, gap), day);
728
- const dateOnly = values.every((value) => typeof value === "string" && /^\d{4}-\d{2}-\d{2}$/.test(value));
729
- const seconds = times.some((value) => value % 60000 !== 0) || precision < 60000;
730
- const milliseconds = times.some((value) => value % 1000 !== 0) || precision < 1000;
758
+ if (start == null || end == null)
759
+ return null;
760
+ let minimumInterval = Infinity;
761
+ for (let index = 1;index < times.length; index++) {
762
+ minimumInterval = Math.min(minimumInterval, times[index] - times[index - 1]);
763
+ }
764
+ if (times.length === 1)
765
+ minimumInterval = day;
766
+ const dateOnly = values.every(isCalendarDate);
767
+ const seconds = times.some((value) => value % 60000 !== 0) || minimumInterval < 60000;
768
+ const milliseconds = times.some((value) => value % 1000 !== 0) || minimumInterval < 1000;
731
769
  function tooltip(value) {
732
770
  const time = chartTimestamp(value, true);
733
771
  if (time == null)
@@ -756,7 +794,7 @@ function timeModel(values, numeric = false) {
756
794
  start,
757
795
  end,
758
796
  times,
759
- precision: gaps.length ? gaps.reduce((minimum, gap) => Math.min(minimum, gap), Infinity) : day,
797
+ minimumInterval,
760
798
  tooltip
761
799
  };
762
800
  }
@@ -773,8 +811,8 @@ function timeTicks2(model, width) {
773
811
  const spansYears = firstDate.getUTCFullYear() !== lastDate.getUTCFullYear();
774
812
  const spansDates = firstDate.toISOString().slice(0, 10) !== lastDate.toISOString().slice(0, 10);
775
813
  const count = Math.max(2, Math.min(12, Math.floor(width / 80), model.times.length));
776
- let ticks = start === end ? [start] : utcTicks(new Date(start), new Date(end), Math.min(count, (end - start) / model.precision)).map(Number);
777
- const step = ticks.length > 1 ? ticks[1] - ticks[0] : Math.max(end - start, model.precision);
814
+ let ticks = start === end ? [start] : utcTicks(new Date(start), new Date(end), Math.min(count, (end - start) / model.minimumInterval)).map(Number);
815
+ const step = ticks.length > 1 ? ticks[1] - ticks[0] : Math.max(end - start, model.minimumInterval);
778
816
  const candidates = [...new Set([start, ...ticks, end])].sort((a, b) => a - b);
779
817
  ticks = [start];
780
818
  const gap = step < 1000 ? 110 : 80;
@@ -794,12 +832,12 @@ function timeTicks2(model, width) {
794
832
  const dateChanged = !previous || previous.toISOString().slice(0, 10) !== date.toISOString().slice(0, 10);
795
833
  if (step >= 300 * day)
796
834
  return { main: String(date.getUTCFullYear()), context: "" };
797
- if (step >= 28 * day && (model.precision >= 28 * day || end - start >= 180 * day))
835
+ if (step >= 28 * day && (model.minimumInterval >= 28 * day || end - start >= 180 * day))
798
836
  return {
799
837
  main: datePart(value, { month: "short" }),
800
838
  context: spansYears && yearChanged ? String(date.getUTCFullYear()) : ""
801
839
  };
802
- if (step >= day && !(model.precision < day && end - start <= 3 * day))
840
+ if (step >= day && !(model.minimumInterval < day && end - start <= 3 * day))
803
841
  return {
804
842
  main: datePart(value, { month: "short", day: "numeric" }),
805
843
  context: spansYears && yearChanged ? String(date.getUTCFullYear()) : ""
@@ -824,7 +862,7 @@ function timeTicks2(model, width) {
824
862
 
825
863
  // src/react/ui/chart-date-axis.tsx
826
864
  import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
827
- var DateAxes = createContext(null);
865
+ var ChartDateAxesContext = createContext(null);
828
866
  function ChartDateAxes({
829
867
  data,
830
868
  children
@@ -838,13 +876,13 @@ function ChartDateAxes({
838
876
  return next;
839
877
  });
840
878
  }, []);
841
- return /* @__PURE__ */ jsx5(DateAxes.Provider, {
879
+ return /* @__PURE__ */ jsx5(ChartDateAxesContext.Provider, {
842
880
  value: { data, formatters, register },
843
881
  children
844
882
  });
845
883
  }
846
884
  function useDateAxisLabel(id = 0) {
847
- return useContext(DateAxes)?.formatters.get(id);
885
+ return useContext(ChartDateAxesContext)?.formatters.get(id);
848
886
  }
849
887
  function field(row, key) {
850
888
  if (row == null || typeof row !== "object")
@@ -853,11 +891,18 @@ function field(row, key) {
853
891
  return row[key];
854
892
  return String(key).replace(/\[(\d+)\]/g, ".$1").split(".").reduce((value, part) => value != null && typeof value === "object" ? value[part] : undefined, row);
855
893
  }
894
+ var xAxisDefaults = {
895
+ stroke: "var(--atbl-muted)",
896
+ tickFormatter: (value) => typeof value === "number" ? formatNumber2(value) : String(value),
897
+ tickLine: false,
898
+ axisLine: { stroke: "var(--atbl-border)" },
899
+ tick: { fontSize: "var(--atbl-type-meta-size)" }
900
+ };
856
901
  function ChartXAxis(props) {
857
- const context = useContext(DateAxes);
902
+ const context = useContext(ChartDateAxesContext);
858
903
  const plot = usePlotArea();
859
904
  const data = context?.data;
860
- const dataKey = props.dataKey;
905
+ const { dataKey, ...axisProps } = props;
861
906
  const numeric = props.scale === "utc";
862
907
  const enabled = numeric || props.type == null && props.scale == null && props.tickFormatter == null && props.ticks == null;
863
908
  const model = useMemo(() => {
@@ -868,56 +913,54 @@ function ChartXAxis(props) {
868
913
  const register = context?.register;
869
914
  const id = props.xAxisId ?? 0;
870
915
  useEffect(() => model ? register?.(id, model.tooltip) : undefined, [register, id, model]);
871
- const axis = model ? timeTicks2(model, plot?.width ?? 400) : undefined;
916
+ if (!model || dataKey == null) {
917
+ return /* @__PURE__ */ jsx5(XAxis, {
918
+ ...xAxisDefaults,
919
+ ...props
920
+ });
921
+ }
922
+ const automaticTicks = props.ticks == null && props.tickFormatter == null ? timeTicks2(model, plot?.width ?? 400) : null;
872
923
  return /* @__PURE__ */ jsx5(XAxis, {
873
- stroke: "var(--atbl-muted)",
874
- tickFormatter: (value) => typeof value === "number" ? formatNumber2(value) : String(value),
875
- tickLine: false,
876
- axisLine: { stroke: "var(--atbl-border)" },
877
- tick: { fontSize: "var(--atbl-type-meta-size)" },
878
- ...model && axis ? {
879
- type: "number",
880
- scale: "utc",
881
- domain: model.start === model.end ? [
882
- model.start - model.precision / 2,
883
- model.end + model.precision / 2
884
- ] : [model.start, model.end],
885
- ticks: axis.ticks,
886
- interval: 0,
887
- height: 48,
888
- tick: ({ x, y, payload, index }) => {
889
- const label = axis.label(Number(payload.value), index);
890
- return /* @__PURE__ */ jsxs3("text", {
891
- x,
892
- y: Number(y) + 5,
893
- fill: "var(--atbl-muted)",
894
- fontSize: "var(--atbl-type-meta-size)",
895
- textAnchor: index === 0 ? "start" : index === axis.ticks.length - 1 ? "end" : "middle",
896
- children: [
897
- /* @__PURE__ */ jsx5("tspan", {
898
- x,
899
- dy: "0.8em",
900
- children: label.main
901
- }),
902
- label.context && /* @__PURE__ */ jsx5("tspan", {
903
- x,
904
- dy: "1.4em",
905
- children: label.context
906
- })
907
- ]
908
- });
909
- }
910
- } : {},
911
- ...props,
912
- ...model ? {
913
- type: "number",
914
- dataKey: (row) => chartTimestamp(typeof dataKey === "function" ? dataKey(row) : field(row, dataKey), numeric)
915
- } : {}
924
+ ...xAxisDefaults,
925
+ scale: "utc",
926
+ domain: model.start === model.end ? [
927
+ model.start - model.minimumInterval / 2,
928
+ model.end + model.minimumInterval / 2
929
+ ] : [model.start, model.end],
930
+ ticks: automaticTicks?.ticks,
931
+ interval: automaticTicks ? 0 : undefined,
932
+ height: 48,
933
+ tickFormatter: model.tooltip,
934
+ tick: automaticTicks ? ({ x, y, payload, index }) => {
935
+ const label = automaticTicks.label(Number(payload.value), index);
936
+ return /* @__PURE__ */ jsxs3("text", {
937
+ x,
938
+ y: Number(y) + 5,
939
+ fill: "var(--atbl-muted)",
940
+ fontSize: "var(--atbl-type-meta-size)",
941
+ textAnchor: index === 0 ? "start" : index === automaticTicks.ticks.length - 1 ? "end" : "middle",
942
+ children: [
943
+ /* @__PURE__ */ jsx5("tspan", {
944
+ x,
945
+ dy: "0.8em",
946
+ children: label.main
947
+ }),
948
+ label.context && /* @__PURE__ */ jsx5("tspan", {
949
+ x,
950
+ dy: "1.4em",
951
+ children: label.context
952
+ })
953
+ ]
954
+ });
955
+ } : xAxisDefaults.tick,
956
+ ...axisProps,
957
+ type: "number",
958
+ dataKey: (row) => chartTimestamp(typeof dataKey === "function" ? dataKey(row) : field(row, dataKey), numeric)
916
959
  });
917
960
  }
918
961
 
919
962
  // src/react/ui/chart-primitives.tsx
920
- import { useContext as useContext3, useLayoutEffect } from "react";
963
+ import { useContext as useContext3, useLayoutEffect as useLayoutEffect2 } from "react";
921
964
 
922
965
  // src/react/ui/chart-interaction.tsx
923
966
  import {
@@ -927,26 +970,29 @@ import {
927
970
  useEffect as useEffect2
928
971
  } from "react";
929
972
  import { jsx as jsx6 } from "react/jsx-runtime";
930
- var ChartInteraction = createContext2(null);
973
+ var ChartInteractionContext = createContext2(null);
974
+ function isChartSeriesActive(interaction, seriesId) {
975
+ return !interaction?.isPointerInspection || interaction.seriesCount === 1 || interaction.activeSeriesId === seriesId;
976
+ }
931
977
  function useChartSeries(id) {
932
978
  const generatedId = useId();
933
- const interaction = useContext2(ChartInteraction);
979
+ const interaction = useContext2(ChartInteractionContext);
934
980
  const seriesId = id ?? generatedId;
935
981
  const registerSeries = interaction?.registerSeries;
936
982
  useEffect2(() => registerSeries?.(seriesId), [registerSeries, seriesId]);
937
983
  return {
938
984
  id: seriesId,
939
- active: !interaction?.pointer || interaction.seriesCount === 1 || interaction.hovered === seriesId
985
+ active: isChartSeriesActive(interaction, seriesId)
940
986
  };
941
987
  }
942
988
  function ChartSeries({
943
989
  id,
944
990
  children
945
991
  }) {
946
- const interaction = useContext2(ChartInteraction);
992
+ const interaction = useContext2(ChartInteractionContext);
947
993
  return /* @__PURE__ */ jsx6("g", {
948
- onPointerOver: () => interaction?.setHovered(id),
949
- onPointerDown: () => interaction?.setHovered(id),
994
+ onPointerOver: () => interaction?.setHoveredSeriesId(id),
995
+ onPointerDown: () => interaction?.setHoveredSeriesId(id),
950
996
  children
951
997
  });
952
998
  }
@@ -969,7 +1015,7 @@ import {
969
1015
  Children,
970
1016
  useId as useId2,
971
1017
  useEffect as useEffect3,
972
- useRef,
1018
+ useRef as useRef2,
973
1019
  useState as useState2
974
1020
  } from "react";
975
1021
  import { jsx as jsx7, jsxs as jsxs4, Fragment } from "react/jsx-runtime";
@@ -984,7 +1030,7 @@ function ChartLegendRoot({
984
1030
  }) {
985
1031
  const [expanded, setExpanded] = useState2(false);
986
1032
  const listId = useId2();
987
- const containerRef = useRef(null);
1033
+ const containerRef = useRef2(null);
988
1034
  const [columns, setColumns] = useState2(2);
989
1035
  useEffect3(() => {
990
1036
  const container = containerRef.current;
@@ -1169,14 +1215,14 @@ function NearestChartDot({
1169
1215
  cy,
1170
1216
  stroke
1171
1217
  }) {
1172
- const interaction = useContext3(ChartInteraction);
1218
+ const interaction = useContext3(ChartInteractionContext);
1173
1219
  const registerPoint = interaction?.registerPoint;
1174
- useLayoutEffect(() => {
1220
+ useLayoutEffect2(() => {
1175
1221
  if (cx == null || cy == null)
1176
1222
  return;
1177
1223
  return registerPoint?.(seriesId, cx, cy);
1178
1224
  }, [registerPoint, seriesId, cx, cy]);
1179
- const active = !interaction?.pointer || interaction.seriesCount === 1 || interaction.hovered === seriesId;
1225
+ const active = isChartSeriesActive(interaction, seriesId);
1180
1226
  return active ? /* @__PURE__ */ jsx8(ChartDot, {
1181
1227
  cx,
1182
1228
  cy,
@@ -1364,14 +1410,14 @@ function ChartTooltipContent(props) {
1364
1410
  }
1365
1411
  function ChartTooltip(props) {
1366
1412
  const dateLabel = useDateAxisLabel(props.axisId);
1367
- const interaction = useContext3(ChartInteraction);
1413
+ const interaction = useContext3(ChartInteractionContext);
1368
1414
  return /* @__PURE__ */ jsx8(Tooltip, {
1369
1415
  labelFormatter: dateLabel,
1370
1416
  content: (content) => /* @__PURE__ */ jsx8(ChartTooltipContent, {
1371
1417
  ...content,
1372
- payload: interaction?.pointer && interaction.seriesCount !== 1 && props.shared !== true ? content.payload.filter((entry) => entry.graphicalItemId === interaction.hovered) : content.payload
1418
+ payload: interaction?.isPointerInspection && interaction.seriesCount !== 1 && props.shared !== true ? content.payload.filter((entry) => entry.graphicalItemId === interaction.activeSeriesId) : content.payload
1373
1419
  }),
1374
- position: interaction?.pointer && interaction.point ? { y: interaction.point.y } : undefined,
1420
+ position: interaction?.isPointerInspection && interaction.activePoint ? { y: interaction.activePoint.y } : undefined,
1375
1421
  cursor: false,
1376
1422
  isAnimationActive: false,
1377
1423
  ...props
@@ -1379,41 +1425,44 @@ function ChartTooltip(props) {
1379
1425
  }
1380
1426
 
1381
1427
  // src/react/ui/chart-data.ts
1382
- function validateChartItems(kind, items) {
1428
+ function validateChartIds(kind, items) {
1383
1429
  const ids = new Set;
1384
1430
  for (const item of items) {
1385
1431
  invariant(item.id.trim().length > 0, `${kind} chart IDs must be nonempty and unique: blank ID.`);
1386
1432
  invariant(!ids.has(item.id), `${kind} chart IDs must be nonempty and unique: duplicate "${item.id}".`);
1387
1433
  ids.add(item.id);
1388
- if (kind === "scatter") {
1389
- const point = item;
1390
- invariant(Number.isFinite(point.x) && Number.isFinite(point.y), `scatter chart "${item.id}" requires finite values for x and y.`);
1391
- } else {
1392
- const point = item;
1393
- invariant(Number.isFinite(point.value), `${kind} chart "${item.id}" requires finite values.`);
1394
- invariant(kind !== "bar" && kind !== "pie" || point.value >= 0, `${kind} chart "${item.id}" requires nonnegative values.`);
1395
- }
1434
+ }
1435
+ }
1436
+ function validateValueChartItems(kind, items) {
1437
+ validateChartIds(kind, items);
1438
+ for (const item of items) {
1439
+ invariant(Number.isFinite(item.value), `${kind} chart "${item.id}" requires finite values.`);
1440
+ invariant(kind !== "bar" && kind !== "pie" || item.value >= 0, `${kind} chart "${item.id}" requires nonnegative values.`);
1441
+ }
1442
+ }
1443
+ function validateScatterChartItems(items) {
1444
+ validateChartIds("scatter", items);
1445
+ for (const item of items) {
1446
+ invariant(Number.isFinite(item.x) && Number.isFinite(item.y), `scatter chart "${item.id}" requires finite values for x and y.`);
1396
1447
  }
1397
1448
  }
1398
1449
 
1399
1450
  // src/react/ui/TrendChart.tsx
1400
- import { jsx as jsx9, jsxs as jsxs6, Fragment as Fragment2 } from "react/jsx-runtime";
1451
+ import { jsx as jsx9, jsxs as jsxs6, Fragment as Fragment3 } from "react/jsx-runtime";
1401
1452
  function TrendChart({
1402
1453
  items,
1403
1454
  unit,
1404
1455
  ariaLabel,
1405
1456
  formatValue = formatNumber2,
1406
- area = false
1457
+ kind,
1458
+ itemActions
1407
1459
  }) {
1408
- validateChartItems(area ? "area" : "line", items);
1409
- const Plot = area ? RechartsAreaChart : RechartsLineChart;
1460
+ validateValueChartItems(kind, items);
1461
+ const Plot = kind === "area" ? RechartsAreaChart : RechartsLineChart;
1462
+ const chartActions = useChartActions();
1410
1463
  const [activeIndex, setActiveIndex] = useState3();
1411
- const scrollport = useRef2(null);
1412
- useLayoutEffect2(() => {
1413
- const element = scrollport.current;
1414
- if (element)
1415
- element.scrollLeft = element.scrollWidth - element.clientWidth;
1416
- }, [items]);
1464
+ const scrollport = useChartScrollToEnd(items);
1465
+ const menuTriggers = useRef3(new Map);
1417
1466
  const magnitude = items.reduce((max, item) => Math.max(max, Math.abs(item.value)), 1);
1418
1467
  const low = items.reduce((min, item) => Math.min(min, item.value / magnitude), 0);
1419
1468
  const high = items.reduce((max, item) => Math.max(max, item.value / magnitude), 0);
@@ -1424,7 +1473,7 @@ function TrendChart({
1424
1473
  items.length === 0 && /* @__PURE__ */ jsx9("span", {
1425
1474
  children: "No data"
1426
1475
  }),
1427
- items.length > 0 && /* @__PURE__ */ jsx9(Fragment2, {
1476
+ items.length > 0 && /* @__PURE__ */ jsx9(Fragment3, {
1428
1477
  children: /* @__PURE__ */ jsx9("div", {
1429
1478
  className: "altertable-trend-scroll",
1430
1479
  ref: scrollport,
@@ -1460,7 +1509,7 @@ function TrendChart({
1460
1509
  y: 0,
1461
1510
  stroke: "var(--atbl-border)"
1462
1511
  }),
1463
- area && /* @__PURE__ */ jsx9(ChartArea, {
1512
+ kind === "area" && /* @__PURE__ */ jsx9(ChartArea, {
1464
1513
  dataKey: "plotValue",
1465
1514
  stroke: "none",
1466
1515
  fill: "var(--atbl-chart-1)",
@@ -1481,47 +1530,123 @@ function TrendChart({
1481
1530
  }),
1482
1531
  /* @__PURE__ */ jsx9("div", {
1483
1532
  className: "altertable-trend-points",
1484
- children: items.map((item, index) => /* @__PURE__ */ jsx9(Tooltip2, {
1485
- variant: "chart",
1486
- onOpenChange: (open) => setActiveIndex((current) => open ? index : current === index ? undefined : current),
1487
- content: /* @__PURE__ */ jsxs6(Fragment2, {
1488
- children: [
1489
- /* @__PURE__ */ jsx9("strong", {
1490
- children: item.label
1491
- }),
1492
- /* @__PURE__ */ jsxs6("span", {
1493
- children: [
1494
- formatValue(item.value),
1495
- " ",
1496
- unit
1497
- ]
1498
- })
1499
- ]
1500
- }),
1501
- className: "altertable-chart-column",
1502
- children: /* @__PURE__ */ jsxs6("button", {
1503
- "data-atbl-focus": "ring",
1504
- "data-atbl-control": "default",
1505
- type: "button",
1506
- tabIndex: -1,
1507
- className: "altertable-trend-point",
1508
- "aria-label": `${item.label}: ${formatValue(item.value)} ${unit}`,
1509
- children: [
1510
- /* @__PURE__ */ jsx9("span", {
1511
- className: "altertable-trend-hit"
1512
- }),
1513
- /* @__PURE__ */ jsx9("span", {
1514
- className: "altertable-trend-label",
1515
- children: item.label
1516
- })
1517
- ]
1518
- })
1519
- }, item.id))
1533
+ children: items.map((item, index) => {
1534
+ const declaredActions = itemActions?.(item) ?? [];
1535
+ const actions = chartActions.actions(declaredActions, item.label, `${formatValue(item.value)} ${unit}`);
1536
+ const action = getPrimaryExplorationAction(actions);
1537
+ const menuTrigger = {
1538
+ get current() {
1539
+ return menuTriggers.current.get(item.id) ?? null;
1540
+ }
1541
+ };
1542
+ return /* @__PURE__ */ jsx9(Fragment2, {
1543
+ children: /* @__PURE__ */ jsxs6("div", {
1544
+ className: "altertable-chart-item-actions",
1545
+ children: [
1546
+ /* @__PURE__ */ jsx9(Tooltip2, {
1547
+ variant: "chart",
1548
+ onOpenChange: (open) => setActiveIndex((current) => open ? index : current === index ? undefined : current),
1549
+ content: /* @__PURE__ */ jsxs6(Fragment3, {
1550
+ children: [
1551
+ /* @__PURE__ */ jsx9("strong", {
1552
+ children: item.label
1553
+ }),
1554
+ /* @__PURE__ */ jsxs6("span", {
1555
+ children: [
1556
+ formatValue(item.value),
1557
+ " ",
1558
+ unit
1559
+ ]
1560
+ })
1561
+ ]
1562
+ }),
1563
+ className: "altertable-chart-column",
1564
+ children: action ? /* @__PURE__ */ jsxs6("button", {
1565
+ "data-atbl-focus": "ring",
1566
+ "data-atbl-control": "action",
1567
+ type: "button",
1568
+ className: "altertable-trend-point",
1569
+ "aria-label": `${item.label}: ${formatValue(item.value)} ${unit}. ${action.label}`,
1570
+ ...explorationMenuEvents(menuTrigger),
1571
+ onClick: (event) => action.onSelect(event.currentTarget),
1572
+ children: [
1573
+ /* @__PURE__ */ jsx9("span", {
1574
+ className: "altertable-trend-hit"
1575
+ }),
1576
+ /* @__PURE__ */ jsx9("span", {
1577
+ className: "altertable-trend-label",
1578
+ children: item.label
1579
+ })
1580
+ ]
1581
+ }) : actions.length > 1 ? /* @__PURE__ */ jsxs6(MenuTrigger2, {
1582
+ children: [
1583
+ /* @__PURE__ */ jsxs6(PressButton, {
1584
+ ...explorationMenuEvents(menuTrigger),
1585
+ ref: (element) => {
1586
+ if (element)
1587
+ menuTriggers.current.set(item.id, element);
1588
+ else
1589
+ menuTriggers.current.delete(item.id);
1590
+ },
1591
+ className: "altertable-trend-point",
1592
+ "aria-label": `${item.label}: ${formatValue(item.value)} ${unit}. Actions`,
1593
+ children: [
1594
+ /* @__PURE__ */ jsx9("span", {
1595
+ className: "altertable-trend-hit"
1596
+ }),
1597
+ /* @__PURE__ */ jsx9("span", {
1598
+ className: "altertable-trend-label",
1599
+ children: item.label
1600
+ })
1601
+ ]
1602
+ }),
1603
+ /* @__PURE__ */ jsx9(ExplorationActionMenu, {
1604
+ actions,
1605
+ ariaLabel: `${item.label} actions`,
1606
+ triggerRef: menuTrigger
1607
+ })
1608
+ ]
1609
+ }) : /* @__PURE__ */ jsxs6("button", {
1610
+ "data-atbl-focus": "ring",
1611
+ "data-atbl-control": "default",
1612
+ type: "button",
1613
+ tabIndex: -1,
1614
+ className: "altertable-trend-point",
1615
+ "aria-label": `${item.label}: ${formatValue(item.value)} ${unit}`,
1616
+ children: [
1617
+ /* @__PURE__ */ jsx9("span", {
1618
+ className: "altertable-trend-hit"
1619
+ }),
1620
+ /* @__PURE__ */ jsx9("span", {
1621
+ className: "altertable-trend-label",
1622
+ children: item.label
1623
+ })
1624
+ ]
1625
+ })
1626
+ }),
1627
+ action && /* @__PURE__ */ jsx9(ExplorationActionControl2, {
1628
+ contextOnly: declaredActions.length === 1,
1629
+ indicator: "chevron",
1630
+ ref: (element) => {
1631
+ if (element)
1632
+ menuTriggers.current.set(item.id, element);
1633
+ else
1634
+ menuTriggers.current.delete(item.id);
1635
+ },
1636
+ actions,
1637
+ ariaLabel: `${item.label} actions`,
1638
+ hidePrimary: Boolean(action)
1639
+ })
1640
+ ]
1641
+ })
1642
+ }, item.id);
1643
+ })
1520
1644
  })
1521
1645
  ]
1522
1646
  })
1523
1647
  })
1524
- })
1648
+ }),
1649
+ chartActions.feedback
1525
1650
  ]
1526
1651
  });
1527
1652
  }
@@ -1530,7 +1655,8 @@ function TrendChart({
1530
1655
  import { jsx as jsx10 } from "react/jsx-runtime";
1531
1656
  function LineChart(props) {
1532
1657
  return /* @__PURE__ */ jsx10(TrendChart, {
1533
- ...props
1658
+ ...props,
1659
+ kind: "line"
1534
1660
  });
1535
1661
  }
1536
1662
  // src/react/ui/AreaChart.tsx
@@ -1538,23 +1664,27 @@ import { jsx as jsx11 } from "react/jsx-runtime";
1538
1664
  function AreaChart(props) {
1539
1665
  return /* @__PURE__ */ jsx11(TrendChart, {
1540
1666
  ...props,
1541
- area: true
1667
+ kind: "area"
1542
1668
  });
1543
1669
  }
1544
1670
  // src/react/ui/PieChart.tsx
1545
- import { useState as useState4 } from "react";
1546
- import { jsx as jsx12, jsxs as jsxs7, Fragment as Fragment3 } from "react/jsx-runtime";
1671
+ import { useRef as useRef4, useState as useState4 } from "react";
1672
+ import { jsx as jsx12, jsxs as jsxs7, Fragment as Fragment4 } from "react/jsx-runtime";
1547
1673
  function PieChart({
1548
1674
  items,
1549
1675
  unit,
1550
1676
  ariaLabel,
1551
1677
  showLegend = true,
1552
- formatValue = (value) => new Intl.NumberFormat().format(value)
1678
+ formatValue = (value) => new Intl.NumberFormat().format(value),
1679
+ itemActions
1553
1680
  }) {
1554
- validateChartItems("pie", items);
1681
+ validateValueChartItems("pie", items);
1682
+ const chartActions = useChartActions();
1555
1683
  const [previewId, setPreviewId] = useState4(null);
1556
1684
  const [plotOpen, setPlotOpen] = useState4(false);
1557
1685
  const [legendId, setLegendId] = useState4(null);
1686
+ const menuTriggers = useRef4(new Map);
1687
+ const plotMenuTriggers = useRef4(new Map);
1558
1688
  const maximum = items.reduce((max, item) => Math.max(max, item.value), 0);
1559
1689
  const total = maximum ? items.reduce((sum, item) => sum + item.value / maximum, 0) : 0;
1560
1690
  let cursor = -Math.PI / 2;
@@ -1568,7 +1698,7 @@ function PieChart({
1568
1698
  cursor += share * Math.PI * 2;
1569
1699
  const middle = (start + cursor) / 2;
1570
1700
  slices.push({
1571
- ...item,
1701
+ row: item,
1572
1702
  share,
1573
1703
  color: `var(--atbl-chart-${index % 8 + 1})`,
1574
1704
  path: `${share === 1 ? "M" : "M110,110 L"}${point(start)} A100,100 0 0 1 ${point(middle)} A100,100 0 0 1 ${point(cursor)} Z`
@@ -1580,8 +1710,9 @@ function PieChart({
1580
1710
  maximumFractionDigits: 1
1581
1711
  }).format(share);
1582
1712
  }
1583
- function detail(item) {
1584
- return /* @__PURE__ */ jsxs7(Fragment3, {
1713
+ function detail(slice) {
1714
+ const item = slice.row;
1715
+ return /* @__PURE__ */ jsxs7(Fragment4, {
1585
1716
  children: [
1586
1717
  /* @__PURE__ */ jsx12("strong", {
1587
1718
  children: item.label
@@ -1592,13 +1723,17 @@ function PieChart({
1592
1723
  " ",
1593
1724
  unit,
1594
1725
  " · ",
1595
- percent(item.share)
1726
+ percent(slice.share)
1596
1727
  ]
1597
1728
  })
1598
1729
  ]
1599
1730
  });
1600
1731
  }
1601
- const preview = slices.find((item) => item.id === previewId);
1732
+ function actionsFor(slice) {
1733
+ const item = slice.row;
1734
+ return chartActions.actions(itemActions?.(item) ?? [], item.label, `${formatValue(item.value)} ${unit} · ${percent(slice.share)}`);
1735
+ }
1736
+ const preview = slices.find((slice) => slice.row.id === previewId);
1602
1737
  return /* @__PURE__ */ jsxs7("section", {
1603
1738
  className: "altertable-pie-chart",
1604
1739
  "aria-label": ariaLabel,
@@ -1606,7 +1741,7 @@ function PieChart({
1606
1741
  items.length === 0 && /* @__PURE__ */ jsx12("span", {
1607
1742
  children: "No data"
1608
1743
  }),
1609
- items.length > 0 && /* @__PURE__ */ jsxs7(Fragment3, {
1744
+ items.length > 0 && /* @__PURE__ */ jsxs7(Fragment4, {
1610
1745
  children: [
1611
1746
  /* @__PURE__ */ jsxs7("div", {
1612
1747
  className: "altertable-pie-plot",
@@ -1618,34 +1753,88 @@ function PieChart({
1618
1753
  content: preview ? detail(preview) : null,
1619
1754
  children: /* @__PURE__ */ jsx12("svg", {
1620
1755
  viewBox: "0 0 220 220",
1621
- "aria-hidden": "true",
1622
- focusable: "false",
1756
+ "aria-hidden": itemActions ? undefined : true,
1757
+ "aria-label": itemActions ? ariaLabel : undefined,
1758
+ focusable: itemActions ? undefined : false,
1759
+ role: itemActions ? "group" : undefined,
1623
1760
  children: total === 0 ? /* @__PURE__ */ jsx12("circle", {
1624
1761
  cx: "110",
1625
1762
  cy: "110",
1626
1763
  r: "100",
1627
1764
  className: "altertable-pie-empty"
1628
- }) : slices.filter((item) => item.share > 0).map((item) => /* @__PURE__ */ jsx12("path", {
1629
- d: item.path,
1630
- fill: item.color,
1631
- className: "altertable-pie-slice",
1632
- "data-active": item.id === (plotOpen && previewId ? previewId : showLegend ? legendId : null) || undefined,
1633
- onPointerDown: (event) => {
1634
- if (plotOpen && previewId !== item.id)
1635
- event.preventDefault();
1636
- setPreviewId(item.id);
1637
- },
1638
- onPointerEnter: (event) => {
1639
- if (event.pointerType === "mouse")
1765
+ }) : slices.filter((slice) => slice.share > 0).map((slice) => {
1766
+ const item = slice.row;
1767
+ const menuTrigger = {
1768
+ get current() {
1769
+ return menuTriggers.current.get(item.id) ?? plotMenuTriggers.current.get(item.id) ?? null;
1770
+ }
1771
+ };
1772
+ const action = getPrimaryExplorationAction(actionsFor(slice));
1773
+ const opensMenu = !action && (itemActions?.(item).length ?? 0) > 1;
1774
+ return /* @__PURE__ */ jsx12("path", {
1775
+ d: slice.path,
1776
+ fill: slice.color,
1777
+ className: "altertable-pie-slice",
1778
+ "data-active": item.id === (plotOpen && previewId ? previewId : showLegend ? legendId : null) || undefined,
1779
+ onPointerDown: (event) => {
1780
+ if (plotOpen && previewId !== item.id)
1781
+ event.preventDefault();
1640
1782
  setPreviewId(item.id);
1641
- },
1642
- onPointerLeave: (event) => {
1643
- if (event.pointerType === "mouse")
1644
- setPreviewId(null);
1645
- }
1646
- }, item.id))
1783
+ },
1784
+ onClick: (event) => {
1785
+ if (action)
1786
+ action.onSelect(event.currentTarget);
1787
+ else if (opensMenu)
1788
+ menuTrigger.current?.click();
1789
+ },
1790
+ onContextMenu: explorationMenuEvents(menuTrigger).onContextMenu,
1791
+ onKeyDown: (event) => {
1792
+ explorationMenuEvents(menuTrigger).onKeyDown(event);
1793
+ if ((action || opensMenu) && (event.key === "Enter" || event.key === " ")) {
1794
+ event.preventDefault();
1795
+ if (action)
1796
+ action.onSelect(event.currentTarget);
1797
+ else
1798
+ menuTrigger.current?.click();
1799
+ }
1800
+ },
1801
+ "aria-label": action ? `${item.label}: ${formatValue(item.value)} ${unit}. ${action.label}` : opensMenu ? `${item.label}: ${formatValue(item.value)} ${unit}. Actions` : undefined,
1802
+ role: action || opensMenu ? "button" : undefined,
1803
+ "data-atbl-control": action || opensMenu ? "action" : undefined,
1804
+ tabIndex: action || opensMenu ? 0 : undefined,
1805
+ onPointerEnter: (event) => {
1806
+ if (event.pointerType === "mouse")
1807
+ setPreviewId(item.id);
1808
+ },
1809
+ onPointerLeave: (event) => {
1810
+ if (event.pointerType === "mouse")
1811
+ setPreviewId(null);
1812
+ }
1813
+ }, item.id);
1814
+ })
1647
1815
  })
1648
1816
  }),
1817
+ slices.map((slice) => {
1818
+ const item = slice.row;
1819
+ const actions = actionsFor(slice);
1820
+ if (actions.length === 0)
1821
+ return null;
1822
+ return /* @__PURE__ */ jsx12("span", {
1823
+ className: "altertable-sr-only",
1824
+ children: /* @__PURE__ */ jsx12(ExplorationActionControl2, {
1825
+ ref: (element) => {
1826
+ if (element)
1827
+ plotMenuTriggers.current.set(item.id, element);
1828
+ else
1829
+ plotMenuTriggers.current.delete(item.id);
1830
+ },
1831
+ actions,
1832
+ ariaLabel: `${item.label} actions`,
1833
+ contextOnly: true,
1834
+ hidePrimary: true
1835
+ })
1836
+ }, item.id);
1837
+ }),
1649
1838
  total === 0 && /* @__PURE__ */ jsx12("span", {
1650
1839
  className: "altertable-pie-empty-label",
1651
1840
  children: "No nonzero values"
@@ -1656,44 +1845,85 @@ function PieChart({
1656
1845
  layout: "vertical",
1657
1846
  "aria-label": `${ariaLabel} legend`,
1658
1847
  className: "altertable-pie-legend",
1659
- children: slices.map((item) => /* @__PURE__ */ jsx12(ChartLegend.Item, {
1660
- children: /* @__PURE__ */ jsx12(Tooltip2, {
1661
- variant: "chart",
1662
- content: detail(item),
1663
- onOpenChange: (open) => setLegendId((current) => open ? item.id : current === item.id ? null : current),
1664
- children: /* @__PURE__ */ jsxs7("button", {
1665
- "data-atbl-focus": "ring",
1666
- "data-atbl-control": "default",
1667
- type: "button",
1668
- tabIndex: -1,
1669
- "aria-label": `${item.label}: ${formatValue(item.value)} ${unit}, ${percent(item.share)}`,
1670
- children: [
1671
- /* @__PURE__ */ jsx12(ChartLegend.Marker, {
1672
- kind: "square",
1673
- color: item.color
1674
- }),
1675
- /* @__PURE__ */ jsx12(ChartLegend.Label, {
1676
- className: "altertable-pie-label",
1677
- children: item.label
1678
- }),
1679
- /* @__PURE__ */ jsx12("strong", {
1680
- children: formatValue(item.value)
1681
- }),
1682
- /* @__PURE__ */ jsx12("span", {
1683
- children: percent(item.share)
1684
- })
1685
- ]
1848
+ children: slices.map((slice) => {
1849
+ const item = slice.row;
1850
+ const actions = actionsFor(slice);
1851
+ const menuTrigger = {
1852
+ get current() {
1853
+ return menuTriggers.current.get(item.id) ?? null;
1854
+ }
1855
+ };
1856
+ const label = `${item.label}: ${formatValue(item.value)} ${unit}, ${percent(slice.share)}${actions.length ? ". Actions" : ""}`;
1857
+ const contents = /* @__PURE__ */ jsxs7(Fragment4, {
1858
+ children: [
1859
+ /* @__PURE__ */ jsx12(ChartLegend.Marker, {
1860
+ kind: "square",
1861
+ color: slice.color
1862
+ }),
1863
+ /* @__PURE__ */ jsx12(ChartLegend.Label, {
1864
+ className: "altertable-pie-label",
1865
+ children: item.label
1866
+ }),
1867
+ actions.length > 0 && /* @__PURE__ */ jsx12(AppIcon2, {
1868
+ name: "moreActions",
1869
+ size: 14,
1870
+ className: "altertable-pie-menu-indicator"
1871
+ }),
1872
+ /* @__PURE__ */ jsx12("strong", {
1873
+ className: "altertable-pie-value",
1874
+ children: formatValue(item.value)
1875
+ }),
1876
+ /* @__PURE__ */ jsx12("span", {
1877
+ className: "altertable-pie-share",
1878
+ children: percent(slice.share)
1879
+ })
1880
+ ]
1881
+ });
1882
+ return /* @__PURE__ */ jsx12(ChartLegend.Item, {
1883
+ children: /* @__PURE__ */ jsx12(Tooltip2, {
1884
+ variant: "chart",
1885
+ content: detail(slice),
1886
+ onOpenChange: (open) => setLegendId((current) => open ? item.id : current === item.id ? null : current),
1887
+ children: actions.length ? /* @__PURE__ */ jsxs7(MenuTrigger2, {
1888
+ children: [
1889
+ /* @__PURE__ */ jsx12(PressButton, {
1890
+ ...explorationMenuEvents(menuTrigger),
1891
+ ref: (element) => {
1892
+ if (element)
1893
+ menuTriggers.current.set(item.id, element);
1894
+ else
1895
+ menuTriggers.current.delete(item.id);
1896
+ },
1897
+ "aria-label": label,
1898
+ children: contents
1899
+ }),
1900
+ /* @__PURE__ */ jsx12(ExplorationActionMenu, {
1901
+ actions,
1902
+ ariaLabel: item.label,
1903
+ triggerRef: menuTrigger,
1904
+ placement: "bottom start"
1905
+ })
1906
+ ]
1907
+ }) : /* @__PURE__ */ jsx12("button", {
1908
+ type: "button",
1909
+ "data-atbl-focus": "ring",
1910
+ "data-atbl-control": "default",
1911
+ tabIndex: -1,
1912
+ "aria-label": label,
1913
+ children: contents
1914
+ })
1686
1915
  })
1687
- })
1688
- }, item.id))
1916
+ }, item.id);
1917
+ })
1689
1918
  })
1690
1919
  ]
1691
- })
1920
+ }),
1921
+ chartActions.feedback
1692
1922
  ]
1693
1923
  });
1694
1924
  }
1695
1925
  // src/react/ui/ScatterChart.tsx
1696
- import { jsx as jsx13, jsxs as jsxs8, Fragment as Fragment4 } from "react/jsx-runtime";
1926
+ import { jsx as jsx13, jsxs as jsxs8, Fragment as Fragment5 } from "react/jsx-runtime";
1697
1927
  function formatNumber(value) {
1698
1928
  return new Intl.NumberFormat(undefined, { maximumFractionDigits: 1 }).format(value);
1699
1929
  }
@@ -1719,7 +1949,7 @@ function ScatterChart({
1719
1949
  formatX = formatNumber,
1720
1950
  formatY = formatNumber
1721
1951
  }) {
1722
- validateChartItems("scatter", items);
1952
+ validateScatterChartItems(items);
1723
1953
  const xScale = scale(items.map((item) => item.x));
1724
1954
  const yScale = scale(items.map((item) => item.y));
1725
1955
  return /* @__PURE__ */ jsxs8("section", {
@@ -1729,7 +1959,7 @@ function ScatterChart({
1729
1959
  items.length === 0 && /* @__PURE__ */ jsx13("span", {
1730
1960
  children: "No data"
1731
1961
  }),
1732
- items.length > 0 && /* @__PURE__ */ jsxs8(Fragment4, {
1962
+ items.length > 0 && /* @__PURE__ */ jsxs8(Fragment5, {
1733
1963
  children: [
1734
1964
  /* @__PURE__ */ jsxs8("p", {
1735
1965
  className: "altertable-scatter-axis-title",
@@ -1762,7 +1992,7 @@ function ScatterChart({
1762
1992
  }, index)),
1763
1993
  items.map((item) => /* @__PURE__ */ jsx13(Tooltip2, {
1764
1994
  variant: "chart",
1765
- content: /* @__PURE__ */ jsxs8(Fragment4, {
1995
+ content: /* @__PURE__ */ jsxs8(Fragment5, {
1766
1996
  children: [
1767
1997
  /* @__PURE__ */ jsx13("strong", {
1768
1998
  children: item.label
@@ -1818,23 +2048,25 @@ function ScatterChart({
1818
2048
  });
1819
2049
  }
1820
2050
  // src/react/ui/BarChart.tsx
1821
- import { useLayoutEffect as useLayoutEffect3, useRef as useRef3, useState as useState5 } from "react";
2051
+ import {
2052
+ Fragment as Fragment6,
2053
+ useRef as useRef5,
2054
+ useState as useState5
2055
+ } from "react";
1822
2056
  import { BarChart as RechartsBarChart, Cell } from "recharts";
1823
- import { jsx as jsx14, jsxs as jsxs9, Fragment as Fragment5 } from "react/jsx-runtime";
2057
+ import { jsx as jsx14, jsxs as jsxs9, Fragment as Fragment7 } from "react/jsx-runtime";
1824
2058
  function BarChart({
1825
2059
  items,
1826
2060
  unit,
1827
2061
  ariaLabel,
1828
- formatValue = formatNumber2
2062
+ formatValue = formatNumber2,
2063
+ itemActions
1829
2064
  }) {
1830
- validateChartItems("bar", items);
2065
+ validateValueChartItems("bar", items);
2066
+ const chartActions = useChartActions();
1831
2067
  const [activeId, setActiveId] = useState5();
1832
- const scrollport = useRef3(null);
1833
- useLayoutEffect3(() => {
1834
- const element = scrollport.current;
1835
- if (element)
1836
- element.scrollLeft = element.scrollWidth - element.clientWidth;
1837
- }, [items]);
2068
+ const scrollport = useChartScrollToEnd(items);
2069
+ const menuTriggers = useRef5(new Map);
1838
2070
  const maximum = items.reduce((max, item) => Math.max(max, item.value), 1);
1839
2071
  return /* @__PURE__ */ jsxs9("section", {
1840
2072
  className: "altertable-selectable-bars",
@@ -1889,46 +2121,115 @@ function BarChart({
1889
2121
  }),
1890
2122
  /* @__PURE__ */ jsx14("div", {
1891
2123
  className: "altertable-selectable-bars-items",
1892
- children: items.map((item) => /* @__PURE__ */ jsx14(Tooltip2, {
1893
- variant: "chart",
1894
- onOpenChange: (open) => setActiveId((current) => open ? item.id : current === item.id ? undefined : current),
1895
- content: /* @__PURE__ */ jsxs9(Fragment5, {
1896
- children: [
1897
- /* @__PURE__ */ jsx14("strong", {
1898
- children: item.label
1899
- }),
1900
- /* @__PURE__ */ jsxs9("span", {
1901
- children: [
1902
- formatValue(item.value),
1903
- " ",
1904
- unit
1905
- ]
1906
- })
1907
- ]
1908
- }),
1909
- className: "altertable-chart-column",
1910
- children: /* @__PURE__ */ jsxs9("button", {
1911
- "data-atbl-focus": "ring",
1912
- "data-atbl-control": "default",
1913
- type: "button",
1914
- tabIndex: -1,
1915
- className: "altertable-selectable-bars-item",
1916
- "aria-label": `${item.label}: ${formatValue(item.value)} ${unit}`,
1917
- children: [
1918
- /* @__PURE__ */ jsx14("span", {
1919
- className: "altertable-selectable-bars-area"
1920
- }),
1921
- /* @__PURE__ */ jsx14("span", {
1922
- className: "altertable-selectable-bars-label",
1923
- children: item.label
1924
- })
1925
- ]
1926
- })
1927
- }, item.id))
2124
+ children: items.map((item) => {
2125
+ const actions = chartActions.actions(itemActions?.(item) ?? [], item.label, `${formatValue(item.value)} ${unit}`);
2126
+ const action = getPrimaryExplorationAction(actions);
2127
+ const menuTrigger = {
2128
+ get current() {
2129
+ return menuTriggers.current.get(item.id) ?? null;
2130
+ }
2131
+ };
2132
+ return /* @__PURE__ */ jsx14(Fragment6, {
2133
+ children: /* @__PURE__ */ jsxs9("div", {
2134
+ className: "altertable-chart-item-actions",
2135
+ children: [
2136
+ /* @__PURE__ */ jsx14(Tooltip2, {
2137
+ variant: "chart",
2138
+ onOpenChange: (open) => setActiveId((current) => open ? item.id : current === item.id ? undefined : current),
2139
+ content: /* @__PURE__ */ jsxs9(Fragment7, {
2140
+ children: [
2141
+ /* @__PURE__ */ jsx14("strong", {
2142
+ children: item.label
2143
+ }),
2144
+ /* @__PURE__ */ jsxs9("span", {
2145
+ children: [
2146
+ formatValue(item.value),
2147
+ " ",
2148
+ unit
2149
+ ]
2150
+ })
2151
+ ]
2152
+ }),
2153
+ className: "altertable-chart-column",
2154
+ children: action ? /* @__PURE__ */ jsx14("button", {
2155
+ "data-atbl-focus": "ring",
2156
+ "data-atbl-control": "action",
2157
+ type: "button",
2158
+ className: "altertable-selectable-bars-item",
2159
+ "aria-label": `${item.label}: ${formatValue(item.value)} ${unit}. ${action.label}`,
2160
+ ...explorationMenuEvents(menuTrigger),
2161
+ onClick: (event) => action.onSelect(event.currentTarget),
2162
+ children: /* @__PURE__ */ jsx14("span", {
2163
+ className: "altertable-selectable-bars-area"
2164
+ })
2165
+ }) : actions.length ? /* @__PURE__ */ jsx14("button", {
2166
+ type: "button",
2167
+ "data-atbl-focus": "ring",
2168
+ "data-atbl-control": "action",
2169
+ className: "altertable-selectable-bars-item",
2170
+ "aria-label": `${item.label}: ${formatValue(item.value)} ${unit}. Actions`,
2171
+ ...explorationMenuEvents(menuTrigger),
2172
+ onClick: (event) => openExplorationMenu(menuTrigger, event),
2173
+ children: /* @__PURE__ */ jsx14("span", {
2174
+ className: "altertable-selectable-bars-area"
2175
+ })
2176
+ }) : /* @__PURE__ */ jsx14("button", {
2177
+ "data-atbl-focus": "ring",
2178
+ "data-atbl-control": "default",
2179
+ type: "button",
2180
+ tabIndex: -1,
2181
+ className: "altertable-selectable-bars-item",
2182
+ "aria-label": `${item.label}: ${formatValue(item.value)} ${unit}`,
2183
+ children: /* @__PURE__ */ jsx14("span", {
2184
+ className: "altertable-selectable-bars-area"
2185
+ })
2186
+ })
2187
+ }),
2188
+ /* @__PURE__ */ jsx14("div", {
2189
+ className: "altertable-chart-item-label-row",
2190
+ children: actions.length ? /* @__PURE__ */ jsxs9(MenuTrigger2, {
2191
+ children: [
2192
+ /* @__PURE__ */ jsxs9(PressButton, {
2193
+ className: "altertable-selectable-bars-label",
2194
+ variant: "ghost",
2195
+ size: "compact",
2196
+ ...explorationMenuEvents(menuTrigger),
2197
+ ref: (element) => {
2198
+ if (element)
2199
+ menuTriggers.current.set(item.id, element);
2200
+ else
2201
+ menuTriggers.current.delete(item.id);
2202
+ },
2203
+ "aria-label": `${item.label}: Actions`,
2204
+ children: [
2205
+ item.label,
2206
+ /* @__PURE__ */ jsx14(AppIcon2, {
2207
+ name: "disclosure",
2208
+ size: 12
2209
+ })
2210
+ ]
2211
+ }),
2212
+ /* @__PURE__ */ jsx14(ExplorationActionMenu, {
2213
+ actions,
2214
+ ariaLabel: item.label,
2215
+ triggerRef: menuTrigger,
2216
+ placement: "bottom"
2217
+ })
2218
+ ]
2219
+ }) : /* @__PURE__ */ jsx14("span", {
2220
+ className: "altertable-selectable-bars-label",
2221
+ children: item.label
2222
+ })
2223
+ })
2224
+ ]
2225
+ })
2226
+ }, item.id);
2227
+ })
1928
2228
  })
1929
2229
  ]
1930
2230
  })
1931
- })
2231
+ }),
2232
+ chartActions.feedback
1932
2233
  ]
1933
2234
  });
1934
2235
  }
@@ -1938,7 +2239,7 @@ import {
1938
2239
  Radio as AriaRadio,
1939
2240
  Label
1940
2241
  } from "react-aria-components";
1941
- import { jsx as jsx15, jsxs as jsxs10, Fragment as Fragment6 } from "react/jsx-runtime";
2242
+ import { jsx as jsx15, jsxs as jsxs10, Fragment as Fragment8 } from "react/jsx-runtime";
1942
2243
  function RadioGroup({
1943
2244
  label,
1944
2245
  className,
@@ -1963,7 +2264,7 @@ function Radio({ className, children, ...props }) {
1963
2264
  "data-atbl-control": "action",
1964
2265
  "data-atbl-focus": "ring",
1965
2266
  className: classNames("altertable-radio", className),
1966
- children: (state) => /* @__PURE__ */ jsxs10(Fragment6, {
2267
+ children: (state) => /* @__PURE__ */ jsxs10(Fragment8, {
1967
2268
  children: [
1968
2269
  /* @__PURE__ */ jsx15("span", {
1969
2270
  className: "altertable-radio-mark",
@@ -2029,21 +2330,58 @@ function CheckboxGroup({
2029
2330
  }
2030
2331
  // src/react/ui/ComposedChart.tsx
2031
2332
  import {
2032
- useState as useState6,
2033
- useCallback as useCallback2,
2034
- useRef as useRef4,
2035
- useLayoutEffect as useLayoutEffect4
2333
+ useState as useState7,
2334
+ useCallback as useCallback2
2036
2335
  } from "react";
2037
2336
 
2038
2337
  // src/react/ui/ComposedChartLegend.tsx
2338
+ import { useState as useState6 } from "react";
2039
2339
  import { Legend } from "recharts";
2040
- import { jsx as jsx17, jsxs as jsxs12, Fragment as Fragment7 } from "react/jsx-runtime";
2340
+ import { jsx as jsx17, jsxs as jsxs12, Fragment as Fragment9 } from "react/jsx-runtime";
2041
2341
  var legendMarkerKinds = {
2042
2342
  square: "area",
2043
2343
  rect: "bar",
2044
2344
  line: "line",
2045
2345
  plainline: "line"
2046
2346
  };
2347
+ function createLegendItemKeys() {
2348
+ const identities = new WeakMap;
2349
+ let nextIdentity = 0;
2350
+ function identity(value) {
2351
+ let id = identities.get(value);
2352
+ if (id === undefined) {
2353
+ id = nextIdentity++;
2354
+ identities.set(value, id);
2355
+ }
2356
+ return id;
2357
+ }
2358
+ return (payload) => {
2359
+ const keys = payload.map((entry) => {
2360
+ const source = entry.payload;
2361
+ const id = source && typeof source === "object" && "id" in source ? source.id : undefined;
2362
+ if (typeof id === "string" || typeof id === "number")
2363
+ return ["series", typeof id, id].join(KEY_SEPARATOR);
2364
+ const key = entry.dataKey;
2365
+ if (typeof key === "string" || typeof key === "number")
2366
+ return ["data", typeof key, key].join(KEY_SEPARATOR);
2367
+ return ["object", identity(typeof key === "function" ? key : entry)].join(KEY_SEPARATOR);
2368
+ });
2369
+ const counts = new Map;
2370
+ for (const key of keys)
2371
+ counts.set(key, (counts.get(key) ?? 0) + 1);
2372
+ return keys.map((key, index) => {
2373
+ if (counts.get(key) === 1)
2374
+ return key;
2375
+ const entry = payload[index];
2376
+ const source = entry.payload;
2377
+ return [
2378
+ key,
2379
+ "object",
2380
+ identity(source && typeof source === "object" ? source : entry)
2381
+ ].join(KEY_SEPARATOR);
2382
+ });
2383
+ };
2384
+ }
2047
2385
  function LegendContent({
2048
2386
  payload = [],
2049
2387
  maxVisibleItems,
@@ -2061,6 +2399,8 @@ function LegendContent({
2061
2399
  onMouseLeave,
2062
2400
  "aria-label": ariaLabel
2063
2401
  }) {
2402
+ const [getItemKeys] = useState6(createLegendItemKeys);
2403
+ const itemKeys = getItemKeys(payload);
2064
2404
  if (!payload.some((entry) => entry.type !== "none"))
2065
2405
  return null;
2066
2406
  const vertical = layout === "vertical" || layout === "auto" && (position === "left" || position === "right");
@@ -2077,7 +2417,7 @@ function LegendContent({
2077
2417
  const kind = iconType ? legendMarkerKinds[type ?? "none"] ?? "point" : "square";
2078
2418
  const formatLabel = entry.formatter ?? formatter;
2079
2419
  const label = formatLabel ? formatLabel(entry.value, entry, index) : entry.value;
2080
- const content = /* @__PURE__ */ jsxs12(Fragment7, {
2420
+ const content = /* @__PURE__ */ jsxs12(Fragment9, {
2081
2421
  children: [
2082
2422
  type !== "none" && (entry.legendIcon ?? /* @__PURE__ */ jsx17(ChartLegend.Marker, {
2083
2423
  kind,
@@ -2105,7 +2445,7 @@ function LegendContent({
2105
2445
  onClick: (event) => onClick(entry, index, event),
2106
2446
  children: content
2107
2447
  }) : content
2108
- }, index);
2448
+ }, itemKeys[index]);
2109
2449
  })
2110
2450
  });
2111
2451
  }
@@ -2137,16 +2477,16 @@ import {
2137
2477
  ErrorBar
2138
2478
  } from "recharts";
2139
2479
  import { jsx as jsx18 } from "react/jsx-runtime";
2140
- function closestSeries(hovered, points, position) {
2141
- let selected = hovered;
2142
- if (position && points.size > 0 && (hovered == null || points.has(hovered))) {
2143
- let distance = Infinity;
2144
- for (const [id, point] of points) {
2145
- const candidate = Math.hypot(point.x - position.x, point.y - position.y);
2146
- if (candidate < distance) {
2147
- distance = candidate;
2148
- selected = id;
2149
- }
2480
+ function findNearestSeriesId(hoveredSeriesId, points, position) {
2481
+ if (!position || hoveredSeriesId != null && !points.has(hoveredSeriesId))
2482
+ return hoveredSeriesId;
2483
+ let selected = hoveredSeriesId;
2484
+ let distance = Infinity;
2485
+ for (const [id, point] of points) {
2486
+ const candidate = Math.hypot(point.x - position.x, point.y - position.y);
2487
+ if (candidate < distance) {
2488
+ distance = candidate;
2489
+ selected = id;
2150
2490
  }
2151
2491
  }
2152
2492
  return selected;
@@ -2160,12 +2500,11 @@ function ComposedChartRoot({
2160
2500
  className,
2161
2501
  ...props
2162
2502
  }) {
2163
- const [pointerFocus, setPointerFocus] = useState6(false);
2164
- const [pointer, setPointer] = useState6(false);
2165
- const [hovered, setHovered] = useState6(null);
2166
- const pointerPosition = useRef4(null);
2167
- const [nearest, setNearest] = useState6(null);
2168
- const [points, setPoints] = useState6(() => new Map);
2503
+ const [hasPointerFocus, setHasPointerFocus] = useState7(false);
2504
+ const [isPointerInspection, setIsPointerInspection] = useState7(false);
2505
+ const [hoveredSeriesId, setHoveredSeriesId] = useState7(null);
2506
+ const [pointerPosition, setPointerPosition] = useState7(null);
2507
+ const [points, setPoints] = useState7(() => new Map);
2169
2508
  const registerPoint = useCallback2((id, x, y) => {
2170
2509
  setPoints((current) => new Map(current).set(id, { x, y }));
2171
2510
  return () => setPoints((current) => {
@@ -2175,21 +2514,30 @@ function ComposedChartRoot({
2175
2514
  });
2176
2515
  }, []);
2177
2516
  function trackPointer(event) {
2178
- setPointer(true);
2179
2517
  const svg = event.currentTarget.querySelector('svg[role="application"]');
2180
- if (!(svg instanceof SVGSVGElement))
2181
- return;
2518
+ if (!(svg instanceof SVGSVGElement) || !(event.target instanceof Node) || !svg.contains(event.target)) {
2519
+ resetPointerInspection();
2520
+ return false;
2521
+ }
2522
+ setIsPointerInspection(true);
2523
+ if (hoveredSeriesId != null && !points.has(hoveredSeriesId)) {
2524
+ setPointerPosition(null);
2525
+ return true;
2526
+ }
2182
2527
  const matrix = svg.getScreenCTM();
2183
2528
  if (!matrix)
2184
- return;
2529
+ return true;
2185
2530
  const point = new DOMPoint(event.clientX, event.clientY).matrixTransform(matrix.inverse());
2186
- pointerPosition.current = { x: point.x, y: point.y };
2187
- setNearest(closestSeries(hovered, points, pointerPosition.current));
2531
+ setPointerPosition({ x: point.x, y: point.y });
2532
+ return true;
2188
2533
  }
2189
- useLayoutEffect4(() => {
2190
- setNearest(closestSeries(hovered, points, pointerPosition.current));
2191
- }, [hovered, points]);
2192
- const [seriesIds, setSeriesIds] = useState6(() => new Set);
2534
+ function resetPointerInspection() {
2535
+ setIsPointerInspection(false);
2536
+ setHoveredSeriesId(null);
2537
+ setPointerPosition(null);
2538
+ }
2539
+ const activeSeriesId = findNearestSeriesId(hoveredSeriesId, points, pointerPosition);
2540
+ const [seriesIds, setSeriesIds] = useState7(() => new Set);
2193
2541
  const registerSeries = useCallback2((id) => {
2194
2542
  setSeriesIds((current) => new Set(current).add(id));
2195
2543
  return () => {
@@ -2200,43 +2548,39 @@ function ComposedChartRoot({
2200
2548
  });
2201
2549
  };
2202
2550
  }, []);
2203
- return /* @__PURE__ */ jsx18(ChartInteraction.Provider, {
2551
+ return /* @__PURE__ */ jsx18(ChartInteractionContext.Provider, {
2204
2552
  value: {
2205
- pointer,
2206
- hovered: nearest,
2207
- point: nearest == null ? undefined : points.get(nearest),
2553
+ isPointerInspection,
2554
+ activeSeriesId,
2555
+ activePoint: activeSeriesId == null ? undefined : points.get(activeSeriesId),
2208
2556
  registerPoint,
2209
- setHovered,
2557
+ setHoveredSeriesId,
2210
2558
  seriesCount: seriesIds.size,
2211
2559
  registerSeries
2212
2560
  },
2213
2561
  children: /* @__PURE__ */ jsx18("section", {
2214
- className: ["altertable-composed-chart", className].filter(Boolean).join(" "),
2562
+ className: classNames("altertable-composed-chart", className),
2215
2563
  "aria-label": ariaLabel,
2216
- "data-atbl-internal-pointer-focus": pointerFocus || undefined,
2564
+ "data-atbl-internal-pointer-focus": hasPointerFocus || undefined,
2217
2565
  onPointerDownCapture: (event) => {
2218
- setPointerFocus(true);
2219
- trackPointer(event);
2566
+ setHasPointerFocus(trackPointer(event));
2220
2567
  },
2221
2568
  onPointerOverCapture: trackPointer,
2222
2569
  onPointerMoveCapture: trackPointer,
2223
2570
  onPointerLeave: (event) => {
2224
2571
  if (event.pointerType !== "touch") {
2225
- setHovered(null);
2226
- pointerPosition.current = null;
2227
- setNearest(null);
2572
+ resetPointerInspection();
2228
2573
  }
2229
2574
  },
2230
2575
  onKeyDownCapture: () => {
2231
- setPointerFocus(false);
2232
- setPointer(false);
2233
- pointerPosition.current = null;
2234
- setNearest(null);
2235
- setHovered(null);
2576
+ setHasPointerFocus(false);
2577
+ resetPointerInspection();
2236
2578
  },
2237
2579
  onBlurCapture: (event) => {
2238
- if (!event.currentTarget.contains(event.relatedTarget))
2239
- setPointerFocus(false);
2580
+ if (!event.currentTarget.contains(event.relatedTarget)) {
2581
+ setHasPointerFocus(false);
2582
+ resetPointerInspection();
2583
+ }
2240
2584
  },
2241
2585
  children: /* @__PURE__ */ jsx18(ChartDateAxes, {
2242
2586
  data,
@@ -2275,17 +2619,71 @@ var ComposedChart = Object.assign(ComposedChartRoot, {
2275
2619
  ErrorBar
2276
2620
  });
2277
2621
  // src/react/ui/FunnelChart.tsx
2278
- import { Fragment as Fragment8, useEffect as useEffect4, useRef as useRef5, useState as useState7 } from "react";
2622
+ import { Fragment as Fragment10, useEffect as useEffect4, useRef as useRef6, useState as useState8 } from "react";
2279
2623
 
2280
2624
  // src/react/ui/useSvgId.ts
2281
2625
  import { useId as useId3 } from "react";
2626
+ var svgIdCharacterPattern = /[a-zA-Z0-9-]/;
2282
2627
  function useSvgId() {
2283
2628
  const id = useId3();
2284
- return `svg-${Array.from(id, (character) => /[a-zA-Z0-9-]/.test(character) ? character : `_${character.codePointAt(0).toString(16)}_`).join("")}`;
2629
+ const encodedId = Array.from(id, (character) => svgIdCharacterPattern.test(character) ? character : `_${character.codePointAt(0).toString(16)}_`).join("");
2630
+ return ["svg", encodedId].join("-");
2285
2631
  }
2286
2632
 
2287
2633
  // src/react/ui/FunnelChart.tsx
2288
- import { jsx as jsx19, jsxs as jsxs13, Fragment as Fragment9 } from "react/jsx-runtime";
2634
+ import { jsx as jsx19, jsxs as jsxs13, Fragment as Fragment11 } from "react/jsx-runtime";
2635
+ function createFunnelModel(steps, series, chartId) {
2636
+ for (const [kind, items] of [
2637
+ ["funnel step", steps],
2638
+ ["funnel series", series]
2639
+ ]) {
2640
+ const ids = new Set;
2641
+ for (const item of items) {
2642
+ invariant(item.id.trim().length > 0 && !ids.has(item.id), `${kind} chart IDs must be nonblank and unique.`);
2643
+ ids.add(item.id);
2644
+ }
2645
+ }
2646
+ for (const item of series) {
2647
+ invariant(item.values.length === steps.length, "funnel chart counts must align with steps.");
2648
+ item.values.forEach((value, index) => {
2649
+ invariant(Number.isFinite(value) && value >= 0, "funnel chart counts must be finite and nonnegative.");
2650
+ invariant(index === 0 || value <= item.values[index - 1], "funnel chart counts must be nonincreasing.");
2651
+ });
2652
+ }
2653
+ const populations = series.map((item, index) => ({
2654
+ id: item.id,
2655
+ label: item.label,
2656
+ color: `var(--atbl-chart-${index % 8 + 1})`,
2657
+ hatchId: [chartId, "hatch", index].join("-")
2658
+ }));
2659
+ const rows = steps.map((step, index) => ({
2660
+ id: step.id,
2661
+ label: step.label,
2662
+ index,
2663
+ readings: new Map(series.map((item, seriesIndex) => {
2664
+ const first = item.values[0] ?? 0;
2665
+ const current = item.values[index];
2666
+ const previous = item.values[Math.max(0, index - 1)];
2667
+ const dropped = previous - current;
2668
+ const conversion = first > 0 ? current / first : null;
2669
+ const dropOff = first > 0 ? dropped / first : null;
2670
+ return [
2671
+ item.id,
2672
+ {
2673
+ population: populations[seriesIndex],
2674
+ current,
2675
+ previous,
2676
+ dropped,
2677
+ conversion,
2678
+ dropOff,
2679
+ conversionPercent: (conversion ?? 0) * 100,
2680
+ dropOffPercent: (dropOff ?? (index === 0 ? 1 : 0)) * 100
2681
+ }
2682
+ ];
2683
+ }))
2684
+ }));
2685
+ return { populations, rows };
2686
+ }
2289
2687
  function FunnelChart({
2290
2688
  steps,
2291
2689
  series,
@@ -2295,8 +2693,8 @@ function FunnelChart({
2295
2693
  formatValue = formatNumber2
2296
2694
  }) {
2297
2695
  const chartId = useSvgId();
2298
- const [highlighted, setHighlighted] = useState7(null);
2299
- const clearTimer = useRef5(null);
2696
+ const [highlighted, setHighlighted] = useState8(null);
2697
+ const clearTimer = useRef6(null);
2300
2698
  function cancelClear() {
2301
2699
  if (clearTimer.current !== null)
2302
2700
  clearTimeout(clearTimer.current);
@@ -2315,56 +2713,14 @@ function FunnelChart({
2315
2713
  cancelClear();
2316
2714
  clearTimer.current = setTimeout(() => setHighlighted(null), 100);
2317
2715
  }
2318
- for (const [kind, items] of [
2319
- ["funnel step", steps],
2320
- ["funnel series", series]
2321
- ]) {
2322
- const ids = new Set;
2323
- for (const item of items) {
2324
- invariant(item.id.trim().length > 0 && !ids.has(item.id), `${kind} chart IDs must be nonblank and unique.`);
2325
- ids.add(item.id);
2326
- }
2327
- }
2328
- for (const item of series) {
2329
- invariant(item.values.length === steps.length, "funnel chart counts must align with steps.");
2330
- item.values.forEach((value, index) => {
2331
- invariant(Number.isFinite(value) && value >= 0, "funnel chart counts must be finite and nonnegative.");
2332
- invariant(index === 0 || value <= item.values[index - 1], "funnel chart counts must be nonincreasing.");
2333
- });
2334
- }
2335
- function reading(item, index) {
2336
- const first = item.values[0] ?? 0;
2337
- const current = item.values[index];
2338
- const previous = item.values[Math.max(0, index - 1)];
2339
- return {
2340
- current,
2341
- previous,
2342
- dropped: previous - current,
2343
- conversion: first > 0 ? current / first : null,
2344
- dropOff: first > 0 ? (previous - current) / first : null
2345
- };
2346
- }
2347
- const data = steps.map((step, index) => ({
2348
- label: step.label,
2349
- index,
2350
- ...Object.fromEntries(series.flatMap((item, seriesIndex) => {
2351
- const value = reading(item, index);
2352
- return [
2353
- [`conversion${seriesIndex}`, (value.conversion ?? 0) * 100],
2354
- [
2355
- `drop${seriesIndex}`,
2356
- (value.dropOff ?? (index === 0 ? 1 : 0)) * 100
2357
- ]
2358
- ];
2359
- }))
2360
- }));
2716
+ const { populations, rows } = createFunnelModel(steps, series, chartId);
2361
2717
  return /* @__PURE__ */ jsx19("section", {
2362
2718
  className: classNames("altertable-funnel-chart", className),
2363
2719
  "aria-label": ariaLabel,
2364
2720
  onKeyDownCapture: clearHighlight,
2365
2721
  children: steps.length === 0 || series.length === 0 ? /* @__PURE__ */ jsx19("span", {
2366
2722
  children: "No data"
2367
- }) : /* @__PURE__ */ jsxs13(Fragment9, {
2723
+ }) : /* @__PURE__ */ jsxs13(Fragment11, {
2368
2724
  children: [
2369
2725
  /* @__PURE__ */ jsxs13("div", {
2370
2726
  className: "altertable-funnel-header",
@@ -2372,7 +2728,7 @@ function FunnelChart({
2372
2728
  /* @__PURE__ */ jsx19(ChartLegend, {
2373
2729
  "aria-label": "Funnel series",
2374
2730
  layout: "single-row",
2375
- children: series.map((item, index) => /* @__PURE__ */ jsxs13(ChartLegend.Item, {
2731
+ children: populations.map((item) => /* @__PURE__ */ jsxs13(ChartLegend.Item, {
2376
2732
  className: "altertable-funnel-summary-item",
2377
2733
  children: [
2378
2734
  /* @__PURE__ */ jsxs13("span", {
@@ -2380,7 +2736,7 @@ function FunnelChart({
2380
2736
  children: [
2381
2737
  /* @__PURE__ */ jsx19(ChartLegend.Marker, {
2382
2738
  kind: "square",
2383
- color: `var(--atbl-chart-${index % 8 + 1})`
2739
+ color: item.color
2384
2740
  }),
2385
2741
  /* @__PURE__ */ jsx19(ChartLegend.Label, {
2386
2742
  children: item.label
@@ -2389,7 +2745,7 @@ function FunnelChart({
2389
2745
  }),
2390
2746
  /* @__PURE__ */ jsx19("strong", {
2391
2747
  className: "altertable-funnel-series-value",
2392
- children: formatPercent2(reading(item, steps.length - 1).conversion)
2748
+ children: formatPercent2(rows.at(-1)?.readings.get(item.id)?.conversion ?? null)
2393
2749
  })
2394
2750
  ]
2395
2751
  }, item.id))
@@ -2411,7 +2767,7 @@ function FunnelChart({
2411
2767
  minWidth: steps.length * Math.max(96, series.length * 40)
2412
2768
  },
2413
2769
  children: /* @__PURE__ */ jsxs13(ComposedChart, {
2414
- data,
2770
+ data: rows,
2415
2771
  ariaLabel: `${ariaLabel} plot`,
2416
2772
  height: 300,
2417
2773
  barCategoryGap: "4%",
@@ -2430,8 +2786,8 @@ function FunnelChart({
2430
2786
  tickFormatter: (value) => formatPercent2(value / 100)
2431
2787
  }),
2432
2788
  /* @__PURE__ */ jsx19("defs", {
2433
- children: series.map((item, index) => /* @__PURE__ */ jsxs13("pattern", {
2434
- id: `${chartId}-hatch-${index}`,
2789
+ children: populations.map((item) => /* @__PURE__ */ jsxs13("pattern", {
2790
+ id: item.hatchId,
2435
2791
  patternUnits: "userSpaceOnUse",
2436
2792
  width: "6",
2437
2793
  height: "6",
@@ -2440,7 +2796,7 @@ function FunnelChart({
2440
2796
  /* @__PURE__ */ jsx19("rect", {
2441
2797
  width: "8",
2442
2798
  height: "8",
2443
- fill: `var(--atbl-chart-${index % 8 + 1})`,
2799
+ fill: item.color,
2444
2800
  fillOpacity: 0.16
2445
2801
  }),
2446
2802
  /* @__PURE__ */ jsx19("line", {
@@ -2448,20 +2804,20 @@ function FunnelChart({
2448
2804
  y1: "0",
2449
2805
  x2: "0",
2450
2806
  y2: "8",
2451
- stroke: `var(--atbl-chart-${index % 8 + 1})`,
2807
+ stroke: item.color,
2452
2808
  strokeOpacity: 0.4,
2453
2809
  strokeWidth: "2"
2454
2810
  })
2455
2811
  ]
2456
2812
  }, item.id))
2457
2813
  }),
2458
- series.map((item, index) => /* @__PURE__ */ jsxs13(Fragment8, {
2814
+ populations.map((item) => /* @__PURE__ */ jsxs13(Fragment10, {
2459
2815
  children: [
2460
2816
  /* @__PURE__ */ jsx19(ComposedChart.Bar, {
2461
- dataKey: `conversion${index}`,
2817
+ dataKey: (row) => row.readings.get(item.id)?.conversionPercent ?? 0,
2462
2818
  name: item.label,
2463
2819
  stackId: item.id,
2464
- fill: `var(--atbl-chart-${index % 8 + 1})`,
2820
+ fill: item.color,
2465
2821
  radius: 0,
2466
2822
  maxBarSize: undefined,
2467
2823
  activeBar: false,
@@ -2472,10 +2828,10 @@ function FunnelChart({
2472
2828
  onClick: (bar) => highlight(item.id, true, bar.payload.index)
2473
2829
  }),
2474
2830
  /* @__PURE__ */ jsx19(ComposedChart.Bar, {
2475
- dataKey: `drop${index}`,
2831
+ dataKey: (row) => row.readings.get(item.id)?.dropOffPercent ?? 0,
2476
2832
  name: `${item.label} drop-off`,
2477
2833
  stackId: item.id,
2478
- fill: `url(#${chartId}-hatch-${index})`,
2834
+ fill: `url(#${item.hatchId})`,
2479
2835
  opacity: !highlighted || highlighted.id === item.id ? 1 : 0.2,
2480
2836
  onMouseEnter: (bar) => highlight(item.id, false, bar.payload.index),
2481
2837
  onMouseLeave: scheduleClear,
@@ -2487,44 +2843,49 @@ function FunnelChart({
2487
2843
  ]
2488
2844
  }, item.id)),
2489
2845
  /* @__PURE__ */ jsx19(ComposedChart.Tooltip, {
2490
- content: ({ active, payload }) => {
2491
- const index = payload?.[0]?.payload.index;
2492
- if (!active || typeof index !== "number")
2846
+ content: ({ active, activeIndex }) => {
2847
+ const row = activeIndex == null ? undefined : rows[Number(activeIndex)];
2848
+ if (!active || !row)
2493
2849
  return null;
2494
- const tooltipItems = series.filter((item) => !highlighted || highlighted.step !== index || item.id === highlighted.id).flatMap((item) => {
2495
- const value = reading(item, index);
2496
- const selected = highlighted?.step === index;
2850
+ const tooltipItems = [...row.readings.values()].filter((value) => !highlighted || highlighted.step !== row.index || value.population.id === highlighted.id).flatMap((value) => {
2851
+ const item = value.population;
2852
+ const selected = highlighted?.step === row.index;
2497
2853
  const readings = selected ? [highlighted.conversion] : [true, false];
2498
- const seriesIndex = series.indexOf(item);
2499
- return readings.map((conversion) => ({
2500
- name: item.label,
2501
- graphicalItemId: `${item.id}-${conversion ? "conversion" : "drop-off"}`,
2502
- dataKey: `${item.id}-${conversion ? "conversion" : "drop-off"}`,
2503
- color: `var(--atbl-chart-${seriesIndex % 8 + 1})`,
2504
- value: (conversion ? value.conversion : value.dropOff) ?? 0,
2505
- formatter: () => /* @__PURE__ */ jsxs13(Fragment9, {
2506
- children: [
2507
- formatPercent2(conversion ? value.conversion : value.dropOff),
2508
- " ",
2509
- conversion ? "conversion" : "drop-off",
2510
- /* @__PURE__ */ jsxs13("span", {
2511
- className: "altertable-funnel-tooltip-detail",
2512
- children: [
2513
- formatValue(conversion ? value.current : value.dropped),
2514
- " ",
2515
- "of ",
2516
- formatValue(value.previous),
2517
- " ",
2518
- unit
2519
- ]
2520
- })
2521
- ]
2522
- })
2523
- }));
2854
+ return readings.map((conversion) => {
2855
+ const key = [
2856
+ item.id,
2857
+ conversion ? "conversion" : "drop-off"
2858
+ ].join(KEY_SEPARATOR);
2859
+ return {
2860
+ name: item.label,
2861
+ graphicalItemId: key,
2862
+ dataKey: key,
2863
+ color: item.color,
2864
+ value: (conversion ? value.conversion : value.dropOff) ?? 0,
2865
+ formatter: () => /* @__PURE__ */ jsxs13(Fragment11, {
2866
+ children: [
2867
+ formatPercent2(conversion ? value.conversion : value.dropOff),
2868
+ " ",
2869
+ conversion ? "conversion" : "drop-off",
2870
+ /* @__PURE__ */ jsxs13("span", {
2871
+ className: "altertable-funnel-tooltip-detail",
2872
+ children: [
2873
+ formatValue(conversion ? value.current : value.dropped),
2874
+ " ",
2875
+ "of ",
2876
+ formatValue(value.previous),
2877
+ " ",
2878
+ unit
2879
+ ]
2880
+ })
2881
+ ]
2882
+ })
2883
+ };
2884
+ });
2524
2885
  });
2525
2886
  return /* @__PURE__ */ jsx19(ChartTooltipContent, {
2526
2887
  active: true,
2527
- label: steps[index].label,
2888
+ label: row.label,
2528
2889
  payload: tooltipItems
2529
2890
  });
2530
2891
  }
@@ -2535,55 +2896,46 @@ function FunnelChart({
2535
2896
  }),
2536
2897
  /* @__PURE__ */ jsx19("ul", {
2537
2898
  className: "altertable-sr-only",
2538
- children: steps.map((step, index) => /* @__PURE__ */ jsxs13("li", {
2899
+ children: rows.map((row) => /* @__PURE__ */ jsxs13("li", {
2539
2900
  children: [
2540
- step.label,
2541
- series.map((item) => {
2542
- const value = reading(item, index);
2543
- return /* @__PURE__ */ jsxs13("span", {
2544
- children: [
2545
- " ",
2546
- "· ",
2547
- item.label,
2548
- ": ",
2549
- formatValue(value.current),
2550
- " ",
2551
- unit,
2552
- ",",
2553
- " ",
2554
- formatPercent2(value.conversion),
2555
- " conversion,",
2556
- " ",
2557
- formatValue(value.dropped),
2558
- " dropped off"
2559
- ]
2560
- }, item.id);
2561
- })
2901
+ row.label,
2902
+ [...row.readings.values()].map((value) => /* @__PURE__ */ jsxs13("span", {
2903
+ children: [
2904
+ " ",
2905
+ "· ",
2906
+ value.population.label,
2907
+ ": ",
2908
+ formatValue(value.current),
2909
+ " ",
2910
+ unit,
2911
+ ", ",
2912
+ formatPercent2(value.conversion),
2913
+ " conversion,",
2914
+ " ",
2915
+ formatValue(value.dropped),
2916
+ " dropped off"
2917
+ ]
2918
+ }, value.population.id))
2562
2919
  ]
2563
- }, step.id))
2920
+ }, row.id))
2564
2921
  })
2565
2922
  ]
2566
2923
  })
2567
2924
  });
2568
2925
  }
2569
2926
  // src/react/ui/RetentionChart.tsx
2570
- import { Fragment as Fragment10 } from "react";
2571
- import { jsx as jsx20, jsxs as jsxs14, Fragment as Fragment11 } from "react/jsx-runtime";
2572
- function RetentionChart({
2573
- series,
2574
- unit,
2575
- ariaLabel,
2576
- className,
2577
- formatValue = formatNumber2
2578
- }) {
2927
+ import { Fragment as Fragment12 } from "react";
2928
+ import { jsx as jsx20, jsxs as jsxs14, Fragment as Fragment13 } from "react/jsx-runtime";
2929
+ function createRetentionModel(series, unit, formatValue) {
2579
2930
  const ids = new Set;
2580
- const offsets = new Map;
2581
- for (const item of series) {
2931
+ const rowsByOffset = new Map;
2932
+ const cohorts = series.map((item, index) => {
2582
2933
  invariant(item.id.trim().length > 0 && !ids.has(item.id), "retention series chart IDs must be nonblank and unique.");
2583
2934
  ids.add(item.id);
2584
2935
  invariant(Number.isFinite(item.cohortSize) && item.cohortSize >= 0, "retention chart counts must be finite and nonnegative.");
2585
2936
  const seen = new Set;
2586
- for (const point of item.points) {
2937
+ let previous;
2938
+ const readings = [...item.points].sort((a, b) => a.offset - b.offset).map((point) => {
2587
2939
  invariant(Number.isSafeInteger(point.offset) && point.offset >= 0 && !seen.has(point.offset), "retention chart offsets must be unique nonnegative integers within each series.");
2588
2940
  seen.add(point.offset);
2589
2941
  invariant(point.rate === null || Number.isFinite(point.rate) && point.rate >= 0 && point.rate <= 1, "retention chart rates must be finite fractions between 0 and 1, or null.");
@@ -2592,64 +2944,84 @@ function RetentionChart({
2592
2944
  invariant(Number.isFinite(point.retainedCount) && point.retainedCount >= 0, "retention chart counts must be finite and nonnegative.");
2593
2945
  invariant(point.retainedCount <= item.cohortSize, "retention chart retained counts cannot exceed cohort size.");
2594
2946
  }
2595
- invariant(!offsets.has(point.offset) || offsets.get(point.offset) === point.label, "retention chart labels must agree for the same offset.");
2596
- offsets.set(point.offset, point.label);
2597
- }
2598
- }
2599
- const data = [...offsets].sort(([a], [b]) => a - b).map(([offset, label]) => ({
2600
- offset,
2601
- label,
2602
- ...Object.fromEntries(series.flatMap((_, index) => [
2603
- [`rate${index}`, null],
2604
- [`tail${index}`, null]
2605
- ]))
2606
- }));
2607
- series.forEach((item, index) => {
2608
- const points = [...item.points].sort((a, b) => a.offset - b.offset);
2609
- points.forEach((point, pointIndex) => {
2610
- const row = data.find((row) => row.offset === point.offset);
2611
- row[point.incomplete ? `tail${index}` : `rate${index}`] = point.rate === null ? null : point.rate * 100;
2612
- if (point.incomplete && pointIndex > 0) {
2613
- const previous = points[pointIndex - 1];
2614
- data.find((row) => row.offset === previous.offset)[`tail${index}`] = previous.rate === null ? null : previous.rate * 100;
2947
+ let row = rowsByOffset.get(point.offset);
2948
+ invariant(!row || row.label === point.label, "retention chart labels must agree for the same offset.");
2949
+ if (!row) {
2950
+ row = {
2951
+ offset: point.offset,
2952
+ label: point.label,
2953
+ readings: new Map
2954
+ };
2955
+ rowsByOffset.set(point.offset, row);
2615
2956
  }
2957
+ const percent = point.rate === null ? null : point.rate * 100;
2958
+ const reading = {
2959
+ point,
2960
+ completePercent: point.incomplete ? null : percent,
2961
+ incompletePercent: point.incomplete ? percent : null,
2962
+ description: point.rate === null || point.retainedCount === null ? "Not observed" : `${formatPercent2(point.rate)} · ${formatValue(point.retainedCount)} / ${formatValue(item.cohortSize)} ${unit}${point.incomplete ? " · Incomplete period" : ""}`
2963
+ };
2964
+ if (point.incomplete && previous) {
2965
+ previous.incompletePercent = previous.completePercent ?? previous.incompletePercent;
2966
+ }
2967
+ row.readings.set(item.id, reading);
2968
+ previous = reading;
2969
+ return reading;
2616
2970
  });
2971
+ return {
2972
+ id: item.id,
2973
+ label: item.label,
2974
+ color: `var(--atbl-chart-${index % 8 + 1})`,
2975
+ readings
2976
+ };
2617
2977
  });
2978
+ const rows = [...rowsByOffset.values()].sort((a, b) => a.offset - b.offset);
2979
+ return { rows, rowsByOffset, cohorts };
2980
+ }
2981
+ function RetentionChart({
2982
+ series,
2983
+ unit,
2984
+ ariaLabel,
2985
+ className,
2986
+ formatValue = formatNumber2
2987
+ }) {
2988
+ const { rows, rowsByOffset, cohorts } = createRetentionModel(series, unit, formatValue);
2618
2989
  return /* @__PURE__ */ jsx20("section", {
2619
2990
  className: classNames("altertable-retention-chart", className),
2620
2991
  "aria-label": ariaLabel,
2621
- children: data.length === 0 ? /* @__PURE__ */ jsx20("span", {
2992
+ children: rows.length === 0 ? /* @__PURE__ */ jsx20("span", {
2622
2993
  children: "No data"
2623
- }) : /* @__PURE__ */ jsxs14(Fragment11, {
2994
+ }) : /* @__PURE__ */ jsxs14(Fragment13, {
2624
2995
  children: [
2625
2996
  /* @__PURE__ */ jsxs14(ComposedChart, {
2626
- data,
2997
+ data: rows,
2627
2998
  ariaLabel: `${ariaLabel} plot`,
2628
2999
  children: [
2629
3000
  /* @__PURE__ */ jsx20(ComposedChart.CartesianGrid, {}),
2630
3001
  /* @__PURE__ */ jsx20(ComposedChart.XAxis, {
2631
3002
  dataKey: "offset",
2632
3003
  type: "number",
2633
- domain: [0, Math.max(1, ...offsets.keys())],
2634
- tickFormatter: (value) => offsets.get(Number(value)) ?? (data[0]?.label.replace(/\d+(?:\.\d+)?/, String(value)) || String(value))
3004
+ domain: [0, Math.max(1, rows.at(-1)?.offset ?? 0)],
3005
+ ticks: rows.map((row) => row.offset),
3006
+ tickFormatter: (value) => rowsByOffset.get(Number(value))?.label ?? ""
2635
3007
  }),
2636
3008
  /* @__PURE__ */ jsx20(ComposedChart.YAxis, {
2637
3009
  domain: [0, 100],
2638
3010
  width: 42,
2639
3011
  tickFormatter: (value) => `${value}%`
2640
3012
  }),
2641
- series.map((item, index) => /* @__PURE__ */ jsxs14(Fragment10, {
3013
+ cohorts.map((item) => /* @__PURE__ */ jsxs14(Fragment12, {
2642
3014
  children: [
2643
3015
  /* @__PURE__ */ jsx20(ComposedChart.Line, {
2644
- dataKey: `rate${index}`,
3016
+ dataKey: (row) => row.readings.get(item.id)?.completePercent ?? null,
2645
3017
  name: item.label,
2646
- stroke: `var(--atbl-chart-${index % 8 + 1})`,
3018
+ stroke: item.color,
2647
3019
  connectNulls: false
2648
3020
  }),
2649
3021
  /* @__PURE__ */ jsx20(ComposedChart.Line, {
2650
- dataKey: `tail${index}`,
3022
+ dataKey: (row) => row.readings.get(item.id)?.incompletePercent ?? null,
2651
3023
  name: item.label,
2652
- stroke: `var(--atbl-chart-${index % 8 + 1})`,
3024
+ stroke: item.color,
2653
3025
  strokeDasharray: "3 3",
2654
3026
  dot: false,
2655
3027
  activeDot: false,
@@ -2659,27 +3031,26 @@ function RetentionChart({
2659
3031
  }, item.id)),
2660
3032
  /* @__PURE__ */ jsx20(ComposedChart.Tooltip, {
2661
3033
  filterNull: false,
2662
- content: ({ active, payload }) => {
2663
- const offset = payload?.[0]?.payload.offset;
2664
- if (!active || typeof offset !== "number")
3034
+ content: ({ active, label }) => {
3035
+ const row = typeof label === "number" ? rowsByOffset.get(label) : undefined;
3036
+ if (!active || !row)
2665
3037
  return null;
2666
3038
  return /* @__PURE__ */ jsxs14(TooltipSurface, {
2667
3039
  "data-variant": "chart",
2668
3040
  role: "tooltip",
2669
3041
  children: [
2670
3042
  /* @__PURE__ */ jsx20("strong", {
2671
- children: offsets.get(offset)
3043
+ children: row.label
2672
3044
  }),
2673
- series.map((item) => {
2674
- const point = item.points.find((point) => point.offset === offset);
2675
- if (!point)
3045
+ cohorts.map((item) => {
3046
+ const reading = row.readings.get(item.id);
3047
+ if (!reading)
2676
3048
  return null;
2677
3049
  return /* @__PURE__ */ jsxs14("span", {
2678
3050
  children: [
2679
3051
  item.label,
2680
- ":",
2681
- " ",
2682
- point.rate === null ? "Not observed" : `${formatPercent2(point.rate)} · ${formatValue(point.retainedCount)} / ${formatValue(item.cohortSize)} ${unit}${point.incomplete ? " · Incomplete period" : ""}`
3052
+ ": ",
3053
+ reading.description
2683
3054
  ]
2684
3055
  }, item.id);
2685
3056
  })
@@ -2691,11 +3062,11 @@ function RetentionChart({
2691
3062
  }),
2692
3063
  /* @__PURE__ */ jsx20(ChartLegend, {
2693
3064
  "aria-label": `${ariaLabel} cohorts`,
2694
- children: series.map((item, index) => /* @__PURE__ */ jsxs14(ChartLegend.Item, {
3065
+ children: cohorts.map((item) => /* @__PURE__ */ jsxs14(ChartLegend.Item, {
2695
3066
  children: [
2696
3067
  /* @__PURE__ */ jsx20(ChartLegend.Marker, {
2697
3068
  kind: "square",
2698
- color: `var(--atbl-chart-${index % 8 + 1})`
3069
+ color: item.color
2699
3070
  }),
2700
3071
  /* @__PURE__ */ jsx20(ChartLegend.Label, {
2701
3072
  children: item.label
@@ -2705,19 +3076,19 @@ function RetentionChart({
2705
3076
  }),
2706
3077
  /* @__PURE__ */ jsx20("ul", {
2707
3078
  className: "altertable-sr-only",
2708
- children: series.map((item) => /* @__PURE__ */ jsxs14("li", {
3079
+ "aria-label": `${ariaLabel} readings`,
3080
+ children: cohorts.map((item) => /* @__PURE__ */ jsxs14("li", {
2709
3081
  children: [
2710
3082
  item.label,
2711
- item.points.map((point) => /* @__PURE__ */ jsxs14("span", {
3083
+ item.readings.map((reading) => /* @__PURE__ */ jsxs14("span", {
2712
3084
  children: [
2713
3085
  " ",
2714
3086
  "· ",
2715
- point.label,
2716
- ":",
2717
- " ",
2718
- point.rate === null ? "Not observed" : `${formatPercent2(point.rate)} · ${formatValue(point.retainedCount)} / ${formatValue(item.cohortSize)} ${unit}${point.incomplete ? " · Incomplete period" : ""}`
3087
+ reading.point.label,
3088
+ ": ",
3089
+ reading.description
2719
3090
  ]
2720
- }, point.offset))
3091
+ }, reading.point.offset))
2721
3092
  ]
2722
3093
  }, item.id))
2723
3094
  })
@@ -2726,7 +3097,7 @@ function RetentionChart({
2726
3097
  });
2727
3098
  }
2728
3099
  // src/react/ui/JourneyChart.tsx
2729
- import { useLayoutEffect as useLayoutEffect5, useRef as useRef6, useState as useState8 } from "react";
3100
+ import { useLayoutEffect as useLayoutEffect3, useRef as useRef7, useState as useState9 } from "react";
2730
3101
 
2731
3102
  // src/react/ui/journey-flow.ts
2732
3103
  var journeyOutcomeLabels = {
@@ -2886,11 +3257,11 @@ function JourneyFlow({
2886
3257
  unit,
2887
3258
  formatValue
2888
3259
  }) {
2889
- const [expandedBranch, setExpandedBranch] = useState8([]);
2890
- const [visibleEventsByDepth, setVisibleEventsByDepth] = useState8({});
3260
+ const [expandedBranch, setExpandedBranch] = useState9([]);
3261
+ const [visibleEventsByDepth, setVisibleEventsByDepth] = useState9({});
2891
3262
  const graph = limitJourneyFlow(buildJourneyFlow(paths, expandedBranch), visibleEventsByDepth);
2892
- const scrollRef = useRef6(null);
2893
- const pendingDepth = useRef6(null);
3263
+ const scrollRef = useRef7(null);
3264
+ const pendingDepth = useRef7(null);
2894
3265
  const depthCount = Math.max(0, ...graph.nodes.map((node) => node.depth)) + 1;
2895
3266
  const startingCount = graph.nodes.filter((node) => node.depth === 0).reduce((sum, node) => sum + node.count, 0);
2896
3267
  function percent(count) {
@@ -2905,7 +3276,7 @@ function JourneyFlow({
2905
3276
  function columnX(depth) {
2906
3277
  return 10 + depth * columnSpacing;
2907
3278
  }
2908
- useLayoutEffect5(() => {
3279
+ useLayoutEffect3(() => {
2909
3280
  const depth = pendingDepth.current;
2910
3281
  const container = scrollRef.current;
2911
3282
  if (depth === null || !container || depth >= depthCount)
@@ -3083,6 +3454,7 @@ export {
3083
3454
  DateDisplay2 as DateDisplay,
3084
3455
  DateRangePicker2 as DateRangePicker,
3085
3456
  DimensionPicker2 as DimensionPicker,
3457
+ ExplorationActionControl2 as ExplorationActionControl,
3086
3458
  FilterActions2 as FilterActions,
3087
3459
  FilterBar2 as FilterBar,
3088
3460
  FunnelChart,
@@ -3139,4 +3511,4 @@ export {
3139
3511
  useViewTab2 as useViewTab
3140
3512
  };
3141
3513
 
3142
- //# debugId=3D3A9CC87FD5C9DB64756E2164756E21
3514
+ //# debugId=7CD02365D10882B064756E2164756E21