@altertable/data-app-react 0.77.0 → 0.78.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/README.md +3 -4
- package/dist/chunks/{SectionHeading-Bz5RIXit.js → SectionHeading-BKvi7HVv.js} +250 -103
- package/dist/chunks/SectionHeading-BKvi7HVv.js.map +1 -0
- package/dist/index.js +10 -7
- package/dist/index.js.map +1 -1
- package/dist/types/chunks/DateTimeRangePicker.d.ts +19 -4
- package/dist/types/index.d.ts +2 -2
- package/dist/types/ui/index.d.ts +20 -9
- package/dist/ui/index.js +449 -152
- package/dist/ui/index.js.map +1 -1
- package/package.json +3 -3
- package/dist/chunks/SectionHeading-Bz5RIXit.js.map +0 -1
package/dist/ui/index.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { $ as
|
|
2
|
-
import { createDataClient } from "@altertable/data-app/client";
|
|
1
|
+
import { $ as NumberRangeField, $t as Button$1, A as PresentStory, At as ShimmerText, Bt as useViewTab, D as DataAppFrame, E as Notice, F as MenuSection, Ft as Tab, Gt as ChartTooltip$1, H as createDataHooks, Ht as GradientScroll, I as MenuSeparator, It as TabList, J as ControlBar, K as useDeclaredResult, Kt as TooltipSurface, L as MenuTrigger, Lt as TabPanel, M as Menu, Mt as DataAppProvider, N as MenuItem, P as MenuPopover, Pt as AboutData, Q as NumberField, Rt as TabPanels, S as withWidgetBoundary, St as HelpPopover, T as DataValue, Ut as Tooltip, V as isPlainKeyEvent, Vt as Sheet, Wt as TooltipProvider, X as SearchField, Y as SearchTypeahead, Z as NumberFilterPicker, Zt as AppIcon, _ as explorationMenuEvents, a as TextWidget$1, an as injectDataAppStyles, b as useChartActions, bt as DateDisplay, c as DataTableEmptyRow, ct as dateTimeRangeFilter, d as MetricWidget$1, en as PressButton, et as DimensionPicker, f as VisualizationWidget$1, ft as matchSearchText, g as ExplorationActionMenu, h as ExplorationActionControl, it as ChoicePicker, j as LiveControl, l as DataTableShare, lt as dateTimeRangePresets, n as createDataContext, nt as DateTimeRangePicker, o as TableWidget$1, ot as SelectionMark, pt as searchItems, q as FilterActions, r as chartBarFill, rn as useDateFormatting, rt as Select, s as DataTable, st as SearchMatch, t as SectionHeading, tn as classNames, tt as FilterBar, u as DataTableTimestamp, ut as useAppFilters, v as getPrimaryExplorationAction, x as DataWidget, y as openExplorationMenu, zt as Tabs } from "../chunks/SectionHeading-BKvi7HVv.js";
|
|
3
2
|
import { KEY_SEPARATOR, invariant, validateChoiceOptions } from "@altertable/data-app/internal";
|
|
4
3
|
import { Children, Fragment, cloneElement, createContext, isValidElement, useCallback, useContext, useEffect, useId, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
5
4
|
import { Label, Radio as Radio$1, RadioGroup as RadioGroup$1 } from "react-aria-components";
|
|
6
5
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
7
6
|
import { formatDate, formatDateTime, formatMetric, formatNumber, formatPercent, parseDateTime } from "@altertable/data-app/format";
|
|
8
|
-
import { Area, AreaChart as AreaChart$1, Bar, BarChart as BarChart$1, Brush, CartesianGrid, Cell, ComposedChart as ComposedChart$1, DefaultTooltipContent, Dot, ErrorBar, Label as Label$1, LabelList, Legend, Line, LineChart as LineChart$1, ReferenceArea, ReferenceDot, ReferenceLine, Scatter, Tooltip as Tooltip$1, XAxis, YAxis, ZAxis, useActiveTooltipLabel, useCartesianChartLayout, useIsTooltipActive, useMargin, useOffset, usePlotArea, useXAxisScale, useYAxisTicks } from "recharts";
|
|
7
|
+
import { Area, AreaChart as AreaChart$1, Bar, BarChart as BarChart$1, Brush, CartesianGrid, Cell, ComposedChart as ComposedChart$1, DefaultTooltipContent, Dot, ErrorBar, Label as Label$1, LabelList, Legend, Line, LineChart as LineChart$1, Rectangle, ReferenceArea, ReferenceDot, ReferenceLine, Scatter, Tooltip as Tooltip$1, XAxis, YAxis, ZAxis, useActiveTooltipLabel, useCartesianChartLayout, useIsTooltipActive, useMargin, useOffset, usePlotArea, useXAxisScale, useYAxisTicks } from "recharts";
|
|
9
8
|
//#region src/ui/StaticDataApp.tsx
|
|
10
9
|
/** Setup and static screens; fetched data uses the declared-view DataApp. */
|
|
11
10
|
function DataApp({ csvExport, ...props }) {
|
|
@@ -23,15 +22,14 @@ const connectionContext = createDataContext({})({
|
|
|
23
22
|
description: "Connection setup",
|
|
24
23
|
glossary: {}
|
|
25
24
|
});
|
|
26
|
-
const { defineView } = /* @__PURE__ */ createDataHooks(/* @__PURE__ */ createDataClient());
|
|
27
|
-
const connectionView = defineView({
|
|
28
|
-
dataContext: connectionContext,
|
|
29
|
-
operation: "connection",
|
|
30
|
-
describeInput: () => "the connection"
|
|
31
|
-
});
|
|
32
25
|
/** Query-backed connection state and next steps for a newly created app. Mount within
|
|
33
|
-
* `DataAppProvider` and
|
|
34
|
-
function GettingStarted({ dataContext }) {
|
|
26
|
+
* `DataAppProvider` and supply the app's registered connection operation. */
|
|
27
|
+
function GettingStarted({ dataContext, client }) {
|
|
28
|
+
const connectionView = useMemo(() => createDataHooks(client).defineView({
|
|
29
|
+
dataContext: connectionContext,
|
|
30
|
+
operation: "connection",
|
|
31
|
+
describeInput: () => "the connection"
|
|
32
|
+
}), [client]);
|
|
35
33
|
const connection = useDeclaredResult(connectionView);
|
|
36
34
|
const state = connection.view.kind === "error" || connection.view.kind === "stale-error" ? "error" : connection.refreshing || !connection.snapshot ? "checking" : "connected";
|
|
37
35
|
return /* @__PURE__ */ jsxs(DataApp, {
|
|
@@ -181,6 +179,12 @@ function Checkbox({ label, description, checked, value, onChange, disabled, clas
|
|
|
181
179
|
}
|
|
182
180
|
//#endregion
|
|
183
181
|
//#region src/ui/chart-data.ts
|
|
182
|
+
/** Match Recharts data keys, including nested paths and literal dotted keys. */
|
|
183
|
+
function chartField(row, key) {
|
|
184
|
+
if (row == null || typeof row !== "object") return void 0;
|
|
185
|
+
if (key in row) return row[key];
|
|
186
|
+
return String(key).replace(/\[(\d+)\]/g, ".$1").split(".").reduce((value, part) => value != null && typeof value === "object" ? value[part] : void 0, row);
|
|
187
|
+
}
|
|
184
188
|
function validateChartIds(kind, items) {
|
|
185
189
|
const ids = /* @__PURE__ */ new Set();
|
|
186
190
|
for (const item of items) {
|
|
@@ -201,6 +205,36 @@ function validateScatterChartItems(items) {
|
|
|
201
205
|
for (const item of items) invariant(Number.isFinite(item.x) && Number.isFinite(item.y), `scatter chart "${item.id}" requires finite values for x and y.`);
|
|
202
206
|
}
|
|
203
207
|
//#endregion
|
|
208
|
+
//#region src/ui/chart-interaction.tsx
|
|
209
|
+
function chartAxisKey(axis, id) {
|
|
210
|
+
return `${axis}:${typeof id}:${id}`;
|
|
211
|
+
}
|
|
212
|
+
const ChartInteractionContext = createContext(null);
|
|
213
|
+
const ChartRegistrationContext = createContext(null);
|
|
214
|
+
function isChartSeriesActive(interaction, seriesId) {
|
|
215
|
+
return !interaction?.isPointerInspection || interaction.seriesCount === 1 || interaction.activeSeriesId === seriesId;
|
|
216
|
+
}
|
|
217
|
+
function useChartSeries(id) {
|
|
218
|
+
const generatedId = useId();
|
|
219
|
+
const interaction = useContext(ChartInteractionContext);
|
|
220
|
+
const registration = useContext(ChartRegistrationContext);
|
|
221
|
+
const seriesId = id ?? generatedId;
|
|
222
|
+
const registerSeries = registration?.registerSeries;
|
|
223
|
+
useEffect(() => registerSeries?.(seriesId), [registerSeries, seriesId]);
|
|
224
|
+
return {
|
|
225
|
+
id: seriesId,
|
|
226
|
+
active: isChartSeriesActive(interaction, seriesId)
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
function ChartSeries({ id, children }) {
|
|
230
|
+
const registration = useContext(ChartRegistrationContext);
|
|
231
|
+
return /* @__PURE__ */ jsx("g", {
|
|
232
|
+
onPointerOver: () => registration?.setHoveredSeriesId(id),
|
|
233
|
+
onPointerDown: () => registration?.setHoveredSeriesId(id),
|
|
234
|
+
children
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
//#endregion
|
|
204
238
|
//#region src/ui/time-interval.ts
|
|
205
239
|
/*!
|
|
206
240
|
* TypeScript port of d3-time 3.1.0 (ISC), https://github.com/d3/d3-time/tree/v3.1.0
|
|
@@ -894,11 +928,6 @@ function useDateAxisBar(id = 0) {
|
|
|
894
928
|
function useDateAxisLabel(id = 0) {
|
|
895
929
|
return useContext(ChartDateAxesContext)?.formatters.get(id);
|
|
896
930
|
}
|
|
897
|
-
function field(row, key) {
|
|
898
|
-
if (row == null || typeof row !== "object") return void 0;
|
|
899
|
-
if (key in row) return row[key];
|
|
900
|
-
return String(key).replace(/\[(\d+)\]/g, ".$1").split(".").reduce((value, part) => value != null && typeof value === "object" ? value[part] : void 0, row);
|
|
901
|
-
}
|
|
902
931
|
const xAxisDefaults = {
|
|
903
932
|
interval: "preserveStartEnd",
|
|
904
933
|
stroke: "var(--atbl-muted)",
|
|
@@ -949,7 +978,8 @@ function LinkedTimeCursor({ times, axisId }) {
|
|
|
949
978
|
/**
|
|
950
979
|
* Infers temporal input from ISO dates, zoned ISO timestamps, and Date values.
|
|
951
980
|
* Use scale="utc" for epoch milliseconds or type="category" for date-like categories.
|
|
952
|
-
* Explicit tick formatters and tick lists retain authored axis behavior
|
|
981
|
+
* Explicit tick formatters and tick lists retain authored axis behavior while
|
|
982
|
+
* date-like values still receive readable tooltip labels.
|
|
953
983
|
*/
|
|
954
984
|
function ChartXAxis(props) {
|
|
955
985
|
const context = useContext(ChartDateAxesContext);
|
|
@@ -958,31 +988,34 @@ function ChartXAxis(props) {
|
|
|
958
988
|
const { dataKey, ...axisProps } = props;
|
|
959
989
|
const numeric = props.scale === "utc";
|
|
960
990
|
const enabled = numeric || props.type == null && props.scale == null && props.tickFormatter == null && props.ticks == null;
|
|
961
|
-
const
|
|
962
|
-
if (!
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
data,
|
|
966
|
-
dataKey,
|
|
967
|
-
enabled,
|
|
968
|
-
numeric
|
|
969
|
-
]);
|
|
970
|
-
const cursorModel = useMemo(() => {
|
|
971
|
-
if (!data?.length || dataKey == null || props.type === "category") return null;
|
|
972
|
-
if (props.scale !== "utc" && props.scale !== "time") return null;
|
|
973
|
-
return timeModel(data.map((row) => typeof dataKey === "function" ? dataKey(row) : field(row, dataKey)), props.scale === "utc" || props.scale === "time");
|
|
991
|
+
const dateLabelModel = useMemo(() => {
|
|
992
|
+
if (!data?.length || dataKey == null) return null;
|
|
993
|
+
if (props.type === "category" && props.scale !== "utc") return null;
|
|
994
|
+
if (props.type === "number" && props.scale !== "utc" && props.scale !== "time") return null;
|
|
995
|
+
return timeModel(data.map((row) => typeof dataKey === "function" ? dataKey(row) : chartField(row, dataKey)), props.scale === "utc" || props.scale === "time");
|
|
974
996
|
}, [
|
|
975
997
|
data,
|
|
976
998
|
dataKey,
|
|
977
999
|
props.type,
|
|
978
1000
|
props.scale
|
|
979
1001
|
]);
|
|
1002
|
+
const model = enabled ? dateLabelModel : null;
|
|
1003
|
+
const cursorModel = props.type !== "category" && (props.scale === "utc" || props.scale === "time") ? dateLabelModel : null;
|
|
980
1004
|
const register = context?.register;
|
|
981
1005
|
const id = props.xAxisId ?? 0;
|
|
982
|
-
|
|
1006
|
+
const registerCategoryAxis = useContext(ChartRegistrationContext)?.registerCategoryAxis;
|
|
1007
|
+
useLayoutEffect(() => {
|
|
1008
|
+
if (dataKey == null) return;
|
|
1009
|
+
return registerCategoryAxis?.("x", id, dataKey);
|
|
1010
|
+
}, [
|
|
1011
|
+
registerCategoryAxis,
|
|
1012
|
+
id,
|
|
1013
|
+
dataKey
|
|
1014
|
+
]);
|
|
1015
|
+
useEffect(() => dateLabelModel ? register?.(id, dateLabelModel.tooltip) : void 0, [
|
|
983
1016
|
register,
|
|
984
1017
|
id,
|
|
985
|
-
|
|
1018
|
+
dateLabelModel
|
|
986
1019
|
]);
|
|
987
1020
|
if (!model || dataKey == null) return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(XAxis, {
|
|
988
1021
|
...xAxisDefaults,
|
|
@@ -1021,38 +1054,13 @@ function ChartXAxis(props) {
|
|
|
1021
1054
|
} : xAxisDefaults.tick,
|
|
1022
1055
|
...axisProps,
|
|
1023
1056
|
type: "number",
|
|
1024
|
-
dataKey: (row) => chartTimestamp(typeof dataKey === "function" ? dataKey(row) :
|
|
1057
|
+
dataKey: (row) => chartTimestamp(typeof dataKey === "function" ? dataKey(row) : chartField(row, dataKey), numeric)
|
|
1025
1058
|
}), /* @__PURE__ */ jsx(LinkedTimeCursor, {
|
|
1026
1059
|
times: model.times,
|
|
1027
1060
|
axisId: id
|
|
1028
1061
|
})] });
|
|
1029
1062
|
}
|
|
1030
1063
|
//#endregion
|
|
1031
|
-
//#region src/ui/chart-interaction.tsx
|
|
1032
|
-
const ChartInteractionContext = createContext(null);
|
|
1033
|
-
function isChartSeriesActive(interaction, seriesId) {
|
|
1034
|
-
return !interaction?.isPointerInspection || interaction.seriesCount === 1 || interaction.activeSeriesId === seriesId;
|
|
1035
|
-
}
|
|
1036
|
-
function useChartSeries(id) {
|
|
1037
|
-
const generatedId = useId();
|
|
1038
|
-
const interaction = useContext(ChartInteractionContext);
|
|
1039
|
-
const seriesId = id ?? generatedId;
|
|
1040
|
-
const registerSeries = interaction?.registerSeries;
|
|
1041
|
-
useEffect(() => registerSeries?.(seriesId), [registerSeries, seriesId]);
|
|
1042
|
-
return {
|
|
1043
|
-
id: seriesId,
|
|
1044
|
-
active: isChartSeriesActive(interaction, seriesId)
|
|
1045
|
-
};
|
|
1046
|
-
}
|
|
1047
|
-
function ChartSeries({ id, children }) {
|
|
1048
|
-
const interaction = useContext(ChartInteractionContext);
|
|
1049
|
-
return /* @__PURE__ */ jsx("g", {
|
|
1050
|
-
onPointerOver: () => interaction?.setHoveredSeriesId(id),
|
|
1051
|
-
onPointerDown: () => interaction?.setHoveredSeriesId(id),
|
|
1052
|
-
children
|
|
1053
|
-
});
|
|
1054
|
-
}
|
|
1055
|
-
//#endregion
|
|
1056
1064
|
//#region src/ui/chart-legend-interaction.tsx
|
|
1057
1065
|
function chartLegendSeriesKey(id, dataKey) {
|
|
1058
1066
|
if (typeof id === "string" || typeof id === "number") return [
|
|
@@ -1302,7 +1310,7 @@ function ChartDot({ active = false, stroke = seriesColor, fill = active ? stroke
|
|
|
1302
1310
|
}
|
|
1303
1311
|
function NearestChartDot({ seriesId, cx, cy, stroke }) {
|
|
1304
1312
|
const interaction = useContext(ChartInteractionContext);
|
|
1305
|
-
const registerPoint =
|
|
1313
|
+
const registerPoint = useContext(ChartRegistrationContext)?.registerPoint;
|
|
1306
1314
|
const legend = useChartLegendSeries(seriesId, void 0);
|
|
1307
1315
|
useLayoutEffect(() => {
|
|
1308
1316
|
if (legend.hidden || cx == null || cy == null) return;
|
|
@@ -1322,7 +1330,69 @@ function NearestChartDot({ seriesId, cx, cy, stroke }) {
|
|
|
1322
1330
|
style: { pointerEvents: "none" }
|
|
1323
1331
|
}) : null;
|
|
1324
1332
|
}
|
|
1333
|
+
/** Recharts does not export its bar-shape dispatcher; keep this adapter isolated. */
|
|
1334
|
+
function renderBarShape(option, props) {
|
|
1335
|
+
if (isValidElement(option)) return cloneElement(option, {
|
|
1336
|
+
...props,
|
|
1337
|
+
...option.props
|
|
1338
|
+
});
|
|
1339
|
+
if (option === Rectangle) return /* @__PURE__ */ jsx(Rectangle, { ...props });
|
|
1340
|
+
if (typeof option === "function") return option(props, props.index);
|
|
1341
|
+
if (option && typeof option === "object") return /* @__PURE__ */ jsx(Rectangle, {
|
|
1342
|
+
...props,
|
|
1343
|
+
...option
|
|
1344
|
+
});
|
|
1345
|
+
return /* @__PURE__ */ jsx(Rectangle, { ...props });
|
|
1346
|
+
}
|
|
1347
|
+
function InspectedBarVisual({ seriesId, shape, activeShape, dimmed, ...props }) {
|
|
1348
|
+
const interaction = useContext(ChartInteractionContext);
|
|
1349
|
+
const selected = interaction?.isPointerInspection && interaction.activeBar?.seriesId === seriesId && interaction.activeBar.index === props.originalDataIndex;
|
|
1350
|
+
const renderedProps = {
|
|
1351
|
+
...props,
|
|
1352
|
+
isActive: Boolean(selected || props.isActive),
|
|
1353
|
+
opacity: dimmed ? void 0 : selected ? .75 : props.opacity
|
|
1354
|
+
};
|
|
1355
|
+
const rendered = renderBarShape(selected && activeShape && activeShape !== true ? activeShape : shape, renderedProps);
|
|
1356
|
+
return dimmed ? /* @__PURE__ */ jsx("g", {
|
|
1357
|
+
opacity: .2,
|
|
1358
|
+
children: rendered
|
|
1359
|
+
}) : rendered;
|
|
1360
|
+
}
|
|
1325
1361
|
/** Shared series defaults; native props override every authored choice. */
|
|
1362
|
+
function InspectedBarShape({ seriesId, shape, activeShape, dimmed, ...props }) {
|
|
1363
|
+
const registerBar = useContext(ChartRegistrationContext)?.registerBar;
|
|
1364
|
+
const { x, y, width, height, originalDataIndex, value, payload } = props;
|
|
1365
|
+
const reading = Array.isArray(value) ? value[1] - value[0] : value;
|
|
1366
|
+
useLayoutEffect(() => {
|
|
1367
|
+
if (reading === 0 || width <= 0 || height <= 0) return;
|
|
1368
|
+
return registerBar?.({
|
|
1369
|
+
seriesId,
|
|
1370
|
+
index: originalDataIndex,
|
|
1371
|
+
x,
|
|
1372
|
+
y,
|
|
1373
|
+
width,
|
|
1374
|
+
height,
|
|
1375
|
+
payload
|
|
1376
|
+
});
|
|
1377
|
+
}, [
|
|
1378
|
+
registerBar,
|
|
1379
|
+
seriesId,
|
|
1380
|
+
originalDataIndex,
|
|
1381
|
+
x,
|
|
1382
|
+
y,
|
|
1383
|
+
width,
|
|
1384
|
+
height,
|
|
1385
|
+
reading,
|
|
1386
|
+
payload
|
|
1387
|
+
]);
|
|
1388
|
+
return /* @__PURE__ */ jsx(InspectedBarVisual, {
|
|
1389
|
+
...props,
|
|
1390
|
+
seriesId,
|
|
1391
|
+
shape,
|
|
1392
|
+
activeShape,
|
|
1393
|
+
dimmed
|
|
1394
|
+
});
|
|
1395
|
+
}
|
|
1326
1396
|
function ChartBar(props) {
|
|
1327
1397
|
useDateAxisBar(props.xAxisId);
|
|
1328
1398
|
const series = useChartSeries(props.id);
|
|
@@ -1332,6 +1402,19 @@ function ChartBar(props) {
|
|
|
1332
1402
|
const registerBarAxis = interaction?.registerBarAxis;
|
|
1333
1403
|
const key = chartLegendSeriesKey(series.id, props.dataKey);
|
|
1334
1404
|
const axisId = layout === "vertical" ? props.xAxisId ?? 0 : props.yAxisId ?? 0;
|
|
1405
|
+
const inspectStack = props.stackId != null;
|
|
1406
|
+
const inspectedShape = useCallback((shapeProps) => /* @__PURE__ */ jsx(InspectedBarShape, {
|
|
1407
|
+
...shapeProps,
|
|
1408
|
+
seriesId: series.id,
|
|
1409
|
+
shape: props.shape,
|
|
1410
|
+
activeShape: props.activeBar,
|
|
1411
|
+
dimmed: legend.dimmed
|
|
1412
|
+
}), [
|
|
1413
|
+
series.id,
|
|
1414
|
+
props.shape,
|
|
1415
|
+
props.activeBar,
|
|
1416
|
+
legend.dimmed
|
|
1417
|
+
]);
|
|
1335
1418
|
useLayoutEffect(() => key && !props.hide ? registerBarAxis?.(key, axisId) : void 0, [
|
|
1336
1419
|
registerBarAxis,
|
|
1337
1420
|
key,
|
|
@@ -1349,9 +1432,10 @@ function ChartBar(props) {
|
|
|
1349
1432
|
0
|
|
1350
1433
|
] : 0,
|
|
1351
1434
|
maxBarSize: 30,
|
|
1352
|
-
activeBar: series.active ? { opacity: .75 } : false,
|
|
1353
1435
|
isAnimationActive: false,
|
|
1354
1436
|
...props,
|
|
1437
|
+
activeBar: inspectStack ? false : props.activeBar ?? (series.active ? { opacity: .75 } : false),
|
|
1438
|
+
shape: inspectStack ? inspectedShape : props.shape,
|
|
1355
1439
|
id: series.id,
|
|
1356
1440
|
hide: legend.hidden || props.hide,
|
|
1357
1441
|
opacity: legend.hidden ? 0 : legend.dimmed ? .2 : props.opacity,
|
|
@@ -1456,6 +1540,16 @@ function ChartScatter(props) {
|
|
|
1456
1540
|
});
|
|
1457
1541
|
}
|
|
1458
1542
|
function ChartYAxis(props) {
|
|
1543
|
+
const registerCategoryAxis = useContext(ChartRegistrationContext)?.registerCategoryAxis;
|
|
1544
|
+
const id = props.yAxisId ?? 0;
|
|
1545
|
+
useLayoutEffect(() => {
|
|
1546
|
+
if (props.dataKey == null) return;
|
|
1547
|
+
return registerCategoryAxis?.("y", id, props.dataKey);
|
|
1548
|
+
}, [
|
|
1549
|
+
registerCategoryAxis,
|
|
1550
|
+
id,
|
|
1551
|
+
props.dataKey
|
|
1552
|
+
]);
|
|
1459
1553
|
const format = useContext(ChartValueFormat);
|
|
1460
1554
|
const formatter = axisValueFormatter((useYAxisTicks(props.yAxisId) ?? []).map((tick) => tick.value).filter((value) => typeof value === "number"), format);
|
|
1461
1555
|
return /* @__PURE__ */ jsx(YAxis, {
|
|
@@ -1469,11 +1563,21 @@ function ChartYAxis(props) {
|
|
|
1469
1563
|
});
|
|
1470
1564
|
}
|
|
1471
1565
|
function ChartGrid(props) {
|
|
1472
|
-
|
|
1566
|
+
const vertical = useCartesianChartLayout() === "vertical";
|
|
1567
|
+
const showZero = vertical ? props.vertical === true : props.horizontal === void 0 || props.horizontal === true;
|
|
1568
|
+
return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(CartesianGrid, {
|
|
1473
1569
|
stroke: "var(--atbl-border)",
|
|
1474
1570
|
vertical: false,
|
|
1475
1571
|
...props
|
|
1476
|
-
})
|
|
1572
|
+
}), showZero && /* @__PURE__ */ jsx(ReferenceLine, {
|
|
1573
|
+
...vertical ? { x: 0 } : { y: 0 },
|
|
1574
|
+
xAxisId: props.xAxisId,
|
|
1575
|
+
yAxisId: props.yAxisId,
|
|
1576
|
+
ifOverflow: "discard",
|
|
1577
|
+
stroke: props.stroke ?? "var(--atbl-muted)",
|
|
1578
|
+
strokeOpacity: props.strokeOpacity ?? .55,
|
|
1579
|
+
strokeWidth: props.strokeWidth ?? 1.5
|
|
1580
|
+
})] });
|
|
1477
1581
|
}
|
|
1478
1582
|
function ChartTooltipContent(props) {
|
|
1479
1583
|
const valueFormat = useContext(ChartValueFormat);
|
|
@@ -1537,50 +1641,112 @@ function ChartTooltipContent(props) {
|
|
|
1537
1641
|
})
|
|
1538
1642
|
});
|
|
1539
1643
|
}
|
|
1644
|
+
function MeasuredTooltipContent({ children, onMeasure }) {
|
|
1645
|
+
const ref = useRef(null);
|
|
1646
|
+
useLayoutEffect(() => {
|
|
1647
|
+
const element = ref.current;
|
|
1648
|
+
if (!element) return;
|
|
1649
|
+
const target = element;
|
|
1650
|
+
function measure() {
|
|
1651
|
+
onMeasure(target.offsetWidth, target.offsetHeight);
|
|
1652
|
+
}
|
|
1653
|
+
measure();
|
|
1654
|
+
if (typeof ResizeObserver === "undefined") return;
|
|
1655
|
+
const observer = new ResizeObserver(measure);
|
|
1656
|
+
observer.observe(element);
|
|
1657
|
+
return () => observer.disconnect();
|
|
1658
|
+
}, [onMeasure]);
|
|
1659
|
+
return /* @__PURE__ */ jsx("span", {
|
|
1660
|
+
ref,
|
|
1661
|
+
style: { display: "block" },
|
|
1662
|
+
children
|
|
1663
|
+
});
|
|
1664
|
+
}
|
|
1665
|
+
function barTooltipPosition(bar, plot, size) {
|
|
1666
|
+
const gap = 10;
|
|
1667
|
+
const right = bar.x + bar.width + gap;
|
|
1668
|
+
const left = bar.x - size.width - gap;
|
|
1669
|
+
const plotRight = plot.x + plot.width;
|
|
1670
|
+
const x = right + size.width <= plotRight ? right : left >= plot.x ? left : Math.max(plot.x, Math.min(right, plotRight - size.width));
|
|
1671
|
+
const edgeInset = Math.min(8, Math.max(0, (plot.height - size.height) / 2));
|
|
1672
|
+
return {
|
|
1673
|
+
x,
|
|
1674
|
+
y: Math.max(plot.y + edgeInset, Math.min(bar.y + bar.height / 2 - size.height / 2, plot.y + plot.height - size.height - edgeInset))
|
|
1675
|
+
};
|
|
1676
|
+
}
|
|
1540
1677
|
/** Uses the same surface as single-series inspection; Recharts owns interaction. */
|
|
1541
1678
|
function ChartTooltip(props) {
|
|
1542
1679
|
const dateLabel = useDateAxisLabel(props.axisId);
|
|
1543
1680
|
const interaction = useContext(ChartInteractionContext);
|
|
1544
1681
|
const legendInteraction = useContext(ChartLegendInteractionContext);
|
|
1682
|
+
const plot = usePlotArea();
|
|
1683
|
+
const [tooltipSize, setTooltipSize] = useState({
|
|
1684
|
+
width: 0,
|
|
1685
|
+
height: 0
|
|
1686
|
+
});
|
|
1687
|
+
const measureTooltip = useCallback((width, height) => {
|
|
1688
|
+
setTooltipSize((current) => current.width === width && current.height === height ? current : {
|
|
1689
|
+
width,
|
|
1690
|
+
height
|
|
1691
|
+
});
|
|
1692
|
+
}, []);
|
|
1545
1693
|
const { content: authoredContent, ...tooltipProps } = props;
|
|
1694
|
+
const activeBar = interaction?.isPointerInspection ? interaction.activeBar : null;
|
|
1695
|
+
const position = activeBar && plot && tooltipSize.width && tooltipSize.height ? barTooltipPosition(activeBar, plot, tooltipSize) : interaction?.isPointerInspection && interaction.activePoint ? { y: interaction.activePoint.y } : void 0;
|
|
1546
1696
|
return /* @__PURE__ */ jsx(Tooltip$1, {
|
|
1547
1697
|
labelFormatter: dateLabel,
|
|
1548
|
-
position
|
|
1698
|
+
position,
|
|
1549
1699
|
cursor: false,
|
|
1550
1700
|
isAnimationActive: false,
|
|
1551
1701
|
...tooltipProps,
|
|
1702
|
+
filterNull: activeBar ? false : props.filterNull,
|
|
1552
1703
|
content: (content) => {
|
|
1553
1704
|
if (legendInteraction?.suppressPlotInspection) return null;
|
|
1705
|
+
const selectedRow = activeBar?.payload;
|
|
1554
1706
|
const payload = (interaction?.isPointerInspection && interaction.seriesCount !== 1 && props.shared !== true ? content.payload.filter((entry) => entry.graphicalItemId === interaction.activeSeriesId) : content.payload).filter((entry) => {
|
|
1555
1707
|
if (!legendInteraction?.focusedKeys) return true;
|
|
1556
1708
|
const key = chartLegendSeriesKey(entry.graphicalItemId, entry.dataKey);
|
|
1557
1709
|
return key == null || legendInteraction.focusedKeys.has(key);
|
|
1558
1710
|
});
|
|
1711
|
+
const selectedPayload = selectedRow == null ? payload : payload.map((entry) => {
|
|
1712
|
+
const key = entry.dataKey;
|
|
1713
|
+
const value = typeof key === "function" ? key(selectedRow) : key == null ? entry.value : chartField(selectedRow, key);
|
|
1714
|
+
return {
|
|
1715
|
+
...entry,
|
|
1716
|
+
payload: selectedRow,
|
|
1717
|
+
value
|
|
1718
|
+
};
|
|
1719
|
+
});
|
|
1720
|
+
const categoryKey = interaction?.getCategoryDataKey(props.axisId ?? 0);
|
|
1721
|
+
const label = selectedRow == null || categoryKey == null ? content.label : typeof categoryKey === "function" ? categoryKey(selectedRow) : chartField(selectedRow, categoryKey);
|
|
1559
1722
|
const filtered = {
|
|
1560
1723
|
...content,
|
|
1561
|
-
payload
|
|
1724
|
+
payload: selectedPayload,
|
|
1725
|
+
label
|
|
1562
1726
|
};
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1727
|
+
const rendered = typeof authoredContent === "function" ? authoredContent(filtered) : isValidElement(authoredContent) ? cloneElement(authoredContent, filtered) : /* @__PURE__ */ jsx(ChartTooltipContent, { ...filtered });
|
|
1728
|
+
return /* @__PURE__ */ jsx(MeasuredTooltipContent, {
|
|
1729
|
+
onMeasure: measureTooltip,
|
|
1730
|
+
children: rendered
|
|
1731
|
+
});
|
|
1566
1732
|
}
|
|
1567
1733
|
});
|
|
1568
1734
|
}
|
|
1569
1735
|
//#endregion
|
|
1570
1736
|
//#region src/ui/use-chart-scroll-to-end.ts
|
|
1571
1737
|
/** Keep the latest supplied samples visible when the displayed items change. */
|
|
1572
|
-
function useChartScrollToEnd(items) {
|
|
1738
|
+
function useChartScrollToEnd(items, enabled = true) {
|
|
1573
1739
|
const scrollport = useRef(null);
|
|
1574
1740
|
useLayoutEffect(() => {
|
|
1575
1741
|
const element = scrollport.current;
|
|
1576
|
-
if (element) element.scrollLeft = element.scrollWidth - element.clientWidth;
|
|
1577
|
-
}, [items]);
|
|
1742
|
+
if (element && enabled) element.scrollLeft = element.scrollWidth - element.clientWidth;
|
|
1743
|
+
}, [items, enabled]);
|
|
1578
1744
|
return scrollport;
|
|
1579
1745
|
}
|
|
1580
1746
|
//#endregion
|
|
1581
1747
|
//#region src/ui/TrendChart.tsx
|
|
1582
1748
|
/** Ordered, equally spaced samples; negative values share an explicit zero baseline. */
|
|
1583
|
-
function TrendChart({ items, unit, ariaLabel, formatValue = formatNumber, kind, itemActions, cursorGroup, horizontalGrid =
|
|
1749
|
+
function TrendChart({ items, unit, ariaLabel, formatValue = formatNumber, kind, itemActions, cursorGroup, horizontalGrid = true }) {
|
|
1584
1750
|
validateValueChartItems(kind, items);
|
|
1585
1751
|
const Plot = kind === "area" ? AreaChart$1 : LineChart$1;
|
|
1586
1752
|
const chartActions = useChartActions();
|
|
@@ -1864,7 +2030,7 @@ function AreaChart(props) {
|
|
|
1864
2030
|
* Include Other to represent the whole. Zero values remain in the legend; all-zero
|
|
1865
2031
|
* data shows an empty circle. Colors follow item order. Compose inside VisualizationWidget;
|
|
1866
2032
|
* hover/touch tooltips coordinate slice and legend emphasis without caller state. */
|
|
1867
|
-
function PieChart({ items, unit, ariaLabel, showLegend = true, formatValue =
|
|
2033
|
+
function PieChart({ items, unit, ariaLabel, showLegend = true, formatValue = formatNumber, itemActions }) {
|
|
1868
2034
|
validateValueChartItems("pie", items);
|
|
1869
2035
|
const chartActions = useChartActions();
|
|
1870
2036
|
const [previewId, setPreviewId] = useState(null);
|
|
@@ -2206,29 +2372,55 @@ function timeTickIndices(items, width) {
|
|
|
2206
2372
|
for (let tick = 0; tick < count; tick++) indices.add(start + tick * stride);
|
|
2207
2373
|
return indices;
|
|
2208
2374
|
}
|
|
2375
|
+
function PlotBoundsObserver({ overlayRef }) {
|
|
2376
|
+
const plot = usePlotArea();
|
|
2377
|
+
const left = plot?.x;
|
|
2378
|
+
const width = plot?.width;
|
|
2379
|
+
useLayoutEffect(() => {
|
|
2380
|
+
if (left === void 0 || width === void 0 || !Number.isFinite(left) || !Number.isFinite(width) || !overlayRef.current) return;
|
|
2381
|
+
const overlay = overlayRef.current;
|
|
2382
|
+
overlay.style.marginLeft = `${left}px`;
|
|
2383
|
+
overlay.style.width = `${width}px`;
|
|
2384
|
+
return () => {
|
|
2385
|
+
overlay.style.marginLeft = "";
|
|
2386
|
+
overlay.style.width = "";
|
|
2387
|
+
};
|
|
2388
|
+
}, [
|
|
2389
|
+
overlayRef,
|
|
2390
|
+
left,
|
|
2391
|
+
width
|
|
2392
|
+
]);
|
|
2393
|
+
return null;
|
|
2394
|
+
}
|
|
2209
2395
|
/** Nonnegative category values. Compose inside VisualizationWidget for a titled panel.
|
|
2210
2396
|
* Owns hover/touch tooltips; no selection state or keyboard navigation. */
|
|
2211
|
-
function BarChart({ items, unit, ariaLabel, formatValue
|
|
2397
|
+
function BarChart({ items, unit, ariaLabel, formatValue: authoredFormatValue, itemActions, cursorGroup, horizontalGrid = true, showYAxis = false, scrollToEnd = true, valueFormat }) {
|
|
2398
|
+
const formatValue = authoredFormatValue ?? (valueFormat ? (value) => formatMetric(value, valueFormat) : formatNumber);
|
|
2399
|
+
const axisLabelSpace = showYAxis ? 10 : 0;
|
|
2212
2400
|
validateValueChartItems("bar", items);
|
|
2213
2401
|
const chartActions = useChartActions();
|
|
2214
2402
|
const cursor = useLinkedChartCursor(cursorGroup);
|
|
2215
2403
|
const linkedItem = items.find((item) => item.time === cursor.time && cursor.time != null);
|
|
2216
2404
|
const [activeId, setActiveId] = useState();
|
|
2217
2405
|
const [viewportWidth, setViewportWidth] = useState(0);
|
|
2218
|
-
const scrollport = useChartScrollToEnd(items);
|
|
2219
2406
|
const plotRef = useRef(null);
|
|
2220
2407
|
const canvasRef = useRef(null);
|
|
2408
|
+
const itemOverlayRef = useRef(null);
|
|
2221
2409
|
const menuTriggers = useRef(/* @__PURE__ */ new Map());
|
|
2222
|
-
const maximum = items.reduce((max, item) => Math.max(max, item.value), 1
|
|
2223
|
-
const
|
|
2224
|
-
const
|
|
2410
|
+
const maximum = items.reduce((max, item) => Math.max(max, item.value), 0) || 1;
|
|
2411
|
+
const hasTimeAxis = items.length > 0 && items.every((item, index) => typeof item.time === "number" && Number.isFinite(item.time) && (index === 0 || item.time > items[index - 1].time));
|
|
2412
|
+
const scrollport = useChartScrollToEnd(items, scrollToEnd);
|
|
2413
|
+
const compactTimeAxis = hasTimeAxis && !itemActions;
|
|
2414
|
+
const minimumSlotWidth = compactTimeAxis ? 3.5 : 120;
|
|
2225
2415
|
const plotWidth = Math.max(viewportWidth, items.length * minimumSlotWidth);
|
|
2226
2416
|
const ticks = compactTimeAxis ? timeTickIndices(items, plotWidth) : null;
|
|
2227
2417
|
useLayoutEffect(() => {
|
|
2228
2418
|
const element = scrollport.current;
|
|
2229
2419
|
if (!element) return;
|
|
2230
2420
|
function updateWidth() {
|
|
2231
|
-
|
|
2421
|
+
const style = getComputedStyle(element);
|
|
2422
|
+
const padding = parseFloat(style.paddingLeft) + parseFloat(style.paddingRight);
|
|
2423
|
+
setViewportWidth(Math.floor(element.getBoundingClientRect().width - padding));
|
|
2232
2424
|
}
|
|
2233
2425
|
updateWidth();
|
|
2234
2426
|
const observer = new ResizeObserver(updateWidth);
|
|
@@ -2257,59 +2449,64 @@ function BarChart({ items, unit, ariaLabel, formatValue = formatNumber, itemActi
|
|
|
2257
2449
|
className: "altertable-chart-canvas",
|
|
2258
2450
|
"aria-hidden": "true",
|
|
2259
2451
|
ref: canvasRef,
|
|
2260
|
-
children: /* @__PURE__ */
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
width,
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2452
|
+
children: /* @__PURE__ */ jsx(ChartValueFormat.Provider, {
|
|
2453
|
+
value: valueFormat,
|
|
2454
|
+
children: /* @__PURE__ */ jsxs(BarChart$1, {
|
|
2455
|
+
data: showYAxis ? items : items.map((item) => ({
|
|
2456
|
+
...item,
|
|
2457
|
+
plotValue: item.value / maximum
|
|
2458
|
+
})),
|
|
2459
|
+
responsive: true,
|
|
2460
|
+
width: "100%",
|
|
2461
|
+
height: 220 + axisLabelSpace,
|
|
2462
|
+
margin: {
|
|
2463
|
+
top: 0,
|
|
2464
|
+
right: 0,
|
|
2465
|
+
bottom: axisLabelSpace,
|
|
2466
|
+
left: 0
|
|
2467
|
+
},
|
|
2468
|
+
accessibilityLayer: false,
|
|
2469
|
+
tabIndex: -1,
|
|
2470
|
+
barCategoryGap: "24%",
|
|
2471
|
+
children: [
|
|
2472
|
+
showYAxis && /* @__PURE__ */ jsx(PlotBoundsObserver, { overlayRef: itemOverlayRef }),
|
|
2473
|
+
/* @__PURE__ */ jsx(ChartXAxis, {
|
|
2474
|
+
hide: true,
|
|
2475
|
+
dataKey: "id",
|
|
2476
|
+
scale: "band"
|
|
2477
|
+
}),
|
|
2478
|
+
showYAxis ? /* @__PURE__ */ jsx(ChartYAxis, { domain: [0, "auto"] }) : /* @__PURE__ */ jsx(ChartYAxis, {
|
|
2479
|
+
hide: true,
|
|
2480
|
+
domain: [0, 1],
|
|
2481
|
+
allowDataOverflow: true
|
|
2482
|
+
}),
|
|
2483
|
+
horizontalGrid && /* @__PURE__ */ jsx(ChartGrid, {}),
|
|
2484
|
+
/* @__PURE__ */ jsx(ChartBar, {
|
|
2485
|
+
dataKey: showYAxis ? "value" : "plotValue",
|
|
2486
|
+
minPointSize: (value) => (value ?? 0) > 0 ? 7 : 0,
|
|
2487
|
+
background: linkedItem ? ({ index, x, y, width, height }) => /* @__PURE__ */ jsx("g", { children: items[index]?.id === linkedItem.id && /* @__PURE__ */ jsx("rect", {
|
|
2488
|
+
x,
|
|
2489
|
+
y,
|
|
2490
|
+
width,
|
|
2491
|
+
height,
|
|
2492
|
+
fill: "var(--atbl-muted)",
|
|
2493
|
+
fillOpacity: .14,
|
|
2494
|
+
pointerEvents: "none",
|
|
2495
|
+
"aria-hidden": "true",
|
|
2496
|
+
"data-atbl-internal-linked-cursor": "true"
|
|
2497
|
+
}) }) : false,
|
|
2498
|
+
children: items.map((item) => /* @__PURE__ */ jsx(Cell, {
|
|
2499
|
+
fill: chartBarFill,
|
|
2500
|
+
opacity: activeId === item.id ? .75 : 1,
|
|
2501
|
+
"data-atbl-internal-bar-id": item.id
|
|
2502
|
+
}, item.id))
|
|
2503
|
+
})
|
|
2504
|
+
]
|
|
2505
|
+
})
|
|
2310
2506
|
})
|
|
2311
2507
|
}), /* @__PURE__ */ jsx("div", {
|
|
2312
2508
|
className: "altertable-selectable-bars-items",
|
|
2509
|
+
ref: itemOverlayRef,
|
|
2313
2510
|
children: items.map((item, index) => {
|
|
2314
2511
|
const actions = chartActions.actions(itemActions?.(item) ?? [], item.label, `${formatValue(item.value)} ${unit}`);
|
|
2315
2512
|
const action = getPrimaryExplorationAction(actions);
|
|
@@ -2422,9 +2619,9 @@ function RadioGroup({ label, className, children, ...props }) {
|
|
|
2422
2619
|
}
|
|
2423
2620
|
function Radio({ className, children, ...props }) {
|
|
2424
2621
|
return /* @__PURE__ */ jsx(Radio$1, {
|
|
2622
|
+
"data-atbl-focus": "ring",
|
|
2425
2623
|
...props,
|
|
2426
2624
|
"data-atbl-control": "action",
|
|
2427
|
-
"data-atbl-focus": "ring",
|
|
2428
2625
|
className: classNames("altertable-radio", className),
|
|
2429
2626
|
children: (state) => /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("span", {
|
|
2430
2627
|
className: "altertable-radio-mark",
|
|
@@ -2444,6 +2641,7 @@ function SegmentedControl({ options, className, ...props }) {
|
|
|
2444
2641
|
children: options.map((option) => /* @__PURE__ */ jsx(Radio, {
|
|
2445
2642
|
value: option.id,
|
|
2446
2643
|
"data-atbl-internal-surface": "option",
|
|
2644
|
+
"data-atbl-focus": "inset",
|
|
2447
2645
|
children: option.label
|
|
2448
2646
|
}, option.id))
|
|
2449
2647
|
})
|
|
@@ -2607,6 +2805,44 @@ function findNearestSeriesId(hoveredSeriesId, points, position) {
|
|
|
2607
2805
|
}
|
|
2608
2806
|
return selected;
|
|
2609
2807
|
}
|
|
2808
|
+
function findNearestBar(bars, position, layout) {
|
|
2809
|
+
if (!position) return null;
|
|
2810
|
+
let nearest = null;
|
|
2811
|
+
let categoryDistance = Infinity;
|
|
2812
|
+
let valueDistance = Infinity;
|
|
2813
|
+
for (const bar of bars.values()) {
|
|
2814
|
+
const category = layout === "horizontal" ? Math.abs(position.x - (bar.x + bar.width / 2)) : Math.abs(position.y - (bar.y + bar.height / 2));
|
|
2815
|
+
const value = layout === "horizontal" ? Math.max(bar.y - position.y, 0, position.y - bar.y - bar.height) : Math.max(bar.x - position.x, 0, position.x - bar.x - bar.width);
|
|
2816
|
+
if (category < categoryDistance || category === categoryDistance && value < valueDistance) {
|
|
2817
|
+
nearest = bar;
|
|
2818
|
+
categoryDistance = category;
|
|
2819
|
+
valueDistance = value;
|
|
2820
|
+
}
|
|
2821
|
+
}
|
|
2822
|
+
return nearest;
|
|
2823
|
+
}
|
|
2824
|
+
function barCloserThanPoints(bar, points, position) {
|
|
2825
|
+
if (!bar || !position) return false;
|
|
2826
|
+
const dx = Math.max(bar.x - position.x, 0, position.x - bar.x - bar.width);
|
|
2827
|
+
const dy = Math.max(bar.y - position.y, 0, position.y - bar.y - bar.height);
|
|
2828
|
+
const barDistance = Math.hypot(dx, dy);
|
|
2829
|
+
let pointDistance = Infinity;
|
|
2830
|
+
for (const point of points.values()) pointDistance = Math.min(pointDistance, Math.hypot(point.x - position.x, point.y - position.y));
|
|
2831
|
+
return barDistance <= pointDistance;
|
|
2832
|
+
}
|
|
2833
|
+
function categoryDataKey(children, layout, axisId) {
|
|
2834
|
+
for (const child of Children.toArray(children)) {
|
|
2835
|
+
if (!isValidElement(child)) continue;
|
|
2836
|
+
if (child.type === Fragment) {
|
|
2837
|
+
const nested = categoryDataKey(child.props.children, layout, axisId);
|
|
2838
|
+
if (nested != null) return nested;
|
|
2839
|
+
}
|
|
2840
|
+
if (child.type !== (layout === "horizontal" ? ChartXAxis : ChartYAxis) && child.type !== (layout === "horizontal" ? XAxis : YAxis)) continue;
|
|
2841
|
+
if (((layout === "horizontal" ? child.props.xAxisId : child.props.yAxisId) ?? 0) !== axisId) continue;
|
|
2842
|
+
const key = child.props.dataKey;
|
|
2843
|
+
if (typeof key === "string" || typeof key === "number" || typeof key === "function") return key;
|
|
2844
|
+
}
|
|
2845
|
+
}
|
|
2610
2846
|
function hasAuthoredGrid(children) {
|
|
2611
2847
|
return Children.toArray(children).some((child) => isValidElement(child) && (child.type === ChartGrid || child.type === CartesianGrid || child.type === Fragment && hasAuthoredGrid(child.props.children)));
|
|
2612
2848
|
}
|
|
@@ -2733,15 +2969,41 @@ function PlotOffsets({ onChange }) {
|
|
|
2733
2969
|
* for stacks. Preserve missing measures as null and choose connectNulls deliberately.
|
|
2734
2970
|
* Use public chart tokens for series colors. Dataset bindings own
|
|
2735
2971
|
* loading, empty results, evidence, and CSV; this primitive owns only the plot. */
|
|
2736
|
-
function ComposedChartRoot({ data, ariaLabel, valueFormat, cursorGroup, horizontalGrid =
|
|
2972
|
+
function ComposedChartRoot({ data, ariaLabel, valueFormat, cursorGroup, horizontalGrid = true, children, width = "100%", height = 300, responsive = true, layout = "horizontal", className, ...props }) {
|
|
2737
2973
|
const cursor = useLinkedChartCursor(cursorGroup);
|
|
2738
2974
|
const [mouseHover, setMouseHover] = useState(false);
|
|
2739
2975
|
const [hasPointerFocus, setHasPointerFocus] = useState(false);
|
|
2740
2976
|
const [isPointerInspection, setIsPointerInspection] = useState(false);
|
|
2741
2977
|
const [hoveredSeriesId, setHoveredSeriesId] = useState(null);
|
|
2742
2978
|
const [pointerPosition, setPointerPosition] = useState(null);
|
|
2979
|
+
const [nearestBar, setNearestBar] = useState(null);
|
|
2743
2980
|
const latestPointerPosition = useRef(null);
|
|
2744
2981
|
const [points, setPoints] = useState(() => /* @__PURE__ */ new Map());
|
|
2982
|
+
const bars = useRef(/* @__PURE__ */ new Map());
|
|
2983
|
+
const barRefreshFrame = useRef(null);
|
|
2984
|
+
const refreshNearestBar = useCallback(() => {
|
|
2985
|
+
if (barRefreshFrame.current != null || !latestPointerPosition.current) return;
|
|
2986
|
+
barRefreshFrame.current = requestAnimationFrame(() => {
|
|
2987
|
+
barRefreshFrame.current = null;
|
|
2988
|
+
const selected = findNearestBar(bars.current, latestPointerPosition.current, layout);
|
|
2989
|
+
setNearestBar(selected);
|
|
2990
|
+
setPointerPosition(latestPointerPosition.current);
|
|
2991
|
+
});
|
|
2992
|
+
}, [layout]);
|
|
2993
|
+
useEffect(() => () => {
|
|
2994
|
+
if (barRefreshFrame.current != null) cancelAnimationFrame(barRefreshFrame.current);
|
|
2995
|
+
}, []);
|
|
2996
|
+
const registerBar = useCallback((bar) => {
|
|
2997
|
+
const key = `${bar.seriesId}:${bar.index}`;
|
|
2998
|
+
bars.current.set(key, bar);
|
|
2999
|
+
refreshNearestBar();
|
|
3000
|
+
return () => {
|
|
3001
|
+
if (bars.current.get(key) === bar) {
|
|
3002
|
+
bars.current.delete(key);
|
|
3003
|
+
refreshNearestBar();
|
|
3004
|
+
}
|
|
3005
|
+
};
|
|
3006
|
+
}, [refreshNearestBar]);
|
|
2745
3007
|
const registerPoint = useCallback((id, x, y) => {
|
|
2746
3008
|
setPoints((current) => new Map(current).set(id, {
|
|
2747
3009
|
x,
|
|
@@ -2753,6 +3015,17 @@ function ComposedChartRoot({ data, ariaLabel, valueFormat, cursorGroup, horizont
|
|
|
2753
3015
|
return next;
|
|
2754
3016
|
});
|
|
2755
3017
|
}, []);
|
|
3018
|
+
const [categoryAxisKeys, setCategoryAxisKeys] = useState(() => /* @__PURE__ */ new Map());
|
|
3019
|
+
const registerCategoryAxis = useCallback((axis, id, dataKey) => {
|
|
3020
|
+
const key = chartAxisKey(axis, id);
|
|
3021
|
+
setCategoryAxisKeys((current) => current.get(key) === dataKey ? current : new Map(current).set(key, dataKey));
|
|
3022
|
+
return () => setCategoryAxisKeys((current) => {
|
|
3023
|
+
if (current.get(key) !== dataKey) return current;
|
|
3024
|
+
const next = new Map(current);
|
|
3025
|
+
next.delete(key);
|
|
3026
|
+
return next;
|
|
3027
|
+
});
|
|
3028
|
+
}, []);
|
|
2756
3029
|
useEffect(() => {
|
|
2757
3030
|
setPointerPosition(latestPointerPosition.current);
|
|
2758
3031
|
}, [points]);
|
|
@@ -2765,9 +3038,10 @@ function ComposedChartRoot({ data, ariaLabel, valueFormat, cursorGroup, horizont
|
|
|
2765
3038
|
}
|
|
2766
3039
|
setSuppressPlotInspection(false);
|
|
2767
3040
|
setIsPointerInspection(true);
|
|
2768
|
-
if (hoveredSeriesId != null && !points.has(hoveredSeriesId)) {
|
|
3041
|
+
if (bars.current.size === 0 && hoveredSeriesId != null && !points.has(hoveredSeriesId)) {
|
|
2769
3042
|
latestPointerPosition.current = null;
|
|
2770
3043
|
setPointerPosition(null);
|
|
3044
|
+
setNearestBar(null);
|
|
2771
3045
|
return true;
|
|
2772
3046
|
}
|
|
2773
3047
|
const matrix = svg.getScreenCTM();
|
|
@@ -2778,7 +3052,12 @@ function ComposedChartRoot({ data, ariaLabel, valueFormat, cursorGroup, horizont
|
|
|
2778
3052
|
y: point.y
|
|
2779
3053
|
};
|
|
2780
3054
|
latestPointerPosition.current = nextPosition;
|
|
2781
|
-
|
|
3055
|
+
const selected = findNearestBar(bars.current, nextPosition, layout);
|
|
3056
|
+
setNearestBar(selected);
|
|
3057
|
+
setPointerPosition((current) => {
|
|
3058
|
+
const currentBar = findNearestBar(bars.current, current, layout);
|
|
3059
|
+
return (barCloserThanPoints(currentBar, points, current) ? currentBar : findNearestSeriesId(hoveredSeriesId, points, current)) === (barCloserThanPoints(selected, points, nextPosition) ? selected : findNearestSeriesId(hoveredSeriesId, points, nextPosition)) ? current : nextPosition;
|
|
3060
|
+
});
|
|
2782
3061
|
return true;
|
|
2783
3062
|
}
|
|
2784
3063
|
function resetPointerInspection() {
|
|
@@ -2788,8 +3067,10 @@ function ComposedChartRoot({ data, ariaLabel, valueFormat, cursorGroup, horizont
|
|
|
2788
3067
|
setHoveredSeriesId(null);
|
|
2789
3068
|
latestPointerPosition.current = null;
|
|
2790
3069
|
setPointerPosition(null);
|
|
3070
|
+
setNearestBar(null);
|
|
2791
3071
|
}
|
|
2792
|
-
const
|
|
3072
|
+
const activeBar = barCloserThanPoints(nearestBar, points, pointerPosition) ? nearestBar : null;
|
|
3073
|
+
const activeSeriesId = activeBar?.seriesId ?? findNearestSeriesId(hoveredSeriesId, points, pointerPosition);
|
|
2793
3074
|
const [seriesIds, setSeriesIds] = useState(() => /* @__PURE__ */ new Set());
|
|
2794
3075
|
const registerSeries = useCallback((id) => {
|
|
2795
3076
|
setSeriesIds((current) => new Set(current).add(id));
|
|
@@ -2837,6 +3118,18 @@ function ComposedChartRoot({ data, ariaLabel, valueFormat, cursorGroup, horizont
|
|
|
2837
3118
|
setSuppressPlotInspection(true);
|
|
2838
3119
|
setFocusedLegendKeys((current) => toggleLegendFocus(current, key, keys));
|
|
2839
3120
|
}, []);
|
|
3121
|
+
const registration = useMemo(() => ({
|
|
3122
|
+
registerPoint,
|
|
3123
|
+
registerBar,
|
|
3124
|
+
registerSeries,
|
|
3125
|
+
registerCategoryAxis,
|
|
3126
|
+
setHoveredSeriesId
|
|
3127
|
+
}), [
|
|
3128
|
+
registerPoint,
|
|
3129
|
+
registerBar,
|
|
3130
|
+
registerSeries,
|
|
3131
|
+
registerCategoryAxis
|
|
3132
|
+
]);
|
|
2840
3133
|
return /* @__PURE__ */ jsx(ChartCursorChartContext.Provider, {
|
|
2841
3134
|
value: {
|
|
2842
3135
|
cursor,
|
|
@@ -2860,10 +3153,9 @@ function ComposedChartRoot({ data, ariaLabel, valueFormat, cursorGroup, horizont
|
|
|
2860
3153
|
isPointerInspection,
|
|
2861
3154
|
activeSeriesId,
|
|
2862
3155
|
activePoint: activeSeriesId == null ? void 0 : points.get(activeSeriesId),
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
seriesCount: seriesIds.size
|
|
2866
|
-
registerSeries
|
|
3156
|
+
activeBar,
|
|
3157
|
+
getCategoryDataKey: (axisId) => categoryAxisKeys.get(chartAxisKey(layout === "horizontal" ? "x" : "y", axisId)) ?? categoryDataKey(children, layout, axisId),
|
|
3158
|
+
seriesCount: seriesIds.size
|
|
2867
3159
|
},
|
|
2868
3160
|
children: /* @__PURE__ */ jsx("section", {
|
|
2869
3161
|
className: classNames("altertable-composed-chart", className),
|
|
@@ -2894,20 +3186,23 @@ function ComposedChartRoot({ data, ariaLabel, valueFormat, cursorGroup, horizont
|
|
|
2894
3186
|
value: valueFormat,
|
|
2895
3187
|
children: /* @__PURE__ */ jsx(ChartDateAxes, {
|
|
2896
3188
|
data,
|
|
2897
|
-
children: /* @__PURE__ */
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
3189
|
+
children: /* @__PURE__ */ jsx(ChartRegistrationContext.Provider, {
|
|
3190
|
+
value: registration,
|
|
3191
|
+
children: /* @__PURE__ */ jsxs(ComposedChart$1, {
|
|
3192
|
+
"data-atbl-focus": "inset",
|
|
3193
|
+
...props,
|
|
3194
|
+
data,
|
|
3195
|
+
width,
|
|
3196
|
+
height,
|
|
3197
|
+
responsive,
|
|
3198
|
+
layout,
|
|
3199
|
+
"aria-label": ariaLabel,
|
|
3200
|
+
children: [
|
|
3201
|
+
valueAxis === "y" && axisLayout.autoYAxis && axisLayout.interactiveLegend && /* @__PURE__ */ jsx(PlotOffsets, { onChange: trackPlotOffsets }),
|
|
3202
|
+
horizontalGrid && !hasAuthoredGrid(children) && /* @__PURE__ */ jsx(ChartGrid, {}),
|
|
3203
|
+
applyNativeLegendInteraction(children, focusedLegendKeys, legendHoveredKey, suppressPlotInspection, valueAxis, visibleBarAxisIds, fullAxisSpace, axisLayout, nativeKeyCounts)
|
|
3204
|
+
]
|
|
3205
|
+
})
|
|
2911
3206
|
})
|
|
2912
3207
|
})
|
|
2913
3208
|
})
|
|
@@ -3091,6 +3386,7 @@ function FunnelChart({ steps, series, unit, ariaLabel, className, formatValue =
|
|
|
3091
3386
|
children: /* @__PURE__ */ jsxs(ComposedChart, {
|
|
3092
3387
|
data: rows,
|
|
3093
3388
|
ariaLabel: `${ariaLabel} plot`,
|
|
3389
|
+
horizontalGrid,
|
|
3094
3390
|
height: 300,
|
|
3095
3391
|
barCategoryGap: "4%",
|
|
3096
3392
|
barGap: 1,
|
|
@@ -3286,6 +3582,7 @@ function RetentionChart({ series, unit, ariaLabel, className, formatValue = form
|
|
|
3286
3582
|
/* @__PURE__ */ jsxs(ComposedChart, {
|
|
3287
3583
|
data: rows,
|
|
3288
3584
|
ariaLabel: `${ariaLabel} plot`,
|
|
3585
|
+
horizontalGrid,
|
|
3289
3586
|
children: [
|
|
3290
3587
|
horizontalGrid && /* @__PURE__ */ jsx(ComposedChart.CartesianGrid, {}),
|
|
3291
3588
|
/* @__PURE__ */ jsx(ComposedChart.XAxis, {
|
|
@@ -3705,6 +4002,6 @@ const VisualizationWidget = withWidgetBoundary(VisualizationWidget$1);
|
|
|
3705
4002
|
const TableWidget = withWidgetBoundary(TableWidget$1);
|
|
3706
4003
|
const MetricWidget = withWidgetBoundary(MetricWidget$1);
|
|
3707
4004
|
//#endregion
|
|
3708
|
-
export { AboutData, AppIcon, AreaChart, BarChart, ChartLegend, Checkbox, CheckboxGroup, ChoicePicker, ComposedChart, ControlBar, DataApp, DataAppProvider, DataTable, DataTableEmptyRow, DataTableShare, DataTableTimestamp, DataValue, DataWidget, DateDisplay, DateTimeRangePicker, DimensionPicker, ExplorationActionControl, FilterActions, FilterBar, FunnelChart, GettingStarted, GlossaryDefinition, GlossaryExplanation, GradientScroll, HelpPopover, JourneyChart, LineChart, LiveControl, Menu, PressButton as MenuButton, MenuItem, MenuPopover, MenuSection, MenuSeparator, MenuTrigger, MetricWidget, NumberField, NumberFilterPicker, NumberRangeField, PieChart, PresentStory, Radio, RadioGroup, RetentionChart, ScatterChart, SearchField, SearchMatch, SearchTypeahead, SectionHeading, SegmentedControl, Select, Sheet, ShimmerText, Tab, TabList, TabPanel, TabPanels, TableWidget, Tabs, TextWidget, Tooltip, TooltipProvider, VisualizationWidget, dateTimeRangeFilter, dateTimeRangePresets, injectDataAppStyles, isPlainKeyEvent, matchSearchText, searchItems, useAppFilters, useChartCursorGroup, useDateFormatting, useSvgId, useViewTab };
|
|
4005
|
+
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, Notice, 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 };
|
|
3709
4006
|
|
|
3710
4007
|
//# sourceMappingURL=index.js.map
|