@alpic-ai/ui 1.154.0 → 1.155.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/area-chart.mjs +20 -109
- package/dist/components/bar-chart.mjs +10 -68
- package/dist/components/chart-primitives.d.mts +69 -0
- package/dist/components/chart-primitives.mjs +134 -0
- package/dist/components/field.d.mts +14 -0
- package/dist/components/field.mjs +41 -0
- package/dist/components/input.mjs +25 -49
- package/dist/components/line-chart.mjs +20 -102
- package/dist/components/textarea.mjs +17 -41
- package/dist/lib/chart.d.mts +5 -1
- package/package.json +1 -1
- package/src/components/area-chart.tsx +21 -142
- package/src/components/bar-chart.tsx +12 -81
- package/src/components/chart-primitives.tsx +188 -0
- package/src/components/field.tsx +57 -0
- package/src/components/input.tsx +3 -33
- package/src/components/line-chart.tsx +21 -133
- package/src/components/textarea.tsx +3 -33
- package/src/stories/area-chart.stories.tsx +8 -6
- package/src/stories/bar-chart.stories.tsx +8 -6
- package/src/stories/donut-chart.stories.tsx +8 -6
- package/src/stories/line-chart.stories.tsx +8 -6
- package/src/stories/stat.stories.tsx +8 -6
|
@@ -3,11 +3,12 @@ import { cn } from "../lib/cn.mjs";
|
|
|
3
3
|
import { makeXAxisTick, resolveSeries } from "../lib/chart.mjs";
|
|
4
4
|
import { useChartContext } from "./chart-container.mjs";
|
|
5
5
|
import { ChartLegend } from "./chart-legend.mjs";
|
|
6
|
+
import { computeNumericMax, makeActiveDot, makeChartAxis, makeLastValueLabel, makeLegendItems, renderMarkers, renderReferenceLine } from "./chart-primitives.mjs";
|
|
6
7
|
import { ChartTooltipContent } from "./chart-tooltip.mjs";
|
|
7
8
|
import { Skeleton } from "./skeleton.mjs";
|
|
8
9
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
9
10
|
import * as React$1 from "react";
|
|
10
|
-
import { CartesianGrid, LabelList, Line, LineChart as LineChart$1,
|
|
11
|
+
import { CartesianGrid, LabelList, Line, LineChart as LineChart$1, ResponsiveContainer, Tooltip, XAxis, YAxis } from "recharts";
|
|
11
12
|
//#region src/components/line-chart.tsx
|
|
12
13
|
const CURVE_TYPE = {
|
|
13
14
|
monotone: "monotone",
|
|
@@ -17,14 +18,7 @@ const CURVE_TYPE = {
|
|
|
17
18
|
function LineChart({ data, index, series, curve = "monotone", legend = false, legendAlign = "left", valueFlags = false, dots = false, height = 200, yAxisWidth = 48, palette, referenceLine, markers, lastValueLabel = false, loading = false, valueFormatter = (value) => value.toLocaleString("en-US"), labelFormatter, className }) {
|
|
18
19
|
const { palette: paletteColors, theme } = useChartContext(palette);
|
|
19
20
|
const resolved = resolveSeries(series, paletteColors, theme);
|
|
20
|
-
const numericMax = React$1.useMemo(() =>
|
|
21
|
-
let max = 0;
|
|
22
|
-
for (const row of data) for (const entry of series) {
|
|
23
|
-
const value = Number(row[entry.key]);
|
|
24
|
-
if (Number.isFinite(value) && value > max) max = value;
|
|
25
|
-
}
|
|
26
|
-
return max;
|
|
27
|
-
}, [data, series]);
|
|
21
|
+
const numericMax = React$1.useMemo(() => computeNumericMax(data, series, false), [data, series]);
|
|
28
22
|
const curveType = CURVE_TYPE[curve];
|
|
29
23
|
const margin = {
|
|
30
24
|
top: markers?.length ? 18 : 8,
|
|
@@ -32,63 +26,8 @@ function LineChart({ data, index, series, curve = "monotone", legend = false, le
|
|
|
32
26
|
bottom: 2,
|
|
33
27
|
left: 0
|
|
34
28
|
};
|
|
35
|
-
const axis =
|
|
36
|
-
|
|
37
|
-
tick: {
|
|
38
|
-
fill: theme.axisForeground,
|
|
39
|
-
fontSize: 10,
|
|
40
|
-
fontFamily: theme.fontMono
|
|
41
|
-
},
|
|
42
|
-
tickLine: false,
|
|
43
|
-
axisLine: {
|
|
44
|
-
stroke: theme.border,
|
|
45
|
-
strokeOpacity: .6
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
const legendItems = resolved.map((entry) => ({
|
|
49
|
-
name: entry.name,
|
|
50
|
-
color: entry.color,
|
|
51
|
-
dashed: entry.dashed
|
|
52
|
-
}));
|
|
53
|
-
const activeDotFor = (entry) => valueFlags ? (dotProps) => {
|
|
54
|
-
if (dotProps.cx == null || dotProps.cy == null) return /* @__PURE__ */ jsx("g", {});
|
|
55
|
-
return /* @__PURE__ */ jsxs("g", { children: [/* @__PURE__ */ jsx("circle", {
|
|
56
|
-
cx: dotProps.cx,
|
|
57
|
-
cy: dotProps.cy,
|
|
58
|
-
r: 3.5,
|
|
59
|
-
fill: entry.color,
|
|
60
|
-
stroke: theme.card,
|
|
61
|
-
strokeWidth: 2
|
|
62
|
-
}), /* @__PURE__ */ jsx("text", {
|
|
63
|
-
x: dotProps.cx,
|
|
64
|
-
y: dotProps.cy - 8,
|
|
65
|
-
textAnchor: "middle",
|
|
66
|
-
fill: entry.color,
|
|
67
|
-
fontFamily: theme.fontMono,
|
|
68
|
-
fontSize: 10,
|
|
69
|
-
style: { fontVariantNumeric: "tabular-nums" },
|
|
70
|
-
children: valueFormatter(Number(dotProps.value ?? 0))
|
|
71
|
-
})] });
|
|
72
|
-
} : {
|
|
73
|
-
r: 3.5,
|
|
74
|
-
fill: entry.color,
|
|
75
|
-
stroke: theme.card,
|
|
76
|
-
strokeWidth: 2
|
|
77
|
-
};
|
|
78
|
-
const renderLastLabel = (color) => (props) => {
|
|
79
|
-
if (props.index !== data.length - 1 || props.x == null || props.y == null) return null;
|
|
80
|
-
return /* @__PURE__ */ jsx("text", {
|
|
81
|
-
x: Number(props.x) + 6,
|
|
82
|
-
y: Number(props.y),
|
|
83
|
-
dy: 3,
|
|
84
|
-
fill: color,
|
|
85
|
-
fontFamily: theme.fontMono,
|
|
86
|
-
fontSize: 10,
|
|
87
|
-
textAnchor: "start",
|
|
88
|
-
style: { fontVariantNumeric: "tabular-nums" },
|
|
89
|
-
children: valueFormatter(Number(props.value ?? 0))
|
|
90
|
-
});
|
|
91
|
-
};
|
|
29
|
+
const axis = makeChartAxis(theme);
|
|
30
|
+
const legendItems = makeLegendItems(resolved);
|
|
92
31
|
const isEmpty = data.length === 0 || resolved.length === 0;
|
|
93
32
|
return /* @__PURE__ */ jsxs("div", {
|
|
94
33
|
"data-slot": "line-chart",
|
|
@@ -144,25 +83,10 @@ function LineChart({ data, index, series, curve = "monotone", legend = false, le
|
|
|
144
83
|
labelFormatter
|
|
145
84
|
})
|
|
146
85
|
}),
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
fillOpacity: .06,
|
|
152
|
-
ifOverflow: "extendDomain"
|
|
153
|
-
}),
|
|
154
|
-
referenceLine && /* @__PURE__ */ jsx(ReferenceLine, {
|
|
155
|
-
y: referenceLine.y,
|
|
156
|
-
stroke: theme.warning,
|
|
157
|
-
strokeDasharray: "4 4",
|
|
158
|
-
strokeOpacity: .6,
|
|
159
|
-
label: referenceLine.label ? {
|
|
160
|
-
value: referenceLine.label,
|
|
161
|
-
fill: theme.warning,
|
|
162
|
-
fontSize: 9,
|
|
163
|
-
fontFamily: theme.fontMono,
|
|
164
|
-
position: "insideBottomRight"
|
|
165
|
-
} : void 0
|
|
86
|
+
renderReferenceLine({
|
|
87
|
+
referenceLine,
|
|
88
|
+
numericMax,
|
|
89
|
+
theme
|
|
166
90
|
}),
|
|
167
91
|
resolved.map((entry) => /* @__PURE__ */ jsx(Line, {
|
|
168
92
|
type: curveType,
|
|
@@ -176,30 +100,24 @@ function LineChart({ data, index, series, curve = "monotone", legend = false, le
|
|
|
176
100
|
fill: entry.color,
|
|
177
101
|
strokeWidth: 0
|
|
178
102
|
} : false,
|
|
179
|
-
activeDot:
|
|
103
|
+
activeDot: makeActiveDot(entry, {
|
|
104
|
+
valueFlags,
|
|
105
|
+
theme,
|
|
106
|
+
valueFormatter
|
|
107
|
+
}),
|
|
180
108
|
isAnimationActive: false,
|
|
181
109
|
animationDuration: 650,
|
|
182
110
|
animationEasing: "ease-out",
|
|
183
111
|
children: lastValueLabel && /* @__PURE__ */ jsx(LabelList, {
|
|
184
112
|
dataKey: entry.key,
|
|
185
|
-
content:
|
|
113
|
+
content: makeLastValueLabel(entry.color, {
|
|
114
|
+
dataLength: data.length,
|
|
115
|
+
theme,
|
|
116
|
+
valueFormatter
|
|
117
|
+
})
|
|
186
118
|
})
|
|
187
119
|
}, entry.key)),
|
|
188
|
-
markers
|
|
189
|
-
x: marker.x,
|
|
190
|
-
y: marker.y,
|
|
191
|
-
r: 3.5,
|
|
192
|
-
fill: marker.color ?? theme.foreground,
|
|
193
|
-
stroke: theme.card,
|
|
194
|
-
strokeWidth: 2,
|
|
195
|
-
label: marker.label ? {
|
|
196
|
-
value: marker.label,
|
|
197
|
-
fill: marker.color ?? theme.foreground,
|
|
198
|
-
fontSize: 9,
|
|
199
|
-
fontFamily: theme.fontMono,
|
|
200
|
-
position: "top"
|
|
201
|
-
} : void 0
|
|
202
|
-
}, `${marker.x}-${marker.y}`))
|
|
120
|
+
renderMarkers(markers, theme)
|
|
203
121
|
]
|
|
204
122
|
})
|
|
205
123
|
})
|
|
@@ -1,52 +1,28 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { cn } from "../lib/cn.mjs";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { Info } from "lucide-react";
|
|
6
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Field } from "./field.mjs";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
7
5
|
import * as React$1 from "react";
|
|
8
6
|
//#region src/components/textarea.tsx
|
|
9
7
|
function Textarea({ className, id, label, required, hint, error, tooltip, ...props }) {
|
|
10
8
|
const generatedId = React$1.useId();
|
|
11
9
|
const fieldId = id ?? generatedId;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
className: cn("block w-full min-h-[120px] max-h-[480px] resize-y [field-sizing:content]", "px-3.5 py-3", "type-text-md text-foreground placeholder:text-placeholder", "bg-background border border-border rounded-md", "transition-colors", "outline-none focus-visible:border-ring focus-visible:border-2", "disabled:bg-disabled disabled:text-disabled-foreground disabled:cursor-not-allowed", "aria-invalid:border-border-error [@media(hover:hover)]:aria-invalid:hover:border-border-error", error && "border-border-error [@media(hover:hover)]:hover:border-border-error", className),
|
|
10
|
+
return /* @__PURE__ */ jsx(Field, {
|
|
11
|
+
fieldId,
|
|
12
|
+
label,
|
|
16
13
|
required,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
className: "type-text-sm font-medium text-muted-foreground",
|
|
30
|
-
children: label
|
|
31
|
-
}),
|
|
32
|
-
required && /* @__PURE__ */ jsx("span", {
|
|
33
|
-
"aria-hidden": true,
|
|
34
|
-
className: "type-text-sm font-medium text-required",
|
|
35
|
-
children: "*"
|
|
36
|
-
}),
|
|
37
|
-
tooltip && /* @__PURE__ */ jsxs(Tooltip, { children: [/* @__PURE__ */ jsx(TooltipTrigger, {
|
|
38
|
-
asChild: true,
|
|
39
|
-
children: /* @__PURE__ */ jsx(Info, { className: "size-4 text-muted-foreground" })
|
|
40
|
-
}), /* @__PURE__ */ jsx(TooltipContent, { children: tooltip })] })
|
|
41
|
-
]
|
|
42
|
-
}),
|
|
43
|
-
textarea,
|
|
44
|
-
(hint || error) && /* @__PURE__ */ jsx("p", {
|
|
45
|
-
id: fieldId ? `${fieldId}-description` : void 0,
|
|
46
|
-
className: cn("type-text-sm", error ? "text-destructive" : "text-subtle-foreground"),
|
|
47
|
-
children: error ?? hint
|
|
48
|
-
})
|
|
49
|
-
]
|
|
14
|
+
hint,
|
|
15
|
+
error,
|
|
16
|
+
tooltip,
|
|
17
|
+
children: /* @__PURE__ */ jsx("textarea", {
|
|
18
|
+
id: fieldId,
|
|
19
|
+
"data-slot": "textarea",
|
|
20
|
+
className: cn("block w-full min-h-[120px] max-h-[480px] resize-y [field-sizing:content]", "px-3.5 py-3", "type-text-md text-foreground placeholder:text-placeholder", "bg-background border border-border rounded-md", "transition-colors", "outline-none focus-visible:border-ring focus-visible:border-2", "disabled:bg-disabled disabled:text-disabled-foreground disabled:cursor-not-allowed", "aria-invalid:border-border-error [@media(hover:hover)]:aria-invalid:hover:border-border-error", error && "border-border-error [@media(hover:hover)]:hover:border-border-error", className),
|
|
21
|
+
required,
|
|
22
|
+
"aria-invalid": error ? true : void 0,
|
|
23
|
+
"aria-describedby": fieldId && (hint || error) ? `${fieldId}-description` : void 0,
|
|
24
|
+
...props
|
|
25
|
+
})
|
|
50
26
|
});
|
|
51
27
|
}
|
|
52
28
|
//#endregion
|
package/dist/lib/chart.d.mts
CHANGED
|
@@ -11,5 +11,9 @@ interface ChartSeries {
|
|
|
11
11
|
semantic?: "error" | "warning" | "success";
|
|
12
12
|
dashed?: boolean;
|
|
13
13
|
}
|
|
14
|
+
interface ResolvedSeries extends ChartSeries {
|
|
15
|
+
name: string;
|
|
16
|
+
color: string;
|
|
17
|
+
}
|
|
14
18
|
//#endregion
|
|
15
|
-
export { ChartSeries };
|
|
19
|
+
export { ChartSeries, ResolvedSeries };
|
package/package.json
CHANGED
|
@@ -6,9 +6,6 @@ import {
|
|
|
6
6
|
CartesianGrid,
|
|
7
7
|
LabelList,
|
|
8
8
|
AreaChart as RechartsAreaChart,
|
|
9
|
-
ReferenceArea,
|
|
10
|
-
ReferenceDot,
|
|
11
|
-
ReferenceLine,
|
|
12
9
|
ResponsiveContainer,
|
|
13
10
|
Tooltip,
|
|
14
11
|
XAxis,
|
|
@@ -20,6 +17,15 @@ import type { ChartPaletteName } from "../lib/chart-palette";
|
|
|
20
17
|
import { cn } from "../lib/cn";
|
|
21
18
|
import { useChartContext } from "./chart-container";
|
|
22
19
|
import { ChartLegend } from "./chart-legend";
|
|
20
|
+
import {
|
|
21
|
+
computeNumericMax,
|
|
22
|
+
makeActiveDot,
|
|
23
|
+
makeChartAxis,
|
|
24
|
+
makeLastValueLabel,
|
|
25
|
+
makeLegendItems,
|
|
26
|
+
renderMarkers,
|
|
27
|
+
renderReferenceLine,
|
|
28
|
+
} from "./chart-primitives";
|
|
23
29
|
import { ChartTooltipContent } from "./chart-tooltip";
|
|
24
30
|
import { Skeleton } from "./skeleton";
|
|
25
31
|
|
|
@@ -87,71 +93,14 @@ function AreaChart({
|
|
|
87
93
|
const lead = resolved[0];
|
|
88
94
|
const withTotal = stacked && rendered.length > 1;
|
|
89
95
|
|
|
90
|
-
|
|
91
|
-
// single series, or the reference band stops short of the chart top.
|
|
92
|
-
const numericMax = React.useMemo(() => {
|
|
93
|
-
let max = 0;
|
|
94
|
-
for (const row of data) {
|
|
95
|
-
let rowTotal = 0;
|
|
96
|
-
for (const entry of series) {
|
|
97
|
-
const value = Number(row[entry.key]);
|
|
98
|
-
if (Number.isFinite(value)) {
|
|
99
|
-
rowTotal += value;
|
|
100
|
-
if (!stacked && value > max) {
|
|
101
|
-
max = value;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
if (stacked && rowTotal > max) {
|
|
106
|
-
max = rowTotal;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
return max;
|
|
110
|
-
}, [data, series, stacked]);
|
|
96
|
+
const numericMax = React.useMemo(() => computeNumericMax(data, series, stacked), [data, series, stacked]);
|
|
111
97
|
|
|
112
98
|
const curveType = CURVE_TYPE[curve];
|
|
113
99
|
const margin = { top: markers?.length ? 18 : 8, right: lastValueLabel ? 56 : 8, bottom: 2, left: 0 };
|
|
114
100
|
|
|
115
|
-
const axis =
|
|
116
|
-
stroke: theme.border,
|
|
117
|
-
tick: { fill: theme.axisForeground, fontSize: 10, fontFamily: theme.fontMono },
|
|
118
|
-
tickLine: false as const,
|
|
119
|
-
axisLine: { stroke: theme.border, strokeOpacity: 0.6 },
|
|
120
|
-
};
|
|
101
|
+
const axis = makeChartAxis(theme);
|
|
121
102
|
|
|
122
|
-
const legendItems = resolved
|
|
123
|
-
|
|
124
|
-
const activeDotFor = (entry: (typeof rendered)[number]) =>
|
|
125
|
-
valueFlags
|
|
126
|
-
? (dotProps: { cx?: number; cy?: number; value?: number | string }) => {
|
|
127
|
-
if (dotProps.cx == null || dotProps.cy == null) {
|
|
128
|
-
return <g />;
|
|
129
|
-
}
|
|
130
|
-
return (
|
|
131
|
-
<g>
|
|
132
|
-
<circle
|
|
133
|
-
cx={dotProps.cx}
|
|
134
|
-
cy={dotProps.cy}
|
|
135
|
-
r={3.5}
|
|
136
|
-
fill={entry.color}
|
|
137
|
-
stroke={theme.card}
|
|
138
|
-
strokeWidth={2}
|
|
139
|
-
/>
|
|
140
|
-
<text
|
|
141
|
-
x={dotProps.cx}
|
|
142
|
-
y={dotProps.cy - 8}
|
|
143
|
-
textAnchor="middle"
|
|
144
|
-
fill={entry.color}
|
|
145
|
-
fontFamily={theme.fontMono}
|
|
146
|
-
fontSize={10}
|
|
147
|
-
style={{ fontVariantNumeric: "tabular-nums" }}
|
|
148
|
-
>
|
|
149
|
-
{valueFormatter(Number(dotProps.value ?? 0))}
|
|
150
|
-
</text>
|
|
151
|
-
</g>
|
|
152
|
-
);
|
|
153
|
-
}
|
|
154
|
-
: { r: 3.5, fill: entry.color, stroke: theme.card, strokeWidth: 2 };
|
|
103
|
+
const legendItems = makeLegendItems(resolved);
|
|
155
104
|
|
|
156
105
|
const fillFor = (entry: (typeof rendered)[number], slot: number) => {
|
|
157
106
|
if (!filled) {
|
|
@@ -163,33 +112,6 @@ function AreaChart({
|
|
|
163
112
|
return `url(#area-${reactId}-${slot})`;
|
|
164
113
|
};
|
|
165
114
|
|
|
166
|
-
const renderLastLabel =
|
|
167
|
-
(color: string) =>
|
|
168
|
-
(props: {
|
|
169
|
-
x?: string | number;
|
|
170
|
-
y?: string | number;
|
|
171
|
-
value?: string | number | boolean | Array<string | number | boolean> | null;
|
|
172
|
-
index?: number;
|
|
173
|
-
}) => {
|
|
174
|
-
if (props.index !== data.length - 1 || props.x == null || props.y == null) {
|
|
175
|
-
return null;
|
|
176
|
-
}
|
|
177
|
-
return (
|
|
178
|
-
<text
|
|
179
|
-
x={Number(props.x) + 6}
|
|
180
|
-
y={Number(props.y)}
|
|
181
|
-
dy={3}
|
|
182
|
-
fill={color}
|
|
183
|
-
fontFamily={theme.fontMono}
|
|
184
|
-
fontSize={10}
|
|
185
|
-
textAnchor="start"
|
|
186
|
-
style={{ fontVariantNumeric: "tabular-nums" }}
|
|
187
|
-
>
|
|
188
|
-
{valueFormatter(Number(props.value ?? 0))}
|
|
189
|
-
</text>
|
|
190
|
-
);
|
|
191
|
-
};
|
|
192
|
-
|
|
193
115
|
const isEmpty = data.length === 0 || rendered.length === 0;
|
|
194
116
|
|
|
195
117
|
return (
|
|
@@ -264,34 +186,7 @@ function AreaChart({
|
|
|
264
186
|
/>
|
|
265
187
|
}
|
|
266
188
|
/>
|
|
267
|
-
{referenceLine
|
|
268
|
-
<ReferenceArea
|
|
269
|
-
y1={referenceLine.y}
|
|
270
|
-
y2={numericMax}
|
|
271
|
-
fill={theme.warning}
|
|
272
|
-
fillOpacity={0.06}
|
|
273
|
-
ifOverflow="extendDomain"
|
|
274
|
-
/>
|
|
275
|
-
)}
|
|
276
|
-
{referenceLine && (
|
|
277
|
-
<ReferenceLine
|
|
278
|
-
y={referenceLine.y}
|
|
279
|
-
stroke={theme.warning}
|
|
280
|
-
strokeDasharray="4 4"
|
|
281
|
-
strokeOpacity={0.6}
|
|
282
|
-
label={
|
|
283
|
-
referenceLine.label
|
|
284
|
-
? {
|
|
285
|
-
value: referenceLine.label,
|
|
286
|
-
fill: theme.warning,
|
|
287
|
-
fontSize: 9,
|
|
288
|
-
fontFamily: theme.fontMono,
|
|
289
|
-
position: "insideBottomRight",
|
|
290
|
-
}
|
|
291
|
-
: undefined
|
|
292
|
-
}
|
|
293
|
-
/>
|
|
294
|
-
)}
|
|
189
|
+
{renderReferenceLine({ referenceLine, numericMax, theme })}
|
|
295
190
|
|
|
296
191
|
{rendered.map((entry, slot) => (
|
|
297
192
|
<Area
|
|
@@ -305,37 +200,21 @@ function AreaChart({
|
|
|
305
200
|
strokeDasharray={entry.dashed ? "5 3" : undefined}
|
|
306
201
|
fill={fillFor(entry, slot)}
|
|
307
202
|
dot={false}
|
|
308
|
-
activeDot={
|
|
203
|
+
activeDot={makeActiveDot(entry, { valueFlags, theme, valueFormatter })}
|
|
309
204
|
isAnimationActive={false}
|
|
310
205
|
animationDuration={650}
|
|
311
206
|
animationEasing="ease-out"
|
|
312
207
|
>
|
|
313
|
-
{lastValueLabel &&
|
|
208
|
+
{lastValueLabel && (
|
|
209
|
+
<LabelList
|
|
210
|
+
dataKey={entry.key}
|
|
211
|
+
content={makeLastValueLabel(entry.color, { dataLength: data.length, theme, valueFormatter })}
|
|
212
|
+
/>
|
|
213
|
+
)}
|
|
314
214
|
</Area>
|
|
315
215
|
))}
|
|
316
216
|
|
|
317
|
-
{markers
|
|
318
|
-
<ReferenceDot
|
|
319
|
-
key={`${marker.x}-${marker.y}`}
|
|
320
|
-
x={marker.x}
|
|
321
|
-
y={marker.y}
|
|
322
|
-
r={3.5}
|
|
323
|
-
fill={marker.color ?? theme.foreground}
|
|
324
|
-
stroke={theme.card}
|
|
325
|
-
strokeWidth={2}
|
|
326
|
-
label={
|
|
327
|
-
marker.label
|
|
328
|
-
? {
|
|
329
|
-
value: marker.label,
|
|
330
|
-
fill: marker.color ?? theme.foreground,
|
|
331
|
-
fontSize: 9,
|
|
332
|
-
fontFamily: theme.fontMono,
|
|
333
|
-
position: "top",
|
|
334
|
-
}
|
|
335
|
-
: undefined
|
|
336
|
-
}
|
|
337
|
-
/>
|
|
338
|
-
))}
|
|
217
|
+
{renderMarkers(markers, theme)}
|
|
339
218
|
</RechartsAreaChart>
|
|
340
219
|
</ResponsiveContainer>
|
|
341
220
|
)}
|
|
@@ -7,9 +7,6 @@ import {
|
|
|
7
7
|
Cell,
|
|
8
8
|
LabelList,
|
|
9
9
|
BarChart as RechartsBarChart,
|
|
10
|
-
ReferenceArea,
|
|
11
|
-
ReferenceDot,
|
|
12
|
-
ReferenceLine,
|
|
13
10
|
ResponsiveContainer,
|
|
14
11
|
Tooltip,
|
|
15
12
|
XAxis,
|
|
@@ -22,6 +19,13 @@ import { cn } from "../lib/cn";
|
|
|
22
19
|
import type { ChartMarker } from "./area-chart";
|
|
23
20
|
import { useChartContext } from "./chart-container";
|
|
24
21
|
import { ChartLegend } from "./chart-legend";
|
|
22
|
+
import {
|
|
23
|
+
computeNumericMax,
|
|
24
|
+
makeChartAxis,
|
|
25
|
+
makeLegendItems,
|
|
26
|
+
renderMarkers,
|
|
27
|
+
renderReferenceLine,
|
|
28
|
+
} from "./chart-primitives";
|
|
25
29
|
import { ChartTooltipContent } from "./chart-tooltip";
|
|
26
30
|
import { Skeleton } from "./skeleton";
|
|
27
31
|
|
|
@@ -78,27 +82,7 @@ function BarChart({
|
|
|
78
82
|
const lead = resolved[0];
|
|
79
83
|
const withTotal = stacked && rendered.length > 1;
|
|
80
84
|
|
|
81
|
-
|
|
82
|
-
// series, so the explicit YAxis domain must not clip a tall stack short.
|
|
83
|
-
const numericMax = React.useMemo(() => {
|
|
84
|
-
let max = 0;
|
|
85
|
-
for (const row of data) {
|
|
86
|
-
let rowTotal = 0;
|
|
87
|
-
for (const entry of series) {
|
|
88
|
-
const value = Number(row[entry.key]);
|
|
89
|
-
if (Number.isFinite(value)) {
|
|
90
|
-
rowTotal += value;
|
|
91
|
-
if (!stacked && value > max) {
|
|
92
|
-
max = value;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
if (stacked && rowTotal > max) {
|
|
97
|
-
max = rowTotal;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
return max;
|
|
101
|
-
}, [data, series, stacked]);
|
|
85
|
+
const numericMax = React.useMemo(() => computeNumericMax(data, series, stacked), [data, series, stacked]);
|
|
102
86
|
|
|
103
87
|
const topSlotByRow = React.useMemo(() => {
|
|
104
88
|
if (!stacked) {
|
|
@@ -117,14 +101,9 @@ function BarChart({
|
|
|
117
101
|
|
|
118
102
|
const margin = { top: markers?.length || valueLabels ? 18 : 8, right: 8, bottom: 2, left: 0 };
|
|
119
103
|
|
|
120
|
-
const axis =
|
|
121
|
-
stroke: theme.border,
|
|
122
|
-
tick: { fill: theme.axisForeground, fontSize: 10, fontFamily: theme.fontMono },
|
|
123
|
-
tickLine: false as const,
|
|
124
|
-
axisLine: { stroke: theme.border, strokeOpacity: 0.6 },
|
|
125
|
-
};
|
|
104
|
+
const axis = makeChartAxis(theme);
|
|
126
105
|
|
|
127
|
-
const legendItems = resolved
|
|
106
|
+
const legendItems = makeLegendItems(resolved);
|
|
128
107
|
|
|
129
108
|
const radiusFor = (slot: number): [number, number, number, number] => {
|
|
130
109
|
if (!stacked || slot === rendered.length - 1) {
|
|
@@ -251,34 +230,7 @@ function BarChart({
|
|
|
251
230
|
/>
|
|
252
231
|
}
|
|
253
232
|
/>
|
|
254
|
-
{referenceLine
|
|
255
|
-
<ReferenceArea
|
|
256
|
-
y1={referenceLine.y}
|
|
257
|
-
y2={numericMax}
|
|
258
|
-
fill={theme.warning}
|
|
259
|
-
fillOpacity={0.06}
|
|
260
|
-
ifOverflow="extendDomain"
|
|
261
|
-
/>
|
|
262
|
-
)}
|
|
263
|
-
{referenceLine && (
|
|
264
|
-
<ReferenceLine
|
|
265
|
-
y={referenceLine.y}
|
|
266
|
-
stroke={theme.warning}
|
|
267
|
-
strokeDasharray="4 4"
|
|
268
|
-
strokeOpacity={0.6}
|
|
269
|
-
label={
|
|
270
|
-
referenceLine.label
|
|
271
|
-
? {
|
|
272
|
-
value: referenceLine.label,
|
|
273
|
-
fill: theme.warning,
|
|
274
|
-
fontSize: 9,
|
|
275
|
-
fontFamily: theme.fontMono,
|
|
276
|
-
position: "insideBottomRight",
|
|
277
|
-
}
|
|
278
|
-
: undefined
|
|
279
|
-
}
|
|
280
|
-
/>
|
|
281
|
-
)}
|
|
233
|
+
{renderReferenceLine({ referenceLine, numericMax, theme })}
|
|
282
234
|
|
|
283
235
|
{rendered.map((entry, slot) => (
|
|
284
236
|
<Bar
|
|
@@ -320,28 +272,7 @@ function BarChart({
|
|
|
320
272
|
</Bar>
|
|
321
273
|
))}
|
|
322
274
|
|
|
323
|
-
{markers
|
|
324
|
-
<ReferenceDot
|
|
325
|
-
key={`${marker.x}-${marker.y}`}
|
|
326
|
-
x={marker.x}
|
|
327
|
-
y={marker.y}
|
|
328
|
-
r={3.5}
|
|
329
|
-
fill={marker.color ?? theme.foreground}
|
|
330
|
-
stroke={theme.card}
|
|
331
|
-
strokeWidth={2}
|
|
332
|
-
label={
|
|
333
|
-
marker.label
|
|
334
|
-
? {
|
|
335
|
-
value: marker.label,
|
|
336
|
-
fill: marker.color ?? theme.foreground,
|
|
337
|
-
fontSize: 9,
|
|
338
|
-
fontFamily: theme.fontMono,
|
|
339
|
-
position: "top",
|
|
340
|
-
}
|
|
341
|
-
: undefined
|
|
342
|
-
}
|
|
343
|
-
/>
|
|
344
|
-
))}
|
|
275
|
+
{renderMarkers(markers, theme)}
|
|
345
276
|
</RechartsBarChart>
|
|
346
277
|
</ResponsiveContainer>
|
|
347
278
|
)}
|