@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
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Framework-free geometry and tick helpers shared by the chart components.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* The smallest "nice" step (1, 2 or 5 × 10^k) that is at least `rawStep`,
|
|
6
|
+
* never below `minStep` (1 for whole-number data such as counts).
|
|
7
|
+
*/
|
|
8
|
+
export function niceStep(rawStep, minStep = 0) {
|
|
9
|
+
if (!Number.isFinite(rawStep) || rawStep <= 0) {
|
|
10
|
+
return Math.max(minStep, 1);
|
|
11
|
+
}
|
|
12
|
+
const magnitude = 10 ** Math.floor(Math.log10(rawStep));
|
|
13
|
+
const residual = rawStep / magnitude;
|
|
14
|
+
const nice = residual <= 1 ? 1 : residual <= 2 ? 2 : residual <= 5 ? 5 : 10;
|
|
15
|
+
return Math.max(minStep, nice * magnitude);
|
|
16
|
+
}
|
|
17
|
+
/** Rounds away float drift (0.1 + 0.2) so tick labels stay clean. */
|
|
18
|
+
export function cleanNumber(value) {
|
|
19
|
+
return Number(value.toPrecision(12));
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* A zero-based value axis: nice ticks from 0 up to the first tick at or
|
|
23
|
+
* above `max`, with about `target` intervals.
|
|
24
|
+
*/
|
|
25
|
+
export function niceAxis(max, target = 4, minStep = 0) {
|
|
26
|
+
const safeMax = Number.isFinite(max) ? Math.max(0, max) : 0;
|
|
27
|
+
const step = niceStep(safeMax / Math.max(1, target), minStep);
|
|
28
|
+
const top = Math.max(step, Math.ceil(cleanNumber(safeMax / step)) * step);
|
|
29
|
+
const ticks = [];
|
|
30
|
+
for (let value = 0; value <= top + step * 1e-9; value += step) {
|
|
31
|
+
ticks.push(cleanNumber(value));
|
|
32
|
+
}
|
|
33
|
+
return { ticks, top: cleanNumber(top), step };
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Log-scale ticks at whole decades covering `[min, max]`. The bottom decade
|
|
37
|
+
* is the one holding the smallest positive value, so zeros and negatives
|
|
38
|
+
* (which a log scale cannot place) sit on the bottom line.
|
|
39
|
+
*/
|
|
40
|
+
export function logDecadeTicks(min, max) {
|
|
41
|
+
const floor = Number.isFinite(min) && min > 0 ? Math.floor(Math.log10(min)) : 0;
|
|
42
|
+
const ceiling = Number.isFinite(max) && max > 0
|
|
43
|
+
? Math.max(floor + 1, Math.ceil(cleanNumber(Math.log10(max))))
|
|
44
|
+
: floor + 1;
|
|
45
|
+
const ticks = [];
|
|
46
|
+
for (let exponent = floor; exponent <= ceiling; exponent += 1) {
|
|
47
|
+
ticks.push(cleanNumber(10 ** exponent));
|
|
48
|
+
}
|
|
49
|
+
return ticks;
|
|
50
|
+
}
|
|
51
|
+
/** Evenly spaced indices (always the first and last) so at most `maxLabels` labels render. */
|
|
52
|
+
export function thinIndices(count, maxLabels) {
|
|
53
|
+
if (count <= 0)
|
|
54
|
+
return [];
|
|
55
|
+
if (count <= maxLabels) {
|
|
56
|
+
return Array.from({ length: count }, (_, index) => index);
|
|
57
|
+
}
|
|
58
|
+
const step = Math.ceil((count - 1) / Math.max(1, maxLabels - 1));
|
|
59
|
+
const indices = [];
|
|
60
|
+
for (let index = 0; index < count - 1; index += step) {
|
|
61
|
+
indices.push(index);
|
|
62
|
+
}
|
|
63
|
+
// Drop the last regular label when it would crowd the closing one.
|
|
64
|
+
if (count - 1 - indices[indices.length - 1] < step / 2 && indices.length > 1) {
|
|
65
|
+
indices.pop();
|
|
66
|
+
}
|
|
67
|
+
indices.push(count - 1);
|
|
68
|
+
return indices;
|
|
69
|
+
}
|
|
70
|
+
/** Index of the value in ascending `sorted` closest to `target`; -1 when empty. */
|
|
71
|
+
export function nearestSortedIndex(sorted, target) {
|
|
72
|
+
if (sorted.length === 0)
|
|
73
|
+
return -1;
|
|
74
|
+
let low = 0;
|
|
75
|
+
let high = sorted.length - 1;
|
|
76
|
+
while (low < high) {
|
|
77
|
+
const mid = (low + high) >> 1;
|
|
78
|
+
if (sorted[mid] < target)
|
|
79
|
+
low = mid + 1;
|
|
80
|
+
else
|
|
81
|
+
high = mid;
|
|
82
|
+
}
|
|
83
|
+
if (low > 0 && Math.abs(sorted[low - 1] - target) <= Math.abs(sorted[low] - target)) {
|
|
84
|
+
return low - 1;
|
|
85
|
+
}
|
|
86
|
+
return low;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* SVG path of a bar with its free end rounded (`radius`, clamped to the
|
|
90
|
+
* bar's size) and a square end on the baseline: the top for columns, the
|
|
91
|
+
* right for horizontal bars.
|
|
92
|
+
*/
|
|
93
|
+
export function roundedBarPath(x, y, width, height, radius, freeEnd = "top") {
|
|
94
|
+
if (!(width > 0) || !(height > 0))
|
|
95
|
+
return "";
|
|
96
|
+
const f = (value) => value.toFixed(2);
|
|
97
|
+
if (freeEnd === "right") {
|
|
98
|
+
const r = Math.max(0, Math.min(radius, height / 2, width));
|
|
99
|
+
const right = x + width;
|
|
100
|
+
return [
|
|
101
|
+
`M${f(x)},${f(y)}`,
|
|
102
|
+
`H${f(right - r)}`,
|
|
103
|
+
`Q${f(right)},${f(y)} ${f(right)},${f(y + r)}`,
|
|
104
|
+
`V${f(y + height - r)}`,
|
|
105
|
+
`Q${f(right)},${f(y + height)} ${f(right - r)},${f(y + height)}`,
|
|
106
|
+
`H${f(x)}`,
|
|
107
|
+
"Z",
|
|
108
|
+
].join(" ");
|
|
109
|
+
}
|
|
110
|
+
const r = Math.max(0, Math.min(radius, width / 2, height));
|
|
111
|
+
const bottom = y + height;
|
|
112
|
+
return [
|
|
113
|
+
`M${f(x)},${f(bottom)}`,
|
|
114
|
+
`V${f(y + r)}`,
|
|
115
|
+
`Q${f(x)},${f(y)} ${f(x + r)},${f(y)}`,
|
|
116
|
+
`H${f(x + width - r)}`,
|
|
117
|
+
`Q${f(x + width)},${f(y)} ${f(x + width)},${f(y + r)}`,
|
|
118
|
+
`V${f(bottom)}`,
|
|
119
|
+
"Z",
|
|
120
|
+
].join(" ");
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* The 1, 2 or 5 × 10^k step that splits `span` into the count of intervals
|
|
124
|
+
* closest to `count` (d3's rounding), rather than the next one up.
|
|
125
|
+
*/
|
|
126
|
+
export function closestNiceStep(span, count) {
|
|
127
|
+
if (!Number.isFinite(span) || span <= 0)
|
|
128
|
+
return 1;
|
|
129
|
+
const raw = span / Math.max(1, count);
|
|
130
|
+
const power = Math.floor(Math.log10(raw));
|
|
131
|
+
const error = raw / 10 ** power;
|
|
132
|
+
const factor = error >= Math.sqrt(50) ? 10 : error >= Math.sqrt(10) ? 5 : error >= Math.SQRT2 ? 2 : 1;
|
|
133
|
+
return factor * 10 ** power;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Round tick values inside `[min, max]` (the domain itself is left alone),
|
|
137
|
+
* about `count` intervals apart and at least `minStep` (1 for indices).
|
|
138
|
+
*/
|
|
139
|
+
export function niceTicksWithin(min, max, count, minStep = 0) {
|
|
140
|
+
if (!Number.isFinite(min) || !Number.isFinite(max))
|
|
141
|
+
return [];
|
|
142
|
+
if (max <= min)
|
|
143
|
+
return [cleanNumber(min)];
|
|
144
|
+
const step = Math.max(minStep, closestNiceStep(max - min, count));
|
|
145
|
+
const first = Math.ceil(cleanNumber(min / step)) * step;
|
|
146
|
+
const ticks = [];
|
|
147
|
+
for (let value = first; value <= max + step * 1e-9; value += step) {
|
|
148
|
+
ticks.push(cleanNumber(value));
|
|
149
|
+
}
|
|
150
|
+
return ticks;
|
|
151
|
+
}
|
|
152
|
+
/** Rough width of a tick label: SVG text can't be measured before it renders. */
|
|
153
|
+
export function estimateLabelWidth(text, fontPx) {
|
|
154
|
+
return text.length * fontPx * 0.62;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Drops axis labels that would overlap their neighbour at `fontPx`, keeping
|
|
158
|
+
* the first and (when it fits) the last, so ticks thin out on a narrow chart
|
|
159
|
+
* instead of running together.
|
|
160
|
+
*/
|
|
161
|
+
export function thinLabels(labels, fontPx, minGap = 8) {
|
|
162
|
+
const half = (label) => estimateLabelWidth(String(label.text), fontPx) / 2;
|
|
163
|
+
const fits = (left, right) => right.x - half(right) >= left.x + half(left) + minGap;
|
|
164
|
+
const kept = [];
|
|
165
|
+
for (const label of labels) {
|
|
166
|
+
const previous = kept[kept.length - 1];
|
|
167
|
+
if (!previous || fits(previous, label))
|
|
168
|
+
kept.push(label);
|
|
169
|
+
}
|
|
170
|
+
const last = labels[labels.length - 1];
|
|
171
|
+
// Prefer ending on the last label (the domain's end) over its neighbour.
|
|
172
|
+
if (last && kept.length > 1 && kept[kept.length - 1] !== last) {
|
|
173
|
+
const dropped = kept.pop();
|
|
174
|
+
kept.push(fits(kept[kept.length - 1], last) ? last : dropped);
|
|
175
|
+
}
|
|
176
|
+
return kept;
|
|
177
|
+
}
|
|
178
|
+
//# sourceMappingURL=chart-scale.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chart-scale.js","sourceRoot":"","sources":["../../../../src/components/ui/chart-primitives/chart-scale.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;GAGG;AACH,MAAM,UAAU,QAAQ,CAAC,OAAe,EAAE,UAAkB,CAAC;IAC3D,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,OAAO,IAAI,CAAC,EAAE,CAAC;QAC9C,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;IAC9B,CAAC;IACD,MAAM,SAAS,GAAW,EAAE,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;IAChE,MAAM,QAAQ,GAAW,OAAO,GAAG,SAAS,CAAC;IAC7C,MAAM,IAAI,GACR,QAAQ,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,IAAI,CAAC,CAAC,CAA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CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { ReactElement, ReactNode } from "react";
|
|
2
|
+
export interface ChartTooltipProps {
|
|
3
|
+
/** Anchor x in the chart container's pixels (the tooltip centers on it). */
|
|
4
|
+
x: number;
|
|
5
|
+
/** Anchor y in the chart container's pixels (the tooltip sits above it). */
|
|
6
|
+
y: number;
|
|
7
|
+
/**
|
|
8
|
+
* Width of the chart container. The tooltip is clamped inside it and never
|
|
9
|
+
* grows wider than it.
|
|
10
|
+
*/
|
|
11
|
+
containerWidth: number;
|
|
12
|
+
/** Gap between the anchor and the tooltip, in pixels. Defaults to `10`. */
|
|
13
|
+
offset?: number;
|
|
14
|
+
children: ReactNode;
|
|
15
|
+
className?: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* A floating readout drawn in HTML over a chart. Render it inside the
|
|
19
|
+
* chart's `position: relative` container. It centers on its anchor, clamps
|
|
20
|
+
* itself inside the container horizontally, and flips below the anchor when
|
|
21
|
+
* there is no room above.
|
|
22
|
+
*
|
|
23
|
+
* Lead each row with the value and follow with the label: `ChartTooltipRow`
|
|
24
|
+
* does that and keys each series with a short line in its colour.
|
|
25
|
+
*
|
|
26
|
+
* It is visual only (`aria-hidden`): pair it with a `ChartLiveRegion` that
|
|
27
|
+
* announces keyboard moves, since a live region that mounts together with
|
|
28
|
+
* its text is not read out.
|
|
29
|
+
*/
|
|
30
|
+
declare function ChartTooltip({ x, y, containerWidth, offset, children, className, }: ChartTooltipProps): ReactElement;
|
|
31
|
+
declare namespace ChartTooltip {
|
|
32
|
+
var displayName: string;
|
|
33
|
+
}
|
|
34
|
+
export interface ChartTooltipRowProps {
|
|
35
|
+
/** The value, shown first in strong text. */
|
|
36
|
+
value: ReactNode;
|
|
37
|
+
/** What the value is, shown after it in muted text. */
|
|
38
|
+
label?: ReactNode;
|
|
39
|
+
/**
|
|
40
|
+
* Classes for the series key (a short line in the series colour), e.g.
|
|
41
|
+
* `getChartColorClasses("chart-2").bg`. Leave the key out on single-series
|
|
42
|
+
* charts.
|
|
43
|
+
*/
|
|
44
|
+
colorClassName?: string;
|
|
45
|
+
/** A raw CSS colour for the series key; wins over `colorClassName`. */
|
|
46
|
+
color?: string;
|
|
47
|
+
className?: string;
|
|
48
|
+
}
|
|
49
|
+
/** One `value · label` line of a chart tooltip. */
|
|
50
|
+
declare function ChartTooltipRow({ value, label, colorClassName, color, className, }: ChartTooltipRowProps): ReactElement;
|
|
51
|
+
declare namespace ChartTooltipRow {
|
|
52
|
+
var displayName: string;
|
|
53
|
+
}
|
|
54
|
+
export interface ChartLiveRegionProps {
|
|
55
|
+
/** What to announce; an empty string says nothing. */
|
|
56
|
+
message: string;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* A visually hidden, always-mounted `role="status"` region: charts put their
|
|
60
|
+
* keyboard readout here so screen readers announce each arrow-key move.
|
|
61
|
+
* Keep it mounted (empty) between moves; don't feed it pointer hovers.
|
|
62
|
+
*/
|
|
63
|
+
declare function ChartLiveRegion({ message }: ChartLiveRegionProps): ReactElement;
|
|
64
|
+
declare namespace ChartLiveRegion {
|
|
65
|
+
var displayName: string;
|
|
66
|
+
}
|
|
67
|
+
export { ChartTooltip, ChartTooltipRow, ChartLiveRegion };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useLayoutEffect, useRef } from "react";
|
|
4
|
+
import { cn } from "../../../lib/utils";
|
|
5
|
+
/**
|
|
6
|
+
* A floating readout drawn in HTML over a chart. Render it inside the
|
|
7
|
+
* chart's `position: relative` container. It centers on its anchor, clamps
|
|
8
|
+
* itself inside the container horizontally, and flips below the anchor when
|
|
9
|
+
* there is no room above.
|
|
10
|
+
*
|
|
11
|
+
* Lead each row with the value and follow with the label: `ChartTooltipRow`
|
|
12
|
+
* does that and keys each series with a short line in its colour.
|
|
13
|
+
*
|
|
14
|
+
* It is visual only (`aria-hidden`): pair it with a `ChartLiveRegion` that
|
|
15
|
+
* announces keyboard moves, since a live region that mounts together with
|
|
16
|
+
* its text is not read out.
|
|
17
|
+
*/
|
|
18
|
+
function ChartTooltip({ x, y, containerWidth, offset = 10, children, className, }) {
|
|
19
|
+
const ref = useRef(null);
|
|
20
|
+
// Position from the rendered size on every render, before the browser
|
|
21
|
+
// paints, so a readout whose content changed never shows a frame at the
|
|
22
|
+
// old width. React never sets left/top/visibility itself, so the values
|
|
23
|
+
// written here stick.
|
|
24
|
+
useLayoutEffect(() => {
|
|
25
|
+
const element = ref.current;
|
|
26
|
+
if (!element)
|
|
27
|
+
return;
|
|
28
|
+
const width = element.offsetWidth;
|
|
29
|
+
const height = element.offsetHeight;
|
|
30
|
+
const left = Math.min(Math.max(0, x - width / 2), Math.max(0, containerWidth - width));
|
|
31
|
+
const below = y - offset - height < 0;
|
|
32
|
+
element.style.left = `${left}px`;
|
|
33
|
+
element.style.top = `${below ? y + offset : y - offset - height}px`;
|
|
34
|
+
element.style.visibility = "visible";
|
|
35
|
+
element.dataset["side"] = below ? "bottom" : "top";
|
|
36
|
+
});
|
|
37
|
+
const style = { maxWidth: Math.max(0, containerWidth) };
|
|
38
|
+
return (_jsx("div", { ref: ref, "aria-hidden": "true", "data-slot": "chart-tooltip", className: cn("pointer-events-none invisible absolute left-0 top-0 z-10 w-max rounded-md border bg-popover px-2.5 py-1.5 text-left text-xs font-normal text-popover-foreground shadow-md", className), style: style, children: children }));
|
|
39
|
+
}
|
|
40
|
+
ChartTooltip.displayName = "ChartTooltip";
|
|
41
|
+
/** One `value · label` line of a chart tooltip. */
|
|
42
|
+
function ChartTooltipRow({ value, label, colorClassName, color, className, }) {
|
|
43
|
+
const hasKey = Boolean(color || colorClassName);
|
|
44
|
+
return (_jsxs("div", { "data-slot": "chart-tooltip-row", className: cn("flex min-w-0 items-center gap-1.5 whitespace-nowrap", className), children: [hasKey ? (_jsx("span", { "aria-hidden": "true", className: cn("inline-block h-0.5 w-3 shrink-0 rounded-full", color ? undefined : colorClassName), style: color ? { backgroundColor: color } : undefined })) : null, _jsx("span", { className: "font-semibold tabular-nums", children: value }), label !== undefined && label !== null && label !== "" ? (_jsx("span", { className: "min-w-0 truncate text-muted-foreground", children: label })) : null] }));
|
|
45
|
+
}
|
|
46
|
+
ChartTooltipRow.displayName = "ChartTooltipRow";
|
|
47
|
+
/**
|
|
48
|
+
* A visually hidden, always-mounted `role="status"` region: charts put their
|
|
49
|
+
* keyboard readout here so screen readers announce each arrow-key move.
|
|
50
|
+
* Keep it mounted (empty) between moves; don't feed it pointer hovers.
|
|
51
|
+
*/
|
|
52
|
+
function ChartLiveRegion({ message }) {
|
|
53
|
+
return (_jsx("span", { role: "status", "aria-live": "polite", "aria-atomic": "true", "data-slot": "chart-live-region", className: "sr-only", children: message }));
|
|
54
|
+
}
|
|
55
|
+
ChartLiveRegion.displayName = "ChartLiveRegion";
|
|
56
|
+
export { ChartTooltip, ChartTooltipRow, ChartLiveRegion };
|
|
57
|
+
//# sourceMappingURL=chart-tooltip.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chart-tooltip.js","sourceRoot":"","sources":["../../../../src/components/ui/chart-primitives/chart-tooltip.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAGb,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAEhD,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AAkBjC;;;;;;;;;;;;GAYG;AACH,SAAS,YAAY,CAAC,EACpB,CAAC,EACD,CAAC,EACD,cAAc,EACd,MAAM,GAAG,EAAE,EACX,QAAQ,EACR,SAAS,GACS;IAClB,MAAM,GAAG,GAAG,MAAM,CAAiB,IAAI,CAAC,CAAC;IAEzC,sEAAsE;IACtE,wEAAwE;IACxE,wEAAwE;IACxE,sBAAsB;IACtB,eAAe,CAAC,GAAS,EAAE;QACzB,MAAM,OAAO,GA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,EACL,cAAc,EACd,KAAK,EACL,SAAS,GACY;IACrB,MAAM,MAAM,GAAY,OAAO,CAAC,KAAK,IAAI,cAAc,CAAC,CAAC;IACzD,OAAO,CACL,4BACY,mBAAmB,EAC7B,SAAS,EAAE,EAAE,CAAC,qDAAqD,EAAE,SAAS,CAAC,aAE9E,MAAM,CAAC,CAAC,CAAC,CACR,8BACc,MAAM,EAClB,SAAS,EAAE,EAAE,CACX,8CAA8C,EAC9C,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,cAAc,CACnC,EACD,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,eAAe,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,GACrD,CACH,CAAC,CAAC,CAAC,IAAI,EACR,eAAM,SAAS,EAAC,4BAA4B,YAAE,KAAK,GAAQ,EAC1D,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,EAAE,CAAC,CAAC,CAAC,CACvD,eAAM,SAAS,EAAC,wCAAwC,YAAE,KAAK,GAAQ,CACxE,CAAC,CAAC,CAAC,IAAI,IACJ,CACP,CAAC;AACJ,CAAC;AACD,eAAe,CAAC,WAAW,GAAG,iBAAiB,CAAC;AAOhD;;;;GAIG;AACH,SAAS,eAAe,CAAC,EAAE,OAAO,EAAwB;IACxD,OAAO,CACL,eACE,IAAI,EAAC,QAAQ,eACH,QAAQ,iBACN,MAAM,eACR,mBAAmB,EAC7B,SAAS,EAAC,SAAS,YAElB,OAAO,GACH,CACR,CAAC;AACJ,CAAC;AACD,eAAe,CAAC,WAAW,GAAG,iBAAiB,CAAC;AAEhD,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,eAAe,EAAE,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from "./chart-colors";
|
|
2
|
+
export type * from "./chart-colors";
|
|
3
|
+
export * from "./chart-tooltip";
|
|
4
|
+
export type * from "./chart-tooltip";
|
|
5
|
+
export * from "./chart-legend";
|
|
6
|
+
export type * from "./chart-legend";
|
|
7
|
+
export * from "./chart-data-table";
|
|
8
|
+
export type * from "./chart-data-table";
|
|
9
|
+
export * from "./responsive-chart";
|
|
10
|
+
export type * from "./responsive-chart";
|
|
11
|
+
export { formatChartNumber } from "./chart-format";
|
|
12
|
+
export type { ChartWidth } from "./use-chart-width";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/ui/chart-primitives/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAG/B,cAAc,iBAAiB,CAAC;AAGhC,cAAc,gBAAgB,CAAC;AAG/B,cAAc,oBAAoB,CAAC;AAGnC,cAAc,oBAAoB,CAAC;AAGnC,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { HTMLAttributes, ReactElement, ReactNode, Ref } from "react";
|
|
2
|
+
export interface ResponsiveChartProps extends Omit<HTMLAttributes<HTMLDivElement>, "children"> {
|
|
3
|
+
/** The chart's height in pixels; also the placeholder's height before the first measurement. */
|
|
4
|
+
height: number;
|
|
5
|
+
/** Draws the chart at the container's current width. */
|
|
6
|
+
children: (width: number) => ReactNode;
|
|
7
|
+
/** Optional ref forwarded to the container element. */
|
|
8
|
+
ref?: Ref<HTMLDivElement>;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* The building block behind every chart's `width="auto"`, for custom charts:
|
|
12
|
+
* a full-width container that measures itself and calls `children` with its
|
|
13
|
+
* width, again on every resize.
|
|
14
|
+
*
|
|
15
|
+
* Until the first measurement (the server render and the first client
|
|
16
|
+
* render) it is an empty placeholder at `height`, so the server HTML holds
|
|
17
|
+
* no pixel width and no tick labels, and nothing jumps from a guessed width
|
|
18
|
+
* to the real one. The container sets `contain: inline-size` so the drawing
|
|
19
|
+
* never holds its parent open; give it a parent whose width does not depend
|
|
20
|
+
* on its content (a block, a card, a grid cell).
|
|
21
|
+
*/
|
|
22
|
+
declare function ResponsiveChart({ height, children, className, style, ref, ...props }: ResponsiveChartProps): ReactElement;
|
|
23
|
+
declare namespace ResponsiveChart {
|
|
24
|
+
var displayName: string;
|
|
25
|
+
}
|
|
26
|
+
export { ResponsiveChart };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useMeasuredWidth } from "../../hooks/use-measured-width";
|
|
4
|
+
import { cn } from "../../../lib/utils";
|
|
5
|
+
import { useMergedRefs } from "./use-chart-width";
|
|
6
|
+
/**
|
|
7
|
+
* The building block behind every chart's `width="auto"`, for custom charts:
|
|
8
|
+
* a full-width container that measures itself and calls `children` with its
|
|
9
|
+
* width, again on every resize.
|
|
10
|
+
*
|
|
11
|
+
* Until the first measurement (the server render and the first client
|
|
12
|
+
* render) it is an empty placeholder at `height`, so the server HTML holds
|
|
13
|
+
* no pixel width and no tick labels, and nothing jumps from a guessed width
|
|
14
|
+
* to the real one. The container sets `contain: inline-size` so the drawing
|
|
15
|
+
* never holds its parent open; give it a parent whose width does not depend
|
|
16
|
+
* on its content (a block, a card, a grid cell).
|
|
17
|
+
*/
|
|
18
|
+
function ResponsiveChart({ height, children, className, style, ref, ...props }) {
|
|
19
|
+
const measured = useMeasuredWidth();
|
|
20
|
+
const containerRef = useMergedRefs(ref, measured.ref);
|
|
21
|
+
return (_jsx("div", { ref: containerRef, "data-slot": "responsive-chart", "data-measured": measured.isMeasured ? "true" : "false", className: cn("relative w-full min-w-0", className), style: { minHeight: height, contain: "inline-size", ...style }, ...props, children: measured.isMeasured ? children(measured.width) : null }));
|
|
22
|
+
}
|
|
23
|
+
ResponsiveChart.displayName = "ResponsiveChart";
|
|
24
|
+
export { ResponsiveChart };
|
|
25
|
+
//# sourceMappingURL=responsive-chart.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"responsive-chart.js","sourceRoot":"","sources":["../../../../src/components/ui/chart-primitives/responsive-chart.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAIb,OAAO,EAAE,gBAAgB,EAAE,MAAM,uCAAuC,CAAC;AACzE,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AAEjC,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAYlD;;;;;;;;;;;GAWG;AACH,SAAS,eAAe,CAAC,EACvB,MAAM,EACN,QAAQ,EACR,SAAS,EACT,KAAK,EACL,GAAG,EACH,GAAG,KAAK,EACa;IACrB,MAAM,QAAQ,GAAG,gBAAgB,EAAkB,CAAC;IACpD,MAAM,YAAY,GAAG,aAAa,CAAiB,GAAG,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAC;IACtE,OAAO,CACL,cACE,GAAG,EAAE,YAAY,eACP,kBAAkB,mBACb,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,EACrD,SAAS,EAAE,EAAE,CAAC,yBAAyB,EAAE,SAAS,CAAC,EACnD,KAAK,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE,GAAG,KAAK,EAAE,KAC1D,KAAK,YAER,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,GAClD,CACP,CAAC;AACJ,CAAC;AACD,eAAe,CAAC,WAAW,GAAG,iBAAiB,CAAC;AAEhD,OAAO,EAAE,eAAe,EAAE,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { CSSProperties, Ref, RefCallback } from "react";
|
|
2
|
+
/** A chart's `width` prop: pixels, or `"auto"` to fill (and follow) its container. */
|
|
3
|
+
export type ChartWidth = number | "auto";
|
|
4
|
+
/** Combines refs into one callback ref (React 19 cleanup semantics included). */
|
|
5
|
+
export declare function useMergedRefs<T>(...refs: ReadonlyArray<Ref<T> | undefined>): RefCallback<T>;
|
|
6
|
+
export interface ChartWidthResult<T extends HTMLElement> {
|
|
7
|
+
/** Attach to the chart's root element (merges the caller's `ref`). */
|
|
8
|
+
ref: RefCallback<T>;
|
|
9
|
+
/**
|
|
10
|
+
* The width to draw at, or `null` while an `"auto"` chart has not been
|
|
11
|
+
* measured yet: render the placeholder then.
|
|
12
|
+
*/
|
|
13
|
+
width: number | null;
|
|
14
|
+
isAuto: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Width styles for the root element: fixed pixels for a numeric width; for
|
|
17
|
+
* `"auto"`, the container's full width with `contain: inline-size`, so the
|
|
18
|
+
* drawing inside never props its container open and the chart can shrink.
|
|
19
|
+
* The chart sets its own height.
|
|
20
|
+
*/
|
|
21
|
+
rootStyle: CSSProperties;
|
|
22
|
+
/** Classes that make an `"auto"` root a full-width block (merge after the variants). */
|
|
23
|
+
rootClassName: string | undefined;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Resolves a chart's `width` prop. A number (or `undefined`, meaning the
|
|
27
|
+
* size preset's `defaultWidth`) is used as-is; `"auto"` measures the root
|
|
28
|
+
* element and follows it on resize.
|
|
29
|
+
*/
|
|
30
|
+
export declare function useChartWidth<T extends HTMLElement = HTMLDivElement>(width: ChartWidth | undefined, defaultWidth: number, ref?: Ref<T>): ChartWidthResult<T>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback } from "react";
|
|
3
|
+
import { useMeasuredWidth } from "../../hooks/use-measured-width";
|
|
4
|
+
/** Combines refs into one callback ref (React 19 cleanup semantics included). */
|
|
5
|
+
export function useMergedRefs(...refs) {
|
|
6
|
+
return useCallback((node) => {
|
|
7
|
+
const cleanups = [];
|
|
8
|
+
for (const ref of refs) {
|
|
9
|
+
if (typeof ref === "function") {
|
|
10
|
+
const cleanup = ref(node);
|
|
11
|
+
cleanups.push(typeof cleanup === "function" ? cleanup : () => void ref(null));
|
|
12
|
+
}
|
|
13
|
+
else if (ref) {
|
|
14
|
+
ref.current = node;
|
|
15
|
+
cleanups.push(() => {
|
|
16
|
+
ref.current = null;
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return () => {
|
|
21
|
+
for (const cleanup of cleanups)
|
|
22
|
+
cleanup();
|
|
23
|
+
};
|
|
24
|
+
},
|
|
25
|
+
// The refs themselves are the dependencies.
|
|
26
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
27
|
+
refs);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Resolves a chart's `width` prop. A number (or `undefined`, meaning the
|
|
31
|
+
* size preset's `defaultWidth`) is used as-is; `"auto"` measures the root
|
|
32
|
+
* element and follows it on resize.
|
|
33
|
+
*/
|
|
34
|
+
export function useChartWidth(width, defaultWidth, ref) {
|
|
35
|
+
const isAuto = width === "auto";
|
|
36
|
+
const measured = useMeasuredWidth();
|
|
37
|
+
const rootRef = useMergedRefs(ref, isAuto ? measured.ref : undefined);
|
|
38
|
+
if (!isAuto) {
|
|
39
|
+
const resolved = typeof width === "number" ? width : defaultWidth;
|
|
40
|
+
return {
|
|
41
|
+
ref: rootRef,
|
|
42
|
+
width: resolved,
|
|
43
|
+
isAuto,
|
|
44
|
+
rootStyle: { width: resolved },
|
|
45
|
+
rootClassName: undefined,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
ref: rootRef,
|
|
50
|
+
width: measured.isMeasured ? measured.width : null,
|
|
51
|
+
isAuto,
|
|
52
|
+
rootStyle: { width: "100%", contain: "inline-size" },
|
|
53
|
+
rootClassName: "flex w-full min-w-0 shrink",
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=use-chart-width.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-chart-width.js","sourceRoot":"","sources":["../../../../src/components/ui/chart-primitives/use-chart-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,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,CAClC,CAAC;IAEF,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,QAAQ,GAAW,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,YAAY,CAAC;QAC1E,OAAO;YACL,GAAG,EAAE,OAAO;YACZ,KAAK,EAAE,QAAQ;YACf,MAAM;YACN,SAAS,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE;YAC9B,aAAa,EAAE,SAAS;SACzB,CAAC;IACJ,CAAC;IACD,OAAO;QACL,GAAG,EAAE,OAAO;QACZ,KAAK,EAAE,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI;QAClD,MAAM;QACN,SAAS,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,aAAa,EAAE;QACpD,aAAa,EAAE,4BAA4B;KAC5C,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Framework-free binning for `Histogram`: turns raw values into adjacent
|
|
3
|
+
* buckets with round edges.
|
|
4
|
+
*/
|
|
5
|
+
/** One histogram bar: the values in `[lower, upper)`. */
|
|
6
|
+
export interface HistogramBucket {
|
|
7
|
+
/** Inclusive lower edge. */
|
|
8
|
+
lower: number;
|
|
9
|
+
/** Exclusive upper edge, or `null` for an open-ended overflow bucket. */
|
|
10
|
+
upper: number | null;
|
|
11
|
+
count: number;
|
|
12
|
+
}
|
|
13
|
+
export declare const histogramScaleIds: ["linear", "log"];
|
|
14
|
+
export type HistogramScaleId = (typeof histogramScaleIds)[number];
|
|
15
|
+
export interface BinValuesOptions {
|
|
16
|
+
/**
|
|
17
|
+
* `"linear"` (default): equal-width bins of a nice width (1, 2 or 5 ×
|
|
18
|
+
* 10^k). `"log"`: edges at 0, 1, 2, 5, 10, 20, 50 … up past the largest
|
|
19
|
+
* value, for data spread over orders of magnitude.
|
|
20
|
+
*/
|
|
21
|
+
scale?: HistogramScaleId;
|
|
22
|
+
/**
|
|
23
|
+
* The data's resolution: no bin is narrower than this, and log edges start
|
|
24
|
+
* no lower. Pass `1` for whole-number data (milliseconds, counts) so there
|
|
25
|
+
* are no bins with nothing in them by construction. Defaults to `0`.
|
|
26
|
+
*/
|
|
27
|
+
minBinWidth?: number;
|
|
28
|
+
/**
|
|
29
|
+
* Linear only: fold values past the 95th percentile into one open-ended
|
|
30
|
+
* overflow bucket when the largest value is more than twice the p95 (and
|
|
31
|
+
* there are at least 20 values), so a long tail doesn't flatten the rest.
|
|
32
|
+
* Defaults to `true`.
|
|
33
|
+
*/
|
|
34
|
+
foldTail?: boolean;
|
|
35
|
+
/** Linear only: fewest bins to aim for. Defaults to `8`. */
|
|
36
|
+
minBins?: number;
|
|
37
|
+
/** Linear only: most bins to aim for. Defaults to `40`. */
|
|
38
|
+
maxBins?: number;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Bins `values` for a `Histogram`. Every finite value lands in exactly one
|
|
42
|
+
* bucket (the counts sum to the number of finite values; `NaN` and
|
|
43
|
+
* infinities are skipped). Empty buckets at either end are trimmed; empty
|
|
44
|
+
* buckets inside the range stay, so gaps show.
|
|
45
|
+
*
|
|
46
|
+
* - linear: bins of a nice width starting at the smallest value, about √n of
|
|
47
|
+
* them (8–40). A long tail past twice the p95 folds into one overflow
|
|
48
|
+
* bucket (`upper: null`).
|
|
49
|
+
* - log: edges at 0, 1, 2, 5, 10 … (scaled to the data's smallest decade),
|
|
50
|
+
* up past the largest value. Values at or below 0 count in the first
|
|
51
|
+
* bucket.
|
|
52
|
+
*/
|
|
53
|
+
export declare function binValues(values: readonly number[], options?: BinValuesOptions): HistogramBucket[];
|