@altertable/data-app-react 0.75.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/chunks/{SectionHeading-CLvnHe1C.js → SectionHeading-Bz5RIXit.js} +767 -1152
- package/dist/chunks/SectionHeading-Bz5RIXit.js.map +1 -0
- package/dist/index.js +174 -37
- package/dist/index.js.map +1 -1
- package/dist/types/chunks/DateTimeRangePicker.d.ts +127 -122
- package/dist/types/index.d.ts +179 -217
- package/dist/types/ui/index.d.ts +70 -54
- package/dist/ui/index.js +921 -187
- package/dist/ui/index.js.map +1 -1
- package/package.json +13 -5
- package/dist/chunks/SectionHeading-CLvnHe1C.js.map +0 -1
package/dist/ui/index.js
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
|
-
import { $ as
|
|
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, useCallback, useContext, useEffect, useId, useLayoutEffect, useMemo, useRef, useState } 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, usePlotArea, useYAxisTicks } from "recharts";
|
|
8
|
+
import { Area, AreaChart as AreaChart$1, Bar, BarChart as BarChart$1, Brush, CartesianGrid, Cell, ComposedChart as ComposedChart$1, DefaultTooltipContent, Dot, ErrorBar, Label as Label$1, LabelList, Legend, Line, LineChart as LineChart$1, ReferenceArea, ReferenceDot, ReferenceLine, Scatter, Tooltip as Tooltip$1, XAxis, YAxis, ZAxis, useActiveTooltipLabel, 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, {
|
|
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 {
|
|
21
|
-
const connectionView =
|
|
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. */
|
|
@@ -143,6 +147,39 @@ function GlossaryDefinition({ entry, children }) {
|
|
|
143
147
|
});
|
|
144
148
|
}
|
|
145
149
|
//#endregion
|
|
150
|
+
//#region src/ui/Checkbox.tsx
|
|
151
|
+
const CheckboxGroupContext = createContext(null);
|
|
152
|
+
function Checkbox({ label, description, checked, value, onChange, disabled, className }) {
|
|
153
|
+
const group = useContext(CheckboxGroupContext);
|
|
154
|
+
const descriptionId = useId();
|
|
155
|
+
invariant(value === void 0 || group, "A checkbox with value must belong to a CheckboxGroup.");
|
|
156
|
+
const selected = value === void 0 ? checked : group.values.includes(value);
|
|
157
|
+
return /* @__PURE__ */ jsxs("label", {
|
|
158
|
+
"data-atbl-focus": "ring",
|
|
159
|
+
"data-atbl-control": "action",
|
|
160
|
+
className: classNames("altertable-checkbox", className),
|
|
161
|
+
children: [
|
|
162
|
+
/* @__PURE__ */ jsx("input", {
|
|
163
|
+
type: "checkbox",
|
|
164
|
+
value,
|
|
165
|
+
checked: selected,
|
|
166
|
+
"aria-label": label,
|
|
167
|
+
"aria-describedby": description ? descriptionId : void 0,
|
|
168
|
+
disabled: disabled || group?.disabled,
|
|
169
|
+
onChange: (event) => {
|
|
170
|
+
if (value === void 0) onChange(event.currentTarget.checked);
|
|
171
|
+
else group.onChange(value, event.currentTarget.checked);
|
|
172
|
+
}
|
|
173
|
+
}),
|
|
174
|
+
/* @__PURE__ */ jsx(SelectionMark, { selected }),
|
|
175
|
+
/* @__PURE__ */ jsxs("span", { children: [label, description && /* @__PURE__ */ jsx("small", {
|
|
176
|
+
id: descriptionId,
|
|
177
|
+
children: description
|
|
178
|
+
})] })
|
|
179
|
+
]
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
//#endregion
|
|
146
183
|
//#region src/ui/chart-data.ts
|
|
147
184
|
function validateChartIds(kind, items) {
|
|
148
185
|
const ids = /* @__PURE__ */ new Set();
|
|
@@ -741,6 +778,81 @@ function timeTicks(model, width) {
|
|
|
741
778
|
};
|
|
742
779
|
}
|
|
743
780
|
//#endregion
|
|
781
|
+
//#region src/ui/use-chart-cursor-group.tsx
|
|
782
|
+
const groupBrand = Symbol("ChartCursorGroup");
|
|
783
|
+
const stores = /* @__PURE__ */ new WeakMap();
|
|
784
|
+
function createGroup() {
|
|
785
|
+
const group = { [groupBrand]: true };
|
|
786
|
+
let cursor = null;
|
|
787
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
788
|
+
function notify() {
|
|
789
|
+
for (const listener of listeners) listener();
|
|
790
|
+
}
|
|
791
|
+
stores.set(group, {
|
|
792
|
+
snapshot: () => cursor,
|
|
793
|
+
subscribe: (listener) => {
|
|
794
|
+
listeners.add(listener);
|
|
795
|
+
return () => {
|
|
796
|
+
listeners.delete(listener);
|
|
797
|
+
};
|
|
798
|
+
},
|
|
799
|
+
publish: (source, time) => {
|
|
800
|
+
if (!Number.isFinite(time) || cursor?.source === source && cursor.time === time) return;
|
|
801
|
+
cursor = {
|
|
802
|
+
source,
|
|
803
|
+
time
|
|
804
|
+
};
|
|
805
|
+
notify();
|
|
806
|
+
},
|
|
807
|
+
clear: (source) => {
|
|
808
|
+
if (cursor?.source !== source) return;
|
|
809
|
+
cursor = null;
|
|
810
|
+
notify();
|
|
811
|
+
}
|
|
812
|
+
});
|
|
813
|
+
return group;
|
|
814
|
+
}
|
|
815
|
+
/** Creates a stable shared mouse-hover cursor handle. Pass it explicitly to each participating chart's cursorGroup prop.
|
|
816
|
+
* Peers indicate exact timestamp matches while tooltips remain local. Mouse leave clears the cursor.
|
|
817
|
+
* Each hook call creates an independent group; handles can be passed through component props.
|
|
818
|
+
* @example
|
|
819
|
+
* function Dashboard() {
|
|
820
|
+
* const operations = useChartCursorGroup();
|
|
821
|
+
* const samples = [{ id: 'noon', label: '12:00', time: 1767268800000, value: 42 }];
|
|
822
|
+
* return <>
|
|
823
|
+
* <BarChart cursorGroup={operations} items={samples} unit="requests" ariaLabel="Traffic" />
|
|
824
|
+
* <LineChart cursorGroup={operations} items={samples} unit="ms" ariaLabel="Latency" />
|
|
825
|
+
* </>;
|
|
826
|
+
* }
|
|
827
|
+
*/
|
|
828
|
+
function useChartCursorGroup() {
|
|
829
|
+
const [group] = useState(createGroup);
|
|
830
|
+
return group;
|
|
831
|
+
}
|
|
832
|
+
function emptySnapshot() {
|
|
833
|
+
return null;
|
|
834
|
+
}
|
|
835
|
+
function emptySubscribe() {
|
|
836
|
+
return () => {};
|
|
837
|
+
}
|
|
838
|
+
function useLinkedChartCursor(group) {
|
|
839
|
+
const store = group == null ? void 0 : stores.get(group);
|
|
840
|
+
const cursor = useSyncExternalStore(store?.subscribe ?? emptySubscribe, store?.snapshot ?? emptySnapshot, emptySnapshot);
|
|
841
|
+
const id = useId();
|
|
842
|
+
const setTime = useCallback((time) => {
|
|
843
|
+
if (time != null) store?.publish(id, time);
|
|
844
|
+
else store?.clear(id);
|
|
845
|
+
}, [store, id]);
|
|
846
|
+
const reset = useCallback(() => store?.clear(id), [store, id]);
|
|
847
|
+
useEffect(() => reset, [reset]);
|
|
848
|
+
return {
|
|
849
|
+
time: cursor?.source !== id ? cursor?.time : void 0,
|
|
850
|
+
setTime,
|
|
851
|
+
reset
|
|
852
|
+
};
|
|
853
|
+
}
|
|
854
|
+
const ChartCursorChartContext = createContext(null);
|
|
855
|
+
//#endregion
|
|
744
856
|
//#region src/ui/chart-date-axis.tsx
|
|
745
857
|
const ChartDateAxesContext = createContext(null);
|
|
746
858
|
function ChartDateAxes({ data, children }) {
|
|
@@ -795,6 +907,45 @@ const xAxisDefaults = {
|
|
|
795
907
|
axisLine: { stroke: "var(--atbl-border)" },
|
|
796
908
|
tick: { fontSize: "var(--atbl-type-meta-size)" }
|
|
797
909
|
};
|
|
910
|
+
function LinkedTimeCursor({ times, axisId }) {
|
|
911
|
+
const context = useContext(ChartCursorChartContext);
|
|
912
|
+
const label = useActiveTooltipLabel();
|
|
913
|
+
const active = useIsTooltipActive();
|
|
914
|
+
const scale = useXAxisScale(axisId);
|
|
915
|
+
const plot = usePlotArea();
|
|
916
|
+
const mouseHover = context?.mouseHover;
|
|
917
|
+
const setTime = context?.cursor.setTime;
|
|
918
|
+
const reset = context?.cursor.reset;
|
|
919
|
+
useEffect(() => {
|
|
920
|
+
if (!mouseHover || !active) reset?.();
|
|
921
|
+
else {
|
|
922
|
+
const time = chartTimestamp(label, true);
|
|
923
|
+
if (time != null && times.includes(time)) setTime?.(time);
|
|
924
|
+
}
|
|
925
|
+
}, [
|
|
926
|
+
mouseHover,
|
|
927
|
+
active,
|
|
928
|
+
label,
|
|
929
|
+
times,
|
|
930
|
+
setTime,
|
|
931
|
+
reset
|
|
932
|
+
]);
|
|
933
|
+
const time = context?.cursor.time;
|
|
934
|
+
if (time == null || !times.includes(time)) return null;
|
|
935
|
+
const x = scale?.(time);
|
|
936
|
+
if (!plot || x == null || !Number.isFinite(x) || x < plot.x || x > plot.x + plot.width) return null;
|
|
937
|
+
return /* @__PURE__ */ jsx("line", {
|
|
938
|
+
"aria-hidden": "true",
|
|
939
|
+
x1: x,
|
|
940
|
+
x2: x,
|
|
941
|
+
y1: plot.y,
|
|
942
|
+
y2: plot.y + plot.height,
|
|
943
|
+
stroke: "var(--atbl-muted)",
|
|
944
|
+
strokeOpacity: .3,
|
|
945
|
+
pointerEvents: "none",
|
|
946
|
+
"data-atbl-internal-linked-cursor": "true"
|
|
947
|
+
});
|
|
948
|
+
}
|
|
798
949
|
/**
|
|
799
950
|
* Infers temporal input from ISO dates, zoned ISO timestamps, and Date values.
|
|
800
951
|
* Use scale="utc" for epoch milliseconds or type="category" for date-like categories.
|
|
@@ -816,6 +967,16 @@ function ChartXAxis(props) {
|
|
|
816
967
|
enabled,
|
|
817
968
|
numeric
|
|
818
969
|
]);
|
|
970
|
+
const cursorModel = useMemo(() => {
|
|
971
|
+
if (!data?.length || dataKey == null || props.type === "category") return null;
|
|
972
|
+
if (props.scale !== "utc" && props.scale !== "time") return null;
|
|
973
|
+
return timeModel(data.map((row) => typeof dataKey === "function" ? dataKey(row) : field(row, dataKey)), props.scale === "utc" || props.scale === "time");
|
|
974
|
+
}, [
|
|
975
|
+
data,
|
|
976
|
+
dataKey,
|
|
977
|
+
props.type,
|
|
978
|
+
props.scale
|
|
979
|
+
]);
|
|
819
980
|
const register = context?.register;
|
|
820
981
|
const id = props.xAxisId ?? 0;
|
|
821
982
|
useEffect(() => model ? register?.(id, model.tooltip) : void 0, [
|
|
@@ -823,12 +984,15 @@ function ChartXAxis(props) {
|
|
|
823
984
|
id,
|
|
824
985
|
model
|
|
825
986
|
]);
|
|
826
|
-
if (!model || dataKey == null) return /* @__PURE__ */ jsx(XAxis, {
|
|
987
|
+
if (!model || dataKey == null) return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(XAxis, {
|
|
827
988
|
...xAxisDefaults,
|
|
828
989
|
...props
|
|
829
|
-
})
|
|
990
|
+
}), cursorModel && /* @__PURE__ */ jsx(LinkedTimeCursor, {
|
|
991
|
+
times: cursorModel.times,
|
|
992
|
+
axisId: id
|
|
993
|
+
})] });
|
|
830
994
|
const automaticTicks = props.ticks == null && props.tickFormatter == null ? timeTicks(model, plot?.width ?? 400) : null;
|
|
831
|
-
return /* @__PURE__ */ jsx(XAxis, {
|
|
995
|
+
return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(XAxis, {
|
|
832
996
|
...xAxisDefaults,
|
|
833
997
|
scale: "utc",
|
|
834
998
|
domain: model.start === model.end || context?.barAxes.has(id) ? [model.start - model.minimumInterval / 2, model.end + model.minimumInterval / 2] : [model.start, model.end],
|
|
@@ -858,7 +1022,10 @@ function ChartXAxis(props) {
|
|
|
858
1022
|
...axisProps,
|
|
859
1023
|
type: "number",
|
|
860
1024
|
dataKey: (row) => chartTimestamp(typeof dataKey === "function" ? dataKey(row) : field(row, dataKey), numeric)
|
|
861
|
-
})
|
|
1025
|
+
}), /* @__PURE__ */ jsx(LinkedTimeCursor, {
|
|
1026
|
+
times: model.times,
|
|
1027
|
+
axisId: id
|
|
1028
|
+
})] });
|
|
862
1029
|
}
|
|
863
1030
|
//#endregion
|
|
864
1031
|
//#region src/ui/chart-interaction.tsx
|
|
@@ -886,6 +1053,62 @@ function ChartSeries({ id, children }) {
|
|
|
886
1053
|
});
|
|
887
1054
|
}
|
|
888
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
|
|
889
1112
|
//#region src/ui/chart-value-format.ts
|
|
890
1113
|
const ChartValueFormat = createContext(void 0);
|
|
891
1114
|
/** Use one magnitude for every tick, and enough precision to distinguish them. */
|
|
@@ -935,7 +1158,7 @@ function ChartLegendRoot({ children, layout = "horizontal", align = "start", max
|
|
|
935
1158
|
const container = containerRef.current;
|
|
936
1159
|
if (!container) return;
|
|
937
1160
|
function measure() {
|
|
938
|
-
const list = containerRef.current?.
|
|
1161
|
+
const list = containerRef.current?.querySelector(".altertable-chart-legend");
|
|
939
1162
|
if (list) setColumns(getComputedStyle(list).gridTemplateColumns.split(" ").length);
|
|
940
1163
|
}
|
|
941
1164
|
const observer = new ResizeObserver(measure);
|
|
@@ -1080,16 +1303,18 @@ function ChartDot({ active = false, stroke = seriesColor, fill = active ? stroke
|
|
|
1080
1303
|
function NearestChartDot({ seriesId, cx, cy, stroke }) {
|
|
1081
1304
|
const interaction = useContext(ChartInteractionContext);
|
|
1082
1305
|
const registerPoint = interaction?.registerPoint;
|
|
1306
|
+
const legend = useChartLegendSeries(seriesId, void 0);
|
|
1083
1307
|
useLayoutEffect(() => {
|
|
1084
|
-
if (cx == null || cy == null) return;
|
|
1308
|
+
if (legend.hidden || cx == null || cy == null) return;
|
|
1085
1309
|
return registerPoint?.(seriesId, cx, cy);
|
|
1086
1310
|
}, [
|
|
1087
1311
|
registerPoint,
|
|
1088
1312
|
seriesId,
|
|
1089
1313
|
cx,
|
|
1090
|
-
cy
|
|
1314
|
+
cy,
|
|
1315
|
+
legend.hidden
|
|
1091
1316
|
]);
|
|
1092
|
-
return isChartSeriesActive(interaction, seriesId) ? /* @__PURE__ */ jsx(ChartDot, {
|
|
1317
|
+
return !legend.hidden && isChartSeriesActive(interaction, seriesId) ? /* @__PURE__ */ jsx(ChartDot, {
|
|
1093
1318
|
cx,
|
|
1094
1319
|
cy,
|
|
1095
1320
|
stroke,
|
|
@@ -1101,6 +1326,18 @@ function NearestChartDot({ seriesId, cx, cy, stroke }) {
|
|
|
1101
1326
|
function ChartBar(props) {
|
|
1102
1327
|
useDateAxisBar(props.xAxisId);
|
|
1103
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
|
+
]);
|
|
1104
1341
|
return /* @__PURE__ */ jsx(ChartSeries, {
|
|
1105
1342
|
id: series.id,
|
|
1106
1343
|
children: /* @__PURE__ */ jsx(Bar, {
|
|
@@ -1115,7 +1352,13 @@ function ChartBar(props) {
|
|
|
1115
1352
|
activeBar: series.active ? { opacity: .75 } : false,
|
|
1116
1353
|
isAnimationActive: false,
|
|
1117
1354
|
...props,
|
|
1118
|
-
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
|
+
}
|
|
1119
1362
|
})
|
|
1120
1363
|
});
|
|
1121
1364
|
}
|
|
@@ -1123,6 +1366,7 @@ function ChartBar(props) {
|
|
|
1123
1366
|
* activeDot independently controls the hovered point. Native dot props and renderers remain available. */
|
|
1124
1367
|
function ChartLine({ stroke = seriesColor, dot = false, activeDot, ...props }) {
|
|
1125
1368
|
const series = useChartSeries(props.id);
|
|
1369
|
+
const legend = useChartLegendSeries(series.id, props.dataKey);
|
|
1126
1370
|
return /* @__PURE__ */ jsx(ChartSeries, {
|
|
1127
1371
|
id: series.id,
|
|
1128
1372
|
children: /* @__PURE__ */ jsx(Line, {
|
|
@@ -1131,12 +1375,12 @@ function ChartLine({ stroke = seriesColor, dot = false, activeDot, ...props }) {
|
|
|
1131
1375
|
strokeWidth: 2,
|
|
1132
1376
|
strokeLinecap: "round",
|
|
1133
1377
|
strokeLinejoin: "round",
|
|
1134
|
-
dot: dot === true ? ({ cx, cy }) => /* @__PURE__ */ jsx(ChartDot, {
|
|
1378
|
+
dot: legend.hidden ? false : dot === true ? ({ cx, cy }) => /* @__PURE__ */ jsx(ChartDot, {
|
|
1135
1379
|
cx,
|
|
1136
1380
|
cy,
|
|
1137
1381
|
stroke
|
|
1138
1382
|
}) : dot,
|
|
1139
|
-
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, {
|
|
1140
1384
|
seriesId: series.id,
|
|
1141
1385
|
cx,
|
|
1142
1386
|
cy,
|
|
@@ -1144,13 +1388,20 @@ function ChartLine({ stroke = seriesColor, dot = false, activeDot, ...props }) {
|
|
|
1144
1388
|
}) : activeDot,
|
|
1145
1389
|
isAnimationActive: false,
|
|
1146
1390
|
...props,
|
|
1147
|
-
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
|
+
}
|
|
1148
1398
|
})
|
|
1149
1399
|
});
|
|
1150
1400
|
}
|
|
1151
1401
|
/** Filled series with the same sample-dot and activeDot options as ChartLine. */
|
|
1152
1402
|
function ChartArea({ stroke = seriesColor, dot = false, activeDot, ...props }) {
|
|
1153
1403
|
const series = useChartSeries(props.id);
|
|
1404
|
+
const legend = useChartLegendSeries(series.id, props.dataKey);
|
|
1154
1405
|
return /* @__PURE__ */ jsx(ChartSeries, {
|
|
1155
1406
|
id: series.id,
|
|
1156
1407
|
children: /* @__PURE__ */ jsx(Area, {
|
|
@@ -1162,12 +1413,12 @@ function ChartArea({ stroke = seriesColor, dot = false, activeDot, ...props }) {
|
|
|
1162
1413
|
strokeLinejoin: "round",
|
|
1163
1414
|
fill: stroke,
|
|
1164
1415
|
fillOpacity: .14,
|
|
1165
|
-
dot: dot === true ? ({ cx, cy }) => /* @__PURE__ */ jsx(ChartDot, {
|
|
1416
|
+
dot: legend.hidden ? false : dot === true ? ({ cx, cy }) => /* @__PURE__ */ jsx(ChartDot, {
|
|
1166
1417
|
cx,
|
|
1167
1418
|
cy,
|
|
1168
1419
|
stroke
|
|
1169
1420
|
}) : dot,
|
|
1170
|
-
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, {
|
|
1171
1422
|
seriesId: series.id,
|
|
1172
1423
|
cx,
|
|
1173
1424
|
cy,
|
|
@@ -1175,19 +1426,32 @@ function ChartArea({ stroke = seriesColor, dot = false, activeDot, ...props }) {
|
|
|
1175
1426
|
}) : activeDot,
|
|
1176
1427
|
isAnimationActive: false,
|
|
1177
1428
|
...props,
|
|
1178
|
-
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
|
+
}
|
|
1179
1436
|
})
|
|
1180
1437
|
});
|
|
1181
1438
|
}
|
|
1182
1439
|
function ChartScatter(props) {
|
|
1183
1440
|
const series = useChartSeries(props.id);
|
|
1441
|
+
const legend = useChartLegendSeries(series.id, props.dataKey);
|
|
1184
1442
|
return /* @__PURE__ */ jsx(ChartSeries, {
|
|
1185
1443
|
id: series.id,
|
|
1186
1444
|
children: /* @__PURE__ */ jsx(Scatter, {
|
|
1187
1445
|
fill: seriesColor,
|
|
1188
1446
|
isAnimationActive: false,
|
|
1189
1447
|
...props,
|
|
1190
|
-
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
|
+
}
|
|
1191
1455
|
})
|
|
1192
1456
|
});
|
|
1193
1457
|
}
|
|
@@ -1277,16 +1541,29 @@ function ChartTooltipContent(props) {
|
|
|
1277
1541
|
function ChartTooltip(props) {
|
|
1278
1542
|
const dateLabel = useDateAxisLabel(props.axisId);
|
|
1279
1543
|
const interaction = useContext(ChartInteractionContext);
|
|
1544
|
+
const legendInteraction = useContext(ChartLegendInteractionContext);
|
|
1545
|
+
const { content: authoredContent, ...tooltipProps } = props;
|
|
1280
1546
|
return /* @__PURE__ */ jsx(Tooltip$1, {
|
|
1281
1547
|
labelFormatter: dateLabel,
|
|
1282
|
-
content: (content) => /* @__PURE__ */ jsx(ChartTooltipContent, {
|
|
1283
|
-
...content,
|
|
1284
|
-
payload: interaction?.isPointerInspection && interaction.seriesCount !== 1 && props.shared !== true ? content.payload.filter((entry) => entry.graphicalItemId === interaction.activeSeriesId) : content.payload
|
|
1285
|
-
}),
|
|
1286
1548
|
position: interaction?.isPointerInspection && interaction.activePoint ? { y: interaction.activePoint.y } : void 0,
|
|
1287
1549
|
cursor: false,
|
|
1288
1550
|
isAnimationActive: false,
|
|
1289
|
-
...
|
|
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
|
+
}
|
|
1290
1567
|
});
|
|
1291
1568
|
}
|
|
1292
1569
|
//#endregion
|
|
@@ -1303,19 +1580,81 @@ function useChartScrollToEnd(items) {
|
|
|
1303
1580
|
//#endregion
|
|
1304
1581
|
//#region src/ui/TrendChart.tsx
|
|
1305
1582
|
/** Ordered, equally spaced samples; negative values share an explicit zero baseline. */
|
|
1306
|
-
function TrendChart({ items, unit, ariaLabel, formatValue = formatNumber, kind, itemActions }) {
|
|
1583
|
+
function TrendChart({ items, unit, ariaLabel, formatValue = formatNumber, kind, itemActions, cursorGroup, horizontalGrid = false }) {
|
|
1307
1584
|
validateValueChartItems(kind, items);
|
|
1308
1585
|
const Plot = kind === "area" ? AreaChart$1 : LineChart$1;
|
|
1309
1586
|
const chartActions = useChartActions();
|
|
1587
|
+
const cursor = useLinkedChartCursor(cursorGroup);
|
|
1588
|
+
const linkedItem = items.find((item) => item.time === cursor.time && cursor.time != null);
|
|
1310
1589
|
const [activeIndex, setActiveIndex] = useState();
|
|
1590
|
+
const [nearestIndex, setNearestIndex] = useState();
|
|
1591
|
+
const [mouseVisible, setMouseVisible] = useState(false);
|
|
1592
|
+
const nearest = useRef(void 0);
|
|
1593
|
+
const points = useRef(/* @__PURE__ */ new Map());
|
|
1594
|
+
const plotRef = useRef(null);
|
|
1595
|
+
const canvasRef = useRef(null);
|
|
1596
|
+
const highlightedIndex = mouseVisible ? nearestIndex : activeIndex;
|
|
1311
1597
|
const scrollport = useChartScrollToEnd(items);
|
|
1312
1598
|
const menuTriggers = useRef(/* @__PURE__ */ new Map());
|
|
1313
1599
|
const magnitude = items.reduce((max, item) => Math.max(max, Math.abs(item.value)), 1);
|
|
1314
1600
|
const low = items.reduce((min, item) => Math.min(min, item.value / magnitude), 0);
|
|
1315
1601
|
const high = items.reduce((max, item) => Math.max(max, item.value / magnitude), 0);
|
|
1602
|
+
function screenPoint(index) {
|
|
1603
|
+
if (index == null) return null;
|
|
1604
|
+
const point = points.current.get(index);
|
|
1605
|
+
const matrix = plotRef.current?.querySelector("svg")?.getScreenCTM();
|
|
1606
|
+
return point && matrix ? new DOMPoint(point.x, point.y).matrixTransform(matrix) : null;
|
|
1607
|
+
}
|
|
1608
|
+
function inspectNearest(event) {
|
|
1609
|
+
if (event.pointerType !== "mouse") return;
|
|
1610
|
+
const matrix = plotRef.current?.querySelector("svg")?.getScreenCTM();
|
|
1611
|
+
if (!matrix) return;
|
|
1612
|
+
let distance = Infinity;
|
|
1613
|
+
let selected;
|
|
1614
|
+
const viewport = scrollport.current?.getBoundingClientRect();
|
|
1615
|
+
const overLabels = event.clientY >= (plotRef.current?.getBoundingClientRect().top ?? 0) + 220;
|
|
1616
|
+
for (let index = 0; index < items.length; index++) {
|
|
1617
|
+
const sample = points.current.get(index);
|
|
1618
|
+
if (!sample) continue;
|
|
1619
|
+
const point = new DOMPoint(sample.x, sample.y).matrixTransform(matrix);
|
|
1620
|
+
if (viewport && (point.x < viewport.left || point.x > viewport.right)) continue;
|
|
1621
|
+
const candidate = overLabels ? Math.abs(point.x - event.clientX) : Math.hypot(point.x - event.clientX, point.y - event.clientY);
|
|
1622
|
+
if (candidate < distance) {
|
|
1623
|
+
distance = candidate;
|
|
1624
|
+
selected = index;
|
|
1625
|
+
}
|
|
1626
|
+
}
|
|
1627
|
+
nearest.current = selected;
|
|
1628
|
+
setNearestIndex(selected);
|
|
1629
|
+
cursor.setTime(selected == null ? void 0 : items[selected]?.time);
|
|
1630
|
+
}
|
|
1631
|
+
function inspectAction(event) {
|
|
1632
|
+
if (!mouseVisible || nearest.current == null || !(event.target instanceof Element)) return;
|
|
1633
|
+
if (event.clientY >= (plotRef.current?.getBoundingClientRect().top ?? 0) + 220) return;
|
|
1634
|
+
if (event.type === "click" && event.detail === 0) return;
|
|
1635
|
+
if (event.type === "contextmenu" && event.clientX === 0 && event.clientY === 0) return;
|
|
1636
|
+
const target = event.target.closest(".altertable-trend-point");
|
|
1637
|
+
const selected = plotRef.current?.querySelectorAll(".altertable-trend-point")[nearest.current];
|
|
1638
|
+
if (!target || !selected || target === selected) return;
|
|
1639
|
+
event.preventDefault();
|
|
1640
|
+
event.stopPropagation();
|
|
1641
|
+
if (event.type === "click") selected.click();
|
|
1642
|
+
else selected.dispatchEvent(new MouseEvent("contextmenu", {
|
|
1643
|
+
bubbles: true,
|
|
1644
|
+
cancelable: true,
|
|
1645
|
+
button: 2,
|
|
1646
|
+
clientX: event.clientX,
|
|
1647
|
+
clientY: event.clientY
|
|
1648
|
+
}));
|
|
1649
|
+
}
|
|
1316
1650
|
return /* @__PURE__ */ jsxs("section", {
|
|
1317
1651
|
className: "altertable-trend-chart",
|
|
1318
1652
|
"aria-label": ariaLabel,
|
|
1653
|
+
onPointerLeave: cursor.reset,
|
|
1654
|
+
onKeyDownCapture: cursor.reset,
|
|
1655
|
+
onPointerDownCapture: (event) => {
|
|
1656
|
+
if (event.pointerType !== "mouse") cursor.reset();
|
|
1657
|
+
},
|
|
1319
1658
|
children: [
|
|
1320
1659
|
items.length === 0 && /* @__PURE__ */ jsx("span", { children: "No data" }),
|
|
1321
1660
|
items.length > 0 && /* @__PURE__ */ jsx(Fragment$1, { children: /* @__PURE__ */ jsx("div", {
|
|
@@ -1323,10 +1662,12 @@ function TrendChart({ items, unit, ariaLabel, formatValue = formatNumber, kind,
|
|
|
1323
1662
|
ref: scrollport,
|
|
1324
1663
|
children: /* @__PURE__ */ jsxs("div", {
|
|
1325
1664
|
className: "altertable-trend-plot",
|
|
1665
|
+
ref: plotRef,
|
|
1326
1666
|
style: { minWidth: items.length * 40 },
|
|
1327
1667
|
children: [/* @__PURE__ */ jsx("div", {
|
|
1328
1668
|
className: "altertable-chart-canvas",
|
|
1329
1669
|
"aria-hidden": "true",
|
|
1670
|
+
ref: canvasRef,
|
|
1330
1671
|
children: /* @__PURE__ */ jsxs(Plot, {
|
|
1331
1672
|
data: items.map((item) => ({
|
|
1332
1673
|
...item,
|
|
@@ -1357,6 +1698,7 @@ function TrendChart({ items, unit, ariaLabel, formatValue = formatNumber, kind,
|
|
|
1357
1698
|
y: 0,
|
|
1358
1699
|
stroke: "var(--atbl-border)"
|
|
1359
1700
|
}),
|
|
1701
|
+
horizontalGrid && /* @__PURE__ */ jsx(ChartGrid, {}),
|
|
1360
1702
|
kind === "area" && /* @__PURE__ */ jsx(ChartArea, {
|
|
1361
1703
|
dataKey: "plotValue",
|
|
1362
1704
|
stroke: "none",
|
|
@@ -1366,87 +1708,126 @@ function TrendChart({ items, unit, ariaLabel, formatValue = formatNumber, kind,
|
|
|
1366
1708
|
}),
|
|
1367
1709
|
/* @__PURE__ */ jsx(ChartLine, {
|
|
1368
1710
|
dataKey: "plotValue",
|
|
1369
|
-
dot: ({ cx, cy, index }) =>
|
|
1370
|
-
cx,
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1711
|
+
dot: ({ cx, cy, index }) => {
|
|
1712
|
+
if (index != null && cx != null && cy != null) points.current.set(index, {
|
|
1713
|
+
x: cx,
|
|
1714
|
+
y: cy
|
|
1715
|
+
});
|
|
1716
|
+
return /* @__PURE__ */ jsx("g", {
|
|
1717
|
+
"data-atbl-internal-sample": index,
|
|
1718
|
+
transform: `translate(${cx}, ${cy})`,
|
|
1719
|
+
children: index === highlightedIndex && /* @__PURE__ */ jsx(ChartDot, {
|
|
1720
|
+
cx: 0,
|
|
1721
|
+
cy: 0,
|
|
1722
|
+
active: true
|
|
1723
|
+
})
|
|
1724
|
+
});
|
|
1725
|
+
},
|
|
1374
1726
|
activeDot: false
|
|
1727
|
+
}),
|
|
1728
|
+
linkedItem && /* @__PURE__ */ jsx(ReferenceLine, {
|
|
1729
|
+
x: linkedItem.id,
|
|
1730
|
+
stroke: "var(--atbl-muted)",
|
|
1731
|
+
strokeOpacity: .3,
|
|
1732
|
+
pointerEvents: "none",
|
|
1733
|
+
"data-atbl-internal-linked-cursor": "true"
|
|
1375
1734
|
})
|
|
1376
1735
|
]
|
|
1377
1736
|
})
|
|
1378
|
-
}), /* @__PURE__ */ jsx(
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1737
|
+
}), /* @__PURE__ */ jsx(ChartTooltip$1, {
|
|
1738
|
+
variant: "chart",
|
|
1739
|
+
touchInspection: false,
|
|
1740
|
+
boundaryRefs: [canvasRef, scrollport],
|
|
1741
|
+
onPointerEnter: inspectNearest,
|
|
1742
|
+
onPointerMove: inspectNearest,
|
|
1743
|
+
onPointerLeave: cursor.reset,
|
|
1744
|
+
onOpenChange: setMouseVisible,
|
|
1745
|
+
anchorRect: () => {
|
|
1746
|
+
const point = screenPoint(nearest.current);
|
|
1747
|
+
return point ? new DOMRect(point.x, point.y, 0, 0) : null;
|
|
1748
|
+
},
|
|
1749
|
+
content: nearestIndex == null || !items[nearestIndex] ? null : /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("strong", { children: items[nearestIndex].label }), /* @__PURE__ */ jsxs("span", { children: [
|
|
1750
|
+
formatValue(items[nearestIndex].value),
|
|
1751
|
+
" ",
|
|
1752
|
+
unit
|
|
1753
|
+
] })] }),
|
|
1754
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
1755
|
+
className: "altertable-trend-points",
|
|
1756
|
+
onClickCapture: inspectAction,
|
|
1757
|
+
onContextMenuCapture: inspectAction,
|
|
1758
|
+
children: items.map((item, index) => {
|
|
1759
|
+
const declaredActions = itemActions?.(item) ?? [];
|
|
1760
|
+
const actions = chartActions.actions(declaredActions, item.label, `${formatValue(item.value)} ${unit}`);
|
|
1761
|
+
const action = getPrimaryExplorationAction(actions);
|
|
1762
|
+
const menuTrigger = { get current() {
|
|
1763
|
+
return menuTriggers.current.get(item.id) ?? null;
|
|
1764
|
+
} };
|
|
1765
|
+
return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsxs("div", {
|
|
1766
|
+
className: "altertable-chart-item-actions",
|
|
1767
|
+
children: [/* @__PURE__ */ jsx(ChartTooltip$1, {
|
|
1768
|
+
variant: "chart",
|
|
1769
|
+
mouseHover: false,
|
|
1770
|
+
followCursor: false,
|
|
1771
|
+
onOpenChange: (open) => setActiveIndex((current) => open ? index : current === index ? void 0 : current),
|
|
1772
|
+
content: /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("strong", { children: item.label }), /* @__PURE__ */ jsxs("span", { children: [
|
|
1773
|
+
formatValue(item.value),
|
|
1774
|
+
" ",
|
|
1775
|
+
unit
|
|
1776
|
+
] })] }),
|
|
1777
|
+
className: "altertable-chart-column",
|
|
1778
|
+
children: action ? /* @__PURE__ */ jsxs("button", {
|
|
1779
|
+
"data-atbl-focus": "ring",
|
|
1780
|
+
"data-atbl-control": "action",
|
|
1781
|
+
type: "button",
|
|
1782
|
+
className: "altertable-trend-point",
|
|
1783
|
+
"aria-label": `${item.label}: ${formatValue(item.value)} ${unit}. ${action.label}`,
|
|
1784
|
+
...explorationMenuEvents(menuTrigger),
|
|
1785
|
+
onClick: (event) => action.onSelect(event.currentTarget),
|
|
1786
|
+
children: [/* @__PURE__ */ jsx("span", { className: "altertable-trend-hit" }), /* @__PURE__ */ jsx("span", {
|
|
1787
|
+
className: "altertable-trend-label",
|
|
1788
|
+
children: item.label
|
|
1789
|
+
})]
|
|
1790
|
+
}) : actions.length > 1 ? /* @__PURE__ */ jsxs(MenuTrigger, { children: [/* @__PURE__ */ jsxs(PressButton, {
|
|
1791
|
+
...explorationMenuEvents(menuTrigger),
|
|
1792
|
+
ref: (element) => {
|
|
1793
|
+
if (element) menuTriggers.current.set(item.id, element);
|
|
1794
|
+
else menuTriggers.current.delete(item.id);
|
|
1795
|
+
},
|
|
1796
|
+
className: "altertable-trend-point",
|
|
1797
|
+
"aria-label": `${item.label}: ${formatValue(item.value)} ${unit}. Actions`,
|
|
1798
|
+
children: [/* @__PURE__ */ jsx("span", { className: "altertable-trend-hit" }), /* @__PURE__ */ jsx("span", {
|
|
1799
|
+
className: "altertable-trend-label",
|
|
1800
|
+
children: item.label
|
|
1801
|
+
})]
|
|
1802
|
+
}), /* @__PURE__ */ jsx(ExplorationActionMenu, {
|
|
1803
|
+
actions,
|
|
1804
|
+
ariaLabel: `${item.label} actions`,
|
|
1805
|
+
triggerRef: menuTrigger
|
|
1806
|
+
})] }) : /* @__PURE__ */ jsxs("button", {
|
|
1807
|
+
"data-atbl-focus": "ring",
|
|
1808
|
+
"data-atbl-control": "default",
|
|
1809
|
+
type: "button",
|
|
1810
|
+
tabIndex: -1,
|
|
1811
|
+
className: "altertable-trend-point",
|
|
1812
|
+
"aria-label": `${item.label}: ${formatValue(item.value)} ${unit}`,
|
|
1813
|
+
children: [/* @__PURE__ */ jsx("span", { className: "altertable-trend-hit" }), /* @__PURE__ */ jsx("span", {
|
|
1814
|
+
className: "altertable-trend-label",
|
|
1815
|
+
children: item.label
|
|
1816
|
+
})]
|
|
1817
|
+
})
|
|
1818
|
+
}), action && /* @__PURE__ */ jsx(ExplorationActionControl, {
|
|
1819
|
+
contextOnly: declaredActions.length === 1,
|
|
1820
|
+
indicator: "chevron",
|
|
1412
1821
|
ref: (element) => {
|
|
1413
1822
|
if (element) menuTriggers.current.set(item.id, element);
|
|
1414
1823
|
else menuTriggers.current.delete(item.id);
|
|
1415
1824
|
},
|
|
1416
|
-
className: "altertable-trend-point",
|
|
1417
|
-
"aria-label": `${item.label}: ${formatValue(item.value)} ${unit}. Actions`,
|
|
1418
|
-
children: [/* @__PURE__ */ jsx("span", { className: "altertable-trend-hit" }), /* @__PURE__ */ jsx("span", {
|
|
1419
|
-
className: "altertable-trend-label",
|
|
1420
|
-
children: item.label
|
|
1421
|
-
})]
|
|
1422
|
-
}), /* @__PURE__ */ jsx(ExplorationActionMenu, {
|
|
1423
1825
|
actions,
|
|
1424
1826
|
ariaLabel: `${item.label} actions`,
|
|
1425
|
-
|
|
1426
|
-
})]
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
type: "button",
|
|
1430
|
-
tabIndex: -1,
|
|
1431
|
-
className: "altertable-trend-point",
|
|
1432
|
-
"aria-label": `${item.label}: ${formatValue(item.value)} ${unit}`,
|
|
1433
|
-
children: [/* @__PURE__ */ jsx("span", { className: "altertable-trend-hit" }), /* @__PURE__ */ jsx("span", {
|
|
1434
|
-
className: "altertable-trend-label",
|
|
1435
|
-
children: item.label
|
|
1436
|
-
})]
|
|
1437
|
-
})
|
|
1438
|
-
}), action && /* @__PURE__ */ jsx(ExplorationActionControl, {
|
|
1439
|
-
contextOnly: declaredActions.length === 1,
|
|
1440
|
-
indicator: "chevron",
|
|
1441
|
-
ref: (element) => {
|
|
1442
|
-
if (element) menuTriggers.current.set(item.id, element);
|
|
1443
|
-
else menuTriggers.current.delete(item.id);
|
|
1444
|
-
},
|
|
1445
|
-
actions,
|
|
1446
|
-
ariaLabel: `${item.label} actions`,
|
|
1447
|
-
hidePrimary: Boolean(action)
|
|
1448
|
-
})]
|
|
1449
|
-
}) }, item.id);
|
|
1827
|
+
hidePrimary: Boolean(action)
|
|
1828
|
+
})]
|
|
1829
|
+
}) }, item.id);
|
|
1830
|
+
})
|
|
1450
1831
|
})
|
|
1451
1832
|
})]
|
|
1452
1833
|
})
|
|
@@ -1712,7 +2093,7 @@ function scale(values) {
|
|
|
1712
2093
|
* Negative and constant coordinates are supported. Axis labels and units describe
|
|
1713
2094
|
* tooltips as well as the plot; formatX/formatY format ticks and tooltip values.
|
|
1714
2095
|
* Compose inside VisualizationWidget; hover/touch tooltips need no caller state. */
|
|
1715
|
-
function ScatterChart({ items, xLabel, yLabel, xUnit, yUnit, ariaLabel, formatX = formatNumber$1, formatY = formatNumber$1 }) {
|
|
2096
|
+
function ScatterChart({ items, xLabel, yLabel, xUnit, yUnit, ariaLabel, formatX = formatNumber$1, formatY = formatNumber$1, horizontalGrid = true }) {
|
|
1716
2097
|
validateScatterChartItems(items);
|
|
1717
2098
|
const xScale = scale(items.map((item) => item.x));
|
|
1718
2099
|
const yScale = scale(items.map((item) => item.y));
|
|
@@ -1731,7 +2112,10 @@ function ScatterChart({ items, xLabel, yLabel, xUnit, yUnit, ariaLabel, formatX
|
|
|
1731
2112
|
children: [
|
|
1732
2113
|
yScale.ticks.map((value, index) => /* @__PURE__ */ jsx("div", {
|
|
1733
2114
|
className: "altertable-scatter-gridline",
|
|
1734
|
-
style: {
|
|
2115
|
+
style: {
|
|
2116
|
+
bottom: `${index * 50}%`,
|
|
2117
|
+
borderTopStyle: horizontalGrid ? void 0 : "none"
|
|
2118
|
+
},
|
|
1735
2119
|
"aria-hidden": "true",
|
|
1736
2120
|
children: /* @__PURE__ */ jsx("span", {
|
|
1737
2121
|
title: formatY(value),
|
|
@@ -1792,29 +2176,87 @@ function ScatterChart({ items, xLabel, yLabel, xUnit, yUnit, ariaLabel, formatX
|
|
|
1792
2176
|
}
|
|
1793
2177
|
//#endregion
|
|
1794
2178
|
//#region src/ui/BarChart.tsx
|
|
2179
|
+
const timeTickIntervals = [
|
|
2180
|
+
6e4,
|
|
2181
|
+
12e4,
|
|
2182
|
+
3e5,
|
|
2183
|
+
6e5,
|
|
2184
|
+
9e5,
|
|
2185
|
+
18e5,
|
|
2186
|
+
36e5,
|
|
2187
|
+
72e5,
|
|
2188
|
+
216e5,
|
|
2189
|
+
432e5,
|
|
2190
|
+
864e5,
|
|
2191
|
+
1728e5,
|
|
2192
|
+
6048e5,
|
|
2193
|
+
12096e5
|
|
2194
|
+
];
|
|
2195
|
+
function timeTickIndices(items, width) {
|
|
2196
|
+
if (items.length === 1) return /* @__PURE__ */ new Set([0]);
|
|
2197
|
+
if (items.length < 2 || width <= 0) return /* @__PURE__ */ new Set();
|
|
2198
|
+
const slotWidth = width / items.length;
|
|
2199
|
+
const cadence = (items.at(-1).time - items[0].time) / (items.length - 1);
|
|
2200
|
+
const minimumInterval = Math.max(cadence, 100 / slotWidth * cadence);
|
|
2201
|
+
const interval = timeTickIntervals.find((candidate) => candidate >= minimumInterval) ?? Math.ceil(minimumInterval / timeTickIntervals.at(-1)) * timeTickIntervals.at(-1);
|
|
2202
|
+
const indices = /* @__PURE__ */ new Set();
|
|
2203
|
+
const stride = Math.max(1, Math.ceil(interval / cadence));
|
|
2204
|
+
const count = Math.max(1, Math.min(Math.floor((items.length - 1) / stride) + 1, Math.floor(Math.max(0, width - 60) / (stride * slotWidth)) + 1));
|
|
2205
|
+
const start = Math.floor((items.length - 1 - (count - 1) * stride) / 2);
|
|
2206
|
+
for (let tick = 0; tick < count; tick++) indices.add(start + tick * stride);
|
|
2207
|
+
return indices;
|
|
2208
|
+
}
|
|
1795
2209
|
/** Nonnegative category values. Compose inside VisualizationWidget for a titled panel.
|
|
1796
2210
|
* Owns hover/touch tooltips; no selection state or keyboard navigation. */
|
|
1797
|
-
function BarChart({ items, unit, ariaLabel, formatValue = formatNumber, itemActions }) {
|
|
2211
|
+
function BarChart({ items, unit, ariaLabel, formatValue = formatNumber, itemActions, cursorGroup, horizontalGrid = false }) {
|
|
1798
2212
|
validateValueChartItems("bar", items);
|
|
1799
2213
|
const chartActions = useChartActions();
|
|
2214
|
+
const cursor = useLinkedChartCursor(cursorGroup);
|
|
2215
|
+
const linkedItem = items.find((item) => item.time === cursor.time && cursor.time != null);
|
|
1800
2216
|
const [activeId, setActiveId] = useState();
|
|
2217
|
+
const [viewportWidth, setViewportWidth] = useState(0);
|
|
1801
2218
|
const scrollport = useChartScrollToEnd(items);
|
|
2219
|
+
const plotRef = useRef(null);
|
|
2220
|
+
const canvasRef = useRef(null);
|
|
1802
2221
|
const menuTriggers = useRef(/* @__PURE__ */ new Map());
|
|
1803
2222
|
const maximum = items.reduce((max, item) => Math.max(max, item.value), 1);
|
|
2223
|
+
const compactTimeAxis = items.length > 0 && items.every((item, index) => typeof item.time === "number" && Number.isFinite(item.time) && (index === 0 || item.time > items[index - 1].time)) && !itemActions;
|
|
2224
|
+
const minimumSlotWidth = compactTimeAxis ? 3.5 : 45;
|
|
2225
|
+
const plotWidth = Math.max(viewportWidth, items.length * minimumSlotWidth);
|
|
2226
|
+
const ticks = compactTimeAxis ? timeTickIndices(items, plotWidth) : null;
|
|
2227
|
+
useLayoutEffect(() => {
|
|
2228
|
+
const element = scrollport.current;
|
|
2229
|
+
if (!element) return;
|
|
2230
|
+
function updateWidth() {
|
|
2231
|
+
setViewportWidth(Math.floor(element.getBoundingClientRect().width));
|
|
2232
|
+
}
|
|
2233
|
+
updateWidth();
|
|
2234
|
+
const observer = new ResizeObserver(updateWidth);
|
|
2235
|
+
observer.observe(element);
|
|
2236
|
+
return () => observer.disconnect();
|
|
2237
|
+
}, [scrollport]);
|
|
1804
2238
|
return /* @__PURE__ */ jsxs("section", {
|
|
1805
2239
|
className: "altertable-selectable-bars",
|
|
1806
2240
|
"aria-label": ariaLabel,
|
|
2241
|
+
onPointerLeave: cursor.reset,
|
|
2242
|
+
onKeyDownCapture: cursor.reset,
|
|
2243
|
+
onPointerDownCapture: (event) => {
|
|
2244
|
+
if (event.pointerType !== "mouse") cursor.reset();
|
|
2245
|
+
},
|
|
1807
2246
|
children: [
|
|
1808
2247
|
items.length === 0 && /* @__PURE__ */ jsx("span", { children: "No data" }),
|
|
1809
2248
|
/* @__PURE__ */ jsx("div", {
|
|
1810
2249
|
className: "altertable-selectable-bars-scroll",
|
|
2250
|
+
"data-time-axis": compactTimeAxis || void 0,
|
|
1811
2251
|
ref: scrollport,
|
|
1812
2252
|
children: /* @__PURE__ */ jsxs("div", {
|
|
1813
2253
|
className: "altertable-selectable-bars-plot",
|
|
1814
|
-
|
|
2254
|
+
ref: plotRef,
|
|
2255
|
+
style: { width: plotWidth },
|
|
1815
2256
|
children: [/* @__PURE__ */ jsx("div", {
|
|
1816
2257
|
className: "altertable-chart-canvas",
|
|
1817
2258
|
"aria-hidden": "true",
|
|
2259
|
+
ref: canvasRef,
|
|
1818
2260
|
children: /* @__PURE__ */ jsxs(BarChart$1, {
|
|
1819
2261
|
data: items.map((item) => ({
|
|
1820
2262
|
...item,
|
|
@@ -1843,19 +2285,32 @@ function BarChart({ items, unit, ariaLabel, formatValue = formatNumber, itemActi
|
|
|
1843
2285
|
domain: [0, 1],
|
|
1844
2286
|
allowDataOverflow: true
|
|
1845
2287
|
}),
|
|
2288
|
+
horizontalGrid && /* @__PURE__ */ jsx(ChartGrid, {}),
|
|
1846
2289
|
/* @__PURE__ */ jsx(ChartBar, {
|
|
1847
2290
|
dataKey: "plotValue",
|
|
1848
2291
|
minPointSize: (value) => (value ?? 0) > 0 ? 7 : 0,
|
|
2292
|
+
background: linkedItem ? ({ index, x, y, width, height }) => /* @__PURE__ */ jsx("g", { children: items[index]?.id === linkedItem.id && /* @__PURE__ */ jsx("rect", {
|
|
2293
|
+
x,
|
|
2294
|
+
y,
|
|
2295
|
+
width,
|
|
2296
|
+
height,
|
|
2297
|
+
fill: "var(--atbl-muted)",
|
|
2298
|
+
fillOpacity: .14,
|
|
2299
|
+
pointerEvents: "none",
|
|
2300
|
+
"aria-hidden": "true",
|
|
2301
|
+
"data-atbl-internal-linked-cursor": "true"
|
|
2302
|
+
}) }) : false,
|
|
1849
2303
|
children: items.map((item) => /* @__PURE__ */ jsx(Cell, {
|
|
1850
2304
|
fill: chartBarFill,
|
|
1851
|
-
opacity: activeId === item.id ? .75 : 1
|
|
2305
|
+
opacity: activeId === item.id ? .75 : 1,
|
|
2306
|
+
"data-atbl-internal-bar-id": item.id
|
|
1852
2307
|
}, item.id))
|
|
1853
2308
|
})
|
|
1854
2309
|
]
|
|
1855
2310
|
})
|
|
1856
2311
|
}), /* @__PURE__ */ jsx("div", {
|
|
1857
2312
|
className: "altertable-selectable-bars-items",
|
|
1858
|
-
children: items.map((item) => {
|
|
2313
|
+
children: items.map((item, index) => {
|
|
1859
2314
|
const actions = chartActions.actions(itemActions?.(item) ?? [], item.label, `${formatValue(item.value)} ${unit}`);
|
|
1860
2315
|
const action = getPrimaryExplorationAction(actions);
|
|
1861
2316
|
const menuTrigger = { get current() {
|
|
@@ -1863,8 +2318,20 @@ function BarChart({ items, unit, ariaLabel, formatValue = formatNumber, itemActi
|
|
|
1863
2318
|
} };
|
|
1864
2319
|
return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsxs("div", {
|
|
1865
2320
|
className: "altertable-chart-item-actions",
|
|
1866
|
-
|
|
2321
|
+
onPointerMove: (event) => {
|
|
2322
|
+
if (event.pointerType === "mouse") cursor.setTime(item.time);
|
|
2323
|
+
},
|
|
2324
|
+
children: [/* @__PURE__ */ jsx(ChartTooltip$1, {
|
|
1867
2325
|
variant: "chart",
|
|
2326
|
+
followCursor: false,
|
|
2327
|
+
boundaryRefs: [canvasRef, scrollport],
|
|
2328
|
+
anchorRect: (trigger) => {
|
|
2329
|
+
const bar = plotRef.current?.querySelector(`[data-atbl-internal-bar-id="${CSS.escape(item.id)}"]`);
|
|
2330
|
+
const bounds = bar?.getBoundingClientRect() ?? trigger?.getBoundingClientRect();
|
|
2331
|
+
if (!bounds) return null;
|
|
2332
|
+
const top = bar ? bounds.top : bounds.top + 220;
|
|
2333
|
+
return new DOMRect(bounds.left + bounds.width / 2, top, 0, 0);
|
|
2334
|
+
},
|
|
1868
2335
|
onOpenChange: (open) => setActiveId((current) => open ? item.id : current === item.id ? void 0 : current),
|
|
1869
2336
|
content: /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("strong", { children: item.label }), /* @__PURE__ */ jsxs("span", { children: [
|
|
1870
2337
|
formatValue(item.value),
|
|
@@ -1901,6 +2368,7 @@ function BarChart({ items, unit, ariaLabel, formatValue = formatNumber, itemActi
|
|
|
1901
2368
|
})
|
|
1902
2369
|
}), /* @__PURE__ */ jsx("div", {
|
|
1903
2370
|
className: "altertable-chart-item-label-row",
|
|
2371
|
+
"data-time-tick": ticks?.has(index) || void 0,
|
|
1904
2372
|
children: actions.length ? /* @__PURE__ */ jsxs(MenuTrigger, { children: [/* @__PURE__ */ jsxs(PressButton, {
|
|
1905
2373
|
className: "altertable-selectable-bars-label",
|
|
1906
2374
|
variant: "ghost",
|
|
@@ -2024,17 +2492,9 @@ function createLegendItemKeys() {
|
|
|
2024
2492
|
const keys = payload.map((entry) => {
|
|
2025
2493
|
const source = entry.payload;
|
|
2026
2494
|
const id = source && typeof source === "object" && "id" in source ? source.id : void 0;
|
|
2027
|
-
if (typeof id === "string" || typeof id === "number") return [
|
|
2028
|
-
"series",
|
|
2029
|
-
typeof id,
|
|
2030
|
-
id
|
|
2031
|
-
].join(KEY_SEPARATOR);
|
|
2032
2495
|
const key = entry.dataKey;
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
typeof key,
|
|
2036
|
-
key
|
|
2037
|
-
].join(KEY_SEPARATOR);
|
|
2496
|
+
const seriesKey = chartLegendSeriesKey(id, key);
|
|
2497
|
+
if (seriesKey) return seriesKey;
|
|
2038
2498
|
return ["object", identity(typeof key === "function" ? key : entry)].join(KEY_SEPARATOR);
|
|
2039
2499
|
});
|
|
2040
2500
|
const counts = /* @__PURE__ */ new Map();
|
|
@@ -2051,9 +2511,15 @@ function createLegendItemKeys() {
|
|
|
2051
2511
|
});
|
|
2052
2512
|
};
|
|
2053
2513
|
}
|
|
2054
|
-
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 }) {
|
|
2055
2515
|
const [getItemKeys] = useState(createLegendItemKeys);
|
|
2516
|
+
const interaction = useContext(ChartLegendInteractionContext);
|
|
2056
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);
|
|
2057
2523
|
if (!payload.some((entry) => entry.type !== "none")) return null;
|
|
2058
2524
|
const vertical = layout === "vertical" || layout === "auto" && (position === "left" || position === "right");
|
|
2059
2525
|
return /* @__PURE__ */ jsx(ChartLegend, {
|
|
@@ -2081,14 +2547,32 @@ function LegendContent({ payload = [], maxVisibleItems, formatter, layout, align
|
|
|
2081
2547
|
})] });
|
|
2082
2548
|
return /* @__PURE__ */ jsx(ChartLegend.Item, {
|
|
2083
2549
|
inactive: entry.inactive,
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
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", {
|
|
2087
2561
|
type: "button",
|
|
2088
2562
|
"data-atbl-control": "action",
|
|
2089
2563
|
"data-atbl-focus": "ring",
|
|
2090
2564
|
className: "altertable-chart-legend-action",
|
|
2091
|
-
|
|
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
|
+
},
|
|
2092
2576
|
children: content
|
|
2093
2577
|
}) : content
|
|
2094
2578
|
}, itemKeys[index]);
|
|
@@ -2096,13 +2580,15 @@ function LegendContent({ payload = [], maxVisibleItems, formatter, layout, align
|
|
|
2096
2580
|
});
|
|
2097
2581
|
}
|
|
2098
2582
|
/** Opt in inside ComposedChart to derive the shared legend from its displayed series.
|
|
2099
|
-
* Give native series unique IDs when they share a data key.
|
|
2100
2583
|
* Native positioning, sorting, formatters, callbacks, and custom content remain available. */
|
|
2101
|
-
function ComposedChartLegend({ maxVisibleItems, ...props }) {
|
|
2584
|
+
function ComposedChartLegend({ maxVisibleItems, interactive = true, ...props }) {
|
|
2102
2585
|
return /* @__PURE__ */ jsx(Legend, {
|
|
2103
2586
|
iconSize: 8,
|
|
2104
2587
|
inactiveColor: "var(--atbl-muted)",
|
|
2105
|
-
content: /* @__PURE__ */ jsx(LegendContent, {
|
|
2588
|
+
content: /* @__PURE__ */ jsx(LegendContent, {
|
|
2589
|
+
maxVisibleItems,
|
|
2590
|
+
interactive
|
|
2591
|
+
}),
|
|
2106
2592
|
...props
|
|
2107
2593
|
});
|
|
2108
2594
|
}
|
|
@@ -2121,6 +2607,125 @@ function findNearestSeriesId(hoveredSeriesId, points, position) {
|
|
|
2121
2607
|
}
|
|
2122
2608
|
return selected;
|
|
2123
2609
|
}
|
|
2610
|
+
function hasAuthoredGrid(children) {
|
|
2611
|
+
return Children.toArray(children).some((child) => isValidElement(child) && (child.type === ChartGrid || child.type === CartesianGrid || child.type === Fragment && hasAuthoredGrid(child.props.children)));
|
|
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
|
+
}
|
|
2124
2729
|
/** Compose Cartesian series inside VisualizationWidget. Defaults to responsive
|
|
2125
2730
|
* full width and 300px height. Children retain native Recharts props and behavior,
|
|
2126
2731
|
* including stacking, numeric/time axes, missing values, tooltips, and keyboard
|
|
@@ -2128,11 +2733,14 @@ function findNearestSeriesId(hoveredSeriesId, points, position) {
|
|
|
2128
2733
|
* for stacks. Preserve missing measures as null and choose connectNulls deliberately.
|
|
2129
2734
|
* Use public chart tokens for series colors. Dataset bindings own
|
|
2130
2735
|
* loading, empty results, evidence, and CSV; this primitive owns only the plot. */
|
|
2131
|
-
function ComposedChartRoot({ data, ariaLabel, valueFormat, width = "100%", height = 300, responsive = true, className, ...props }) {
|
|
2736
|
+
function ComposedChartRoot({ data, ariaLabel, valueFormat, cursorGroup, horizontalGrid = false, children, width = "100%", height = 300, responsive = true, layout = "horizontal", className, ...props }) {
|
|
2737
|
+
const cursor = useLinkedChartCursor(cursorGroup);
|
|
2738
|
+
const [mouseHover, setMouseHover] = useState(false);
|
|
2132
2739
|
const [hasPointerFocus, setHasPointerFocus] = useState(false);
|
|
2133
2740
|
const [isPointerInspection, setIsPointerInspection] = useState(false);
|
|
2134
2741
|
const [hoveredSeriesId, setHoveredSeriesId] = useState(null);
|
|
2135
2742
|
const [pointerPosition, setPointerPosition] = useState(null);
|
|
2743
|
+
const latestPointerPosition = useRef(null);
|
|
2136
2744
|
const [points, setPoints] = useState(() => /* @__PURE__ */ new Map());
|
|
2137
2745
|
const registerPoint = useCallback((id, x, y) => {
|
|
2138
2746
|
setPoints((current) => new Map(current).set(id, {
|
|
@@ -2145,29 +2753,40 @@ function ComposedChartRoot({ data, ariaLabel, valueFormat, width = "100%", heigh
|
|
|
2145
2753
|
return next;
|
|
2146
2754
|
});
|
|
2147
2755
|
}, []);
|
|
2756
|
+
useEffect(() => {
|
|
2757
|
+
setPointerPosition(latestPointerPosition.current);
|
|
2758
|
+
}, [points]);
|
|
2148
2759
|
function trackPointer(event) {
|
|
2760
|
+
setMouseHover(event.pointerType === "mouse");
|
|
2149
2761
|
const svg = event.currentTarget.querySelector("svg[role=\"application\"]");
|
|
2150
2762
|
if (!(svg instanceof SVGSVGElement) || !(event.target instanceof Node) || !svg.contains(event.target)) {
|
|
2151
2763
|
resetPointerInspection();
|
|
2152
2764
|
return false;
|
|
2153
2765
|
}
|
|
2766
|
+
setSuppressPlotInspection(false);
|
|
2154
2767
|
setIsPointerInspection(true);
|
|
2155
2768
|
if (hoveredSeriesId != null && !points.has(hoveredSeriesId)) {
|
|
2769
|
+
latestPointerPosition.current = null;
|
|
2156
2770
|
setPointerPosition(null);
|
|
2157
2771
|
return true;
|
|
2158
2772
|
}
|
|
2159
2773
|
const matrix = svg.getScreenCTM();
|
|
2160
2774
|
if (!matrix) return true;
|
|
2161
2775
|
const point = new DOMPoint(event.clientX, event.clientY).matrixTransform(matrix.inverse());
|
|
2162
|
-
|
|
2776
|
+
const nextPosition = {
|
|
2163
2777
|
x: point.x,
|
|
2164
2778
|
y: point.y
|
|
2165
|
-
}
|
|
2779
|
+
};
|
|
2780
|
+
latestPointerPosition.current = nextPosition;
|
|
2781
|
+
setPointerPosition((current) => findNearestSeriesId(hoveredSeriesId, points, current) === findNearestSeriesId(hoveredSeriesId, points, nextPosition) ? current : nextPosition);
|
|
2166
2782
|
return true;
|
|
2167
2783
|
}
|
|
2168
2784
|
function resetPointerInspection() {
|
|
2785
|
+
setMouseHover(false);
|
|
2786
|
+
cursor.reset();
|
|
2169
2787
|
setIsPointerInspection(false);
|
|
2170
2788
|
setHoveredSeriesId(null);
|
|
2789
|
+
latestPointerPosition.current = null;
|
|
2171
2790
|
setPointerPosition(null);
|
|
2172
2791
|
}
|
|
2173
2792
|
const activeSeriesId = findNearestSeriesId(hoveredSeriesId, points, pointerPosition);
|
|
@@ -2182,50 +2801,115 @@ function ComposedChartRoot({ data, ariaLabel, valueFormat, width = "100%", heigh
|
|
|
2182
2801
|
});
|
|
2183
2802
|
};
|
|
2184
2803
|
}, []);
|
|
2185
|
-
|
|
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
|
+
}, []);
|
|
2840
|
+
return /* @__PURE__ */ jsx(ChartCursorChartContext.Provider, {
|
|
2186
2841
|
value: {
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
activePoint: activeSeriesId == null ? void 0 : points.get(activeSeriesId),
|
|
2190
|
-
registerPoint,
|
|
2191
|
-
setHoveredSeriesId,
|
|
2192
|
-
seriesCount: seriesIds.size,
|
|
2193
|
-
registerSeries
|
|
2842
|
+
cursor,
|
|
2843
|
+
mouseHover
|
|
2194
2844
|
},
|
|
2195
|
-
children: /* @__PURE__ */ jsx(
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
onKeyDownCapture: () => {
|
|
2208
|
-
setHasPointerFocus(false);
|
|
2209
|
-
resetPointerInspection();
|
|
2210
|
-
},
|
|
2211
|
-
onBlurCapture: (event) => {
|
|
2212
|
-
if (!event.currentTarget.contains(event.relatedTarget)) {
|
|
2213
|
-
setHasPointerFocus(false);
|
|
2214
|
-
resetPointerInspection();
|
|
2215
|
-
}
|
|
2845
|
+
children: /* @__PURE__ */ jsx(ChartLegendInteractionContext.Provider, {
|
|
2846
|
+
value: {
|
|
2847
|
+
hoveredKey: legendHoveredKey,
|
|
2848
|
+
focusedKeys: focusedLegendKeys,
|
|
2849
|
+
suppressPlotInspection,
|
|
2850
|
+
hover: (key) => {
|
|
2851
|
+
setLegendHoveredKey(key);
|
|
2852
|
+
if (key) setSuppressPlotInspection(true);
|
|
2853
|
+
},
|
|
2854
|
+
toggle: toggleLegendKey,
|
|
2855
|
+
reconcile: reconcileLegendKeys,
|
|
2856
|
+
registerBarAxis
|
|
2216
2857
|
},
|
|
2217
|
-
children: /* @__PURE__ */ jsx(
|
|
2218
|
-
value:
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2858
|
+
children: /* @__PURE__ */ jsx(ChartInteractionContext.Provider, {
|
|
2859
|
+
value: {
|
|
2860
|
+
isPointerInspection,
|
|
2861
|
+
activeSeriesId,
|
|
2862
|
+
activePoint: activeSeriesId == null ? void 0 : points.get(activeSeriesId),
|
|
2863
|
+
registerPoint,
|
|
2864
|
+
setHoveredSeriesId,
|
|
2865
|
+
seriesCount: seriesIds.size,
|
|
2866
|
+
registerSeries
|
|
2867
|
+
},
|
|
2868
|
+
children: /* @__PURE__ */ jsx("section", {
|
|
2869
|
+
className: classNames("altertable-composed-chart", className),
|
|
2870
|
+
"aria-label": ariaLabel,
|
|
2871
|
+
"data-atbl-internal-pointer-focus": hasPointerFocus || void 0,
|
|
2872
|
+
onPointerDownCapture: (event) => {
|
|
2873
|
+
setHasPointerFocus(trackPointer(event));
|
|
2874
|
+
},
|
|
2875
|
+
onPointerOverCapture: trackPointer,
|
|
2876
|
+
onPointerMoveCapture: trackPointer,
|
|
2877
|
+
onPointerLeave: (event) => {
|
|
2878
|
+
if (event.pointerType !== "touch") resetPointerInspection();
|
|
2879
|
+
},
|
|
2880
|
+
onKeyDownCapture: () => {
|
|
2881
|
+
setHasPointerFocus(false);
|
|
2882
|
+
resetPointerInspection();
|
|
2883
|
+
},
|
|
2884
|
+
onFocusCapture: (event) => {
|
|
2885
|
+
if (event.currentTarget.querySelector("svg[role=\"application\"]")?.contains(event.target)) setSuppressPlotInspection(false);
|
|
2886
|
+
},
|
|
2887
|
+
onBlurCapture: (event) => {
|
|
2888
|
+
if (!event.currentTarget.contains(event.relatedTarget)) {
|
|
2889
|
+
setHasPointerFocus(false);
|
|
2890
|
+
resetPointerInspection();
|
|
2891
|
+
}
|
|
2892
|
+
},
|
|
2893
|
+
children: /* @__PURE__ */ jsx(ChartValueFormat.Provider, {
|
|
2894
|
+
value: valueFormat,
|
|
2895
|
+
children: /* @__PURE__ */ jsx(ChartDateAxes, {
|
|
2896
|
+
data,
|
|
2897
|
+
children: /* @__PURE__ */ jsxs(ComposedChart$1, {
|
|
2898
|
+
"data-atbl-focus": "inset",
|
|
2899
|
+
...props,
|
|
2900
|
+
data,
|
|
2901
|
+
width,
|
|
2902
|
+
height,
|
|
2903
|
+
responsive,
|
|
2904
|
+
layout,
|
|
2905
|
+
"aria-label": ariaLabel,
|
|
2906
|
+
children: [
|
|
2907
|
+
valueAxis === "y" && axisLayout.autoYAxis && axisLayout.interactiveLegend && /* @__PURE__ */ jsx(PlotOffsets, { onChange: trackPlotOffsets }),
|
|
2908
|
+
horizontalGrid && !hasAuthoredGrid(children) && /* @__PURE__ */ jsx(ChartGrid, {}),
|
|
2909
|
+
applyNativeLegendInteraction(children, focusedLegendKeys, legendHoveredKey, suppressPlotInspection, valueAxis, visibleBarAxisIds, fullAxisSpace, axisLayout, nativeKeyCounts)
|
|
2910
|
+
]
|
|
2911
|
+
})
|
|
2912
|
+
})
|
|
2229
2913
|
})
|
|
2230
2914
|
})
|
|
2231
2915
|
})
|
|
@@ -2318,7 +3002,8 @@ function createFunnelModel(steps, series, chartId) {
|
|
|
2318
3002
|
}
|
|
2319
3003
|
/** Conversion columns with previous-step drop-off, normalized to each series' first step.
|
|
2320
3004
|
* Owns series highlighting and portion-specific inspection; compose inside VisualizationWidget. */
|
|
2321
|
-
function FunnelChart({ steps, series, unit, ariaLabel, className, formatValue = formatNumber }) {
|
|
3005
|
+
function FunnelChart({ steps, series, unit, ariaLabel, className, formatValue = formatNumber, horizontalGrid = true, interactiveLegend = true }) {
|
|
3006
|
+
const legendFocus = useChartLegendFocus(series.map((item) => item.id));
|
|
2322
3007
|
const chartId = useSvgId();
|
|
2323
3008
|
const [highlighted, setHighlighted] = useState(null);
|
|
2324
3009
|
const clearTimer = useRef(null);
|
|
@@ -2356,13 +3041,36 @@ function FunnelChart({ steps, series, unit, ariaLabel, className, formatValue =
|
|
|
2356
3041
|
layout: "single-row",
|
|
2357
3042
|
children: populations.map((item) => /* @__PURE__ */ jsxs(ChartLegend.Item, {
|
|
2358
3043
|
className: "altertable-funnel-summary-item",
|
|
2359
|
-
|
|
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", {
|
|
2360
3068
|
className: "altertable-funnel-series-label",
|
|
2361
3069
|
children: [/* @__PURE__ */ jsx(ChartLegend.Marker, {
|
|
2362
3070
|
kind: "square",
|
|
2363
3071
|
color: item.color
|
|
2364
3072
|
}), /* @__PURE__ */ jsx(ChartLegend.Label, { children: item.label })]
|
|
2365
|
-
}), /* @__PURE__ */ jsx("strong", {
|
|
3073
|
+
}), (!interactiveLegend || populations.length <= 1) && /* @__PURE__ */ jsx("strong", {
|
|
2366
3074
|
className: "altertable-funnel-series-value",
|
|
2367
3075
|
children: formatPercent(rows.at(-1)?.readings.get(item.id)?.conversion ?? null)
|
|
2368
3076
|
})]
|
|
@@ -2388,7 +3096,7 @@ function FunnelChart({ steps, series, unit, ariaLabel, className, formatValue =
|
|
|
2388
3096
|
barGap: 1,
|
|
2389
3097
|
onMouseLeave: clearHighlight,
|
|
2390
3098
|
children: [
|
|
2391
|
-
/* @__PURE__ */ jsx(ComposedChart.CartesianGrid, {}),
|
|
3099
|
+
horizontalGrid && /* @__PURE__ */ jsx(ComposedChart.CartesianGrid, {}),
|
|
2392
3100
|
/* @__PURE__ */ jsx(ComposedChart.XAxis, {
|
|
2393
3101
|
dataKey: "label",
|
|
2394
3102
|
interval: 0,
|
|
@@ -2429,7 +3137,8 @@ function FunnelChart({ steps, series, unit, ariaLabel, className, formatValue =
|
|
|
2429
3137
|
maxBarSize: void 0,
|
|
2430
3138
|
activeBar: false,
|
|
2431
3139
|
minPointSize: 0,
|
|
2432
|
-
|
|
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,
|
|
2433
3142
|
onMouseEnter: (bar) => highlight(item.id, true, bar.payload.index),
|
|
2434
3143
|
onMouseLeave: scheduleClear,
|
|
2435
3144
|
onClick: (bar) => highlight(item.id, true, bar.payload.index)
|
|
@@ -2438,7 +3147,8 @@ function FunnelChart({ steps, series, unit, ariaLabel, className, formatValue =
|
|
|
2438
3147
|
name: `${item.label} drop-off`,
|
|
2439
3148
|
stackId: item.id,
|
|
2440
3149
|
fill: `url(#${item.hatchId})`,
|
|
2441
|
-
|
|
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,
|
|
2442
3152
|
onMouseEnter: (bar) => highlight(item.id, false, bar.payload.index),
|
|
2443
3153
|
onMouseLeave: scheduleClear,
|
|
2444
3154
|
onClick: (bar) => highlight(item.id, false, bar.payload.index),
|
|
@@ -2449,7 +3159,7 @@ function FunnelChart({ steps, series, unit, ariaLabel, className, formatValue =
|
|
|
2449
3159
|
/* @__PURE__ */ jsx(ComposedChart.Tooltip, { content: ({ active, activeIndex }) => {
|
|
2450
3160
|
const row = activeIndex == null ? void 0 : rows[Number(activeIndex)];
|
|
2451
3161
|
if (!active || !row) return null;
|
|
2452
|
-
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) => {
|
|
2453
3163
|
const item = value.population;
|
|
2454
3164
|
return (highlighted?.step === row.index ? [highlighted.conversion] : [true, false]).map((conversion) => {
|
|
2455
3165
|
const key = [item.id, conversion ? "conversion" : "drop-off"].join(KEY_SEPARATOR);
|
|
@@ -2566,7 +3276,8 @@ function createRetentionModel(series, unit, formatValue) {
|
|
|
2566
3276
|
}
|
|
2567
3277
|
/** Query-defined retention curves with count inspection and dotted incomplete periods.
|
|
2568
3278
|
* Rates are not recomputed from counts. Compose inside VisualizationWidget. */
|
|
2569
|
-
function RetentionChart({ series, unit, ariaLabel, className, formatValue = formatNumber }) {
|
|
3279
|
+
function RetentionChart({ series, unit, ariaLabel, className, formatValue = formatNumber, horizontalGrid = true, interactiveLegend = true }) {
|
|
3280
|
+
const legendFocus = useChartLegendFocus(series.map((item) => item.id));
|
|
2570
3281
|
const { rows, rowsByOffset, cohorts } = createRetentionModel(series, unit, formatValue);
|
|
2571
3282
|
return /* @__PURE__ */ jsx("section", {
|
|
2572
3283
|
className: classNames("altertable-retention-chart", className),
|
|
@@ -2576,7 +3287,7 @@ function RetentionChart({ series, unit, ariaLabel, className, formatValue = form
|
|
|
2576
3287
|
data: rows,
|
|
2577
3288
|
ariaLabel: `${ariaLabel} plot`,
|
|
2578
3289
|
children: [
|
|
2579
|
-
/* @__PURE__ */ jsx(ComposedChart.CartesianGrid, {}),
|
|
3290
|
+
horizontalGrid && /* @__PURE__ */ jsx(ComposedChart.CartesianGrid, {}),
|
|
2580
3291
|
/* @__PURE__ */ jsx(ComposedChart.XAxis, {
|
|
2581
3292
|
dataKey: "offset",
|
|
2582
3293
|
type: "number",
|
|
@@ -2593,11 +3304,15 @@ function RetentionChart({ series, unit, ariaLabel, className, formatValue = form
|
|
|
2593
3304
|
dataKey: (row) => row.readings.get(item.id)?.completePercent ?? null,
|
|
2594
3305
|
name: item.label,
|
|
2595
3306
|
stroke: item.color,
|
|
3307
|
+
opacity: interactiveLegend ? legendFocus.opacity(item.id) : 1,
|
|
3308
|
+
style: { pointerEvents: interactiveLegend && !legendFocus.visible(item.id) ? "none" : void 0 },
|
|
2596
3309
|
connectNulls: false
|
|
2597
3310
|
}), /* @__PURE__ */ jsx(ComposedChart.Line, {
|
|
2598
3311
|
dataKey: (row) => row.readings.get(item.id)?.incompletePercent ?? null,
|
|
2599
3312
|
name: item.label,
|
|
2600
3313
|
stroke: item.color,
|
|
3314
|
+
opacity: interactiveLegend ? legendFocus.opacity(item.id) : 1,
|
|
3315
|
+
style: { pointerEvents: interactiveLegend && !legendFocus.visible(item.id) ? "none" : void 0 },
|
|
2601
3316
|
strokeDasharray: "3 3",
|
|
2602
3317
|
dot: false,
|
|
2603
3318
|
activeDot: false,
|
|
@@ -2613,7 +3328,7 @@ function RetentionChart({ series, unit, ariaLabel, className, formatValue = form
|
|
|
2613
3328
|
role: "tooltip",
|
|
2614
3329
|
children: [/* @__PURE__ */ jsx("strong", { children: row.label }), cohorts.map((item) => {
|
|
2615
3330
|
const reading = row.readings.get(item.id);
|
|
2616
|
-
if (!reading) return null;
|
|
3331
|
+
if (!reading || interactiveLegend && !legendFocus.visible(item.id)) return null;
|
|
2617
3332
|
return /* @__PURE__ */ jsxs("span", { children: [
|
|
2618
3333
|
item.label,
|
|
2619
3334
|
": ",
|
|
@@ -2627,10 +3342,29 @@ function RetentionChart({ series, unit, ariaLabel, className, formatValue = form
|
|
|
2627
3342
|
}),
|
|
2628
3343
|
/* @__PURE__ */ jsx(ChartLegend, {
|
|
2629
3344
|
"aria-label": `${ariaLabel} cohorts`,
|
|
2630
|
-
children: cohorts.map((item) => /* @__PURE__ */
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
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))
|
|
2634
3368
|
}),
|
|
2635
3369
|
/* @__PURE__ */ jsx("ul", {
|
|
2636
3370
|
className: "altertable-sr-only",
|
|
@@ -2971,6 +3705,6 @@ const VisualizationWidget = withWidgetBoundary(VisualizationWidget$1);
|
|
|
2971
3705
|
const TableWidget = withWidgetBoundary(TableWidget$1);
|
|
2972
3706
|
const MetricWidget = withWidgetBoundary(MetricWidget$1);
|
|
2973
3707
|
//#endregion
|
|
2974
|
-
export { AboutData, AppIcon, AreaChart, BarChart, ChartLegend, Checkbox, CheckboxGroup, ChoicePicker, ComposedChart, DataApp, DataAppProvider, DataTable, DataTableEmptyRow, DataTableShare, DataTableTimestamp, DataValue, DataWidget, DateDisplay,
|
|
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 };
|
|
2975
3709
|
|
|
2976
3710
|
//# sourceMappingURL=index.js.map
|