@schemavaults/ui 0.108.0 → 0.109.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/components/hooks/index.d.ts +2 -0
- package/dist/components/hooks/index.js +1 -0
- package/dist/components/hooks/index.js.map +1 -1
- package/dist/components/hooks/use-measured-width.d.ts +33 -0
- package/dist/components/hooks/use-measured-width.js +61 -0
- package/dist/components/hooks/use-measured-width.js.map +1 -0
- package/dist/components/ui/bar-chart/bar-chart.d.ts +71 -13
- package/dist/components/ui/bar-chart/bar-chart.js +263 -96
- package/dist/components/ui/bar-chart/bar-chart.js.map +1 -1
- package/dist/components/ui/bar-list/bar-list.d.ts +63 -0
- package/dist/components/ui/bar-list/bar-list.js +39 -0
- package/dist/components/ui/bar-list/bar-list.js.map +1 -0
- package/dist/components/ui/bar-list/index.d.ts +2 -0
- package/dist/components/ui/bar-list/index.js +2 -0
- package/dist/components/ui/bar-list/index.js.map +1 -0
- package/dist/components/ui/chart-primitives/chart-colors.d.ts +69 -0
- package/dist/components/ui/chart-primitives/chart-colors.js +201 -0
- package/dist/components/ui/chart-primitives/chart-colors.js.map +1 -0
- package/dist/components/ui/chart-primitives/chart-data-table.d.ts +20 -0
- package/dist/components/ui/chart-primitives/chart-data-table.js +11 -0
- package/dist/components/ui/chart-primitives/chart-data-table.js.map +1 -0
- package/dist/components/ui/chart-primitives/chart-format.d.ts +12 -0
- package/dist/components/ui/chart-primitives/chart-format.js +40 -0
- package/dist/components/ui/chart-primitives/chart-format.js.map +1 -0
- package/dist/components/ui/chart-primitives/chart-legend.d.ts +20 -0
- package/dist/components/ui/chart-primitives/chart-legend.js +22 -0
- package/dist/components/ui/chart-primitives/chart-legend.js.map +1 -0
- package/dist/components/ui/chart-primitives/chart-scale.d.ts +59 -0
- package/dist/components/ui/chart-primitives/chart-scale.js +178 -0
- package/dist/components/ui/chart-primitives/chart-scale.js.map +1 -0
- package/dist/components/ui/chart-primitives/chart-tooltip.d.ts +67 -0
- package/dist/components/ui/chart-primitives/chart-tooltip.js +57 -0
- package/dist/components/ui/chart-primitives/chart-tooltip.js.map +1 -0
- package/dist/components/ui/chart-primitives/index.d.ts +12 -0
- package/dist/components/ui/chart-primitives/index.js +7 -0
- package/dist/components/ui/chart-primitives/index.js.map +1 -0
- package/dist/components/ui/chart-primitives/responsive-chart.d.ts +26 -0
- package/dist/components/ui/chart-primitives/responsive-chart.js +25 -0
- package/dist/components/ui/chart-primitives/responsive-chart.js.map +1 -0
- package/dist/components/ui/chart-primitives/use-chart-width.d.ts +30 -0
- package/dist/components/ui/chart-primitives/use-chart-width.js +56 -0
- package/dist/components/ui/chart-primitives/use-chart-width.js.map +1 -0
- package/dist/components/ui/histogram/bin-values.d.ts +53 -0
- package/dist/components/ui/histogram/bin-values.js +137 -0
- package/dist/components/ui/histogram/bin-values.js.map +1 -0
- package/dist/components/ui/histogram/histogram.d.ts +76 -0
- package/dist/components/ui/histogram/histogram.js +149 -0
- package/dist/components/ui/histogram/histogram.js.map +1 -0
- package/dist/components/ui/histogram/index.d.ts +4 -0
- package/dist/components/ui/histogram/index.js +3 -0
- package/dist/components/ui/histogram/index.js.map +1 -0
- package/dist/components/ui/index.d.ts +6 -0
- package/dist/components/ui/index.js +3 -0
- package/dist/components/ui/index.js.map +1 -1
- package/dist/components/ui/line-chart/line-chart.d.ts +104 -20
- package/dist/components/ui/line-chart/line-chart.js +285 -139
- package/dist/components/ui/line-chart/line-chart.js.map +1 -1
- package/dist/components/ui/pie-chart/pie-chart.d.ts +35 -7
- package/dist/components/ui/pie-chart/pie-chart.js +200 -88
- package/dist/components/ui/pie-chart/pie-chart.js.map +1 -1
- package/dist/components/ui/scatter-plot/scatter-plot.d.ts +123 -21
- package/dist/components/ui/scatter-plot/scatter-plot.js +507 -243
- package/dist/components/ui/scatter-plot/scatter-plot.js.map +1 -1
- package/dist/components/ui/sparkline/sparkline.d.ts +15 -5
- package/dist/components/ui/sparkline/sparkline.js +21 -37
- package/dist/components/ui/sparkline/sparkline.js.map +1 -1
- package/package.json +3 -2
|
@@ -1,28 +1,30 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
3
|
import { cva } from "class-variance-authority";
|
|
4
|
-
import { useId } from "react";
|
|
4
|
+
import { memo, useCallback, useId, useMemo, useState } from "react";
|
|
5
5
|
import { cn } from "../../../lib/utils";
|
|
6
|
+
import { chartColorIds, chartPaintClass, createChartColorScale, getChartSeriesColorId, } from "../../ui/chart-primitives/chart-colors";
|
|
7
|
+
import { ChartDataTable } from "../../ui/chart-primitives/chart-data-table";
|
|
8
|
+
import { formatChartNumber } from "../../ui/chart-primitives/chart-format";
|
|
9
|
+
import { ChartLegend } from "../../ui/chart-primitives/chart-legend";
|
|
10
|
+
import { logDecadeTicks, niceTicksWithin, thinLabels, } from "../../ui/chart-primitives/chart-scale";
|
|
11
|
+
import { ChartLiveRegion, ChartTooltip, ChartTooltipRow, } from "../../ui/chart-primitives/chart-tooltip";
|
|
12
|
+
import { useChartWidth, } from "../../ui/chart-primitives/use-chart-width";
|
|
6
13
|
export const scatterPlotSizeIds = [
|
|
7
14
|
"sm",
|
|
8
15
|
"md",
|
|
9
16
|
"lg",
|
|
10
17
|
"xl",
|
|
11
18
|
];
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
"primary",
|
|
15
|
-
"positive",
|
|
16
|
-
"warning",
|
|
17
|
-
"destructive",
|
|
18
|
-
"muted",
|
|
19
|
-
];
|
|
19
|
+
/** Preset series colours; see `chartColorIds`. */
|
|
20
|
+
export const scatterPlotColorIds = chartColorIds;
|
|
20
21
|
export const scatterPlotShapeIds = [
|
|
21
22
|
"circle",
|
|
22
23
|
"square",
|
|
23
24
|
"triangle",
|
|
24
25
|
"diamond",
|
|
25
26
|
];
|
|
27
|
+
export const scatterPlotYScaleIds = ["linear", "log"];
|
|
26
28
|
/** Default canvas dimensions per size. Either axis can be overridden via the
|
|
27
29
|
* `width` / `height` props. */
|
|
28
30
|
const SIZE_TO_CANVAS = {
|
|
@@ -31,42 +33,35 @@ const SIZE_TO_CANVAS = {
|
|
|
31
33
|
lg: { width: 480, height: 340 },
|
|
32
34
|
xl: { width: 640, height: 440 },
|
|
33
35
|
};
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
muted: "fill-muted-foreground",
|
|
41
|
-
};
|
|
42
|
-
const STROKE_CLASSES = {
|
|
43
|
-
default: "stroke-schemavaults-brand-blue",
|
|
44
|
-
primary: "stroke-primary",
|
|
45
|
-
positive: "stroke-emerald-500 dark:stroke-emerald-400",
|
|
46
|
-
warning: "stroke-warning",
|
|
47
|
-
destructive: "stroke-destructive",
|
|
48
|
-
muted: "stroke-muted-foreground",
|
|
36
|
+
/** Tick-label font size per size preset, for thinning crowded labels. */
|
|
37
|
+
const SIZE_TO_FONT_PX = {
|
|
38
|
+
sm: 10,
|
|
39
|
+
md: 11,
|
|
40
|
+
lg: 12,
|
|
41
|
+
xl: 14,
|
|
49
42
|
};
|
|
50
43
|
/**
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
44
|
+
* With every pair of series able to sit side by side, only the first three
|
|
45
|
+
* palette slots stay distinguishable (colour-blind and full-colour alike),
|
|
46
|
+
* so a fourth series and beyond is painted `"other"` unless it names a
|
|
47
|
+
* colour. Shapes keep them apart.
|
|
48
|
+
*/
|
|
49
|
+
const MAX_COLORED_SERIES = 3;
|
|
50
|
+
/**
|
|
51
|
+
* Shape rotation when a series doesn't specify its own, by colour slot.
|
|
52
|
+
* Shapes rotate alongside colours so overlapping series stay distinguishable
|
|
53
|
+
* without relying on color alone.
|
|
55
54
|
*/
|
|
56
|
-
const DEFAULT_COLOR_ROTATION = [
|
|
57
|
-
"default",
|
|
58
|
-
"positive",
|
|
59
|
-
"warning",
|
|
60
|
-
"destructive",
|
|
61
|
-
"primary",
|
|
62
|
-
"muted",
|
|
63
|
-
];
|
|
64
55
|
const DEFAULT_SHAPE_ROTATION = [
|
|
65
56
|
"circle",
|
|
66
57
|
"triangle",
|
|
67
58
|
"square",
|
|
68
59
|
"diamond",
|
|
69
60
|
];
|
|
61
|
+
/** How close (px) the pointer must come to a point to read it out. */
|
|
62
|
+
const DEFAULT_HIT_RADIUS = 24;
|
|
63
|
+
/** Opacity of the points outside the hovered point's `group`. */
|
|
64
|
+
const FADED_OPACITY = 0.12;
|
|
70
65
|
export const scatterPlotVariants = cva("relative inline-flex shrink-0 items-center justify-center", {
|
|
71
66
|
variants: {
|
|
72
67
|
size: {
|
|
@@ -145,240 +140,509 @@ function computeTrendLine(points) {
|
|
|
145
140
|
return null;
|
|
146
141
|
return { slope, intercept };
|
|
147
142
|
}
|
|
148
|
-
|
|
143
|
+
/**
|
|
144
|
+
* The markers, trend lines and point labels: memoized, so a pointer move
|
|
145
|
+
* re-renders only the readout, not thousands of points. (Group emphasis is
|
|
146
|
+
* a scoped style rule for the same reason.)
|
|
147
|
+
*/
|
|
148
|
+
const PointsLayer = memo(function PointsLayer({ resolved, onPointClick, onPointFocus, formatX, formatY, showValueLabels, valueLabelFormatter, valueLabelClassName, }) {
|
|
149
|
+
return (_jsx("g", { "data-slot": "scatter-plot-points", children: resolved.map((rs) => {
|
|
150
|
+
const handler = rs.series.onPointClick ?? onPointClick;
|
|
151
|
+
const isInteractive = typeof handler === "function";
|
|
152
|
+
const seriesName = rs.series.label ?? rs.series.id;
|
|
153
|
+
return (_jsxs("g", { "data-slot": "scatter-plot-series", "data-series-id": rs.series.id, children: [rs.trend ? (_jsx("line", { "aria-hidden": "true", "data-slot": "scatter-plot-trend-line", x1: rs.trend.x1, y1: rs.trend.y1, x2: rs.trend.x2, y2: rs.trend.y2, stroke: rs.paint.value, strokeWidth: 1.5, strokeDasharray: "5 4", strokeLinecap: "round", className: cn("pointer-events-none", chartPaintClass(rs.paint, "stroke")) })) : null, rs.points.map((rp) => {
|
|
154
|
+
const pointKey = rp.point.id ?? `${rs.series.id}-${rp.index}`;
|
|
155
|
+
const ariaLabel = rp.point.label
|
|
156
|
+
? `${seriesName} – ${rp.point.label}: (${formatX(rp.point.x)}, ${formatY(rp.point.y)})`
|
|
157
|
+
: `${seriesName}: (${formatX(rp.point.x)}, ${formatY(rp.point.y)})`;
|
|
158
|
+
return (_jsx("path", { d: buildMarkerPath(rs.shape, rp.x, rp.y, rp.r), fill: rs.paint.value, fillOpacity: rs.opacity, stroke: "hsl(var(--background))", strokeWidth: 1, "data-point-index": rp.index, "data-group": rp.groupIndex >= 0 ? rp.groupIndex : undefined, "data-testid": `scatter-plot-point-${pointKey}`, role: isInteractive ? "button" : undefined, tabIndex: isInteractive ? 0 : undefined, "aria-label": isInteractive ? ariaLabel : undefined, "aria-hidden": isInteractive ? undefined : "true", onFocus: isInteractive
|
|
159
|
+
? () => onPointFocus(rp.flatIndex)
|
|
160
|
+
: undefined, onClick: isInteractive
|
|
161
|
+
? (event) => {
|
|
162
|
+
handler(rp.point, rs.series, event);
|
|
163
|
+
}
|
|
164
|
+
: undefined, onKeyDown: isInteractive
|
|
165
|
+
? (event) => {
|
|
166
|
+
if (event.key === "Enter" || event.key === " ") {
|
|
167
|
+
event.preventDefault();
|
|
168
|
+
handler(rp.point, rs.series, event);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
: undefined, className: cn("transition-opacity", chartPaintClass(rs.paint, "fill"), isInteractive &&
|
|
172
|
+
"cursor-pointer focus:outline-none", rs.series.className) }, pointKey));
|
|
173
|
+
}), showValueLabels
|
|
174
|
+
? rs.points.map((rp) => {
|
|
175
|
+
const text = valueLabelFormatter
|
|
176
|
+
? valueLabelFormatter({
|
|
177
|
+
series: rs.series,
|
|
178
|
+
point: rp.point,
|
|
179
|
+
index: rp.index,
|
|
180
|
+
})
|
|
181
|
+
: (rp.point.label ??
|
|
182
|
+
`(${formatX(rp.point.x)}, ${formatY(rp.point.y)})`);
|
|
183
|
+
if (text === null || text === "")
|
|
184
|
+
return null;
|
|
185
|
+
const labelKey = (rp.point.id ?? `${rs.series.id}-${rp.index}`) + "-val";
|
|
186
|
+
return (_jsx("text", { x: rp.x, y: rp.y - rp.r - 4, textAnchor: "middle", className: cn("pointer-events-none select-none fill-foreground font-medium", valueLabelClassName), children: text }, labelKey));
|
|
187
|
+
})
|
|
188
|
+
: null] }, rs.series.id));
|
|
189
|
+
}) }));
|
|
190
|
+
});
|
|
191
|
+
function ScatterPlot({ series, label, size, width, height, seriesOrder, xMin, xMax, yMin, yMax, yScale = "linear", pointRadius = 4, sizeRange = [4, 14], pointOpacity = 0.8, showAxis = true, gridLineCount = 0, verticalGridLineCount = 0, formatX = formatChartNumber, formatY = formatChartNumber, formatTooltip, showTooltip = true, hitRadius = DEFAULT_HIT_RADIUS, showLegend, xTickFormatter, xTickCount = 5, xTickValues, showXAxisLabels, yTickFormatter, yTickCount = 5, niceTicks, showYAxisLabels, yTickLabelWidth = 36, xAxisTitle, yAxisTitle, xReferenceLines, yReferenceLines, showValueLabels = false, valueLabelFormatter, loading = false, onPointClick, emptyMessage = "No data", children, className, style, overlayClassName, valueLabelClassName, tickLabelClassName, axisClassName, ref, ...props }) {
|
|
149
192
|
const resolvedSize = size ?? "md";
|
|
150
193
|
const canvas = SIZE_TO_CANVAS[resolvedSize];
|
|
151
|
-
const
|
|
194
|
+
const chart = useChartWidth(width, canvas.width, ref);
|
|
195
|
+
const W = chart.width;
|
|
152
196
|
const H = height ?? canvas.height;
|
|
153
|
-
const
|
|
154
|
-
const
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
const
|
|
159
|
-
const
|
|
160
|
-
(
|
|
161
|
-
const
|
|
162
|
-
|
|
163
|
-
const
|
|
164
|
-
const
|
|
165
|
-
const
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
if (p.
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
197
|
+
const hintId = useId();
|
|
198
|
+
const svgId = useId();
|
|
199
|
+
/** Index into the flat point list of the point being read out. */
|
|
200
|
+
const [active, setActive] = useState(null);
|
|
201
|
+
/** Whether the point was reached with the arrow keys (so it is announced). */
|
|
202
|
+
const [announce, setAnnounce] = useState(false);
|
|
203
|
+
const hasXAxisLabels = typeof xTickFormatter === "function" ||
|
|
204
|
+
(showXAxisLabels ?? formatX !== formatChartNumber);
|
|
205
|
+
const hasYAxisLabels = typeof yTickFormatter === "function" ||
|
|
206
|
+
(showYAxisLabels ?? formatY !== formatChartNumber);
|
|
207
|
+
const isLog = yScale === "log";
|
|
208
|
+
const [minRadius, maxRadius] = sizeRange;
|
|
209
|
+
const layout = useMemo(() => {
|
|
210
|
+
const drawWidth = W ?? 0;
|
|
211
|
+
// Reserve gutters for axis labels / titles.
|
|
212
|
+
const padTop = showValueLabels ? 16 : 8;
|
|
213
|
+
const padBottom = (hasXAxisLabels ? 20 : 8) + (xAxisTitle ? 16 : 0);
|
|
214
|
+
const padLeft = (hasYAxisLabels ? Math.max(8, yTickLabelWidth) : 8) +
|
|
215
|
+
(yAxisTitle ? 16 : 0);
|
|
216
|
+
const padRight = 10;
|
|
217
|
+
const plotX0 = padLeft;
|
|
218
|
+
const plotY0 = padTop;
|
|
219
|
+
const plotW = Math.max(0, drawWidth - padLeft - padRight);
|
|
220
|
+
const plotH = Math.max(0, H - padTop - padBottom);
|
|
221
|
+
// Determine the domain across all series, ignoring non-finite coordinates.
|
|
222
|
+
let domainXMin = Number.POSITIVE_INFINITY;
|
|
223
|
+
let domainXMax = Number.NEGATIVE_INFINITY;
|
|
224
|
+
let domainYMin = Number.POSITIVE_INFINITY;
|
|
225
|
+
let domainYMax = Number.NEGATIVE_INFINITY;
|
|
226
|
+
let smallestPositiveY = Number.POSITIVE_INFINITY;
|
|
227
|
+
let domainSizeMin = Number.POSITIVE_INFINITY;
|
|
228
|
+
let domainSizeMax = Number.NEGATIVE_INFINITY;
|
|
229
|
+
let totalFinitePoints = 0;
|
|
230
|
+
for (const s of series) {
|
|
231
|
+
for (const p of s.points) {
|
|
232
|
+
if (!isFiniteNumber(p.x) || !isFiniteNumber(p.y))
|
|
233
|
+
continue;
|
|
234
|
+
totalFinitePoints += 1;
|
|
235
|
+
if (p.x < domainXMin)
|
|
236
|
+
domainXMin = p.x;
|
|
237
|
+
if (p.x > domainXMax)
|
|
238
|
+
domainXMax = p.x;
|
|
239
|
+
if (p.y < domainYMin)
|
|
240
|
+
domainYMin = p.y;
|
|
241
|
+
if (p.y > domainYMax)
|
|
242
|
+
domainYMax = p.y;
|
|
243
|
+
if (p.y > 0 && p.y < smallestPositiveY)
|
|
244
|
+
smallestPositiveY = p.y;
|
|
245
|
+
if (isFiniteNumber(p.size)) {
|
|
246
|
+
if (p.size < domainSizeMin)
|
|
247
|
+
domainSizeMin = p.size;
|
|
248
|
+
if (p.size > domainSizeMax)
|
|
249
|
+
domainSizeMax = p.size;
|
|
250
|
+
}
|
|
192
251
|
}
|
|
193
252
|
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
?
|
|
253
|
+
const hasData = totalFinitePoints > 0;
|
|
254
|
+
const hasSizedPoints = Number.isFinite(domainSizeMin) && Number.isFinite(domainSizeMax);
|
|
255
|
+
const effectiveXMin = isFiniteNumber(xMin)
|
|
256
|
+
? xMin
|
|
257
|
+
: hasData
|
|
258
|
+
? domainXMin
|
|
259
|
+
: 0;
|
|
260
|
+
const effectiveXMax = isFiniteNumber(xMax)
|
|
261
|
+
? xMax
|
|
262
|
+
: hasData
|
|
263
|
+
? domainXMax
|
|
264
|
+
: 1;
|
|
265
|
+
const xSpan = effectiveXMax > effectiveXMin ? effectiveXMax - effectiveXMin : 1;
|
|
266
|
+
// Y domain: linear from the data (or the pinned bounds); log snapped out
|
|
267
|
+
// to whole decades, the bottom one holding the smallest positive value.
|
|
268
|
+
const logTicks = isLog
|
|
269
|
+
? logDecadeTicks(isFiniteNumber(yMin) && yMin > 0
|
|
270
|
+
? yMin
|
|
271
|
+
: Number.isFinite(smallestPositiveY)
|
|
272
|
+
? smallestPositiveY
|
|
273
|
+
: 1, isFiniteNumber(yMax) && yMax > 0
|
|
274
|
+
? yMax
|
|
275
|
+
: hasData && domainYMax > 0
|
|
276
|
+
? domainYMax
|
|
277
|
+
: 10)
|
|
278
|
+
: [];
|
|
279
|
+
const effectiveYMin = isLog
|
|
280
|
+
? isFiniteNumber(yMin) && yMin > 0
|
|
281
|
+
? yMin
|
|
282
|
+
: logTicks[0]
|
|
283
|
+
: isFiniteNumber(yMin)
|
|
284
|
+
? yMin
|
|
285
|
+
: hasData
|
|
286
|
+
? domainYMin
|
|
287
|
+
: 0;
|
|
288
|
+
const effectiveYMax = isLog
|
|
289
|
+
? isFiniteNumber(yMax) && yMax > 0
|
|
290
|
+
? yMax
|
|
291
|
+
: logTicks[logTicks.length - 1]
|
|
292
|
+
: isFiniteNumber(yMax)
|
|
293
|
+
? yMax
|
|
294
|
+
: hasData
|
|
295
|
+
? domainYMax
|
|
296
|
+
: 1;
|
|
297
|
+
// Inset the data area so markers sitting on the domain edges aren't clipped.
|
|
298
|
+
const markerPad = hasSizedPoints
|
|
299
|
+
? Math.max(minRadius, maxRadius) + 2
|
|
300
|
+
: pointRadius + 2;
|
|
301
|
+
const innerW = Math.max(0, plotW - markerPad * 2);
|
|
302
|
+
const innerH = Math.max(0, plotH - markerPad * 2);
|
|
303
|
+
const projectX = (x) => plotX0 + markerPad + ((x - effectiveXMin) / xSpan) * innerW;
|
|
304
|
+
const yTransform = (y) => isLog ? Math.log10(Math.max(y, effectiveYMin)) : y;
|
|
305
|
+
const yLow = yTransform(effectiveYMin);
|
|
306
|
+
const yHigh = yTransform(effectiveYMax);
|
|
307
|
+
const yTransformedSpan = yHigh > yLow ? yHigh - yLow : 1;
|
|
308
|
+
const projectY = (y) => plotY0 +
|
|
309
|
+
markerPad +
|
|
310
|
+
innerH -
|
|
311
|
+
((yTransform(y) - yLow) / yTransformedSpan) * innerH;
|
|
312
|
+
const sizeSpan = hasSizedPoints
|
|
313
|
+
? domainSizeMax - domainSizeMin
|
|
211
314
|
: 0;
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
const
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
315
|
+
const resolveRadius = (point, seriesRadius) => {
|
|
316
|
+
if (!hasSizedPoints || !isFiniteNumber(point.size))
|
|
317
|
+
return seriesRadius;
|
|
318
|
+
if (sizeSpan <= 0)
|
|
319
|
+
return maxRadius;
|
|
320
|
+
// Square-root scale: marker *area* tracks the value, not the radius.
|
|
321
|
+
const t = (point.size - domainSizeMin) / sizeSpan;
|
|
322
|
+
return minRadius + (maxRadius - minRadius) * Math.sqrt(t);
|
|
323
|
+
};
|
|
324
|
+
const slotOf = seriesOrder
|
|
325
|
+
? (() => {
|
|
326
|
+
const order = new Map();
|
|
327
|
+
for (const id of seriesOrder) {
|
|
328
|
+
if (!order.has(id))
|
|
329
|
+
order.set(id, order.size);
|
|
330
|
+
}
|
|
331
|
+
return (id) => order.get(id) ?? -1;
|
|
332
|
+
})()
|
|
333
|
+
: (_id, index) => index;
|
|
334
|
+
const colorScale = seriesOrder
|
|
335
|
+
? createChartColorScale(seriesOrder, MAX_COLORED_SERIES)
|
|
336
|
+
: null;
|
|
337
|
+
const flat = [];
|
|
338
|
+
const groupIndexByName = new Map();
|
|
339
|
+
const groupIndexOf = (group) => {
|
|
340
|
+
if (group === undefined)
|
|
341
|
+
return -1;
|
|
342
|
+
let index = groupIndexByName.get(group);
|
|
343
|
+
if (index === undefined) {
|
|
344
|
+
index = groupIndexByName.size;
|
|
345
|
+
groupIndexByName.set(group, index);
|
|
346
|
+
}
|
|
347
|
+
return index;
|
|
348
|
+
};
|
|
349
|
+
const resolved = series.map((s, seriesIndex) => {
|
|
350
|
+
const slot = slotOf(s.id, seriesIndex);
|
|
351
|
+
const colorId = s.colorId ??
|
|
352
|
+
(colorScale
|
|
353
|
+
? colorScale(s.id)
|
|
354
|
+
: getChartSeriesColorId(seriesIndex, MAX_COLORED_SERIES));
|
|
355
|
+
const shape = s.shape ??
|
|
356
|
+
DEFAULT_SHAPE_ROTATION[(slot >= 0 ? slot : seriesIndex) % DEFAULT_SHAPE_ROTATION.length];
|
|
357
|
+
const seriesRadius = s.pointRadius ?? pointRadius;
|
|
358
|
+
const points = [];
|
|
359
|
+
s.points.forEach((p, index) => {
|
|
360
|
+
if (!isFiniteNumber(p.x) || !isFiniteNumber(p.y))
|
|
361
|
+
return;
|
|
362
|
+
const rp = {
|
|
363
|
+
point: p,
|
|
364
|
+
x: projectX(p.x),
|
|
365
|
+
y: projectY(p.y),
|
|
366
|
+
r: resolveRadius(p, seriesRadius),
|
|
367
|
+
index,
|
|
368
|
+
flatIndex: flat.length,
|
|
369
|
+
groupIndex: groupIndexOf(p.group),
|
|
370
|
+
};
|
|
371
|
+
points.push(rp);
|
|
372
|
+
flat.push({ seriesIndex, rp });
|
|
256
373
|
});
|
|
374
|
+
// On a log scale the fit is made on log10(y), so it is the straight
|
|
375
|
+
// line the reader sees; values at or below the floor sit on it.
|
|
376
|
+
const fit = s.trendLine
|
|
377
|
+
? computeTrendLine(points.map((rp) => ({
|
|
378
|
+
x: rp.point.x,
|
|
379
|
+
y: isLog
|
|
380
|
+
? Math.log10(Math.max(rp.point.y, effectiveYMin))
|
|
381
|
+
: rp.point.y,
|
|
382
|
+
})))
|
|
383
|
+
: null;
|
|
384
|
+
const fitY = (x) => {
|
|
385
|
+
const y = fit.slope * x + fit.intercept;
|
|
386
|
+
return isLog ? 10 ** y : y;
|
|
387
|
+
};
|
|
388
|
+
return {
|
|
389
|
+
series: s,
|
|
390
|
+
points,
|
|
391
|
+
paint: { colorId, value: s.color },
|
|
392
|
+
shape,
|
|
393
|
+
opacity: s.pointOpacity ?? pointOpacity,
|
|
394
|
+
trend: fit
|
|
395
|
+
? {
|
|
396
|
+
x1: projectX(effectiveXMin),
|
|
397
|
+
y1: projectY(fitY(effectiveXMin)),
|
|
398
|
+
x2: projectX(effectiveXMax),
|
|
399
|
+
y2: projectY(fitY(effectiveXMax)),
|
|
400
|
+
}
|
|
401
|
+
: null,
|
|
402
|
+
};
|
|
257
403
|
});
|
|
404
|
+
// Keyboard order: left to right, then bottom to top.
|
|
405
|
+
const byX = flat
|
|
406
|
+
.map((_, index) => index)
|
|
407
|
+
.sort((a, b) => flat[a].rp.x - flat[b].rp.x || flat[b].rp.y - flat[a].rp.y);
|
|
258
408
|
return {
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
409
|
+
plotX0,
|
|
410
|
+
plotY0,
|
|
411
|
+
plotW,
|
|
412
|
+
plotH,
|
|
413
|
+
hasData,
|
|
414
|
+
effectiveXMin,
|
|
415
|
+
effectiveXMax,
|
|
416
|
+
effectiveYMin,
|
|
417
|
+
effectiveYMax,
|
|
418
|
+
xSpan,
|
|
419
|
+
projectX,
|
|
420
|
+
projectY,
|
|
421
|
+
logTicks,
|
|
422
|
+
resolved,
|
|
423
|
+
flat,
|
|
424
|
+
byX,
|
|
425
|
+
groupCount: groupIndexByName.size,
|
|
264
426
|
};
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
427
|
+
}, [
|
|
428
|
+
W,
|
|
429
|
+
H,
|
|
430
|
+
series,
|
|
431
|
+
seriesOrder,
|
|
432
|
+
xMin,
|
|
433
|
+
xMax,
|
|
434
|
+
yMin,
|
|
435
|
+
yMax,
|
|
436
|
+
isLog,
|
|
437
|
+
pointRadius,
|
|
438
|
+
minRadius,
|
|
439
|
+
maxRadius,
|
|
440
|
+
pointOpacity,
|
|
441
|
+
showValueLabels,
|
|
442
|
+
hasXAxisLabels,
|
|
443
|
+
hasYAxisLabels,
|
|
444
|
+
xAxisTitle,
|
|
445
|
+
yAxisTitle,
|
|
446
|
+
yTickLabelWidth,
|
|
447
|
+
]);
|
|
448
|
+
const { plotX0, plotY0, plotW, plotH, hasData, effectiveXMin, effectiveYMin, effectiveYMax, xSpan, projectX, projectY, logTicks, resolved, flat, byX, } = layout;
|
|
449
|
+
const niceXTicks = niceTicks ?? typeof xTickFormatter !== "function";
|
|
450
|
+
const niceYTicks = niceTicks ?? typeof yTickFormatter !== "function";
|
|
284
451
|
const xTicks = (() => {
|
|
285
452
|
if (!hasXAxisLabels || !hasData)
|
|
286
453
|
return [];
|
|
287
454
|
const count = Math.max(2, xTickCount);
|
|
455
|
+
const values = xTickValues
|
|
456
|
+
? xTickValues.filter((value) => value >= effectiveXMin && value <= layout.effectiveXMax)
|
|
457
|
+
: niceXTicks
|
|
458
|
+
? niceTicksWithin(effectiveXMin, layout.effectiveXMax, count - 1)
|
|
459
|
+
: Array.from({ length: count }, (_, i) => effectiveXMin + (i / (count - 1)) * xSpan);
|
|
288
460
|
const ticks = [];
|
|
289
|
-
|
|
290
|
-
const t = i / (count - 1);
|
|
291
|
-
const value = effectiveXMin + t * xSpan;
|
|
461
|
+
values.forEach((value, i) => {
|
|
292
462
|
const text = typeof xTickFormatter === "function"
|
|
293
463
|
? xTickFormatter(value, i)
|
|
294
|
-
:
|
|
295
|
-
if (text
|
|
296
|
-
|
|
464
|
+
: formatX(value);
|
|
465
|
+
if (typeof text !== "string" || text === "")
|
|
466
|
+
return;
|
|
297
467
|
ticks.push({ x: projectX(value), text });
|
|
298
|
-
}
|
|
299
|
-
return ticks;
|
|
468
|
+
});
|
|
469
|
+
return thinLabels(ticks, SIZE_TO_FONT_PX[resolvedSize]);
|
|
300
470
|
})();
|
|
301
471
|
const yTicks = (() => {
|
|
302
472
|
if (!hasYAxisLabels || !hasData)
|
|
303
473
|
return [];
|
|
304
|
-
|
|
474
|
+
// Log: every decade, top-down. Linear: evenly spaced, endpoints included.
|
|
475
|
+
const values = isLog
|
|
476
|
+
? logTicks
|
|
477
|
+
.filter((v) => v >= effectiveYMin && v <= effectiveYMax)
|
|
478
|
+
.reverse()
|
|
479
|
+
: niceYTicks
|
|
480
|
+
? // Top-down, so a custom formatter sees the largest value first.
|
|
481
|
+
niceTicksWithin(effectiveYMin, effectiveYMax, Math.max(2, yTickCount) - 1).reverse()
|
|
482
|
+
: Array.from({ length: Math.max(2, yTickCount) }, (_, i) => {
|
|
483
|
+
const count = Math.max(2, yTickCount);
|
|
484
|
+
return (effectiveYMax -
|
|
485
|
+
(i / (count - 1)) * (effectiveYMax - effectiveYMin || 1));
|
|
486
|
+
});
|
|
305
487
|
const ticks = [];
|
|
306
|
-
|
|
307
|
-
// Iterate top-down (i = 0 -> yMax) so the first call to a custom
|
|
308
|
-
// formatter receives the largest value -- the order most consumers
|
|
309
|
-
// expect.
|
|
310
|
-
const t = i / (count - 1);
|
|
311
|
-
const value = effectiveYMax - t * ySpan;
|
|
488
|
+
values.forEach((value, i) => {
|
|
312
489
|
const text = typeof yTickFormatter === "function"
|
|
313
490
|
? yTickFormatter(value, i)
|
|
314
|
-
:
|
|
315
|
-
if (text
|
|
316
|
-
|
|
491
|
+
: formatY(value);
|
|
492
|
+
if (typeof text !== "string" || text === "")
|
|
493
|
+
return;
|
|
317
494
|
ticks.push({ y: projectY(value), text });
|
|
318
|
-
}
|
|
495
|
+
});
|
|
319
496
|
return ticks;
|
|
320
497
|
})();
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
498
|
+
// Gridlines (pixel positions) follow the tick labels when they are shown,
|
|
499
|
+
// so every line has its value; otherwise they split the plot evenly.
|
|
500
|
+
const evenFractions = (count) => Array.from({ length: Math.max(0, count) }, (_, i) => (i + 1) / (count + 1));
|
|
501
|
+
const horizontalGridLines = gridLineCount <= 0 || isLog
|
|
502
|
+
? []
|
|
503
|
+
: yTicks.length > 0
|
|
504
|
+
? yTicks
|
|
505
|
+
.map((tick) => tick.y)
|
|
506
|
+
.filter((y) => y > plotY0 + 0.5 && y < plotY0 + plotH - 0.5)
|
|
507
|
+
: evenFractions(gridLineCount).map((t) => plotY0 + plotH - t * plotH);
|
|
508
|
+
const verticalGridLines = verticalGridLineCount <= 0
|
|
509
|
+
? []
|
|
510
|
+
: xTicks.length > 0
|
|
511
|
+
? xTicks
|
|
512
|
+
.map((tick) => tick.x)
|
|
513
|
+
.filter((x) => x > plotX0 + 0.5 && x < plotX0 + plotW - 0.5)
|
|
514
|
+
: evenFractions(verticalGridLineCount).map((t) => plotX0 + t * plotW);
|
|
515
|
+
const readoutEnabled = showTooltip && hasData;
|
|
516
|
+
const activePoint = active === null ? undefined : flat[active];
|
|
517
|
+
const activeSeries = activePoint
|
|
518
|
+
? resolved[activePoint.seriesIndex]
|
|
519
|
+
: undefined;
|
|
520
|
+
const emphasizedGroup = activePoint && layout.groupCount > 1 && activePoint.rp.groupIndex >= 0
|
|
521
|
+
? activePoint.rp.groupIndex
|
|
522
|
+
: null;
|
|
523
|
+
const hasInteractivePoints = series.some((s) => typeof (s.onPointClick ?? onPointClick) === "function");
|
|
524
|
+
const legendVisible = showLegend ?? series.length > 1;
|
|
525
|
+
const onPointerMove = (event) => {
|
|
526
|
+
if (!readoutEnabled || W === null)
|
|
527
|
+
return;
|
|
528
|
+
const bounds = event.currentTarget.getBoundingClientRect();
|
|
529
|
+
const scale = bounds.width > 0 ? W / bounds.width : 1;
|
|
530
|
+
const px = (event.clientX - bounds.left) * scale;
|
|
531
|
+
const py = (event.clientY - bounds.top) * scale;
|
|
532
|
+
// A linear scan is fast enough for a few thousand points.
|
|
533
|
+
let nearest = null;
|
|
534
|
+
let nearestDistance = hitRadius * hitRadius;
|
|
535
|
+
for (let index = 0; index < flat.length; index += 1) {
|
|
536
|
+
const rp = flat[index].rp;
|
|
537
|
+
const distance = (rp.x - px) ** 2 + (rp.y - py) ** 2;
|
|
538
|
+
if (distance <= nearestDistance) {
|
|
539
|
+
nearest = index;
|
|
540
|
+
nearestDistance = distance;
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
if (nearest !== active)
|
|
544
|
+
setActive(nearest);
|
|
545
|
+
if (announce)
|
|
546
|
+
setAnnounce(false);
|
|
547
|
+
};
|
|
548
|
+
const onKeyDown = (event) => {
|
|
549
|
+
if (!readoutEnabled || event.target !== event.currentTarget)
|
|
550
|
+
return;
|
|
551
|
+
if (byX.length === 0)
|
|
552
|
+
return;
|
|
553
|
+
const position = active === null ? -1 : byX.indexOf(active);
|
|
554
|
+
let next;
|
|
555
|
+
if (event.key === "ArrowRight" || event.key === "ArrowUp") {
|
|
556
|
+
next = Math.min(byX.length - 1, position + 1);
|
|
557
|
+
}
|
|
558
|
+
else if (event.key === "ArrowLeft" || event.key === "ArrowDown") {
|
|
559
|
+
next = position < 0 ? byX.length - 1 : Math.max(0, position - 1);
|
|
560
|
+
}
|
|
561
|
+
else if (event.key === "Home") {
|
|
562
|
+
next = 0;
|
|
563
|
+
}
|
|
564
|
+
else if (event.key === "End") {
|
|
565
|
+
next = byX.length - 1;
|
|
566
|
+
}
|
|
567
|
+
else if (event.key === "Escape") {
|
|
568
|
+
event.preventDefault();
|
|
569
|
+
setActive(null);
|
|
570
|
+
return;
|
|
571
|
+
}
|
|
572
|
+
else {
|
|
573
|
+
return;
|
|
574
|
+
}
|
|
575
|
+
event.preventDefault();
|
|
576
|
+
setActive(byX[next]);
|
|
577
|
+
setAnnounce(true);
|
|
578
|
+
};
|
|
579
|
+
const onBlur = (event) => {
|
|
580
|
+
if (!event.currentTarget.contains(event.relatedTarget)) {
|
|
581
|
+
setActive(null);
|
|
582
|
+
}
|
|
583
|
+
};
|
|
584
|
+
// Stable, so the memoized points layer doesn't re-render on hover. The
|
|
585
|
+
// focused point's own label is read out, so it isn't announced again.
|
|
586
|
+
const onPointFocus = useCallback((flatIndex) => {
|
|
587
|
+
setActive(flatIndex);
|
|
588
|
+
setAnnounce(false);
|
|
589
|
+
}, []);
|
|
590
|
+
const pointsLayer = (_jsx(PointsLayer, { resolved: resolved, onPointClick: onPointClick, onPointFocus: onPointFocus, formatX: formatX, formatY: formatY, showValueLabels: showValueLabels, valueLabelFormatter: valueLabelFormatter, valueLabelClassName: valueLabelClassName }));
|
|
591
|
+
// Thousands of rows: build the table view only when the data changes.
|
|
592
|
+
const dataTable = useMemo(() => hasData ? (_jsx(ChartDataTable, { caption: label, columns: [
|
|
593
|
+
"Series",
|
|
594
|
+
xAxisTitle ?? "x",
|
|
595
|
+
yAxisTitle ?? "y",
|
|
596
|
+
"Label",
|
|
597
|
+
], rows: resolved.flatMap((rs) => rs.points.map((rp) => ({
|
|
598
|
+
key: `${rs.series.id}-${rp.point.id ?? rp.index}`,
|
|
599
|
+
cells: [
|
|
600
|
+
rs.series.label ?? rs.series.id,
|
|
601
|
+
formatX(rp.point.x),
|
|
602
|
+
formatY(rp.point.y),
|
|
603
|
+
rp.point.label ?? rp.point.group ?? "",
|
|
604
|
+
],
|
|
605
|
+
}))) })) : null, [hasData, label, resolved, formatX, formatY, xAxisTitle, yAxisTitle]);
|
|
606
|
+
const plot = W === null ? null : (_jsxs("svg", { id: svgId, width: W, height: H, viewBox: `0 0 ${W} ${H}`, role: hasInteractivePoints ? "group" : "img", "aria-label": label, "aria-describedby": readoutEnabled ? hintId : undefined, tabIndex: readoutEnabled ? 0 : undefined, onKeyDown: onKeyDown, onBlur: onBlur, onPointerMove: onPointerMove, onPointerLeave: () => setActive(null), className: "block h-full w-full overflow-visible rounded-sm focus:outline-none focus-visible:ring-2 focus-visible:ring-ring", children: [horizontalGridLines.length > 0 || verticalGridLines.length > 0 ? (_jsxs("g", { "aria-hidden": "true", "data-slot": "scatter-plot-gridlines", className: "pointer-events-none", children: [horizontalGridLines.map((y) => {
|
|
607
|
+
return (_jsx("line", { x1: plotX0, y1: y, x2: plotX0 + plotW, y2: y, strokeWidth: 1, className: cn("stroke-border/60", axisClassName) }, `h-grid-${y}`));
|
|
608
|
+
}), verticalGridLines.map((x) => {
|
|
609
|
+
return (_jsx("line", { x1: x, y1: plotY0, x2: x, y2: plotY0 + plotH, strokeWidth: 1, className: cn("stroke-border/60", axisClassName) }, `v-grid-${x}`));
|
|
610
|
+
})] })) : null, isLog && hasData && hasYAxisLabels ? (_jsx("g", { "aria-hidden": "true", "data-slot": "scatter-plot-decade-lines", className: "pointer-events-none", children: yTicks.map((tick, index) => (_jsx("line", { x1: plotX0, y1: tick.y, x2: plotX0 + plotW, y2: tick.y, strokeWidth: 1, className: cn("stroke-border/60", axisClassName) }, `decade-${index}`))) })) : null, showAxis ? (_jsxs("g", { "aria-hidden": "true", "data-slot": "scatter-plot-axis", className: "pointer-events-none", children: [_jsx("line", { x1: plotX0, y1: plotY0, x2: plotX0, y2: plotY0 + plotH, strokeWidth: 1, className: cn("stroke-border", axisClassName) }), _jsx("line", { x1: plotX0, y1: plotY0 + plotH, x2: plotX0 + plotW, y2: plotY0 + plotH, strokeWidth: 1, className: cn("stroke-border", axisClassName) })] })) : null, emphasizedGroup !== null && typeof CSS !== "undefined" ? (_jsx("style", { children: `#${CSS.escape(svgId)} [data-slot="scatter-plot-points"] path[data-group]:not([data-group="${emphasizedGroup}"]){fill-opacity:${FADED_OPACITY};stroke-opacity:${FADED_OPACITY}}` })) : null, !hasData ? (_jsx("text", { x: W / 2, y: H / 2, textAnchor: "middle", dominantBaseline: "central", className: "fill-muted-foreground", children: emptyMessage })) : (pointsLayer), hasData && xReferenceLines && xReferenceLines.length > 0 ? (_jsx("g", { "aria-hidden": "true", "data-slot": "scatter-plot-x-reference-lines", className: "pointer-events-none select-none", children: xReferenceLines.map((line, index) => {
|
|
611
|
+
const x = projectX(line.value);
|
|
612
|
+
return (_jsxs("g", { children: [_jsx("line", { x1: x, y1: plotY0, x2: x, y2: plotY0 + plotH, strokeWidth: 1, strokeDasharray: "4 3", className: cn("stroke-muted-foreground/70", line.className) }), line.label ? (_jsx("text", { x: x + 4, y: plotY0 + 8, paintOrder: "stroke", stroke: "hsl(var(--background))", strokeWidth: 3, strokeLinejoin: "round", className: "fill-muted-foreground", children: line.label })) : null] }, `x-ref-${index}-${line.value}`));
|
|
613
|
+
}) })) : null, hasData && yReferenceLines && yReferenceLines.length > 0 ? (_jsx("g", { "aria-hidden": "true", "data-slot": "scatter-plot-y-reference-lines", className: "pointer-events-none select-none", children: yReferenceLines.map((line, index) => {
|
|
614
|
+
const y = projectY(line.value);
|
|
615
|
+
return (_jsxs("g", { children: [_jsx("line", { x1: plotX0, y1: y, x2: plotX0 + plotW, y2: y, strokeWidth: 1, strokeDasharray: "4 3", className: cn("stroke-muted-foreground/70", line.className) }), line.label ? (_jsx("text", { x: plotX0 + plotW - 4, y: y - 4, textAnchor: "end", paintOrder: "stroke", stroke: "hsl(var(--background))", strokeWidth: 3, strokeLinejoin: "round", className: "fill-muted-foreground", children: line.label })) : null] }, `y-ref-${index}-${line.value}`));
|
|
616
|
+
}) })) : null, activePoint ? (_jsx("circle", { "aria-hidden": "true", "data-slot": "scatter-plot-active-point", cx: activePoint.rp.x, cy: activePoint.rp.y, r: activePoint.rp.r + 3, strokeWidth: 2, className: "pointer-events-none fill-none stroke-foreground" })) : null, xTicks.length > 0 ? (_jsx("g", { "aria-hidden": "true", "data-slot": "scatter-plot-x-ticks", className: "pointer-events-none select-none", children: xTicks.map((tick, index) => (_jsxs("g", { children: [_jsx("line", { x1: tick.x, x2: tick.x, y1: plotY0 + plotH, y2: plotY0 + plotH + 3, strokeWidth: 1, className: cn("stroke-border", axisClassName) }), _jsx("text", { x: tick.x, y: plotY0 + plotH + 14, textAnchor: "middle", className: cn("fill-muted-foreground tabular-nums", tickLabelClassName), children: tick.text })] }, `xtick-${index}-${tick.text}`))) })) : null, yTicks.length > 0 ? (_jsx("g", { "aria-hidden": "true", "data-slot": "scatter-plot-y-ticks", className: "pointer-events-none select-none", children: yTicks.map((tick, index) => (_jsxs("g", { children: [_jsx("line", { x1: plotX0 - 3, x2: plotX0, y1: tick.y, y2: tick.y, strokeWidth: 1, className: cn("stroke-border", axisClassName) }), _jsx("text", { x: plotX0 - 6, y: tick.y, textAnchor: "end", dominantBaseline: "central", className: cn("fill-muted-foreground tabular-nums", tickLabelClassName), children: tick.text })] }, `ytick-${index}-${tick.text}`))) })) : null, xAxisTitle ? (_jsx("text", { "aria-hidden": "true", "data-slot": "scatter-plot-x-axis-title", x: plotX0 + plotW / 2, y: H - 2, textAnchor: "middle", className: "pointer-events-none select-none fill-muted-foreground font-medium", children: xAxisTitle })) : null, yAxisTitle ? (_jsx("text", { "aria-hidden": "true", "data-slot": "scatter-plot-y-axis-title", x: 10, y: plotY0 + plotH / 2, textAnchor: "middle", transform: `rotate(-90 10 ${plotY0 + plotH / 2})`, className: "pointer-events-none select-none fill-muted-foreground font-medium", children: yAxisTitle })) : null] }));
|
|
617
|
+
const multiSeries = series.length > 1;
|
|
618
|
+
return (_jsxs("div", { ref: chart.ref, "data-slot": "scatter-plot", "aria-busy": loading || undefined, className: cn(scatterPlotVariants({ size }), "flex-col items-stretch justify-start gap-2 transition-opacity", chart.rootClassName, loading && "opacity-60", className), style: { ...chart.rootStyle, ...style }, ...props, children: [legendVisible && series.length > 0 && W !== null ? (_jsx(ChartLegend, { items: resolved.map((rs) => ({
|
|
619
|
+
id: rs.series.id,
|
|
620
|
+
label: rs.series.label ?? rs.series.id,
|
|
621
|
+
paint: rs.paint,
|
|
622
|
+
swatch: rs.shape,
|
|
623
|
+
})) })) : null, _jsxs("div", { "data-slot": "scatter-plot-plot", className: "relative w-full shrink-0", style: { height: H }, children: [plot, readoutEnabled && W !== null ? (_jsxs(_Fragment, { children: [_jsx("span", { id: hintId, hidden: true, children: "Use the arrow keys to read the points from left to right." }), _jsx(ChartLiveRegion, { message: announce && activePoint && activeSeries
|
|
624
|
+
? [
|
|
625
|
+
multiSeries
|
|
626
|
+
? `${activeSeries.series.label ?? activeSeries.series.id}:`
|
|
627
|
+
: "",
|
|
628
|
+
formatY(activePoint.rp.point.y),
|
|
629
|
+
`at ${formatX(activePoint.rp.point.x)}`,
|
|
630
|
+
activePoint.rp.point.label ?? activePoint.rp.point.group ?? "",
|
|
631
|
+
]
|
|
632
|
+
.filter(Boolean)
|
|
633
|
+
.join(" ")
|
|
634
|
+
: "" })] })) : null, showTooltip && activePoint && activeSeries && W !== null ? (_jsx(ChartTooltip, { x: activePoint.rp.x, y: activePoint.rp.y - activePoint.rp.r, containerWidth: W, children: formatTooltip ? (formatTooltip({
|
|
635
|
+
series: activeSeries.series,
|
|
636
|
+
point: activePoint.rp.point,
|
|
637
|
+
formattedX: formatX(activePoint.rp.point.x),
|
|
638
|
+
formattedY: formatY(activePoint.rp.point.y),
|
|
639
|
+
paint: activeSeries.paint,
|
|
640
|
+
})) : (_jsxs(_Fragment, { children: [_jsx(ChartTooltipRow, { value: formatY(activePoint.rp.point.y), label: multiSeries
|
|
641
|
+
? (activeSeries.series.label ?? activeSeries.series.id)
|
|
642
|
+
: yAxisTitle, color: multiSeries ? activeSeries.paint.value : undefined, colorClassName: multiSeries
|
|
643
|
+
? chartPaintClass(activeSeries.paint, "bg")
|
|
644
|
+
: undefined }), _jsxs("div", { className: "text-muted-foreground", children: [xAxisTitle ? `${xAxisTitle} ` : "at ", _jsx("span", { className: "tabular-nums", children: formatX(activePoint.rp.point.x) })] }), activePoint.rp.point.label ? (_jsx("div", { className: "mt-0.5 whitespace-normal break-words font-medium", children: activePoint.rp.point.label })) : null, activePoint.rp.point.group !== undefined &&
|
|
645
|
+
activePoint.rp.point.group !== activePoint.rp.point.label ? (_jsx("div", { className: "whitespace-normal break-words text-muted-foreground", children: activePoint.rp.point.group })) : null] })) })) : null, children ? (_jsx("div", { className: cn("pointer-events-none absolute inset-0 flex items-center justify-center text-center", overlayClassName), children: children })) : null] }), W !== null ? dataTable : null] }));
|
|
382
646
|
}
|
|
383
647
|
ScatterPlot.displayName = "ScatterPlot";
|
|
384
648
|
export { ScatterPlot };
|