panelui-native 0.22.5 → 0.25.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 +8 -3
- package/lib/module/components/area-chart/index.js +826 -0
- package/lib/module/components/area-chart/index.js.map +1 -0
- package/lib/module/components/avatar/index.js +1 -1
- package/lib/module/components/avatar/index.js.map +1 -1
- package/lib/module/components/bar-chart/index.js +853 -0
- package/lib/module/components/bar-chart/index.js.map +1 -0
- package/lib/module/components/bottom-sheet/index.js +207 -23
- package/lib/module/components/bottom-sheet/index.js.map +1 -1
- package/lib/module/components/breadcrumb/index.js +275 -0
- package/lib/module/components/breadcrumb/index.js.map +1 -0
- package/lib/module/components/chip/index.js +2 -2
- package/lib/module/components/direction/index.js +13 -19
- package/lib/module/components/direction/index.js.map +1 -1
- package/lib/module/components/frame/index.js +17 -0
- package/lib/module/components/frame/index.js.map +1 -1
- package/lib/module/components/heatmap-chart/index.js +28 -8
- package/lib/module/components/heatmap-chart/index.js.map +1 -1
- package/lib/module/components/input-group/index.js +2 -2
- package/lib/module/components/input-group/index.js.map +1 -1
- package/lib/module/components/line-chart/index.js +4 -146
- package/lib/module/components/line-chart/index.js.map +1 -1
- package/lib/module/components/loader/index.js +758 -0
- package/lib/module/components/loader/index.js.map +1 -0
- package/lib/module/components/map/basemap.js +265 -0
- package/lib/module/components/map/basemap.js.map +1 -0
- package/lib/module/components/map/index.js +850 -0
- package/lib/module/components/map/index.js.map +1 -0
- package/lib/module/components/map/maplibre.js +87 -0
- package/lib/module/components/map/maplibre.js.map +1 -0
- package/lib/module/components/message/index.js +8 -7
- package/lib/module/components/message/index.js.map +1 -1
- package/lib/module/components/otp-input/index.js +2 -2
- package/lib/module/components/progress/index.js +8 -2
- package/lib/module/components/progress/index.js.map +1 -1
- package/lib/module/components/ring-chart/index.js +423 -0
- package/lib/module/components/ring-chart/index.js.map +1 -0
- package/lib/module/components/section-rail/index.js +2 -2
- package/lib/module/components/separator/index.js +76 -22
- package/lib/module/components/separator/index.js.map +1 -1
- package/lib/module/components/shimmer/index.js +10 -1
- package/lib/module/components/shimmer/index.js.map +1 -1
- package/lib/module/components/slider/index.js +19 -5
- package/lib/module/components/slider/index.js.map +1 -1
- package/lib/module/components/steps/index.js +1 -1
- package/lib/module/components/switch/index.js +6 -1
- package/lib/module/components/switch/index.js.map +1 -1
- package/lib/module/components/typography/index.js +5 -0
- package/lib/module/components/typography/index.js.map +1 -1
- package/lib/module/hooks/use-direction.js +43 -0
- package/lib/module/hooks/use-direction.js.map +1 -0
- package/lib/module/icons/index.js +117 -2
- package/lib/module/icons/index.js.map +1 -1
- package/lib/module/index.js +8 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/primitives/text.js +30 -10
- package/lib/module/primitives/text.js.map +1 -1
- package/lib/module/utils/chart.js +279 -0
- package/lib/module/utils/chart.js.map +1 -0
- package/lib/typescript/src/components/area-chart/index.d.ts +197 -0
- package/lib/typescript/src/components/area-chart/index.d.ts.map +1 -0
- package/lib/typescript/src/components/bar-chart/index.d.ts +228 -0
- package/lib/typescript/src/components/bar-chart/index.d.ts.map +1 -0
- package/lib/typescript/src/components/bottom-sheet/index.d.ts +75 -4
- package/lib/typescript/src/components/bottom-sheet/index.d.ts.map +1 -1
- package/lib/typescript/src/components/breadcrumb/index.d.ts +100 -0
- package/lib/typescript/src/components/breadcrumb/index.d.ts.map +1 -0
- package/lib/typescript/src/components/direction/index.d.ts +11 -10
- package/lib/typescript/src/components/direction/index.d.ts.map +1 -1
- package/lib/typescript/src/components/frame/index.d.ts +17 -0
- package/lib/typescript/src/components/frame/index.d.ts.map +1 -1
- package/lib/typescript/src/components/heatmap-chart/index.d.ts +22 -3
- package/lib/typescript/src/components/heatmap-chart/index.d.ts.map +1 -1
- package/lib/typescript/src/components/line-chart/index.d.ts +1 -0
- package/lib/typescript/src/components/line-chart/index.d.ts.map +1 -1
- package/lib/typescript/src/components/loader/index.d.ts +38 -0
- package/lib/typescript/src/components/loader/index.d.ts.map +1 -0
- package/lib/typescript/src/components/map/basemap.d.ts +76 -0
- package/lib/typescript/src/components/map/basemap.d.ts.map +1 -0
- package/lib/typescript/src/components/map/index.d.ts +367 -0
- package/lib/typescript/src/components/map/index.d.ts.map +1 -0
- package/lib/typescript/src/components/map/maplibre.d.ts +193 -0
- package/lib/typescript/src/components/map/maplibre.d.ts.map +1 -0
- package/lib/typescript/src/components/message/index.d.ts.map +1 -1
- package/lib/typescript/src/components/progress/index.d.ts.map +1 -1
- package/lib/typescript/src/components/ring-chart/index.d.ts +156 -0
- package/lib/typescript/src/components/ring-chart/index.d.ts.map +1 -0
- package/lib/typescript/src/components/separator/index.d.ts +36 -1
- package/lib/typescript/src/components/separator/index.d.ts.map +1 -1
- package/lib/typescript/src/components/shimmer/index.d.ts.map +1 -1
- package/lib/typescript/src/components/slider/index.d.ts.map +1 -1
- package/lib/typescript/src/components/switch/index.d.ts.map +1 -1
- package/lib/typescript/src/components/typography/index.d.ts +6 -0
- package/lib/typescript/src/components/typography/index.d.ts.map +1 -1
- package/lib/typescript/src/hooks/use-direction.d.ts +20 -0
- package/lib/typescript/src/hooks/use-direction.d.ts.map +1 -0
- package/lib/typescript/src/icons/index.d.ts +5 -0
- package/lib/typescript/src/icons/index.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +9 -3
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/primitives/text.d.ts.map +1 -1
- package/lib/typescript/src/utils/chart.d.ts +96 -0
- package/lib/typescript/src/utils/chart.d.ts.map +1 -0
- package/package.json +9 -1
- package/src/components/area-chart/index.tsx +994 -0
- package/src/components/avatar/index.tsx +1 -1
- package/src/components/bar-chart/index.tsx +1048 -0
- package/src/components/bottom-sheet/index.tsx +280 -20
- package/src/components/breadcrumb/index.tsx +365 -0
- package/src/components/chip/index.tsx +2 -2
- package/src/components/direction/index.tsx +20 -21
- package/src/components/frame/index.tsx +17 -0
- package/src/components/heatmap-chart/index.tsx +58 -11
- package/src/components/input-group/index.tsx +2 -2
- package/src/components/line-chart/index.tsx +13 -181
- package/src/components/loader/index.tsx +812 -0
- package/src/components/map/basemap.ts +304 -0
- package/src/components/map/index.tsx +1118 -0
- package/src/components/map/maplibre.ts +201 -0
- package/src/components/message/index.tsx +8 -7
- package/src/components/otp-input/index.tsx +2 -2
- package/src/components/progress/index.tsx +10 -2
- package/src/components/ring-chart/index.tsx +543 -0
- package/src/components/section-rail/index.tsx +2 -2
- package/src/components/separator/index.tsx +77 -19
- package/src/components/shimmer/index.tsx +10 -1
- package/src/components/slider/index.tsx +20 -5
- package/src/components/steps/index.tsx +1 -1
- package/src/components/switch/index.tsx +6 -1
- package/src/components/typography/index.tsx +5 -0
- package/src/hooks/use-direction.ts +45 -0
- package/src/icons/index.tsx +66 -0
- package/src/index.ts +84 -0
- package/src/primitives/text.tsx +25 -7
- package/src/utils/chart.ts +355 -0
|
@@ -0,0 +1,826 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* AreaChart — filled bands over time, stacked or overlaid.
|
|
5
|
+
*
|
|
6
|
+
* ```tsx
|
|
7
|
+
* <AreaChart data={traffic} xDataKey="date" stacked>
|
|
8
|
+
* <AreaChart.Grid />
|
|
9
|
+
* <AreaChart.Area dataKey="direct" />
|
|
10
|
+
* <AreaChart.Area dataKey="search" colorIndex={2} />
|
|
11
|
+
* <AreaChart.XAxis />
|
|
12
|
+
* <AreaChart.Tooltip />
|
|
13
|
+
* </AreaChart>
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* ## Why this is not `LineChart.Area`
|
|
17
|
+
*
|
|
18
|
+
* `LineChart.Area` shades under a line, which is one series saying "this is
|
|
19
|
+
* the shape of the thing". This chart answers a different question — *what is
|
|
20
|
+
* it made of* — and that needs stacking: each band sits on the running total
|
|
21
|
+
* of the ones below it, so the top edge is the whole and the thickness of each
|
|
22
|
+
* band is its share.
|
|
23
|
+
*
|
|
24
|
+
* Stacking is not a flag that could be bolted on. It changes the y-domain from
|
|
25
|
+
* the largest single series to the largest *sum*, it makes each area's
|
|
26
|
+
* baseline a curve rather than the axis, and it makes the order the series are
|
|
27
|
+
* declared in load-bearing. A chart where all of that is true of some children
|
|
28
|
+
* and not others is a chart nobody can read, so it is a chart of its own.
|
|
29
|
+
*
|
|
30
|
+
* Unstacked, the bands overlay each other and the fills are drawn translucent,
|
|
31
|
+
* which is the right reading when the series are alternatives rather than
|
|
32
|
+
* parts — two plans compared, not two slices of one total.
|
|
33
|
+
*/
|
|
34
|
+
import { Children, createContext, forwardRef, isValidElement, useContext, useEffect, useId, useImperativeHandle, useMemo, useRef, useState } from 'react';
|
|
35
|
+
import { StyleSheet, View } from 'react-native';
|
|
36
|
+
import { Gesture, GestureDetector } from 'react-native-gesture-handler';
|
|
37
|
+
import Animated, { Easing, runOnJS, useAnimatedProps, useAnimatedStyle, useReducedMotion, useSharedValue, withTiming } from 'react-native-reanimated';
|
|
38
|
+
import Svg, { Circle, ClipPath, Defs, G, Line as SvgLine, LinearGradient, Path, Rect, Stop } from 'react-native-svg';
|
|
39
|
+
import { useCSSVariable } from 'uniwind';
|
|
40
|
+
import { Text } from "../../primitives/text.js";
|
|
41
|
+
import { areaPath, columnValues, compactNumber, linePath, useSeriesColor, xOf, yOf } from "../../utils/chart.js";
|
|
42
|
+
import { cn } from "../../utils/cn.js";
|
|
43
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
44
|
+
const AnimatedPath = Animated.createAnimatedComponent(Path);
|
|
45
|
+
const AnimatedRect = Animated.createAnimatedComponent(Rect);
|
|
46
|
+
const AnimatedCircle = Animated.createAnimatedComponent(Circle);
|
|
47
|
+
const PADDING = {
|
|
48
|
+
top: 12,
|
|
49
|
+
right: 10,
|
|
50
|
+
bottom: 22,
|
|
51
|
+
left: 10
|
|
52
|
+
};
|
|
53
|
+
const LABEL_WIDTH = 132;
|
|
54
|
+
const DOT = 9;
|
|
55
|
+
|
|
56
|
+
/** Left gutter reserved when a `YAxis` is present, for its labels to sit in. */
|
|
57
|
+
const Y_AXIS_WIDTH = 40;
|
|
58
|
+
const AreaChartContext = /*#__PURE__*/createContext(null);
|
|
59
|
+
function useChart(component) {
|
|
60
|
+
const context = useContext(AreaChartContext);
|
|
61
|
+
if (!context) {
|
|
62
|
+
throw new Error(`${component} must be used within an <AreaChart>`);
|
|
63
|
+
}
|
|
64
|
+
return context;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* The point under the crosshair, for something rendered *inside* the chart.
|
|
69
|
+
* A readout in the card's header is outside this provider — use
|
|
70
|
+
* `onActiveIndexChange` for that.
|
|
71
|
+
*/
|
|
72
|
+
export function useAreaChart() {
|
|
73
|
+
const {
|
|
74
|
+
data,
|
|
75
|
+
activeIndexJS,
|
|
76
|
+
xDataKey
|
|
77
|
+
} = useChart('useAreaChart');
|
|
78
|
+
return {
|
|
79
|
+
activeIndex: activeIndexJS,
|
|
80
|
+
activePoint: activeIndexJS >= 0 ? data[activeIndexJS] ?? null : null,
|
|
81
|
+
xDataKey
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Imperative handle: re-run the reveal on demand, for a "replay" control. */
|
|
86
|
+
|
|
87
|
+
function ChildSlot({
|
|
88
|
+
children
|
|
89
|
+
}) {
|
|
90
|
+
return /*#__PURE__*/_jsx(_Fragment, {
|
|
91
|
+
children: children
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
function partition(children) {
|
|
95
|
+
const svg = [];
|
|
96
|
+
const overlay = [];
|
|
97
|
+
Children.forEach(children, (child, index) => {
|
|
98
|
+
if (! /*#__PURE__*/isValidElement(child)) return;
|
|
99
|
+
const layer = child.type.layer ?? 'svg';
|
|
100
|
+
const slot = /*#__PURE__*/_jsx(ChildSlot, {
|
|
101
|
+
children: child
|
|
102
|
+
}, index);
|
|
103
|
+
(layer === 'overlay' ? overlay : svg).push(slot);
|
|
104
|
+
});
|
|
105
|
+
return {
|
|
106
|
+
svg,
|
|
107
|
+
overlay
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
const AreaChartRoot = /*#__PURE__*/forwardRef(function AreaChartRoot({
|
|
111
|
+
className,
|
|
112
|
+
data,
|
|
113
|
+
xDataKey = 'date',
|
|
114
|
+
status = 'ready',
|
|
115
|
+
aspectRatio = 2,
|
|
116
|
+
animationDuration = 1100,
|
|
117
|
+
domainDuration = 500,
|
|
118
|
+
yDomain,
|
|
119
|
+
stacked = false,
|
|
120
|
+
curve = 'monotone',
|
|
121
|
+
onActiveIndexChange,
|
|
122
|
+
compact = false,
|
|
123
|
+
children,
|
|
124
|
+
...props
|
|
125
|
+
}, ref) {
|
|
126
|
+
const [size, setSize] = useState({
|
|
127
|
+
width: 0,
|
|
128
|
+
height: 0
|
|
129
|
+
});
|
|
130
|
+
const [series, setSeries] = useState([]);
|
|
131
|
+
const [activeIndexJS, setActiveIndexJS] = useState(-1);
|
|
132
|
+
const clipId = `panelui-area-clip-${useId().replace(/[^a-zA-Z0-9]/g, '')}`;
|
|
133
|
+
const reveal = useSharedValue(0);
|
|
134
|
+
const domainMin = useSharedValue(0);
|
|
135
|
+
const domainMax = useSharedValue(0);
|
|
136
|
+
const activeIndex = useSharedValue(-1);
|
|
137
|
+
const reducedMotion = useReducedMotion();
|
|
138
|
+
const registerSeries = useMemo(() => (key, color) => setSeries(current => {
|
|
139
|
+
const existing = current.find(([k]) => k === key);
|
|
140
|
+
if (existing?.[1] === color) return current;
|
|
141
|
+
return [...current.filter(([k]) => k !== key), [key, color]];
|
|
142
|
+
}), []);
|
|
143
|
+
const unregisterSeries = useMemo(() => key => setSeries(current => current.filter(([k]) => k !== key)), []);
|
|
144
|
+
|
|
145
|
+
/*
|
|
146
|
+
* Whether an axis is asking for room. It has to be known before the plot is
|
|
147
|
+
* laid out, and only the root sees the children early enough to ask — the
|
|
148
|
+
* axis itself renders into a box that has already been decided.
|
|
149
|
+
*/
|
|
150
|
+
const hasYAxis = useMemo(() => {
|
|
151
|
+
let found = false;
|
|
152
|
+
Children.forEach(children, child => {
|
|
153
|
+
if (/*#__PURE__*/isValidElement(child) && child.type.axis === 'y') {
|
|
154
|
+
found = true;
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
return found;
|
|
158
|
+
}, [children]);
|
|
159
|
+
const pad = compact ? {
|
|
160
|
+
top: 2,
|
|
161
|
+
right: 1,
|
|
162
|
+
bottom: 2,
|
|
163
|
+
left: 1
|
|
164
|
+
} : {
|
|
165
|
+
...PADDING,
|
|
166
|
+
left: hasYAxis ? Y_AXIS_WIDTH : PADDING.left
|
|
167
|
+
};
|
|
168
|
+
const plot = {
|
|
169
|
+
left: pad.left,
|
|
170
|
+
top: pad.top,
|
|
171
|
+
width: Math.max(size.width - pad.left - pad.right, 0),
|
|
172
|
+
height: Math.max(size.height - pad.top - pad.bottom, 0)
|
|
173
|
+
};
|
|
174
|
+
const seriesKeys = series.map(([key]) => key).join('|');
|
|
175
|
+
const extent = useMemo(() => {
|
|
176
|
+
if (yDomain) return yDomain;
|
|
177
|
+
const keys = seriesKeys ? seriesKeys.split('|') : [];
|
|
178
|
+
let min = Infinity;
|
|
179
|
+
let max = -Infinity;
|
|
180
|
+
for (const row of data) {
|
|
181
|
+
/*
|
|
182
|
+
* Stacked, the tall thing is the sum of the row; overlaid, it is the
|
|
183
|
+
* largest single value in it. Reading the same number for both crops a
|
|
184
|
+
* stack at its largest band and clips everything above it.
|
|
185
|
+
*/
|
|
186
|
+
let rowTotal = 0;
|
|
187
|
+
for (const key of keys) {
|
|
188
|
+
const value = row[key];
|
|
189
|
+
if (typeof value !== 'number' || Number.isNaN(value)) continue;
|
|
190
|
+
if (stacked) {
|
|
191
|
+
rowTotal += value;
|
|
192
|
+
} else {
|
|
193
|
+
if (value < min) min = value;
|
|
194
|
+
if (value > max) max = value;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
if (stacked) {
|
|
198
|
+
if (rowTotal < min) min = rowTotal;
|
|
199
|
+
if (rowTotal > max) max = rowTotal;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
if (min === Infinity) return [0, 1];
|
|
203
|
+
if (min === max) return [min - 1, max + 1];
|
|
204
|
+
/*
|
|
205
|
+
* An area is a filled region, and a region floating above the bottom of
|
|
206
|
+
* the plot reads as a shape rather than as a quantity — so a series that
|
|
207
|
+
* never goes below zero is drawn from zero. Padding only the top.
|
|
208
|
+
*/
|
|
209
|
+
const floor = min >= 0 ? 0 : min - (max - min) * 0.1;
|
|
210
|
+
return [floor, max + (max - min) * 0.1];
|
|
211
|
+
}, [data, yDomain, seriesKeys, stacked]);
|
|
212
|
+
const loading = status === 'loading';
|
|
213
|
+
useEffect(() => {
|
|
214
|
+
if (loading) return;
|
|
215
|
+
const [min, max] = extent;
|
|
216
|
+
const first = domainMin.value === 0 && domainMax.value === 0;
|
|
217
|
+
if (first || reducedMotion) {
|
|
218
|
+
domainMin.value = min;
|
|
219
|
+
domainMax.value = max;
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
domainMin.value = withTiming(min, {
|
|
223
|
+
duration: domainDuration
|
|
224
|
+
});
|
|
225
|
+
domainMax.value = withTiming(max, {
|
|
226
|
+
duration: domainDuration
|
|
227
|
+
});
|
|
228
|
+
}, [extent, loading, reducedMotion, domainDuration, domainMin, domainMax]);
|
|
229
|
+
const revealed = useRef(false);
|
|
230
|
+
const playReveal = useMemo(() => () => {
|
|
231
|
+
if (reducedMotion) {
|
|
232
|
+
reveal.value = 1;
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
reveal.value = 0;
|
|
236
|
+
reveal.value = withTiming(1, {
|
|
237
|
+
duration: animationDuration,
|
|
238
|
+
easing: Easing.bezier(0.85, 0, 0.15, 1)
|
|
239
|
+
});
|
|
240
|
+
}, [reducedMotion, animationDuration, reveal]);
|
|
241
|
+
useEffect(() => {
|
|
242
|
+
if (revealed.current || loading || plot.width <= 0 || !data.length) return;
|
|
243
|
+
revealed.current = true;
|
|
244
|
+
playReveal();
|
|
245
|
+
}, [loading, plot.width, data.length, playReveal]);
|
|
246
|
+
useImperativeHandle(ref, () => ({
|
|
247
|
+
replay: playReveal
|
|
248
|
+
}), [playReveal]);
|
|
249
|
+
const clipProps = useAnimatedProps(() => ({
|
|
250
|
+
width: plot.width * reveal.value
|
|
251
|
+
}));
|
|
252
|
+
const handleActiveIndex = useMemo(() => index => {
|
|
253
|
+
setActiveIndexJS(index);
|
|
254
|
+
onActiveIndexChange?.(index, index >= 0 ? data[index] ?? null : null);
|
|
255
|
+
}, [onActiveIndexChange, data]);
|
|
256
|
+
const onLayout = event => {
|
|
257
|
+
const {
|
|
258
|
+
width,
|
|
259
|
+
height
|
|
260
|
+
} = event.nativeEvent.layout;
|
|
261
|
+
setSize(current => Math.abs(current.width - width) < 1 && Math.abs(current.height - height) < 1 ? current : {
|
|
262
|
+
width,
|
|
263
|
+
height
|
|
264
|
+
});
|
|
265
|
+
props.onLayout?.(event);
|
|
266
|
+
};
|
|
267
|
+
const context = useMemo(() => ({
|
|
268
|
+
data,
|
|
269
|
+
xDataKey,
|
|
270
|
+
plot,
|
|
271
|
+
status,
|
|
272
|
+
curve,
|
|
273
|
+
stacked,
|
|
274
|
+
series,
|
|
275
|
+
registerSeries,
|
|
276
|
+
unregisterSeries,
|
|
277
|
+
domainMin,
|
|
278
|
+
domainMax,
|
|
279
|
+
extent,
|
|
280
|
+
activeIndex,
|
|
281
|
+
activeIndexJS,
|
|
282
|
+
setActiveIndexJS: handleActiveIndex,
|
|
283
|
+
clipId
|
|
284
|
+
}),
|
|
285
|
+
// `plot` is rebuilt every render from `size`, so it is compared by value.
|
|
286
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
287
|
+
[data, xDataKey, plot.width, plot.height, plot.left, plot.top, status, curve, stacked, series, registerSeries, unregisterSeries, domainMin, domainMax, extent, activeIndex, activeIndexJS, handleActiveIndex, clipId]);
|
|
288
|
+
const {
|
|
289
|
+
svg,
|
|
290
|
+
overlay
|
|
291
|
+
} = partition(children);
|
|
292
|
+
return /*#__PURE__*/_jsx(AreaChartContext.Provider, {
|
|
293
|
+
value: context,
|
|
294
|
+
children: /*#__PURE__*/_jsx(View, {
|
|
295
|
+
...props,
|
|
296
|
+
onLayout: onLayout,
|
|
297
|
+
style: [{
|
|
298
|
+
aspectRatio
|
|
299
|
+
}, props.style],
|
|
300
|
+
className: cn('w-full', className),
|
|
301
|
+
children: plot.width > 0 ? /*#__PURE__*/_jsxs(_Fragment, {
|
|
302
|
+
children: [/*#__PURE__*/_jsxs(Svg, {
|
|
303
|
+
width: "100%",
|
|
304
|
+
height: "100%",
|
|
305
|
+
style: StyleSheet.absoluteFill,
|
|
306
|
+
children: [/*#__PURE__*/_jsx(Defs, {
|
|
307
|
+
children: /*#__PURE__*/_jsx(ClipPath, {
|
|
308
|
+
id: clipId,
|
|
309
|
+
children: /*#__PURE__*/_jsx(AnimatedRect, {
|
|
310
|
+
x: plot.left,
|
|
311
|
+
y: 0,
|
|
312
|
+
height: size.height,
|
|
313
|
+
animatedProps: clipProps
|
|
314
|
+
})
|
|
315
|
+
})
|
|
316
|
+
}), svg]
|
|
317
|
+
}), overlay]
|
|
318
|
+
}) : null
|
|
319
|
+
})
|
|
320
|
+
});
|
|
321
|
+
});
|
|
322
|
+
AreaChartRoot.displayName = 'AreaChart';
|
|
323
|
+
|
|
324
|
+
/* -------------------------------------------------------------------------- */
|
|
325
|
+
/* SVG layer */
|
|
326
|
+
/* -------------------------------------------------------------------------- */
|
|
327
|
+
|
|
328
|
+
/** Horizontal rules, so a band can be read against a number. */
|
|
329
|
+
function AreaChartGrid({
|
|
330
|
+
rows = 4,
|
|
331
|
+
color,
|
|
332
|
+
dashArray = '4,6',
|
|
333
|
+
opacity = 1
|
|
334
|
+
}) {
|
|
335
|
+
const {
|
|
336
|
+
plot
|
|
337
|
+
} = useChart('AreaChart.Grid');
|
|
338
|
+
const token = useCSSVariable('--color-border');
|
|
339
|
+
const stroke = color ?? (typeof token === 'string' ? token : 'rgba(0,0,0,0.1)');
|
|
340
|
+
return /*#__PURE__*/_jsx(G, {
|
|
341
|
+
opacity: opacity,
|
|
342
|
+
children: Array.from({
|
|
343
|
+
length: rows + 1
|
|
344
|
+
}, (_unused, index) => index / rows).map(fraction => /*#__PURE__*/_jsx(SvgLine, {
|
|
345
|
+
x1: plot.left,
|
|
346
|
+
x2: plot.left + plot.width,
|
|
347
|
+
y1: plot.top + plot.height * fraction,
|
|
348
|
+
y2: plot.top + plot.height * fraction,
|
|
349
|
+
stroke: stroke,
|
|
350
|
+
strokeDasharray: dashArray,
|
|
351
|
+
strokeWidth: 1
|
|
352
|
+
}, fraction))
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
AreaChartGrid.displayName = 'AreaChart.Grid';
|
|
356
|
+
AreaChartGrid.layer = 'svg';
|
|
357
|
+
/**
|
|
358
|
+
* One filled band.
|
|
359
|
+
*
|
|
360
|
+
* The fill is a gradient by default rather than a flat wash, because a flat
|
|
361
|
+
* fill of any weight competes with the line on top of it — fading it downward
|
|
362
|
+
* keeps the top edge, which is the part carrying the numbers, the darkest
|
|
363
|
+
* thing in the band.
|
|
364
|
+
*/
|
|
365
|
+
function AreaChartArea({
|
|
366
|
+
dataKey,
|
|
367
|
+
color,
|
|
368
|
+
colorIndex = 1,
|
|
369
|
+
fillOpacity,
|
|
370
|
+
gradientToOpacity = 0,
|
|
371
|
+
showLine = true,
|
|
372
|
+
strokeWidth = 2
|
|
373
|
+
}) {
|
|
374
|
+
const {
|
|
375
|
+
data,
|
|
376
|
+
plot,
|
|
377
|
+
status,
|
|
378
|
+
curve,
|
|
379
|
+
stacked,
|
|
380
|
+
series,
|
|
381
|
+
registerSeries,
|
|
382
|
+
unregisterSeries,
|
|
383
|
+
domainMin,
|
|
384
|
+
domainMax,
|
|
385
|
+
clipId
|
|
386
|
+
} = useChart('AreaChart.Area');
|
|
387
|
+
const stroke = useSeriesColor(color, colorIndex);
|
|
388
|
+
const gradientId = `panelui-area-fill-${useId().replace(/[^a-zA-Z0-9]/g, '')}`;
|
|
389
|
+
|
|
390
|
+
// Stacked bands touch, so a translucent one shows the band beneath through
|
|
391
|
+
// it and the two read as a third colour. Overlaid they must be translucent,
|
|
392
|
+
// because the one in front would otherwise hide the ones behind entirely.
|
|
393
|
+
const topOpacity = fillOpacity ?? (stacked ? 0.85 : 0.35);
|
|
394
|
+
useEffect(() => {
|
|
395
|
+
registerSeries(dataKey, stroke);
|
|
396
|
+
return () => unregisterSeries(dataKey);
|
|
397
|
+
}, [dataKey, stroke, registerSeries, unregisterSeries]);
|
|
398
|
+
const values = useMemo(() => columnValues(data, dataKey), [data, dataKey]);
|
|
399
|
+
|
|
400
|
+
/*
|
|
401
|
+
* The running total of the series declared below this one, which is what
|
|
402
|
+
* this band sits on. Registration order is declaration order, so the first
|
|
403
|
+
* `Area` child is the bottom of the stack.
|
|
404
|
+
*/
|
|
405
|
+
const baselines = useMemo(() => {
|
|
406
|
+
if (!stacked) return undefined;
|
|
407
|
+
const below = series.slice(0, series.findIndex(([key]) => key === dataKey));
|
|
408
|
+
if (!below.length) return undefined;
|
|
409
|
+
return data.map(row => {
|
|
410
|
+
let total = 0;
|
|
411
|
+
for (const [key] of below) {
|
|
412
|
+
const value = row[key];
|
|
413
|
+
if (typeof value === 'number' && !Number.isNaN(value)) total += value;
|
|
414
|
+
}
|
|
415
|
+
return total;
|
|
416
|
+
});
|
|
417
|
+
}, [stacked, series, dataKey, data]);
|
|
418
|
+
const loading = status === 'loading';
|
|
419
|
+
const fillProps = useAnimatedProps(() => ({
|
|
420
|
+
d: areaPath(values, plot, domainMin.value, domainMax.value, curve, loading, baselines)
|
|
421
|
+
}));
|
|
422
|
+
const lineProps = useAnimatedProps(() => ({
|
|
423
|
+
d: linePath(values, plot, domainMin.value, domainMax.value, curve, loading, baselines)
|
|
424
|
+
}));
|
|
425
|
+
return /*#__PURE__*/_jsxs(G, {
|
|
426
|
+
clipPath: `url(#${clipId})`,
|
|
427
|
+
children: [/*#__PURE__*/_jsx(Defs, {
|
|
428
|
+
children: /*#__PURE__*/_jsxs(LinearGradient, {
|
|
429
|
+
id: gradientId,
|
|
430
|
+
x1: "0",
|
|
431
|
+
y1: "0",
|
|
432
|
+
x2: "0",
|
|
433
|
+
y2: "1",
|
|
434
|
+
children: [/*#__PURE__*/_jsx(Stop, {
|
|
435
|
+
offset: "0",
|
|
436
|
+
stopColor: stroke,
|
|
437
|
+
stopOpacity: topOpacity
|
|
438
|
+
}), /*#__PURE__*/_jsx(Stop, {
|
|
439
|
+
offset: "1",
|
|
440
|
+
stopColor: stroke,
|
|
441
|
+
stopOpacity: gradientToOpacity
|
|
442
|
+
})]
|
|
443
|
+
})
|
|
444
|
+
}), /*#__PURE__*/_jsx(AnimatedPath, {
|
|
445
|
+
animatedProps: fillProps,
|
|
446
|
+
fill: `url(#${gradientId})`
|
|
447
|
+
}), showLine ? /*#__PURE__*/_jsx(AnimatedPath, {
|
|
448
|
+
animatedProps: lineProps,
|
|
449
|
+
stroke: stroke,
|
|
450
|
+
strokeWidth: strokeWidth,
|
|
451
|
+
strokeLinecap: "round",
|
|
452
|
+
strokeLinejoin: "round",
|
|
453
|
+
fill: "none"
|
|
454
|
+
}) : null]
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
AreaChartArea.displayName = 'AreaChart.Area';
|
|
458
|
+
AreaChartArea.layer = 'svg';
|
|
459
|
+
|
|
460
|
+
/* -------------------------------------------------------------------------- */
|
|
461
|
+
/* Overlay layer */
|
|
462
|
+
/* -------------------------------------------------------------------------- */
|
|
463
|
+
|
|
464
|
+
/** The x labels. Real text, so they follow the theme's font and text scaling. */
|
|
465
|
+
function AreaChartXAxis({
|
|
466
|
+
ticks = 4,
|
|
467
|
+
format,
|
|
468
|
+
className
|
|
469
|
+
}) {
|
|
470
|
+
const {
|
|
471
|
+
data,
|
|
472
|
+
xDataKey,
|
|
473
|
+
plot
|
|
474
|
+
} = useChart('AreaChart.XAxis');
|
|
475
|
+
const labels = useMemo(() => {
|
|
476
|
+
if (!data.length) return [];
|
|
477
|
+
const count = Math.min(ticks, data.length);
|
|
478
|
+
const step = count > 1 ? (data.length - 1) / (count - 1) : 0;
|
|
479
|
+
return Array.from({
|
|
480
|
+
length: count
|
|
481
|
+
}, (_unused, index) => {
|
|
482
|
+
const dataIndex = Math.round(index * step);
|
|
483
|
+
const datum = data[dataIndex];
|
|
484
|
+
if (!datum) return null;
|
|
485
|
+
return {
|
|
486
|
+
key: dataIndex,
|
|
487
|
+
text: format ? format(datum, dataIndex) : String(datum[xDataKey] ?? '')
|
|
488
|
+
};
|
|
489
|
+
}).filter(label => label !== null);
|
|
490
|
+
}, [data, ticks, format, xDataKey]);
|
|
491
|
+
return /*#__PURE__*/_jsx(View, {
|
|
492
|
+
pointerEvents: "none",
|
|
493
|
+
style: {
|
|
494
|
+
position: 'absolute',
|
|
495
|
+
left: plot.left,
|
|
496
|
+
right: PADDING.right,
|
|
497
|
+
bottom: 0,
|
|
498
|
+
height: PADDING.bottom
|
|
499
|
+
},
|
|
500
|
+
className: cn('flex-row items-center justify-between', className),
|
|
501
|
+
children: labels.map(label => /*#__PURE__*/_jsx(Text, {
|
|
502
|
+
size: "xs",
|
|
503
|
+
muted: true,
|
|
504
|
+
children: label.text
|
|
505
|
+
}, label.key))
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
AreaChartXAxis.displayName = 'AreaChart.XAxis';
|
|
509
|
+
AreaChartXAxis.layer = 'overlay';
|
|
510
|
+
/** Value labels down the side, aligned to the grid lines. */
|
|
511
|
+
function AreaChartYAxis({
|
|
512
|
+
ticks = 4,
|
|
513
|
+
format,
|
|
514
|
+
className
|
|
515
|
+
}) {
|
|
516
|
+
const {
|
|
517
|
+
plot,
|
|
518
|
+
extent
|
|
519
|
+
} = useChart('AreaChart.YAxis');
|
|
520
|
+
const labels = useMemo(() => {
|
|
521
|
+
const [min, max] = extent;
|
|
522
|
+
if (min === 0 && max === 0) return [];
|
|
523
|
+
return Array.from({
|
|
524
|
+
length: ticks + 1
|
|
525
|
+
}, (_unused, index) => {
|
|
526
|
+
const value = max - (max - min) * index / ticks;
|
|
527
|
+
return {
|
|
528
|
+
key: index,
|
|
529
|
+
text: format ? format(value) : compactNumber(value)
|
|
530
|
+
};
|
|
531
|
+
});
|
|
532
|
+
}, [extent, ticks, format]);
|
|
533
|
+
return /*#__PURE__*/_jsx(View, {
|
|
534
|
+
pointerEvents: "none",
|
|
535
|
+
style: {
|
|
536
|
+
position: 'absolute',
|
|
537
|
+
left: 0,
|
|
538
|
+
top: plot.top,
|
|
539
|
+
height: plot.height
|
|
540
|
+
},
|
|
541
|
+
className: cn('justify-between', className),
|
|
542
|
+
children: labels.map(label => /*#__PURE__*/_jsx(Text, {
|
|
543
|
+
size: "xs",
|
|
544
|
+
muted: true,
|
|
545
|
+
numberOfLines: 1,
|
|
546
|
+
children: label.text
|
|
547
|
+
}, label.key))
|
|
548
|
+
});
|
|
549
|
+
}
|
|
550
|
+
AreaChartYAxis.displayName = 'AreaChart.YAxis';
|
|
551
|
+
AreaChartYAxis.layer = 'overlay';
|
|
552
|
+
// Read by the root, which has to leave room for the labels before it
|
|
553
|
+
// lays the plot out — an axis drawn over the plot is unreadable, and
|
|
554
|
+
// makes what it is drawn over unreadable too.
|
|
555
|
+
AreaChartYAxis.axis = 'y';
|
|
556
|
+
|
|
557
|
+
/** A dot riding the top edge of one band as the crosshair moves. */
|
|
558
|
+
function CrosshairDot({
|
|
559
|
+
values,
|
|
560
|
+
baselines,
|
|
561
|
+
plot,
|
|
562
|
+
domainMin,
|
|
563
|
+
domainMax,
|
|
564
|
+
activeIndex,
|
|
565
|
+
total,
|
|
566
|
+
color
|
|
567
|
+
}) {
|
|
568
|
+
const props = useAnimatedProps(() => {
|
|
569
|
+
const index = activeIndex.value;
|
|
570
|
+
const value = index >= 0 ? values[index] : null;
|
|
571
|
+
if (index < 0 || value === null || value === undefined) {
|
|
572
|
+
return {
|
|
573
|
+
opacity: 0,
|
|
574
|
+
cx: 0,
|
|
575
|
+
cy: 0
|
|
576
|
+
};
|
|
577
|
+
}
|
|
578
|
+
const stacked = value + (baselines?.[index] ?? 0);
|
|
579
|
+
return {
|
|
580
|
+
opacity: 1,
|
|
581
|
+
cx: xOf(index, total, plot),
|
|
582
|
+
cy: yOf(stacked, plot, domainMin.value, domainMax.value)
|
|
583
|
+
};
|
|
584
|
+
});
|
|
585
|
+
return /*#__PURE__*/_jsx(AnimatedCircle, {
|
|
586
|
+
animatedProps: props,
|
|
587
|
+
r: DOT / 2,
|
|
588
|
+
fill: color,
|
|
589
|
+
stroke: "white",
|
|
590
|
+
strokeWidth: 2
|
|
591
|
+
});
|
|
592
|
+
}
|
|
593
|
+
/**
|
|
594
|
+
* The crosshair, the gesture that drives it, and the readout that rides it.
|
|
595
|
+
*
|
|
596
|
+
* The hit area is the whole plot. A crosshair you have to land on a band to
|
|
597
|
+
* summon is a crosshair nobody finds.
|
|
598
|
+
*/
|
|
599
|
+
function AreaChartTooltip({
|
|
600
|
+
color,
|
|
601
|
+
formatValue,
|
|
602
|
+
formatX,
|
|
603
|
+
className
|
|
604
|
+
}) {
|
|
605
|
+
const {
|
|
606
|
+
data,
|
|
607
|
+
xDataKey,
|
|
608
|
+
plot,
|
|
609
|
+
stacked,
|
|
610
|
+
series,
|
|
611
|
+
domainMin,
|
|
612
|
+
domainMax,
|
|
613
|
+
activeIndex,
|
|
614
|
+
activeIndexJS,
|
|
615
|
+
setActiveIndexJS,
|
|
616
|
+
status
|
|
617
|
+
} = useChart('AreaChart.Tooltip');
|
|
618
|
+
const token = useCSSVariable('--color-foreground');
|
|
619
|
+
const stroke = color ?? (typeof token === 'string' ? token : '#888888');
|
|
620
|
+
const total = data.length;
|
|
621
|
+
const left = plot.left;
|
|
622
|
+
const width = plot.width;
|
|
623
|
+
|
|
624
|
+
/*
|
|
625
|
+
* Declared inside the memo, next to its callers: a worklet may only call
|
|
626
|
+
* another worklet, and the rule is enforced by crashing rather than warning.
|
|
627
|
+
*/
|
|
628
|
+
const pan = useMemo(() => {
|
|
629
|
+
const resolve = x => {
|
|
630
|
+
'worklet';
|
|
631
|
+
|
|
632
|
+
if (total < 2 || width <= 0) return;
|
|
633
|
+
const ratio = (x - left) / width;
|
|
634
|
+
const next = Math.round(Math.min(1, Math.max(0, ratio)) * (total - 1));
|
|
635
|
+
if (next === activeIndex.value) return;
|
|
636
|
+
activeIndex.value = next;
|
|
637
|
+
runOnJS(setActiveIndexJS)(next);
|
|
638
|
+
};
|
|
639
|
+
return Gesture.Pan().minDistance(0).onBegin(event => {
|
|
640
|
+
'worklet';
|
|
641
|
+
|
|
642
|
+
resolve(event.x);
|
|
643
|
+
}).onUpdate(event => {
|
|
644
|
+
'worklet';
|
|
645
|
+
|
|
646
|
+
resolve(event.x);
|
|
647
|
+
}).onFinalize(() => {
|
|
648
|
+
'worklet';
|
|
649
|
+
|
|
650
|
+
activeIndex.value = -1;
|
|
651
|
+
runOnJS(setActiveIndexJS)(-1);
|
|
652
|
+
});
|
|
653
|
+
}, [total, left, width, activeIndex, setActiveIndexJS]);
|
|
654
|
+
const crosshairStyle = useAnimatedStyle(() => {
|
|
655
|
+
const index = activeIndex.value;
|
|
656
|
+
return {
|
|
657
|
+
opacity: index < 0 ? 0 : 0.45,
|
|
658
|
+
transform: [{
|
|
659
|
+
translateX: index < 0 ? 0 : xOf(index, total, plot)
|
|
660
|
+
}]
|
|
661
|
+
};
|
|
662
|
+
});
|
|
663
|
+
const labelStyle = useAnimatedStyle(() => {
|
|
664
|
+
const index = activeIndex.value;
|
|
665
|
+
if (index < 0) return {
|
|
666
|
+
opacity: 0
|
|
667
|
+
};
|
|
668
|
+
const x = xOf(index, total, plot);
|
|
669
|
+
const half = LABEL_WIDTH / 2;
|
|
670
|
+
const clamped = Math.min(plot.left + plot.width - half, Math.max(plot.left + half, x));
|
|
671
|
+
return {
|
|
672
|
+
opacity: 1,
|
|
673
|
+
transform: [{
|
|
674
|
+
translateX: clamped - half
|
|
675
|
+
}]
|
|
676
|
+
};
|
|
677
|
+
});
|
|
678
|
+
|
|
679
|
+
/*
|
|
680
|
+
* The dots ride the *top edge* of each band, which for a stack is the
|
|
681
|
+
* running total rather than the value — so the baselines are recomputed here
|
|
682
|
+
* the same way the bands compute them, and for the same reason.
|
|
683
|
+
*/
|
|
684
|
+
const stacks = useMemo(() => {
|
|
685
|
+
return series.map(([key, seriesColor], index) => {
|
|
686
|
+
const below = series.slice(0, index);
|
|
687
|
+
const baselines = stacked && below.length ? data.map(row => {
|
|
688
|
+
let sum = 0;
|
|
689
|
+
for (const [k] of below) {
|
|
690
|
+
const value = row[k];
|
|
691
|
+
if (typeof value === 'number' && !Number.isNaN(value)) sum += value;
|
|
692
|
+
}
|
|
693
|
+
return sum;
|
|
694
|
+
}) : undefined;
|
|
695
|
+
return {
|
|
696
|
+
key,
|
|
697
|
+
color: seriesColor,
|
|
698
|
+
values: columnValues(data, key),
|
|
699
|
+
baselines
|
|
700
|
+
};
|
|
701
|
+
});
|
|
702
|
+
}, [series, data, stacked]);
|
|
703
|
+
const active = activeIndexJS >= 0 ? data[activeIndexJS] : null;
|
|
704
|
+
const fmtValue = formatValue ?? (value => compactNumber(value));
|
|
705
|
+
const fmtX = formatX ?? (datum => String(datum[xDataKey] ?? ''));
|
|
706
|
+
if (status === 'loading') return null;
|
|
707
|
+
return /*#__PURE__*/_jsx(GestureDetector, {
|
|
708
|
+
gesture: pan,
|
|
709
|
+
children: /*#__PURE__*/_jsxs(View, {
|
|
710
|
+
style: StyleSheet.absoluteFill,
|
|
711
|
+
children: [/*#__PURE__*/_jsx(Animated.View, {
|
|
712
|
+
pointerEvents: "none",
|
|
713
|
+
style: [{
|
|
714
|
+
position: 'absolute',
|
|
715
|
+
left: 0,
|
|
716
|
+
top: plot.top,
|
|
717
|
+
width: 1,
|
|
718
|
+
height: plot.height,
|
|
719
|
+
backgroundColor: stroke
|
|
720
|
+
}, crosshairStyle]
|
|
721
|
+
}), /*#__PURE__*/_jsx(Svg, {
|
|
722
|
+
width: "100%",
|
|
723
|
+
height: "100%",
|
|
724
|
+
style: StyleSheet.absoluteFill,
|
|
725
|
+
pointerEvents: "none",
|
|
726
|
+
children: stacks.map(stack => /*#__PURE__*/_jsx(CrosshairDot, {
|
|
727
|
+
values: stack.values,
|
|
728
|
+
baselines: stack.baselines,
|
|
729
|
+
plot: plot,
|
|
730
|
+
domainMin: domainMin,
|
|
731
|
+
domainMax: domainMax,
|
|
732
|
+
activeIndex: activeIndex,
|
|
733
|
+
total: total,
|
|
734
|
+
color: stack.color
|
|
735
|
+
}, stack.key))
|
|
736
|
+
}), /*#__PURE__*/_jsx(Animated.View, {
|
|
737
|
+
pointerEvents: "none",
|
|
738
|
+
style: [{
|
|
739
|
+
position: 'absolute',
|
|
740
|
+
left: 0,
|
|
741
|
+
top: 0,
|
|
742
|
+
width: LABEL_WIDTH
|
|
743
|
+
}, labelStyle],
|
|
744
|
+
children: active ? /*#__PURE__*/_jsxs(View, {
|
|
745
|
+
className: cn('rounded-xl border border-border bg-popover px-2.5 py-1.5 shadow-lg', className),
|
|
746
|
+
children: [/*#__PURE__*/_jsx(Text, {
|
|
747
|
+
size: "xs",
|
|
748
|
+
muted: true,
|
|
749
|
+
numberOfLines: 1,
|
|
750
|
+
children: fmtX(active)
|
|
751
|
+
}), series.map(([key, seriesColor]) => {
|
|
752
|
+
const value = active[key];
|
|
753
|
+
if (typeof value !== 'number') return null;
|
|
754
|
+
return /*#__PURE__*/_jsxs(View, {
|
|
755
|
+
className: "flex-row items-center gap-1.5",
|
|
756
|
+
children: [/*#__PURE__*/_jsx(View, {
|
|
757
|
+
style: {
|
|
758
|
+
width: 6,
|
|
759
|
+
height: 6,
|
|
760
|
+
borderRadius: 3,
|
|
761
|
+
backgroundColor: seriesColor
|
|
762
|
+
}
|
|
763
|
+
}), /*#__PURE__*/_jsx(Text, {
|
|
764
|
+
size: "xs",
|
|
765
|
+
weight: "medium",
|
|
766
|
+
children: fmtValue(value, key)
|
|
767
|
+
})]
|
|
768
|
+
}, key);
|
|
769
|
+
})]
|
|
770
|
+
}) : null
|
|
771
|
+
})]
|
|
772
|
+
})
|
|
773
|
+
});
|
|
774
|
+
}
|
|
775
|
+
AreaChartTooltip.displayName = 'AreaChart.Tooltip';
|
|
776
|
+
AreaChartTooltip.layer = 'overlay';
|
|
777
|
+
/**
|
|
778
|
+
* A swatch and a name per series.
|
|
779
|
+
*
|
|
780
|
+
* Reversed for a stack, so the key reads in the order the bands appear on the
|
|
781
|
+
* chart: the last one declared is the top band, and a legend listing it last
|
|
782
|
+
* points at the bottom one.
|
|
783
|
+
*/
|
|
784
|
+
function AreaChartLegend({
|
|
785
|
+
className,
|
|
786
|
+
labels,
|
|
787
|
+
...props
|
|
788
|
+
}) {
|
|
789
|
+
const {
|
|
790
|
+
series,
|
|
791
|
+
stacked
|
|
792
|
+
} = useChart('AreaChart.Legend');
|
|
793
|
+
if (!series.length) return null;
|
|
794
|
+
const ordered = stacked ? [...series].reverse() : series;
|
|
795
|
+
return /*#__PURE__*/_jsx(View, {
|
|
796
|
+
...props,
|
|
797
|
+
pointerEvents: "none",
|
|
798
|
+
className: cn('absolute right-2 top-1 flex-row gap-3', className),
|
|
799
|
+
children: ordered.map(([key, color]) => /*#__PURE__*/_jsxs(View, {
|
|
800
|
+
className: "flex-row items-center gap-1.5",
|
|
801
|
+
children: [/*#__PURE__*/_jsx(View, {
|
|
802
|
+
style: {
|
|
803
|
+
width: 8,
|
|
804
|
+
height: 8,
|
|
805
|
+
borderRadius: 2,
|
|
806
|
+
backgroundColor: color
|
|
807
|
+
}
|
|
808
|
+
}), /*#__PURE__*/_jsx(Text, {
|
|
809
|
+
size: "xs",
|
|
810
|
+
muted: true,
|
|
811
|
+
children: labels?.[key] ?? key
|
|
812
|
+
})]
|
|
813
|
+
}, key))
|
|
814
|
+
});
|
|
815
|
+
}
|
|
816
|
+
AreaChartLegend.displayName = 'AreaChart.Legend';
|
|
817
|
+
AreaChartLegend.layer = 'overlay';
|
|
818
|
+
export const AreaChart = Object.assign(AreaChartRoot, {
|
|
819
|
+
Grid: AreaChartGrid,
|
|
820
|
+
Area: AreaChartArea,
|
|
821
|
+
XAxis: AreaChartXAxis,
|
|
822
|
+
YAxis: AreaChartYAxis,
|
|
823
|
+
Tooltip: AreaChartTooltip,
|
|
824
|
+
Legend: AreaChartLegend
|
|
825
|
+
});
|
|
826
|
+
//# sourceMappingURL=index.js.map
|