@wello-dev/charts 0.0.0-stage → 1.0.3
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/LICENSE +47 -0
- package/README.md +155 -3
- package/dist/index.cjs +1999 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +526 -0
- package/dist/index.d.ts +526 -0
- package/dist/index.js +1965 -0
- package/dist/index.js.map +1 -0
- package/dist/styles.css +281 -0
- package/package.json +85 -6
package/dist/index.js
ADDED
|
@@ -0,0 +1,1965 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// #style-inject:#style-inject
|
|
4
|
+
function styleInject(css, { insertAt } = {}) {
|
|
5
|
+
if (!css || typeof document === "undefined") return;
|
|
6
|
+
const head = document.head || document.getElementsByTagName("head")[0];
|
|
7
|
+
const style = document.createElement("style");
|
|
8
|
+
style.type = "text/css";
|
|
9
|
+
if (insertAt === "top") {
|
|
10
|
+
if (head.firstChild) {
|
|
11
|
+
head.insertBefore(style, head.firstChild);
|
|
12
|
+
} else {
|
|
13
|
+
head.appendChild(style);
|
|
14
|
+
}
|
|
15
|
+
} else {
|
|
16
|
+
head.appendChild(style);
|
|
17
|
+
}
|
|
18
|
+
if (style.styleSheet) {
|
|
19
|
+
style.styleSheet.cssText = css;
|
|
20
|
+
} else {
|
|
21
|
+
style.appendChild(document.createTextNode(css));
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// src/styles.css
|
|
26
|
+
styleInject(".wello-chart {\n --wello-chart-primary: var(--wello-primary-color, var(--primary, #26372c));\n --wello-chart-bg: var(--wello-color-surface, var(--card, #ffffff));\n --wello-chart-text-color: var(--wello-color-dimmed, var(--muted-foreground, #64748b));\n --wello-chart-bright-color: var(--wello-color-bright, var(--foreground, #0f172a));\n --wello-chart-dimmed-color: var(--wello-color-dimmed, var(--muted-foreground, #64748b));\n --wello-chart-grid-color: var(--wello-color-border, var(--border, #e2e8f0));\n --wello-chart-cursor-fill: color-mix(in srgb, var(--wello-chart-primary) 8%, transparent);\n --wello-chart-label-line-color: var(--wello-color-border-strong, var(--input, #cbd5e1));\n --wello-chart-tooltip-bg: var(--wello-color-bright, var(--foreground, #0f172a));\n --wello-chart-tooltip-fg: var(--wello-color-body, var(--background, #ffffff));\n --wello-chart-heatmap-empty: color-mix(in srgb, var(--wello-chart-text-color) 15%, transparent);\n --wello-chart-radial-bg: color-mix(in srgb, var(--wello-chart-text-color) 12%, transparent);\n --wello-chart-muted: color-mix(in srgb, var(--wello-chart-text-color) 35%, transparent);\n --wello-chart-font: inherit;\n box-sizing: border-box;\n position: relative;\n padding: 16px;\n border: 1px solid var(--wello-chart-grid-color);\n border-radius: 12px;\n background: var(--wello-chart-bg);\n box-shadow: 0 2px 8px rgb(15 23 42 / 0.08);\n color: var(--wello-chart-text-color);\n font-family: var(--wello-chart-font);\n}\n.dark .wello-chart,\n[data-theme=dark] .wello-chart,\n.wello-chart[data-theme=dark] {\n --wello-chart-primary: var(--wello-primary-color, var(--primary, #9fbfa8));\n --wello-chart-bg: var(--wello-color-surface, var(--card, #0f172a));\n --wello-chart-text-color: var(--wello-color-dimmed, var(--muted-foreground, #94a3b8));\n --wello-chart-bright-color: var(--wello-color-bright, var(--foreground, #f8fafc));\n --wello-chart-dimmed-color: var(--wello-color-dimmed, var(--muted-foreground, #94a3b8));\n --wello-chart-grid-color: var(--wello-color-border, var(--border, #334155));\n --wello-chart-label-line-color: var(--wello-color-border-strong, var(--input, #475569));\n --wello-chart-tooltip-bg: var(--wello-color-bright, var(--foreground, #f8fafc));\n --wello-chart-tooltip-fg: var(--wello-color-body, var(--background, #0f172a));\n}\n.wello-chart .recharts-wrapper:focus,\n.wello-chart .recharts-surface:focus,\n.wello-chart *:focus:not(:focus-visible) {\n outline: none;\n}\n.wello-tooltip {\n min-width: 8.5rem;\n padding: 10px 12px;\n border-radius: 12px;\n background: color-mix(in srgb, var(--wello-chart-tooltip-bg) 94%, transparent);\n color: var(--wello-chart-tooltip-fg);\n box-shadow: 0 12px 32px rgb(0 0 0 / 0.24);\n font-size: 12px;\n line-height: 1.4;\n pointer-events: none;\n}\n.wello-tooltip-label {\n display: flex;\n align-items: center;\n gap: 8px;\n margin-bottom: 4px;\n opacity: 0.8;\n}\n.wello-tooltip--slice .wello-tooltip-label {\n margin-bottom: 6px;\n font-weight: 600;\n opacity: 1;\n}\n.wello-tooltip-body {\n display: flex;\n flex-direction: column;\n gap: 4px;\n}\n.wello-tooltip-item {\n display: flex;\n align-items: center;\n gap: 8px;\n}\n.wello-tooltip-swatch,\n.wello-legend-swatch {\n flex-shrink: 0;\n width: 8px;\n height: 8px;\n border-radius: 999px;\n}\n.wello-tooltip .wello-tooltip-swatch {\n box-shadow: 0 0 0 1px color-mix(in srgb, var(--wello-chart-tooltip-fg) 45%, transparent);\n}\n.wello-tooltip-item-name {\n flex: 1;\n opacity: 0.8;\n}\n.wello-tooltip-item-value {\n margin-inline-start: 16px;\n font-variant-numeric: tabular-nums;\n font-weight: 700;\n}\n.wello-legend {\n display: flex;\n flex-wrap: wrap;\n gap: 4px 16px;\n padding-bottom: 8px;\n font-size: 11px;\n color: var(--wello-chart-text-color);\n}\n.wello-legend--left {\n justify-content: flex-start;\n}\n.wello-legend--center {\n justify-content: center;\n}\n.wello-legend--right {\n justify-content: flex-end;\n}\n.wello-legend-item {\n display: flex;\n align-items: center;\n gap: 6px;\n padding: 2px 6px;\n border-radius: 4px;\n cursor: default;\n}\n.wello-legend-item:hover {\n background: var(--wello-chart-cursor-fill);\n}\n.wello-chart-skeleton {\n border-radius: 12px;\n background: color-mix(in srgb, var(--wello-chart-text-color) 14%, transparent);\n animation: wello-pulse 1.6s ease-in-out infinite;\n}\n.wello-chart-empty {\n display: flex;\n align-items: center;\n justify-content: center;\n padding: 16px;\n font-size: 14px;\n font-weight: 500;\n text-align: center;\n}\n@keyframes wello-pulse {\n 50% {\n opacity: 0.5;\n }\n}\n@media (prefers-reduced-motion: reduce) {\n .wello-chart-skeleton {\n animation: none;\n }\n}\n.wello-pie .wello-legend {\n padding: 8px 0 0;\n}\n.wello-pie-area {\n position: relative;\n}\n.wello-floating-tooltip {\n z-index: 9999;\n pointer-events: none;\n white-space: nowrap;\n font-family: var(--wello-chart-font, inherit);\n}\n.wello-donut-label {\n position: absolute;\n inset: 0;\n display: flex;\n align-items: center;\n justify-content: center;\n pointer-events: none;\n text-align: center;\n}\n.wello-donut-label-inner {\n display: flex;\n flex-direction: column;\n align-items: center;\n line-height: 1;\n}\n.wello-donut-label-main {\n color: var(--wello-chart-primary);\n font-size: 24px;\n font-weight: 900;\n font-variant-numeric: tabular-nums;\n letter-spacing: -0.025em;\n}\n.wello-donut-label-sub {\n margin-top: 6px;\n color: var(--wello-chart-text-color);\n font-size: 12px;\n font-weight: 600;\n}\n.wello-radial-bar .wello-legend {\n padding: 8px 0 0;\n}\n.wello-heatmap {\n display: inline-block;\n}\n.wello-heatmap svg {\n display: block;\n overflow: visible;\n}\n.wello-heatmap-label {\n fill: var(--wello-chart-text-color);\n}\n.wello-heatmap-rect--outside {\n opacity: 0.4;\n}\n.wello-heatmap-tooltip {\n min-width: 0;\n}\n.wello-heatmap-legend {\n display: flex;\n align-items: center;\n justify-content: flex-end;\n gap: 3px;\n margin-top: 8px;\n color: var(--wello-chart-text-color);\n}\n.wello-heatmap-legend > span:first-child {\n margin-inline-end: 4px;\n}\n.wello-heatmap-legend > span:last-child {\n margin-inline-start: 4px;\n}\n");
|
|
27
|
+
|
|
28
|
+
// src/charts/area-chart.tsx
|
|
29
|
+
import { Area, AreaChart as ReAreaChart, LabelList, ResponsiveContainer } from "recharts";
|
|
30
|
+
import { useRef } from "react";
|
|
31
|
+
|
|
32
|
+
// src/shared/cartesian.tsx
|
|
33
|
+
import { useState as useState2 } from "react";
|
|
34
|
+
import { CartesianGrid, Legend, ReferenceLine, Tooltip, XAxis, YAxis } from "recharts";
|
|
35
|
+
|
|
36
|
+
// src/lib/colors.ts
|
|
37
|
+
var DEFAULT_CHART_COLORS = {
|
|
38
|
+
slate: [
|
|
39
|
+
"#f8fafc",
|
|
40
|
+
"#f1f5f9",
|
|
41
|
+
"#e2e8f0",
|
|
42
|
+
"#cbd5e1",
|
|
43
|
+
"#94a3b8",
|
|
44
|
+
"#64748b",
|
|
45
|
+
"#475569",
|
|
46
|
+
"#334155",
|
|
47
|
+
"#1e293b",
|
|
48
|
+
"#0f172a",
|
|
49
|
+
"#020617"
|
|
50
|
+
],
|
|
51
|
+
gray: [
|
|
52
|
+
"#f9fafb",
|
|
53
|
+
"#f3f4f6",
|
|
54
|
+
"#e5e7eb",
|
|
55
|
+
"#d1d5db",
|
|
56
|
+
"#9ca3af",
|
|
57
|
+
"#6b7280",
|
|
58
|
+
"#4b5563",
|
|
59
|
+
"#374151",
|
|
60
|
+
"#1f2937",
|
|
61
|
+
"#111827",
|
|
62
|
+
"#030712"
|
|
63
|
+
],
|
|
64
|
+
zinc: [
|
|
65
|
+
"#fafafa",
|
|
66
|
+
"#f4f4f5",
|
|
67
|
+
"#e4e4e7",
|
|
68
|
+
"#d4d4d8",
|
|
69
|
+
"#a1a1aa",
|
|
70
|
+
"#71717a",
|
|
71
|
+
"#52525b",
|
|
72
|
+
"#3f3f46",
|
|
73
|
+
"#27272a",
|
|
74
|
+
"#18181b",
|
|
75
|
+
"#09090b"
|
|
76
|
+
],
|
|
77
|
+
neutral: [
|
|
78
|
+
"#fafafa",
|
|
79
|
+
"#f5f5f5",
|
|
80
|
+
"#e5e5e5",
|
|
81
|
+
"#d4d4d4",
|
|
82
|
+
"#a3a3a3",
|
|
83
|
+
"#737373",
|
|
84
|
+
"#525252",
|
|
85
|
+
"#404040",
|
|
86
|
+
"#262626",
|
|
87
|
+
"#171717",
|
|
88
|
+
"#0a0a0a"
|
|
89
|
+
],
|
|
90
|
+
stone: [
|
|
91
|
+
"#fafaf9",
|
|
92
|
+
"#f5f5f4",
|
|
93
|
+
"#e7e5e4",
|
|
94
|
+
"#d6d3d1",
|
|
95
|
+
"#a8a29e",
|
|
96
|
+
"#78716c",
|
|
97
|
+
"#57534e",
|
|
98
|
+
"#44403c",
|
|
99
|
+
"#292524",
|
|
100
|
+
"#1c1917",
|
|
101
|
+
"#0c0a09"
|
|
102
|
+
],
|
|
103
|
+
red: [
|
|
104
|
+
"#fef2f2",
|
|
105
|
+
"#fee2e2",
|
|
106
|
+
"#fecaca",
|
|
107
|
+
"#fca5a5",
|
|
108
|
+
"#f87171",
|
|
109
|
+
"#ef4444",
|
|
110
|
+
"#dc2626",
|
|
111
|
+
"#b91c1c",
|
|
112
|
+
"#991b1b",
|
|
113
|
+
"#7f1d1d",
|
|
114
|
+
"#450a0a"
|
|
115
|
+
],
|
|
116
|
+
orange: [
|
|
117
|
+
"#fff7ed",
|
|
118
|
+
"#ffedd5",
|
|
119
|
+
"#fed7aa",
|
|
120
|
+
"#fdba74",
|
|
121
|
+
"#fb923c",
|
|
122
|
+
"#f97316",
|
|
123
|
+
"#ea580c",
|
|
124
|
+
"#c2410c",
|
|
125
|
+
"#9a3412",
|
|
126
|
+
"#7c2d12",
|
|
127
|
+
"#431407"
|
|
128
|
+
],
|
|
129
|
+
amber: [
|
|
130
|
+
"#fffbeb",
|
|
131
|
+
"#fef3c7",
|
|
132
|
+
"#fde68a",
|
|
133
|
+
"#fcd34d",
|
|
134
|
+
"#fbbf24",
|
|
135
|
+
"#f59e0b",
|
|
136
|
+
"#d97706",
|
|
137
|
+
"#b45309",
|
|
138
|
+
"#92400e",
|
|
139
|
+
"#78350f",
|
|
140
|
+
"#451a03"
|
|
141
|
+
],
|
|
142
|
+
yellow: [
|
|
143
|
+
"#fefce8",
|
|
144
|
+
"#fef9c3",
|
|
145
|
+
"#fef08a",
|
|
146
|
+
"#fde047",
|
|
147
|
+
"#facc15",
|
|
148
|
+
"#eab308",
|
|
149
|
+
"#ca8a04",
|
|
150
|
+
"#a16207",
|
|
151
|
+
"#854d0e",
|
|
152
|
+
"#713f12",
|
|
153
|
+
"#422006"
|
|
154
|
+
],
|
|
155
|
+
lime: [
|
|
156
|
+
"#f7fee7",
|
|
157
|
+
"#ecfccb",
|
|
158
|
+
"#d9f99d",
|
|
159
|
+
"#bef264",
|
|
160
|
+
"#a3e635",
|
|
161
|
+
"#84cc16",
|
|
162
|
+
"#65a30d",
|
|
163
|
+
"#4d7c0f",
|
|
164
|
+
"#3f6212",
|
|
165
|
+
"#365314",
|
|
166
|
+
"#1a2e05"
|
|
167
|
+
],
|
|
168
|
+
green: [
|
|
169
|
+
"#f0fdf4",
|
|
170
|
+
"#dcfce7",
|
|
171
|
+
"#bbf7d0",
|
|
172
|
+
"#86efac",
|
|
173
|
+
"#4ade80",
|
|
174
|
+
"#22c55e",
|
|
175
|
+
"#16a34a",
|
|
176
|
+
"#15803d",
|
|
177
|
+
"#166534",
|
|
178
|
+
"#14532d",
|
|
179
|
+
"#052e16"
|
|
180
|
+
],
|
|
181
|
+
emerald: [
|
|
182
|
+
"#ecfdf5",
|
|
183
|
+
"#d1fae5",
|
|
184
|
+
"#a7f3d0",
|
|
185
|
+
"#6ee7b7",
|
|
186
|
+
"#34d399",
|
|
187
|
+
"#10b981",
|
|
188
|
+
"#059669",
|
|
189
|
+
"#047857",
|
|
190
|
+
"#065f46",
|
|
191
|
+
"#064e3b",
|
|
192
|
+
"#022c22"
|
|
193
|
+
],
|
|
194
|
+
teal: [
|
|
195
|
+
"#f0fdfa",
|
|
196
|
+
"#ccfbf1",
|
|
197
|
+
"#99f6e4",
|
|
198
|
+
"#5eead4",
|
|
199
|
+
"#2dd4bf",
|
|
200
|
+
"#14b8a6",
|
|
201
|
+
"#0d9488",
|
|
202
|
+
"#0f766e",
|
|
203
|
+
"#115e59",
|
|
204
|
+
"#134e4a",
|
|
205
|
+
"#042f2e"
|
|
206
|
+
],
|
|
207
|
+
cyan: [
|
|
208
|
+
"#ecfeff",
|
|
209
|
+
"#cffafe",
|
|
210
|
+
"#a5f3fc",
|
|
211
|
+
"#67e8f9",
|
|
212
|
+
"#22d3ee",
|
|
213
|
+
"#06b6d4",
|
|
214
|
+
"#0891b2",
|
|
215
|
+
"#0e7490",
|
|
216
|
+
"#155e75",
|
|
217
|
+
"#164e63",
|
|
218
|
+
"#083344"
|
|
219
|
+
],
|
|
220
|
+
sky: [
|
|
221
|
+
"#f0f9ff",
|
|
222
|
+
"#e0f2fe",
|
|
223
|
+
"#bae6fd",
|
|
224
|
+
"#7dd3fc",
|
|
225
|
+
"#38bdf8",
|
|
226
|
+
"#0ea5e9",
|
|
227
|
+
"#0284c7",
|
|
228
|
+
"#0369a1",
|
|
229
|
+
"#075985",
|
|
230
|
+
"#0c4a6e",
|
|
231
|
+
"#082f49"
|
|
232
|
+
],
|
|
233
|
+
blue: [
|
|
234
|
+
"#eff6ff",
|
|
235
|
+
"#dbeafe",
|
|
236
|
+
"#bfdbfe",
|
|
237
|
+
"#93c5fd",
|
|
238
|
+
"#60a5fa",
|
|
239
|
+
"#3b82f6",
|
|
240
|
+
"#2563eb",
|
|
241
|
+
"#1d4ed8",
|
|
242
|
+
"#1e40af",
|
|
243
|
+
"#1e3a8a",
|
|
244
|
+
"#172554"
|
|
245
|
+
],
|
|
246
|
+
indigo: [
|
|
247
|
+
"#eef2ff",
|
|
248
|
+
"#e0e7ff",
|
|
249
|
+
"#c7d2fe",
|
|
250
|
+
"#a5b4fc",
|
|
251
|
+
"#818cf8",
|
|
252
|
+
"#6366f1",
|
|
253
|
+
"#4f46e5",
|
|
254
|
+
"#4338ca",
|
|
255
|
+
"#3730a3",
|
|
256
|
+
"#312e81",
|
|
257
|
+
"#1e1b4b"
|
|
258
|
+
],
|
|
259
|
+
violet: [
|
|
260
|
+
"#f5f3ff",
|
|
261
|
+
"#ede9fe",
|
|
262
|
+
"#ddd6fe",
|
|
263
|
+
"#c4b5fd",
|
|
264
|
+
"#a78bfa",
|
|
265
|
+
"#8b5cf6",
|
|
266
|
+
"#7c3aed",
|
|
267
|
+
"#6d28d9",
|
|
268
|
+
"#5b21b6",
|
|
269
|
+
"#4c1d95",
|
|
270
|
+
"#2e1065"
|
|
271
|
+
],
|
|
272
|
+
purple: [
|
|
273
|
+
"#faf5ff",
|
|
274
|
+
"#f3e8ff",
|
|
275
|
+
"#e9d5ff",
|
|
276
|
+
"#d8b4fe",
|
|
277
|
+
"#c084fc",
|
|
278
|
+
"#a855f7",
|
|
279
|
+
"#9333ea",
|
|
280
|
+
"#7e22ce",
|
|
281
|
+
"#6b21a8",
|
|
282
|
+
"#581c87",
|
|
283
|
+
"#3b0764"
|
|
284
|
+
],
|
|
285
|
+
fuchsia: [
|
|
286
|
+
"#fdf4ff",
|
|
287
|
+
"#fae8ff",
|
|
288
|
+
"#f5d0fe",
|
|
289
|
+
"#f0abfc",
|
|
290
|
+
"#e879f9",
|
|
291
|
+
"#d946ef",
|
|
292
|
+
"#c026d3",
|
|
293
|
+
"#a21caf",
|
|
294
|
+
"#86198f",
|
|
295
|
+
"#701a75",
|
|
296
|
+
"#4a044e"
|
|
297
|
+
],
|
|
298
|
+
pink: [
|
|
299
|
+
"#fdf2f8",
|
|
300
|
+
"#fce7f3",
|
|
301
|
+
"#fbcfe8",
|
|
302
|
+
"#f9a8d4",
|
|
303
|
+
"#f472b6",
|
|
304
|
+
"#ec4899",
|
|
305
|
+
"#db2777",
|
|
306
|
+
"#be185d",
|
|
307
|
+
"#9d174d",
|
|
308
|
+
"#831843",
|
|
309
|
+
"#500724"
|
|
310
|
+
],
|
|
311
|
+
rose: [
|
|
312
|
+
"#fff1f2",
|
|
313
|
+
"#ffe4e6",
|
|
314
|
+
"#fecdd3",
|
|
315
|
+
"#fda4af",
|
|
316
|
+
"#fb7185",
|
|
317
|
+
"#f43f5e",
|
|
318
|
+
"#e11d48",
|
|
319
|
+
"#be123c",
|
|
320
|
+
"#9f1239",
|
|
321
|
+
"#881337",
|
|
322
|
+
"#4c0519"
|
|
323
|
+
]
|
|
324
|
+
};
|
|
325
|
+
var SHADES = [50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950];
|
|
326
|
+
var DEFAULT_SHADE = 500;
|
|
327
|
+
function getThemeColor(color, fallback = "var(--wello-chart-text-color)") {
|
|
328
|
+
if (!color) return fallback;
|
|
329
|
+
if (color === "dimmed") return "var(--wello-chart-dimmed-color)";
|
|
330
|
+
if (color === "bright") return "var(--wello-chart-bright-color)";
|
|
331
|
+
const match = /^([a-z]+)(?:-(\d{2,3}))?$/.exec(color);
|
|
332
|
+
if (!match) return color;
|
|
333
|
+
const palette = DEFAULT_CHART_COLORS[match[1]];
|
|
334
|
+
if (!palette) return color;
|
|
335
|
+
const shade = match[2] === void 0 ? DEFAULT_SHADE : Number(match[2]);
|
|
336
|
+
const index = SHADES.indexOf(shade);
|
|
337
|
+
if (index === -1) return color;
|
|
338
|
+
return `var(--color-${match[1]}-${shade}, ${palette[index]})`;
|
|
339
|
+
}
|
|
340
|
+
var CHART_COLORS = [
|
|
341
|
+
"emerald-500",
|
|
342
|
+
"amber-500",
|
|
343
|
+
"violet-500",
|
|
344
|
+
"orange-500",
|
|
345
|
+
"cyan-500",
|
|
346
|
+
"pink-500",
|
|
347
|
+
"red-500",
|
|
348
|
+
"lime-500",
|
|
349
|
+
"slate-500",
|
|
350
|
+
"indigo-500",
|
|
351
|
+
"slate-400"
|
|
352
|
+
];
|
|
353
|
+
function seriesColor(color, index, palette = CHART_COLORS) {
|
|
354
|
+
return getThemeColor(color ?? palette[index % palette.length]);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
// src/lib/utils.ts
|
|
358
|
+
import { useId, useLayoutEffect, useState } from "react";
|
|
359
|
+
function cx(...classes) {
|
|
360
|
+
return classes.filter(Boolean).join(" ");
|
|
361
|
+
}
|
|
362
|
+
function formatValue(value, formatter) {
|
|
363
|
+
if (typeof value === "number") return formatter ? formatter(value) : String(value);
|
|
364
|
+
if (Array.isArray(value)) return value.map((v) => formatValue(v, formatter)).join(" \u2013 ");
|
|
365
|
+
return value === void 0 || value === null ? "" : String(value);
|
|
366
|
+
}
|
|
367
|
+
function useSvgId(prefix) {
|
|
368
|
+
return `${prefix}-${useId().replace(/[^a-zA-Z0-9_-]/g, "")}`;
|
|
369
|
+
}
|
|
370
|
+
var useIsomorphicLayoutEffect = typeof window === "undefined" ? () => {
|
|
371
|
+
} : useLayoutEffect;
|
|
372
|
+
function useIsRtl(ref) {
|
|
373
|
+
const [rtl, setRtl] = useState(false);
|
|
374
|
+
useIsomorphicLayoutEffect(() => {
|
|
375
|
+
if (ref.current) setRtl(getComputedStyle(ref.current).direction === "rtl");
|
|
376
|
+
});
|
|
377
|
+
return rtl;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
// src/components/chart-legend.tsx
|
|
381
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
382
|
+
function ChartLegend({ series, onHighlight, align = "right", className }) {
|
|
383
|
+
return /* @__PURE__ */ jsx("div", { className: cx("wello-legend", `wello-legend--${align}`, className), children: series.map((item) => /* @__PURE__ */ jsxs(
|
|
384
|
+
"div",
|
|
385
|
+
{
|
|
386
|
+
className: "wello-legend-item",
|
|
387
|
+
onMouseEnter: () => onHighlight?.(item.name),
|
|
388
|
+
onMouseLeave: () => onHighlight?.(null),
|
|
389
|
+
children: [
|
|
390
|
+
/* @__PURE__ */ jsx("span", { className: "wello-legend-swatch", style: { background: getThemeColor(item.color) } }),
|
|
391
|
+
/* @__PURE__ */ jsx("span", { children: item.label ?? item.name })
|
|
392
|
+
]
|
|
393
|
+
},
|
|
394
|
+
item.name
|
|
395
|
+
)) });
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
// src/components/chart-tooltip.tsx
|
|
399
|
+
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
400
|
+
function ChartTooltip({
|
|
401
|
+
label,
|
|
402
|
+
items,
|
|
403
|
+
series,
|
|
404
|
+
unit,
|
|
405
|
+
valueFormatter,
|
|
406
|
+
className
|
|
407
|
+
}) {
|
|
408
|
+
const visible = items.filter((item) => item.value !== void 0 && item.value !== null);
|
|
409
|
+
if (!visible.length) return null;
|
|
410
|
+
return /* @__PURE__ */ jsxs2("div", { className: cx("wello-tooltip", className), children: [
|
|
411
|
+
label !== void 0 && label !== null && label !== "" && /* @__PURE__ */ jsx2("div", { className: "wello-tooltip-label", children: label }),
|
|
412
|
+
/* @__PURE__ */ jsx2("div", { className: "wello-tooltip-body", children: visible.map((item) => {
|
|
413
|
+
const config = series?.find((s) => s.name === item.name);
|
|
414
|
+
return /* @__PURE__ */ jsxs2("div", { className: "wello-tooltip-item", children: [
|
|
415
|
+
/* @__PURE__ */ jsx2(
|
|
416
|
+
"span",
|
|
417
|
+
{
|
|
418
|
+
className: "wello-tooltip-swatch",
|
|
419
|
+
style: { background: config ? getThemeColor(config.color) : item.color }
|
|
420
|
+
}
|
|
421
|
+
),
|
|
422
|
+
/* @__PURE__ */ jsx2("span", { className: "wello-tooltip-item-name", children: config?.label ?? item.name }),
|
|
423
|
+
/* @__PURE__ */ jsxs2("span", { className: "wello-tooltip-item-value", children: [
|
|
424
|
+
formatValue(item.value, valueFormatter),
|
|
425
|
+
unit
|
|
426
|
+
] })
|
|
427
|
+
] }, item.name);
|
|
428
|
+
}) })
|
|
429
|
+
] });
|
|
430
|
+
}
|
|
431
|
+
function renderCartesianTooltip(options, labelFormatter) {
|
|
432
|
+
return ({ active, label, payload }) => {
|
|
433
|
+
if (!active || !payload?.length) return null;
|
|
434
|
+
return /* @__PURE__ */ jsx2(
|
|
435
|
+
ChartTooltip,
|
|
436
|
+
{
|
|
437
|
+
...options,
|
|
438
|
+
label: labelFormatter ? labelFormatter(label) : label,
|
|
439
|
+
items: payload.map((entry) => ({
|
|
440
|
+
name: String(entry.dataKey ?? entry.name),
|
|
441
|
+
value: entry.payload?.__value ?? entry.payload?.[entry.dataKey] ?? entry.value,
|
|
442
|
+
color: entry.color
|
|
443
|
+
}))
|
|
444
|
+
}
|
|
445
|
+
);
|
|
446
|
+
};
|
|
447
|
+
}
|
|
448
|
+
function ChartSliceTooltip({
|
|
449
|
+
name,
|
|
450
|
+
value,
|
|
451
|
+
color,
|
|
452
|
+
percent,
|
|
453
|
+
valueFormatter
|
|
454
|
+
}) {
|
|
455
|
+
return /* @__PURE__ */ jsxs2("div", { className: "wello-tooltip wello-tooltip--slice", children: [
|
|
456
|
+
/* @__PURE__ */ jsxs2("div", { className: "wello-tooltip-label", children: [
|
|
457
|
+
/* @__PURE__ */ jsx2("span", { className: "wello-tooltip-swatch", style: { background: color } }),
|
|
458
|
+
/* @__PURE__ */ jsx2("span", { children: name })
|
|
459
|
+
] }),
|
|
460
|
+
/* @__PURE__ */ jsxs2("div", { className: "wello-tooltip-item", children: [
|
|
461
|
+
/* @__PURE__ */ jsxs2("span", { className: "wello-tooltip-item-name", children: [
|
|
462
|
+
percent.toFixed(1),
|
|
463
|
+
"%"
|
|
464
|
+
] }),
|
|
465
|
+
/* @__PURE__ */ jsx2("span", { className: "wello-tooltip-item-value", children: formatValue(value, valueFormatter) })
|
|
466
|
+
] })
|
|
467
|
+
] });
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
// src/shared/cartesian.tsx
|
|
471
|
+
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
472
|
+
function resolveSeries(props) {
|
|
473
|
+
return props.series.map((item, index) => ({
|
|
474
|
+
...item,
|
|
475
|
+
color: seriesColor(item.color, index, props.colors)
|
|
476
|
+
}));
|
|
477
|
+
}
|
|
478
|
+
function useHighlight() {
|
|
479
|
+
return useState2(null);
|
|
480
|
+
}
|
|
481
|
+
function isDimmed(highlighted, name) {
|
|
482
|
+
return highlighted !== null && highlighted !== name;
|
|
483
|
+
}
|
|
484
|
+
function withLabelPadding(props) {
|
|
485
|
+
const vertical = props.orientation === "vertical";
|
|
486
|
+
const key = vertical ? "yAxisProps" : "xAxisProps";
|
|
487
|
+
const padding = vertical ? { top: 20, bottom: 20 } : { left: 30, right: 30 };
|
|
488
|
+
return { ...props, [key]: { padding, ...props[key] } };
|
|
489
|
+
}
|
|
490
|
+
function tickFormatter(props) {
|
|
491
|
+
return (value) => `${props.valueFormatter ? props.valueFormatter(value) : value}${props.unit ?? ""}`;
|
|
492
|
+
}
|
|
493
|
+
function axisLabel(value, axis) {
|
|
494
|
+
if (!value) return void 0;
|
|
495
|
+
if (axis === "x")
|
|
496
|
+
return { value, position: "insideBottom", offset: -16, fontSize: 12, fill: "currentColor" };
|
|
497
|
+
return {
|
|
498
|
+
value,
|
|
499
|
+
angle: axis === "y" ? -90 : 90,
|
|
500
|
+
position: axis === "y" ? "insideLeft" : "insideRight",
|
|
501
|
+
fontSize: 12,
|
|
502
|
+
fill: "currentColor",
|
|
503
|
+
style: { textAnchor: "middle" }
|
|
504
|
+
};
|
|
505
|
+
}
|
|
506
|
+
function cartesianElements(props, { onHighlight, cursor, valueTickFormatter, rtl = false }) {
|
|
507
|
+
const {
|
|
508
|
+
dataKey,
|
|
509
|
+
series,
|
|
510
|
+
orientation = "horizontal",
|
|
511
|
+
withLegend = false,
|
|
512
|
+
legendProps,
|
|
513
|
+
withTooltip = true,
|
|
514
|
+
tooltipProps,
|
|
515
|
+
tooltipAnimationDuration = 0,
|
|
516
|
+
withXAxis = true,
|
|
517
|
+
withYAxis = true,
|
|
518
|
+
xAxisProps,
|
|
519
|
+
yAxisProps,
|
|
520
|
+
xAxisLabel,
|
|
521
|
+
yAxisLabel,
|
|
522
|
+
withRightYAxis = false,
|
|
523
|
+
rightYAxisProps,
|
|
524
|
+
rightYAxisLabel,
|
|
525
|
+
gridAxis = "x",
|
|
526
|
+
gridProps,
|
|
527
|
+
tickLine = "none",
|
|
528
|
+
strokeDasharray = "5 5",
|
|
529
|
+
gridColor,
|
|
530
|
+
unit,
|
|
531
|
+
valueFormatter,
|
|
532
|
+
referenceLines
|
|
533
|
+
} = props;
|
|
534
|
+
const vertical = orientation === "vertical";
|
|
535
|
+
const gridStroke = getThemeColor(gridColor, "var(--wello-chart-grid-color)");
|
|
536
|
+
const valueTicks = valueTickFormatter ?? tickFormatter(props);
|
|
537
|
+
const tick = { fill: "currentColor", fontSize: 11 };
|
|
538
|
+
const xTickLine = tickLine === "x" || tickLine === "xy" ? { stroke: "currentColor" } : false;
|
|
539
|
+
const yTickLine = tickLine === "y" || tickLine === "xy" ? { stroke: "currentColor" } : false;
|
|
540
|
+
const categoryAxis = { dataKey, type: "category" };
|
|
541
|
+
const valueAxis = { type: "number", tickFormatter: valueTicks, unit: void 0 };
|
|
542
|
+
const elements = [
|
|
543
|
+
/* @__PURE__ */ jsx3(
|
|
544
|
+
CartesianGrid,
|
|
545
|
+
{
|
|
546
|
+
strokeDasharray,
|
|
547
|
+
stroke: gridStroke,
|
|
548
|
+
strokeOpacity: 0.55,
|
|
549
|
+
horizontal: gridAxis === "x" || gridAxis === "xy",
|
|
550
|
+
vertical: gridAxis === "y" || gridAxis === "xy",
|
|
551
|
+
...gridProps
|
|
552
|
+
},
|
|
553
|
+
"grid"
|
|
554
|
+
),
|
|
555
|
+
/* @__PURE__ */ jsx3(
|
|
556
|
+
XAxis,
|
|
557
|
+
{
|
|
558
|
+
hide: !withXAxis,
|
|
559
|
+
...vertical ? valueAxis : categoryAxis,
|
|
560
|
+
reversed: rtl,
|
|
561
|
+
tick,
|
|
562
|
+
tickLine: xTickLine,
|
|
563
|
+
axisLine: false,
|
|
564
|
+
minTickGap: 5,
|
|
565
|
+
interval: "preserveStartEnd",
|
|
566
|
+
label: axisLabel(xAxisLabel, "x"),
|
|
567
|
+
...xAxisProps
|
|
568
|
+
},
|
|
569
|
+
"x"
|
|
570
|
+
),
|
|
571
|
+
/* @__PURE__ */ jsx3(
|
|
572
|
+
YAxis,
|
|
573
|
+
{
|
|
574
|
+
yAxisId: "left",
|
|
575
|
+
orientation: rtl ? "right" : "left",
|
|
576
|
+
hide: !withYAxis,
|
|
577
|
+
...vertical ? categoryAxis : valueAxis,
|
|
578
|
+
tick,
|
|
579
|
+
tickLine: yTickLine,
|
|
580
|
+
axisLine: false,
|
|
581
|
+
width: vertical ? 80 : 60,
|
|
582
|
+
label: axisLabel(yAxisLabel, "y"),
|
|
583
|
+
...yAxisProps
|
|
584
|
+
},
|
|
585
|
+
"y"
|
|
586
|
+
)
|
|
587
|
+
];
|
|
588
|
+
if (withRightYAxis) {
|
|
589
|
+
elements.push(
|
|
590
|
+
/* @__PURE__ */ jsx3(
|
|
591
|
+
YAxis,
|
|
592
|
+
{
|
|
593
|
+
yAxisId: "right",
|
|
594
|
+
orientation: rtl ? "left" : "right",
|
|
595
|
+
...vertical ? categoryAxis : valueAxis,
|
|
596
|
+
tick,
|
|
597
|
+
tickLine: yTickLine,
|
|
598
|
+
axisLine: false,
|
|
599
|
+
width: 60,
|
|
600
|
+
label: axisLabel(rightYAxisLabel, "right"),
|
|
601
|
+
...rightYAxisProps
|
|
602
|
+
},
|
|
603
|
+
"y-right"
|
|
604
|
+
)
|
|
605
|
+
);
|
|
606
|
+
}
|
|
607
|
+
if (withTooltip) {
|
|
608
|
+
elements.push(
|
|
609
|
+
/* @__PURE__ */ jsx3(
|
|
610
|
+
Tooltip,
|
|
611
|
+
{
|
|
612
|
+
isAnimationActive: tooltipAnimationDuration !== 0,
|
|
613
|
+
animationDuration: tooltipAnimationDuration,
|
|
614
|
+
cursor: cursor === "fill" ? { fill: "var(--wello-chart-cursor-fill)" } : { stroke: gridStroke, strokeWidth: 1 },
|
|
615
|
+
wrapperStyle: { zIndex: 50, outline: "none" },
|
|
616
|
+
offset: 14,
|
|
617
|
+
content: renderCartesianTooltip({ series, unit, valueFormatter }),
|
|
618
|
+
...tooltipProps
|
|
619
|
+
},
|
|
620
|
+
"tooltip"
|
|
621
|
+
)
|
|
622
|
+
);
|
|
623
|
+
}
|
|
624
|
+
if (withLegend) {
|
|
625
|
+
elements.push(
|
|
626
|
+
/* @__PURE__ */ jsx3(
|
|
627
|
+
Legend,
|
|
628
|
+
{
|
|
629
|
+
verticalAlign: legendProps?.verticalAlign ?? "top",
|
|
630
|
+
content: () => /* @__PURE__ */ jsx3(
|
|
631
|
+
ChartLegend,
|
|
632
|
+
{
|
|
633
|
+
series,
|
|
634
|
+
align: legendProps?.align,
|
|
635
|
+
className: props.classNames?.legend,
|
|
636
|
+
onHighlight: legendProps?.highlightOnHover === false ? void 0 : onHighlight
|
|
637
|
+
}
|
|
638
|
+
)
|
|
639
|
+
},
|
|
640
|
+
"legend"
|
|
641
|
+
)
|
|
642
|
+
);
|
|
643
|
+
}
|
|
644
|
+
referenceLines?.forEach((line, index) => {
|
|
645
|
+
const color = getThemeColor(line.color, "var(--wello-chart-text-color)");
|
|
646
|
+
elements.push(
|
|
647
|
+
/* @__PURE__ */ jsx3(
|
|
648
|
+
ReferenceLine,
|
|
649
|
+
{
|
|
650
|
+
yAxisId: line.yAxisId ?? "left",
|
|
651
|
+
x: line.x,
|
|
652
|
+
y: line.y,
|
|
653
|
+
stroke: color,
|
|
654
|
+
strokeDasharray: line.strokeDasharray,
|
|
655
|
+
label: line.label === void 0 ? void 0 : {
|
|
656
|
+
value: line.label,
|
|
657
|
+
fill: color,
|
|
658
|
+
fontSize: 12,
|
|
659
|
+
position: line.y !== void 0 ? "insideBottomLeft" : "insideTopRight"
|
|
660
|
+
},
|
|
661
|
+
ifOverflow: "extendDomain"
|
|
662
|
+
},
|
|
663
|
+
`ref-${index}`
|
|
664
|
+
)
|
|
665
|
+
);
|
|
666
|
+
});
|
|
667
|
+
return elements;
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
// src/components/chart-canvas.tsx
|
|
671
|
+
import { Fragment, jsx as jsx4 } from "react/jsx-runtime";
|
|
672
|
+
function ChartCanvas({
|
|
673
|
+
empty,
|
|
674
|
+
loading = false,
|
|
675
|
+
emptyLabel = "No data",
|
|
676
|
+
height,
|
|
677
|
+
className,
|
|
678
|
+
style,
|
|
679
|
+
children
|
|
680
|
+
}) {
|
|
681
|
+
if (loading)
|
|
682
|
+
return /* @__PURE__ */ jsx4(
|
|
683
|
+
"div",
|
|
684
|
+
{
|
|
685
|
+
className: cx("wello-chart", "wello-chart-skeleton", className),
|
|
686
|
+
style: { height, ...style },
|
|
687
|
+
"aria-busy": true
|
|
688
|
+
}
|
|
689
|
+
);
|
|
690
|
+
if (empty)
|
|
691
|
+
return /* @__PURE__ */ jsx4(
|
|
692
|
+
"div",
|
|
693
|
+
{
|
|
694
|
+
className: cx("wello-chart", "wello-chart-empty", className),
|
|
695
|
+
style: { height, ...style },
|
|
696
|
+
children: emptyLabel
|
|
697
|
+
}
|
|
698
|
+
);
|
|
699
|
+
return /* @__PURE__ */ jsx4(Fragment, { children });
|
|
700
|
+
}
|
|
701
|
+
function isCartesianEmpty(data, keys) {
|
|
702
|
+
return !data.length || !keys.length || !data.some((row) => keys.some((key) => Number(row[key]) !== 0 && row[key] != null));
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
// src/charts/area-chart.tsx
|
|
706
|
+
import { Fragment as Fragment2, jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
707
|
+
function getSplitOffset(data, key) {
|
|
708
|
+
const values = data.map((item) => Number(item[key])).filter((value) => Number.isFinite(value));
|
|
709
|
+
if (!values.length) return 0.5;
|
|
710
|
+
const max = Math.max(...values);
|
|
711
|
+
const min = Math.min(...values);
|
|
712
|
+
if (max <= 0) return 0;
|
|
713
|
+
if (min >= 0) return 1;
|
|
714
|
+
return max / (max - min);
|
|
715
|
+
}
|
|
716
|
+
function AreaChart(props) {
|
|
717
|
+
const {
|
|
718
|
+
data,
|
|
719
|
+
series,
|
|
720
|
+
h = 300,
|
|
721
|
+
w = "100%",
|
|
722
|
+
className,
|
|
723
|
+
classNames,
|
|
724
|
+
style,
|
|
725
|
+
orientation = "horizontal",
|
|
726
|
+
type = "default",
|
|
727
|
+
curveType = "monotone",
|
|
728
|
+
withGradient = true,
|
|
729
|
+
fillOpacity = 0.28,
|
|
730
|
+
strokeWidth = 2.75,
|
|
731
|
+
withDots = false,
|
|
732
|
+
dotProps,
|
|
733
|
+
activeDotProps,
|
|
734
|
+
connectNulls = true,
|
|
735
|
+
withPointLabels = false,
|
|
736
|
+
splitColors = ["green-700", "red-700"],
|
|
737
|
+
splitOffset,
|
|
738
|
+
areaChartProps,
|
|
739
|
+
areaProps,
|
|
740
|
+
textColor,
|
|
741
|
+
animationDuration = 650,
|
|
742
|
+
loading,
|
|
743
|
+
emptyLabel,
|
|
744
|
+
children
|
|
745
|
+
} = props;
|
|
746
|
+
const ref = useRef(null);
|
|
747
|
+
const rtl = useIsRtl(ref);
|
|
748
|
+
const resolved = resolveSeries(props);
|
|
749
|
+
const chartProps = { ...props, series: resolved };
|
|
750
|
+
const [highlighted, setHighlighted] = useHighlight();
|
|
751
|
+
const id = useSvgId("wello-area");
|
|
752
|
+
const stacked = type === "stacked" || type === "percent";
|
|
753
|
+
const areas = resolved.map((item, index) => {
|
|
754
|
+
const color = getThemeColor(item.color);
|
|
755
|
+
const gradientId = `${id}-${index}`;
|
|
756
|
+
const dimmed = isDimmed(highlighted, item.name);
|
|
757
|
+
const extra = typeof areaProps === "function" ? areaProps(item) : areaProps;
|
|
758
|
+
const split = type === "split";
|
|
759
|
+
const offset = splitOffset ?? getSplitOffset(data, item.name);
|
|
760
|
+
return [
|
|
761
|
+
/* @__PURE__ */ jsx5("defs", { children: /* @__PURE__ */ jsx5("linearGradient", { id: gradientId, x1: "0", y1: "0", x2: "0", y2: "1", children: split ? /* @__PURE__ */ jsxs3(Fragment2, { children: [
|
|
762
|
+
/* @__PURE__ */ jsx5(
|
|
763
|
+
"stop",
|
|
764
|
+
{
|
|
765
|
+
offset,
|
|
766
|
+
stopColor: getThemeColor(splitColors[0]),
|
|
767
|
+
stopOpacity: fillOpacity
|
|
768
|
+
}
|
|
769
|
+
),
|
|
770
|
+
/* @__PURE__ */ jsx5(
|
|
771
|
+
"stop",
|
|
772
|
+
{
|
|
773
|
+
offset,
|
|
774
|
+
stopColor: getThemeColor(splitColors[1]),
|
|
775
|
+
stopOpacity: fillOpacity
|
|
776
|
+
}
|
|
777
|
+
)
|
|
778
|
+
] }) : withGradient ? /* @__PURE__ */ jsxs3(Fragment2, { children: [
|
|
779
|
+
/* @__PURE__ */ jsx5("stop", { offset: "0%", stopColor: color, stopOpacity: fillOpacity }),
|
|
780
|
+
/* @__PURE__ */ jsx5("stop", { offset: "100%", stopColor: color, stopOpacity: 0.02 })
|
|
781
|
+
] }) : /* @__PURE__ */ jsx5("stop", { offset: "0%", stopColor: color, stopOpacity: fillOpacity }) }) }, `defs-${item.name}`),
|
|
782
|
+
/* @__PURE__ */ jsx5(
|
|
783
|
+
Area,
|
|
784
|
+
{
|
|
785
|
+
yAxisId: item.yAxisId ?? "left",
|
|
786
|
+
name: item.name,
|
|
787
|
+
dataKey: item.name,
|
|
788
|
+
type: curveType,
|
|
789
|
+
stroke: color,
|
|
790
|
+
strokeWidth,
|
|
791
|
+
strokeDasharray: item.strokeDasharray,
|
|
792
|
+
fill: `url(#${gradientId})`,
|
|
793
|
+
fillOpacity: dimmed ? 0.1 : 1,
|
|
794
|
+
strokeOpacity: dimmed ? 0.3 : 1,
|
|
795
|
+
stackId: stacked ? "stack" : void 0,
|
|
796
|
+
connectNulls,
|
|
797
|
+
dot: withDots ? {
|
|
798
|
+
fill: color,
|
|
799
|
+
fillOpacity: dimmed ? 0 : 1,
|
|
800
|
+
strokeWidth: 2,
|
|
801
|
+
r: 4,
|
|
802
|
+
stroke: "var(--wello-chart-bg)",
|
|
803
|
+
...dotProps
|
|
804
|
+
} : false,
|
|
805
|
+
activeDot: {
|
|
806
|
+
fill: "var(--wello-chart-bg)",
|
|
807
|
+
stroke: color,
|
|
808
|
+
strokeWidth: 2,
|
|
809
|
+
r: 4,
|
|
810
|
+
...activeDotProps
|
|
811
|
+
},
|
|
812
|
+
isAnimationActive: animationDuration > 0,
|
|
813
|
+
animationDuration,
|
|
814
|
+
animationEasing: "ease-out",
|
|
815
|
+
...extra,
|
|
816
|
+
children: withPointLabels && /* @__PURE__ */ jsx5(
|
|
817
|
+
LabelList,
|
|
818
|
+
{
|
|
819
|
+
position: "top",
|
|
820
|
+
fontSize: 12,
|
|
821
|
+
fill: "currentColor",
|
|
822
|
+
formatter: props.valueFormatter
|
|
823
|
+
}
|
|
824
|
+
)
|
|
825
|
+
},
|
|
826
|
+
item.name
|
|
827
|
+
)
|
|
828
|
+
];
|
|
829
|
+
});
|
|
830
|
+
return /* @__PURE__ */ jsx5(
|
|
831
|
+
ChartCanvas,
|
|
832
|
+
{
|
|
833
|
+
empty: isCartesianEmpty(
|
|
834
|
+
data,
|
|
835
|
+
series.map((item) => item.name)
|
|
836
|
+
),
|
|
837
|
+
loading,
|
|
838
|
+
emptyLabel,
|
|
839
|
+
height: h,
|
|
840
|
+
className: cx(className, classNames?.root),
|
|
841
|
+
style,
|
|
842
|
+
children: /* @__PURE__ */ jsx5(
|
|
843
|
+
"div",
|
|
844
|
+
{
|
|
845
|
+
ref,
|
|
846
|
+
className: cx("wello-chart", className, classNames?.root),
|
|
847
|
+
style: {
|
|
848
|
+
height: h,
|
|
849
|
+
width: w,
|
|
850
|
+
color: textColor ? getThemeColor(textColor) : void 0,
|
|
851
|
+
...style
|
|
852
|
+
},
|
|
853
|
+
children: /* @__PURE__ */ jsx5(ResponsiveContainer, { className: classNames?.chart, children: /* @__PURE__ */ jsxs3(
|
|
854
|
+
ReAreaChart,
|
|
855
|
+
{
|
|
856
|
+
data,
|
|
857
|
+
layout: orientation,
|
|
858
|
+
stackOffset: type === "percent" ? "expand" : void 0,
|
|
859
|
+
margin: { top: 10, right: 10, bottom: props.xAxisLabel ? 20 : 0, left: 0 },
|
|
860
|
+
...areaChartProps,
|
|
861
|
+
children: [
|
|
862
|
+
cartesianElements(withPointLabels ? withLabelPadding(chartProps) : chartProps, {
|
|
863
|
+
highlighted,
|
|
864
|
+
onHighlight: setHighlighted,
|
|
865
|
+
cursor: "line",
|
|
866
|
+
rtl,
|
|
867
|
+
valueTickFormatter: type === "percent" ? (value) => `${Math.round(value * 100)}%` : void 0
|
|
868
|
+
}),
|
|
869
|
+
areas,
|
|
870
|
+
children
|
|
871
|
+
]
|
|
872
|
+
}
|
|
873
|
+
) })
|
|
874
|
+
}
|
|
875
|
+
)
|
|
876
|
+
}
|
|
877
|
+
);
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
// src/charts/bar-chart.tsx
|
|
881
|
+
import { useMemo, useRef as useRef2 } from "react";
|
|
882
|
+
import { Bar, BarChart as ReBarChart, Cell, LabelList as LabelList2, ResponsiveContainer as ResponsiveContainer2 } from "recharts";
|
|
883
|
+
import { jsx as jsx6, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
884
|
+
function getWaterfallData(data, key) {
|
|
885
|
+
let total = 0;
|
|
886
|
+
return data.map((item) => {
|
|
887
|
+
const value = Number(item[key]) || 0;
|
|
888
|
+
if (item.standalone) {
|
|
889
|
+
total = value;
|
|
890
|
+
return { ...item, [key]: [0, value], __value: value };
|
|
891
|
+
}
|
|
892
|
+
const start = total;
|
|
893
|
+
total += value;
|
|
894
|
+
return { ...item, [key]: [start, total], __value: value };
|
|
895
|
+
});
|
|
896
|
+
}
|
|
897
|
+
function BarChart(props) {
|
|
898
|
+
const {
|
|
899
|
+
data,
|
|
900
|
+
series,
|
|
901
|
+
h = 300,
|
|
902
|
+
w = "100%",
|
|
903
|
+
className,
|
|
904
|
+
classNames,
|
|
905
|
+
style,
|
|
906
|
+
orientation = "horizontal",
|
|
907
|
+
type = "default",
|
|
908
|
+
fillOpacity = 1,
|
|
909
|
+
maxBarWidth = 26,
|
|
910
|
+
minBarSize,
|
|
911
|
+
withBarValueLabel = false,
|
|
912
|
+
valueLabelProps,
|
|
913
|
+
getBarColor,
|
|
914
|
+
barChartProps,
|
|
915
|
+
barProps,
|
|
916
|
+
valueFormatter,
|
|
917
|
+
textColor,
|
|
918
|
+
animationDuration = 650,
|
|
919
|
+
loading,
|
|
920
|
+
emptyLabel,
|
|
921
|
+
children
|
|
922
|
+
} = props;
|
|
923
|
+
const ref = useRef2(null);
|
|
924
|
+
const rtl = useIsRtl(ref);
|
|
925
|
+
const [highlighted, setHighlighted] = useHighlight();
|
|
926
|
+
const waterfall = type === "waterfall";
|
|
927
|
+
const stacked = type === "stacked" || type === "percent";
|
|
928
|
+
const resolved = resolveSeries(props);
|
|
929
|
+
const visibleSeries = waterfall ? resolved.slice(0, 1) : resolved;
|
|
930
|
+
const chartData = useMemo(
|
|
931
|
+
() => waterfall && series[0] ? getWaterfallData(data, series[0].name) : data,
|
|
932
|
+
[waterfall, data, series]
|
|
933
|
+
);
|
|
934
|
+
const bars = visibleSeries.map((item) => {
|
|
935
|
+
const color = getThemeColor(item.color);
|
|
936
|
+
const dimmed = isDimmed(highlighted, item.name);
|
|
937
|
+
const extra = typeof barProps === "function" ? barProps(item) : barProps;
|
|
938
|
+
const radius = orientation === "vertical" ? [0, 7, 7, 0] : [7, 7, 0, 0];
|
|
939
|
+
return /* @__PURE__ */ jsxs4(
|
|
940
|
+
Bar,
|
|
941
|
+
{
|
|
942
|
+
yAxisId: item.yAxisId ?? "left",
|
|
943
|
+
name: item.name,
|
|
944
|
+
dataKey: item.name,
|
|
945
|
+
fill: color,
|
|
946
|
+
fillOpacity: dimmed ? 0.2 : fillOpacity,
|
|
947
|
+
stroke: color,
|
|
948
|
+
strokeOpacity: dimmed ? 0.2 : fillOpacity,
|
|
949
|
+
strokeWidth: 0,
|
|
950
|
+
stackId: stacked ? "stack" : void 0,
|
|
951
|
+
maxBarSize: maxBarWidth,
|
|
952
|
+
minPointSize: minBarSize,
|
|
953
|
+
radius: stacked || waterfall ? 0 : radius,
|
|
954
|
+
isAnimationActive: animationDuration > 0,
|
|
955
|
+
animationDuration,
|
|
956
|
+
animationEasing: "ease-out",
|
|
957
|
+
...extra,
|
|
958
|
+
children: [
|
|
959
|
+
(waterfall || getBarColor) && chartData.map((row, index) => {
|
|
960
|
+
const value = waterfall ? row.__value : row[item.name];
|
|
961
|
+
const custom = getBarColor?.(value, item) ?? (waterfall ? row.color : void 0);
|
|
962
|
+
return /* @__PURE__ */ jsx6(
|
|
963
|
+
Cell,
|
|
964
|
+
{
|
|
965
|
+
fill: custom ? getThemeColor(custom) : color,
|
|
966
|
+
stroke: custom ? getThemeColor(custom) : color
|
|
967
|
+
},
|
|
968
|
+
index
|
|
969
|
+
);
|
|
970
|
+
}),
|
|
971
|
+
withBarValueLabel && /* @__PURE__ */ jsx6(
|
|
972
|
+
LabelList2,
|
|
973
|
+
{
|
|
974
|
+
position: orientation === "vertical" ? "right" : "top",
|
|
975
|
+
fontSize: 12,
|
|
976
|
+
fill: "currentColor",
|
|
977
|
+
valueAccessor: (entry) => waterfall ? entry.payload.__value : entry.value,
|
|
978
|
+
formatter: (value) => valueFormatter && typeof value === "number" ? valueFormatter(value) : value,
|
|
979
|
+
...valueLabelProps
|
|
980
|
+
}
|
|
981
|
+
)
|
|
982
|
+
]
|
|
983
|
+
},
|
|
984
|
+
item.name
|
|
985
|
+
);
|
|
986
|
+
});
|
|
987
|
+
return /* @__PURE__ */ jsx6(
|
|
988
|
+
ChartCanvas,
|
|
989
|
+
{
|
|
990
|
+
empty: isCartesianEmpty(
|
|
991
|
+
data,
|
|
992
|
+
visibleSeries.map((item) => item.name)
|
|
993
|
+
),
|
|
994
|
+
loading,
|
|
995
|
+
emptyLabel,
|
|
996
|
+
height: h,
|
|
997
|
+
className: cx(className, classNames?.root),
|
|
998
|
+
style,
|
|
999
|
+
children: /* @__PURE__ */ jsx6(
|
|
1000
|
+
"div",
|
|
1001
|
+
{
|
|
1002
|
+
ref,
|
|
1003
|
+
className: cx("wello-chart", className, classNames?.root),
|
|
1004
|
+
style: {
|
|
1005
|
+
height: h,
|
|
1006
|
+
width: w,
|
|
1007
|
+
color: textColor ? getThemeColor(textColor) : void 0,
|
|
1008
|
+
...style
|
|
1009
|
+
},
|
|
1010
|
+
children: /* @__PURE__ */ jsx6(ResponsiveContainer2, { className: classNames?.chart, children: /* @__PURE__ */ jsxs4(
|
|
1011
|
+
ReBarChart,
|
|
1012
|
+
{
|
|
1013
|
+
data: chartData,
|
|
1014
|
+
layout: orientation,
|
|
1015
|
+
stackOffset: type === "percent" ? "expand" : void 0,
|
|
1016
|
+
margin: {
|
|
1017
|
+
top: withBarValueLabel ? 20 : 10,
|
|
1018
|
+
right: 10,
|
|
1019
|
+
bottom: props.xAxisLabel ? 20 : 0,
|
|
1020
|
+
left: 0
|
|
1021
|
+
},
|
|
1022
|
+
...barChartProps,
|
|
1023
|
+
children: [
|
|
1024
|
+
cartesianElements(
|
|
1025
|
+
{ ...props, series: visibleSeries },
|
|
1026
|
+
{
|
|
1027
|
+
highlighted,
|
|
1028
|
+
onHighlight: setHighlighted,
|
|
1029
|
+
cursor: "fill",
|
|
1030
|
+
rtl,
|
|
1031
|
+
valueTickFormatter: type === "percent" ? (value) => `${Math.round(value * 100)}%` : void 0
|
|
1032
|
+
}
|
|
1033
|
+
),
|
|
1034
|
+
bars,
|
|
1035
|
+
children
|
|
1036
|
+
]
|
|
1037
|
+
}
|
|
1038
|
+
) })
|
|
1039
|
+
}
|
|
1040
|
+
)
|
|
1041
|
+
}
|
|
1042
|
+
);
|
|
1043
|
+
}
|
|
1044
|
+
|
|
1045
|
+
// src/charts/line-chart.tsx
|
|
1046
|
+
import { LabelList as LabelList3, Line, LineChart as ReLineChart, ResponsiveContainer as ResponsiveContainer3 } from "recharts";
|
|
1047
|
+
import { useRef as useRef3 } from "react";
|
|
1048
|
+
import { jsx as jsx7, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
1049
|
+
var DEFAULT_GRADIENT = [
|
|
1050
|
+
{ offset: 0, color: "red" },
|
|
1051
|
+
{ offset: 50, color: "yellow" },
|
|
1052
|
+
{ offset: 100, color: "teal" }
|
|
1053
|
+
];
|
|
1054
|
+
function LineChart(props) {
|
|
1055
|
+
const {
|
|
1056
|
+
data,
|
|
1057
|
+
series,
|
|
1058
|
+
h = 300,
|
|
1059
|
+
w = "100%",
|
|
1060
|
+
className,
|
|
1061
|
+
classNames,
|
|
1062
|
+
style,
|
|
1063
|
+
orientation = "horizontal",
|
|
1064
|
+
type = "default",
|
|
1065
|
+
gradientStops = DEFAULT_GRADIENT,
|
|
1066
|
+
curveType = "monotone",
|
|
1067
|
+
strokeWidth = 2.75,
|
|
1068
|
+
withDots = false,
|
|
1069
|
+
dotProps,
|
|
1070
|
+
activeDotProps,
|
|
1071
|
+
connectNulls = true,
|
|
1072
|
+
withPointLabels = false,
|
|
1073
|
+
lineChartProps,
|
|
1074
|
+
lineProps,
|
|
1075
|
+
valueFormatter,
|
|
1076
|
+
textColor,
|
|
1077
|
+
animationDuration = 650,
|
|
1078
|
+
loading,
|
|
1079
|
+
emptyLabel,
|
|
1080
|
+
children
|
|
1081
|
+
} = props;
|
|
1082
|
+
const ref = useRef3(null);
|
|
1083
|
+
const rtl = useIsRtl(ref);
|
|
1084
|
+
const [highlighted, setHighlighted] = useHighlight();
|
|
1085
|
+
const gradientId = useSvgId("wello-line");
|
|
1086
|
+
const gradient = type === "gradient";
|
|
1087
|
+
const resolved = resolveSeries(props);
|
|
1088
|
+
const visibleSeries = gradient ? resolved.slice(0, 1) : resolved;
|
|
1089
|
+
const lines = visibleSeries.map((item) => {
|
|
1090
|
+
const color = gradient ? `url(#${gradientId})` : getThemeColor(item.color);
|
|
1091
|
+
const dotColor = gradient ? "var(--wello-chart-text-color)" : color;
|
|
1092
|
+
const dimmed = isDimmed(highlighted, item.name);
|
|
1093
|
+
const extra = typeof lineProps === "function" ? lineProps(item) : lineProps;
|
|
1094
|
+
return /* @__PURE__ */ jsx7(
|
|
1095
|
+
Line,
|
|
1096
|
+
{
|
|
1097
|
+
yAxisId: item.yAxisId ?? "left",
|
|
1098
|
+
name: item.name,
|
|
1099
|
+
dataKey: item.name,
|
|
1100
|
+
type: curveType,
|
|
1101
|
+
stroke: color,
|
|
1102
|
+
strokeWidth,
|
|
1103
|
+
strokeDasharray: item.strokeDasharray,
|
|
1104
|
+
strokeOpacity: dimmed ? 0.2 : 1,
|
|
1105
|
+
connectNulls,
|
|
1106
|
+
dot: withDots ? {
|
|
1107
|
+
fill: dotColor,
|
|
1108
|
+
fillOpacity: dimmed ? 0 : 1,
|
|
1109
|
+
strokeWidth: 2,
|
|
1110
|
+
r: 4,
|
|
1111
|
+
stroke: "var(--wello-chart-bg)",
|
|
1112
|
+
...dotProps
|
|
1113
|
+
} : false,
|
|
1114
|
+
activeDot: {
|
|
1115
|
+
fill: "var(--wello-chart-bg)",
|
|
1116
|
+
stroke: dotColor,
|
|
1117
|
+
strokeWidth: 2,
|
|
1118
|
+
r: 4,
|
|
1119
|
+
...activeDotProps
|
|
1120
|
+
},
|
|
1121
|
+
isAnimationActive: animationDuration > 0,
|
|
1122
|
+
animationDuration,
|
|
1123
|
+
animationEasing: "ease-out",
|
|
1124
|
+
...extra,
|
|
1125
|
+
children: withPointLabels && /* @__PURE__ */ jsx7(
|
|
1126
|
+
LabelList3,
|
|
1127
|
+
{
|
|
1128
|
+
position: "top",
|
|
1129
|
+
fontSize: 12,
|
|
1130
|
+
fill: "currentColor",
|
|
1131
|
+
formatter: (value) => valueFormatter && typeof value === "number" ? valueFormatter(value) : value
|
|
1132
|
+
}
|
|
1133
|
+
)
|
|
1134
|
+
},
|
|
1135
|
+
item.name
|
|
1136
|
+
);
|
|
1137
|
+
});
|
|
1138
|
+
return /* @__PURE__ */ jsx7(
|
|
1139
|
+
ChartCanvas,
|
|
1140
|
+
{
|
|
1141
|
+
empty: isCartesianEmpty(
|
|
1142
|
+
data,
|
|
1143
|
+
visibleSeries.map((item) => item.name)
|
|
1144
|
+
),
|
|
1145
|
+
loading,
|
|
1146
|
+
emptyLabel,
|
|
1147
|
+
height: h,
|
|
1148
|
+
className: cx(className, classNames?.root),
|
|
1149
|
+
style,
|
|
1150
|
+
children: /* @__PURE__ */ jsx7(
|
|
1151
|
+
"div",
|
|
1152
|
+
{
|
|
1153
|
+
ref,
|
|
1154
|
+
className: cx("wello-chart", className, classNames?.root),
|
|
1155
|
+
style: {
|
|
1156
|
+
height: h,
|
|
1157
|
+
width: w,
|
|
1158
|
+
color: textColor ? getThemeColor(textColor) : void 0,
|
|
1159
|
+
...style
|
|
1160
|
+
},
|
|
1161
|
+
children: /* @__PURE__ */ jsx7(ResponsiveContainer3, { className: classNames?.chart, children: /* @__PURE__ */ jsxs5(
|
|
1162
|
+
ReLineChart,
|
|
1163
|
+
{
|
|
1164
|
+
data,
|
|
1165
|
+
layout: orientation,
|
|
1166
|
+
margin: {
|
|
1167
|
+
top: withPointLabels ? 20 : 10,
|
|
1168
|
+
right: 10,
|
|
1169
|
+
bottom: props.xAxisLabel ? 20 : 0,
|
|
1170
|
+
left: 0
|
|
1171
|
+
},
|
|
1172
|
+
...lineChartProps,
|
|
1173
|
+
children: [
|
|
1174
|
+
gradient && /* @__PURE__ */ jsx7("defs", { children: /* @__PURE__ */ jsx7(
|
|
1175
|
+
"linearGradient",
|
|
1176
|
+
{
|
|
1177
|
+
id: gradientId,
|
|
1178
|
+
gradientUnits: "userSpaceOnUse",
|
|
1179
|
+
x1: "0",
|
|
1180
|
+
y1: "0%",
|
|
1181
|
+
x2: "0",
|
|
1182
|
+
y2: "100%",
|
|
1183
|
+
children: gradientStops.map((stop) => /* @__PURE__ */ jsx7(
|
|
1184
|
+
"stop",
|
|
1185
|
+
{
|
|
1186
|
+
offset: `${stop.offset}%`,
|
|
1187
|
+
stopColor: getThemeColor(stop.color)
|
|
1188
|
+
},
|
|
1189
|
+
stop.offset
|
|
1190
|
+
))
|
|
1191
|
+
}
|
|
1192
|
+
) }),
|
|
1193
|
+
cartesianElements(
|
|
1194
|
+
withPointLabels ? withLabelPadding({ ...props, series: visibleSeries }) : { ...props, series: visibleSeries },
|
|
1195
|
+
{ highlighted, onHighlight: setHighlighted, cursor: "line", rtl }
|
|
1196
|
+
),
|
|
1197
|
+
lines,
|
|
1198
|
+
children
|
|
1199
|
+
]
|
|
1200
|
+
}
|
|
1201
|
+
) })
|
|
1202
|
+
}
|
|
1203
|
+
)
|
|
1204
|
+
}
|
|
1205
|
+
);
|
|
1206
|
+
}
|
|
1207
|
+
|
|
1208
|
+
// src/shared/pie-base.tsx
|
|
1209
|
+
import { useMemo as useMemo2, useState as useState4 } from "react";
|
|
1210
|
+
import { Cell as Cell2, Pie, PieChart as RePieChart, ResponsiveContainer as ResponsiveContainer4, Sector, Tooltip as Tooltip2 } from "recharts";
|
|
1211
|
+
|
|
1212
|
+
// src/components/floating-tooltip.tsx
|
|
1213
|
+
import {
|
|
1214
|
+
useEffect,
|
|
1215
|
+
useLayoutEffect as useLayoutEffect2,
|
|
1216
|
+
useRef as useRef4,
|
|
1217
|
+
useState as useState3,
|
|
1218
|
+
useSyncExternalStore
|
|
1219
|
+
} from "react";
|
|
1220
|
+
import { createPortal } from "react-dom";
|
|
1221
|
+
import { jsx as jsx8 } from "react/jsx-runtime";
|
|
1222
|
+
var GAP = 18;
|
|
1223
|
+
var EDGE = 8;
|
|
1224
|
+
var THEME_VARS = ["--wello-chart-tooltip-bg", "--wello-chart-tooltip-fg", "--wello-chart-font"];
|
|
1225
|
+
function FloatingTooltip({
|
|
1226
|
+
clientX,
|
|
1227
|
+
clientY,
|
|
1228
|
+
side,
|
|
1229
|
+
gap = GAP,
|
|
1230
|
+
anchorHeight = 0,
|
|
1231
|
+
themeSource,
|
|
1232
|
+
children
|
|
1233
|
+
}) {
|
|
1234
|
+
const ref = useRef4(null);
|
|
1235
|
+
const [position, setPosition] = useState3(null);
|
|
1236
|
+
const [scrolledAt, setScrolledAt] = useState3(null);
|
|
1237
|
+
const hidden = scrolledAt !== null && scrolledAt.x === clientX && scrolledAt.y === clientY;
|
|
1238
|
+
useEffect(() => {
|
|
1239
|
+
const onScroll = () => setScrolledAt({ x: clientX, y: clientY });
|
|
1240
|
+
window.addEventListener("scroll", onScroll, { capture: true, passive: true });
|
|
1241
|
+
return () => window.removeEventListener("scroll", onScroll, { capture: true });
|
|
1242
|
+
}, [clientX, clientY]);
|
|
1243
|
+
useLayoutEffect2(() => {
|
|
1244
|
+
const element = ref.current;
|
|
1245
|
+
if (!element) return;
|
|
1246
|
+
const { width, height } = element.getBoundingClientRect();
|
|
1247
|
+
const clampX = (value) => Math.min(Math.max(value, EDGE), Math.max(EDGE, window.innerWidth - width - EDGE));
|
|
1248
|
+
const clampY = (value) => Math.min(Math.max(value, EDGE), Math.max(EDGE, window.innerHeight - height - EDGE));
|
|
1249
|
+
let x;
|
|
1250
|
+
let y;
|
|
1251
|
+
if (side === "top") {
|
|
1252
|
+
const above = clientY - gap - height;
|
|
1253
|
+
x = clampX(clientX - width / 2);
|
|
1254
|
+
y = above >= EDGE ? above : clampY(clientY + anchorHeight + gap);
|
|
1255
|
+
} else {
|
|
1256
|
+
const right = clientX + gap;
|
|
1257
|
+
const left = clientX - gap - width;
|
|
1258
|
+
const fitsRight = right + width <= window.innerWidth - EDGE;
|
|
1259
|
+
const fitsLeft = left >= EDGE;
|
|
1260
|
+
x = clampX(
|
|
1261
|
+
side === "right" ? fitsRight || !fitsLeft ? right : left : fitsLeft || !fitsRight ? left : right
|
|
1262
|
+
);
|
|
1263
|
+
y = clampY(clientY - height / 2);
|
|
1264
|
+
}
|
|
1265
|
+
setPosition(
|
|
1266
|
+
(current) => current && current.left === x && current.top === y ? current : { left: x, top: y }
|
|
1267
|
+
);
|
|
1268
|
+
}, [clientX, clientY, side, gap, anchorHeight, children]);
|
|
1269
|
+
const theme = {};
|
|
1270
|
+
if (themeSource) {
|
|
1271
|
+
const styles = getComputedStyle(themeSource);
|
|
1272
|
+
for (const name of THEME_VARS) theme[name] = styles.getPropertyValue(name);
|
|
1273
|
+
}
|
|
1274
|
+
const style = {
|
|
1275
|
+
...theme,
|
|
1276
|
+
position: "fixed",
|
|
1277
|
+
left: position?.left ?? 0,
|
|
1278
|
+
top: position?.top ?? 0,
|
|
1279
|
+
visibility: position && !hidden ? "visible" : "hidden"
|
|
1280
|
+
};
|
|
1281
|
+
return createPortal(
|
|
1282
|
+
/* @__PURE__ */ jsx8("div", { ref, className: "wello-floating-tooltip", style, children }),
|
|
1283
|
+
document.body
|
|
1284
|
+
);
|
|
1285
|
+
}
|
|
1286
|
+
function createPointerStore() {
|
|
1287
|
+
let state = null;
|
|
1288
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
1289
|
+
return {
|
|
1290
|
+
get: () => state,
|
|
1291
|
+
set: (next) => {
|
|
1292
|
+
state = next;
|
|
1293
|
+
listeners.forEach((listener) => listener());
|
|
1294
|
+
},
|
|
1295
|
+
subscribe: (listener) => {
|
|
1296
|
+
listeners.add(listener);
|
|
1297
|
+
return () => listeners.delete(listener);
|
|
1298
|
+
}
|
|
1299
|
+
};
|
|
1300
|
+
}
|
|
1301
|
+
function PointerTooltip({ store, children }) {
|
|
1302
|
+
const pointer = useSyncExternalStore(store.subscribe, store.get, () => null);
|
|
1303
|
+
if (!pointer) return null;
|
|
1304
|
+
return /* @__PURE__ */ jsx8(
|
|
1305
|
+
FloatingTooltip,
|
|
1306
|
+
{
|
|
1307
|
+
clientX: pointer.clientX,
|
|
1308
|
+
clientY: pointer.clientY,
|
|
1309
|
+
side: pointer.side,
|
|
1310
|
+
themeSource: pointer.source,
|
|
1311
|
+
children
|
|
1312
|
+
}
|
|
1313
|
+
);
|
|
1314
|
+
}
|
|
1315
|
+
|
|
1316
|
+
// src/shared/pie-base.tsx
|
|
1317
|
+
import { jsx as jsx9, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
1318
|
+
var RADIAN = Math.PI / 180;
|
|
1319
|
+
var OUTSIDE_LABEL_SPACE = 80;
|
|
1320
|
+
var HOVER_GROWTH = 6;
|
|
1321
|
+
function getPercent(value, data) {
|
|
1322
|
+
const total = data.reduce((sum, item) => sum + (Number(item.value) || 0), 0);
|
|
1323
|
+
return total > 0 ? value / total * 100 : 0;
|
|
1324
|
+
}
|
|
1325
|
+
function ActiveSlice(props) {
|
|
1326
|
+
return /* @__PURE__ */ jsx9(
|
|
1327
|
+
Sector,
|
|
1328
|
+
{
|
|
1329
|
+
...props,
|
|
1330
|
+
outerRadius: props.outerRadius + HOVER_GROWTH,
|
|
1331
|
+
stroke: props.fill,
|
|
1332
|
+
strokeWidth: 2,
|
|
1333
|
+
style: { filter: `drop-shadow(0 0 7px color-mix(in srgb, ${props.fill} 45%, transparent))` }
|
|
1334
|
+
}
|
|
1335
|
+
);
|
|
1336
|
+
}
|
|
1337
|
+
function PieBase({
|
|
1338
|
+
data,
|
|
1339
|
+
size = 160,
|
|
1340
|
+
colors,
|
|
1341
|
+
withLabels = false,
|
|
1342
|
+
withLabelsLine = true,
|
|
1343
|
+
labelsType = "value",
|
|
1344
|
+
labelColor,
|
|
1345
|
+
labelsPosition,
|
|
1346
|
+
paddingAngle = 0,
|
|
1347
|
+
startAngle = 0,
|
|
1348
|
+
endAngle = 360,
|
|
1349
|
+
cornerRadius = 6,
|
|
1350
|
+
strokeWidth = 3,
|
|
1351
|
+
strokeColor,
|
|
1352
|
+
withTooltip = false,
|
|
1353
|
+
tooltipDataSource = "segment",
|
|
1354
|
+
tooltipProps,
|
|
1355
|
+
tooltipAnimationDuration = 0,
|
|
1356
|
+
withLegend = false,
|
|
1357
|
+
legendPosition = "bottom",
|
|
1358
|
+
valueFormatter,
|
|
1359
|
+
animationDuration = 650,
|
|
1360
|
+
pieProps,
|
|
1361
|
+
pieChartProps,
|
|
1362
|
+
loading,
|
|
1363
|
+
emptyLabel,
|
|
1364
|
+
className,
|
|
1365
|
+
classNames,
|
|
1366
|
+
style,
|
|
1367
|
+
children,
|
|
1368
|
+
innerRadius,
|
|
1369
|
+
center,
|
|
1370
|
+
emptyRing = false,
|
|
1371
|
+
rootClassName
|
|
1372
|
+
}) {
|
|
1373
|
+
const [highlighted, setHighlighted] = useState4(null);
|
|
1374
|
+
const [pointer] = useState4(createPointerStore);
|
|
1375
|
+
const cells = useMemo2(
|
|
1376
|
+
() => data.map((item, index) => ({ ...item, color: seriesColor(item.color, index, colors) })).filter((item) => Number(item.value) > 0),
|
|
1377
|
+
[data, colors]
|
|
1378
|
+
);
|
|
1379
|
+
const total = cells.reduce((sum, item) => sum + Number(item.value), 0);
|
|
1380
|
+
const ring = total <= 0 && emptyRing && data.length > 0;
|
|
1381
|
+
const outside = withLabels && labelsPosition === "outside";
|
|
1382
|
+
const height = size + (outside ? OUTSIDE_LABEL_SPACE : 0) + HOVER_GROWTH * 2;
|
|
1383
|
+
const outerRadius = size / 2;
|
|
1384
|
+
const text = (value) => labelsType === "percent" ? `${getPercent(value, cells).toFixed(0)}%` : formatValue(value, valueFormatter);
|
|
1385
|
+
const renderLabel = (entry) => {
|
|
1386
|
+
const { cx: x0, cy: y0, midAngle, outerRadius: r, innerRadius: ri, value } = entry;
|
|
1387
|
+
const radius = outside ? r + 16 : ri + (r - ri) / 2 || r / 2;
|
|
1388
|
+
const x = x0 + radius * Math.cos(-midAngle * RADIAN);
|
|
1389
|
+
const y = y0 + radius * Math.sin(-midAngle * RADIAN);
|
|
1390
|
+
return /* @__PURE__ */ jsx9(
|
|
1391
|
+
"text",
|
|
1392
|
+
{
|
|
1393
|
+
x,
|
|
1394
|
+
y,
|
|
1395
|
+
fill: outside ? getThemeColor(labelColor, "currentColor") : getThemeColor(labelColor, "#fff"),
|
|
1396
|
+
textAnchor: outside ? x > x0 ? "start" : "end" : "middle",
|
|
1397
|
+
dominantBaseline: "central",
|
|
1398
|
+
fontSize: 11,
|
|
1399
|
+
fontWeight: outside ? 500 : 700,
|
|
1400
|
+
children: text(value)
|
|
1401
|
+
}
|
|
1402
|
+
);
|
|
1403
|
+
};
|
|
1404
|
+
const legend = withLegend && !ring && /* @__PURE__ */ jsx9(
|
|
1405
|
+
ChartLegend,
|
|
1406
|
+
{
|
|
1407
|
+
series: cells.map(({ name, color }) => ({ name, color })),
|
|
1408
|
+
align: "center",
|
|
1409
|
+
className: classNames?.legend,
|
|
1410
|
+
onHighlight: setHighlighted
|
|
1411
|
+
}
|
|
1412
|
+
);
|
|
1413
|
+
return /* @__PURE__ */ jsx9(
|
|
1414
|
+
ChartCanvas,
|
|
1415
|
+
{
|
|
1416
|
+
empty: !cells.length && !ring,
|
|
1417
|
+
loading,
|
|
1418
|
+
emptyLabel,
|
|
1419
|
+
height,
|
|
1420
|
+
className: cx(className, classNames?.root),
|
|
1421
|
+
style,
|
|
1422
|
+
children: /* @__PURE__ */ jsxs6("div", { className: cx("wello-chart", "wello-pie", rootClassName, className, classNames?.root), style: { minWidth: height, ...style }, children: [
|
|
1423
|
+
legendPosition === "top" && legend,
|
|
1424
|
+
/* @__PURE__ */ jsxs6(
|
|
1425
|
+
"div",
|
|
1426
|
+
{
|
|
1427
|
+
className: cx("wello-pie-area", classNames?.chart),
|
|
1428
|
+
style: { height },
|
|
1429
|
+
onMouseMove: (event) => {
|
|
1430
|
+
const area = event.currentTarget;
|
|
1431
|
+
const box = area.getBoundingClientRect();
|
|
1432
|
+
const side = event.clientX >= box.left + box.width / 2 ? "right" : "left";
|
|
1433
|
+
pointer.set({ clientX: event.clientX, clientY: event.clientY, side, source: area });
|
|
1434
|
+
},
|
|
1435
|
+
onMouseLeave: () => pointer.set(null),
|
|
1436
|
+
children: [
|
|
1437
|
+
/* @__PURE__ */ jsx9(ResponsiveContainer4, { children: /* @__PURE__ */ jsxs6(RePieChart, { ...pieChartProps, children: [
|
|
1438
|
+
/* @__PURE__ */ jsx9(
|
|
1439
|
+
Pie,
|
|
1440
|
+
{
|
|
1441
|
+
data: ring ? [{ name: "empty", value: 1 }] : cells,
|
|
1442
|
+
dataKey: "value",
|
|
1443
|
+
nameKey: "name",
|
|
1444
|
+
innerRadius,
|
|
1445
|
+
outerRadius,
|
|
1446
|
+
paddingAngle: ring ? 0 : paddingAngle,
|
|
1447
|
+
startAngle,
|
|
1448
|
+
endAngle,
|
|
1449
|
+
cornerRadius,
|
|
1450
|
+
stroke: getThemeColor(strokeColor, "var(--wello-chart-bg)"),
|
|
1451
|
+
strokeWidth: ring ? 0 : strokeWidth,
|
|
1452
|
+
label: withLabels && !ring ? renderLabel : false,
|
|
1453
|
+
labelLine: outside && withLabelsLine && !ring ? { stroke: "var(--wello-chart-label-line-color)" } : false,
|
|
1454
|
+
activeShape: ring ? void 0 : ActiveSlice,
|
|
1455
|
+
isAnimationActive: animationDuration > 0,
|
|
1456
|
+
animationDuration,
|
|
1457
|
+
animationEasing: "ease-out",
|
|
1458
|
+
...pieProps,
|
|
1459
|
+
children: ring ? /* @__PURE__ */ jsx9(Cell2, { fill: "var(--wello-chart-muted)" }) : cells.map((item) => /* @__PURE__ */ jsx9(
|
|
1460
|
+
Cell2,
|
|
1461
|
+
{
|
|
1462
|
+
fill: item.color,
|
|
1463
|
+
fillOpacity: highlighted !== null && highlighted !== item.name ? 0.2 : 1
|
|
1464
|
+
},
|
|
1465
|
+
item.name
|
|
1466
|
+
))
|
|
1467
|
+
}
|
|
1468
|
+
),
|
|
1469
|
+
withTooltip && !ring && /* @__PURE__ */ jsx9(
|
|
1470
|
+
Tooltip2,
|
|
1471
|
+
{
|
|
1472
|
+
cursor: false,
|
|
1473
|
+
isAnimationActive: false,
|
|
1474
|
+
content: ({ active, payload }) => {
|
|
1475
|
+
const hovered = payload?.[0]?.payload;
|
|
1476
|
+
if (!active || !hovered) return null;
|
|
1477
|
+
return /* @__PURE__ */ jsx9(PointerTooltip, { store: pointer, children: tooltipDataSource === "all" ? /* @__PURE__ */ jsx9(
|
|
1478
|
+
ChartTooltip,
|
|
1479
|
+
{
|
|
1480
|
+
valueFormatter,
|
|
1481
|
+
items: cells.map((item) => ({
|
|
1482
|
+
name: item.name,
|
|
1483
|
+
value: item.value,
|
|
1484
|
+
color: item.color
|
|
1485
|
+
}))
|
|
1486
|
+
}
|
|
1487
|
+
) : /* @__PURE__ */ jsx9(
|
|
1488
|
+
ChartSliceTooltip,
|
|
1489
|
+
{
|
|
1490
|
+
name: hovered.name,
|
|
1491
|
+
value: hovered.value,
|
|
1492
|
+
color: hovered.color,
|
|
1493
|
+
percent: getPercent(hovered.value, cells),
|
|
1494
|
+
valueFormatter
|
|
1495
|
+
}
|
|
1496
|
+
) });
|
|
1497
|
+
},
|
|
1498
|
+
...tooltipProps
|
|
1499
|
+
}
|
|
1500
|
+
),
|
|
1501
|
+
children
|
|
1502
|
+
] }) }),
|
|
1503
|
+
center !== void 0 && center !== null && /* @__PURE__ */ jsx9("div", { className: "wello-donut-label", children: center })
|
|
1504
|
+
]
|
|
1505
|
+
}
|
|
1506
|
+
),
|
|
1507
|
+
legendPosition === "bottom" && legend
|
|
1508
|
+
] })
|
|
1509
|
+
}
|
|
1510
|
+
);
|
|
1511
|
+
}
|
|
1512
|
+
|
|
1513
|
+
// src/charts/pie-chart.tsx
|
|
1514
|
+
import { jsx as jsx10 } from "react/jsx-runtime";
|
|
1515
|
+
function PieChart({ labelsPosition = "outside", ...props }) {
|
|
1516
|
+
return /* @__PURE__ */ jsx10(
|
|
1517
|
+
PieBase,
|
|
1518
|
+
{
|
|
1519
|
+
...props,
|
|
1520
|
+
innerRadius: 0,
|
|
1521
|
+
labelsPosition,
|
|
1522
|
+
rootClassName: "wello-pie-chart"
|
|
1523
|
+
}
|
|
1524
|
+
);
|
|
1525
|
+
}
|
|
1526
|
+
|
|
1527
|
+
// src/charts/donut-chart.tsx
|
|
1528
|
+
import { jsx as jsx11, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
1529
|
+
function DonutChart({
|
|
1530
|
+
thickness,
|
|
1531
|
+
chartLabel,
|
|
1532
|
+
chartSubLabel,
|
|
1533
|
+
emptyRing,
|
|
1534
|
+
withTooltip = true,
|
|
1535
|
+
...props
|
|
1536
|
+
}) {
|
|
1537
|
+
const size = props.size ?? 160;
|
|
1538
|
+
const radius = size / 2;
|
|
1539
|
+
const ring = thickness ?? Math.round(radius * 0.26);
|
|
1540
|
+
const hasCenter = (chartLabel ?? null) !== null || (chartSubLabel ?? null) !== null;
|
|
1541
|
+
return /* @__PURE__ */ jsx11(
|
|
1542
|
+
PieBase,
|
|
1543
|
+
{
|
|
1544
|
+
...props,
|
|
1545
|
+
withTooltip,
|
|
1546
|
+
innerRadius: Math.max(radius - ring, 0),
|
|
1547
|
+
labelsPosition: "outside",
|
|
1548
|
+
emptyRing,
|
|
1549
|
+
center: hasCenter ? /* @__PURE__ */ jsxs7("div", { className: "wello-donut-label-inner", children: [
|
|
1550
|
+
chartLabel !== void 0 && /* @__PURE__ */ jsx11("span", { className: "wello-donut-label-main", children: chartLabel }),
|
|
1551
|
+
chartSubLabel !== void 0 && /* @__PURE__ */ jsx11("span", { className: "wello-donut-label-sub", children: chartSubLabel })
|
|
1552
|
+
] }) : void 0,
|
|
1553
|
+
rootClassName: "wello-donut-chart"
|
|
1554
|
+
}
|
|
1555
|
+
);
|
|
1556
|
+
}
|
|
1557
|
+
|
|
1558
|
+
// src/charts/radial-bar-chart.tsx
|
|
1559
|
+
import { useMemo as useMemo3, useState as useState5 } from "react";
|
|
1560
|
+
import {
|
|
1561
|
+
LabelList as LabelList4,
|
|
1562
|
+
RadialBar,
|
|
1563
|
+
RadialBarChart as ReRadialBarChart,
|
|
1564
|
+
ResponsiveContainer as ResponsiveContainer5,
|
|
1565
|
+
Tooltip as Tooltip3
|
|
1566
|
+
} from "recharts";
|
|
1567
|
+
import { jsx as jsx12, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
1568
|
+
function RadialBarChart({
|
|
1569
|
+
data,
|
|
1570
|
+
dataKey,
|
|
1571
|
+
h = 300,
|
|
1572
|
+
w = "100%",
|
|
1573
|
+
colors,
|
|
1574
|
+
animationDuration = 650,
|
|
1575
|
+
barSize = 20,
|
|
1576
|
+
withBackground = true,
|
|
1577
|
+
emptyBackgroundColor,
|
|
1578
|
+
startAngle = 90,
|
|
1579
|
+
endAngle = -270,
|
|
1580
|
+
withLabels = false,
|
|
1581
|
+
withLegend = false,
|
|
1582
|
+
legendPosition = "bottom",
|
|
1583
|
+
withTooltip = true,
|
|
1584
|
+
tooltipProps,
|
|
1585
|
+
valueFormatter,
|
|
1586
|
+
radialBarProps,
|
|
1587
|
+
radialBarChartProps,
|
|
1588
|
+
className,
|
|
1589
|
+
classNames,
|
|
1590
|
+
style,
|
|
1591
|
+
children
|
|
1592
|
+
}) {
|
|
1593
|
+
const [highlighted, setHighlighted] = useState5(null);
|
|
1594
|
+
const chartData = useMemo3(
|
|
1595
|
+
() => data.map((item, index) => ({
|
|
1596
|
+
...item,
|
|
1597
|
+
fill: seriesColor(item.color, index, colors),
|
|
1598
|
+
fillOpacity: highlighted !== null && highlighted !== item.name ? 0.2 : 1
|
|
1599
|
+
})),
|
|
1600
|
+
[data, colors, highlighted]
|
|
1601
|
+
);
|
|
1602
|
+
const legend = withLegend && /* @__PURE__ */ jsx12(
|
|
1603
|
+
ChartLegend,
|
|
1604
|
+
{
|
|
1605
|
+
series: chartData.map((item, index) => ({
|
|
1606
|
+
name: String(data[index].name),
|
|
1607
|
+
color: item.fill
|
|
1608
|
+
})),
|
|
1609
|
+
align: "center",
|
|
1610
|
+
className: classNames?.legend,
|
|
1611
|
+
onHighlight: setHighlighted
|
|
1612
|
+
}
|
|
1613
|
+
);
|
|
1614
|
+
return /* @__PURE__ */ jsxs8(
|
|
1615
|
+
"div",
|
|
1616
|
+
{
|
|
1617
|
+
className: cx("wello-chart", "wello-radial-bar", className, classNames?.root),
|
|
1618
|
+
style: { width: w, ...style },
|
|
1619
|
+
children: [
|
|
1620
|
+
legendPosition === "top" && legend,
|
|
1621
|
+
/* @__PURE__ */ jsx12("div", { className: classNames?.chart, style: { height: h }, children: /* @__PURE__ */ jsx12(ResponsiveContainer5, { children: /* @__PURE__ */ jsxs8(
|
|
1622
|
+
ReRadialBarChart,
|
|
1623
|
+
{
|
|
1624
|
+
data: chartData,
|
|
1625
|
+
barSize,
|
|
1626
|
+
startAngle,
|
|
1627
|
+
endAngle,
|
|
1628
|
+
innerRadius: "10%",
|
|
1629
|
+
outerRadius: "100%",
|
|
1630
|
+
...radialBarChartProps,
|
|
1631
|
+
children: [
|
|
1632
|
+
/* @__PURE__ */ jsx12(
|
|
1633
|
+
RadialBar,
|
|
1634
|
+
{
|
|
1635
|
+
dataKey,
|
|
1636
|
+
background: withBackground ? { fill: getThemeColor(emptyBackgroundColor, "var(--wello-chart-radial-bg)") } : false,
|
|
1637
|
+
cornerRadius: barSize / 2,
|
|
1638
|
+
isAnimationActive: animationDuration > 0,
|
|
1639
|
+
animationDuration,
|
|
1640
|
+
animationEasing: "ease-out",
|
|
1641
|
+
...radialBarProps,
|
|
1642
|
+
children: withLabels && /* @__PURE__ */ jsx12(
|
|
1643
|
+
LabelList4,
|
|
1644
|
+
{
|
|
1645
|
+
position: "insideStart",
|
|
1646
|
+
dataKey: "name",
|
|
1647
|
+
fill: "#fff",
|
|
1648
|
+
fontSize: 12,
|
|
1649
|
+
fontWeight: 600
|
|
1650
|
+
}
|
|
1651
|
+
)
|
|
1652
|
+
}
|
|
1653
|
+
),
|
|
1654
|
+
withTooltip && /* @__PURE__ */ jsx12(
|
|
1655
|
+
Tooltip3,
|
|
1656
|
+
{
|
|
1657
|
+
isAnimationActive: false,
|
|
1658
|
+
cursor: false,
|
|
1659
|
+
content: ({ active, payload }) => {
|
|
1660
|
+
if (!active || !payload?.length) return null;
|
|
1661
|
+
const item = payload[0].payload;
|
|
1662
|
+
return /* @__PURE__ */ jsx12(
|
|
1663
|
+
ChartTooltip,
|
|
1664
|
+
{
|
|
1665
|
+
valueFormatter,
|
|
1666
|
+
items: [{ name: String(item.name), value: item[dataKey], color: item.fill }]
|
|
1667
|
+
}
|
|
1668
|
+
);
|
|
1669
|
+
},
|
|
1670
|
+
...tooltipProps
|
|
1671
|
+
}
|
|
1672
|
+
),
|
|
1673
|
+
children
|
|
1674
|
+
]
|
|
1675
|
+
}
|
|
1676
|
+
) }) }),
|
|
1677
|
+
legendPosition === "bottom" && legend
|
|
1678
|
+
]
|
|
1679
|
+
}
|
|
1680
|
+
);
|
|
1681
|
+
}
|
|
1682
|
+
|
|
1683
|
+
// src/charts/heatmap.tsx
|
|
1684
|
+
import { useMemo as useMemo4, useState as useState6 } from "react";
|
|
1685
|
+
import { jsx as jsx13, jsxs as jsxs9 } from "react/jsx-runtime";
|
|
1686
|
+
var DAY = 864e5;
|
|
1687
|
+
var DEFAULT_COLORS = ["green-200", "green-400", "green-600", "green-800"];
|
|
1688
|
+
var DEFAULT_MONTHS = [
|
|
1689
|
+
"Jan",
|
|
1690
|
+
"Feb",
|
|
1691
|
+
"Mar",
|
|
1692
|
+
"Apr",
|
|
1693
|
+
"May",
|
|
1694
|
+
"Jun",
|
|
1695
|
+
"Jul",
|
|
1696
|
+
"Aug",
|
|
1697
|
+
"Sep",
|
|
1698
|
+
"Oct",
|
|
1699
|
+
"Nov",
|
|
1700
|
+
"Dec"
|
|
1701
|
+
];
|
|
1702
|
+
var DEFAULT_WEEKDAYS = ["", "Mon", "", "Wed", "", "Fri", ""];
|
|
1703
|
+
function toUtcDay(value) {
|
|
1704
|
+
if (typeof value === "string") {
|
|
1705
|
+
const [y, m, d] = value.slice(0, 10).split("-").map(Number);
|
|
1706
|
+
return Date.UTC(y, m - 1, d);
|
|
1707
|
+
}
|
|
1708
|
+
return Date.UTC(value.getFullYear(), value.getMonth(), value.getDate());
|
|
1709
|
+
}
|
|
1710
|
+
function formatUtcDay(time) {
|
|
1711
|
+
return new Date(time).toISOString().slice(0, 10);
|
|
1712
|
+
}
|
|
1713
|
+
function getHeatmapColumns({
|
|
1714
|
+
startDate,
|
|
1715
|
+
endDate,
|
|
1716
|
+
firstDayOfWeek = 1,
|
|
1717
|
+
splitMonths = false,
|
|
1718
|
+
withOutsideDates = false
|
|
1719
|
+
}) {
|
|
1720
|
+
const columns = [];
|
|
1721
|
+
if (endDate < startDate) return columns;
|
|
1722
|
+
const row = (time) => (new Date(time).getUTCDay() - firstDayOfWeek + 7) % 7;
|
|
1723
|
+
const month = (time) => new Date(time).getUTCMonth();
|
|
1724
|
+
let column = { cells: Array(7).fill(null) };
|
|
1725
|
+
const push = () => {
|
|
1726
|
+
if (column.cells.some(Boolean)) columns.push(column);
|
|
1727
|
+
column = { cells: Array(7).fill(null) };
|
|
1728
|
+
};
|
|
1729
|
+
const first = withOutsideDates ? startDate - row(startDate) * DAY : startDate;
|
|
1730
|
+
const last = withOutsideDates ? endDate + (6 - row(endDate)) * DAY : endDate;
|
|
1731
|
+
let previousMonth = null;
|
|
1732
|
+
for (let time = first; time <= last; time += DAY) {
|
|
1733
|
+
const outside = time < startDate || time > endDate;
|
|
1734
|
+
const currentMonth = month(time);
|
|
1735
|
+
if (time !== first && row(time) === 0) push();
|
|
1736
|
+
if (splitMonths && !outside && previousMonth !== null && currentMonth !== previousMonth) {
|
|
1737
|
+
push();
|
|
1738
|
+
columns.push({ cells: Array(7).fill(null), spacer: true });
|
|
1739
|
+
}
|
|
1740
|
+
if (!outside && previousMonth !== currentMonth) {
|
|
1741
|
+
column.monthLabel = currentMonth;
|
|
1742
|
+
previousMonth = currentMonth;
|
|
1743
|
+
}
|
|
1744
|
+
column.cells[row(time)] = { date: formatUtcDay(time), outside };
|
|
1745
|
+
}
|
|
1746
|
+
push();
|
|
1747
|
+
let lastLabel = -Infinity;
|
|
1748
|
+
columns.forEach((item, index) => {
|
|
1749
|
+
if (item.monthLabel === void 0) return;
|
|
1750
|
+
if (index - lastLabel < 3) {
|
|
1751
|
+
const previous = columns[lastLabel];
|
|
1752
|
+
if (previous) delete previous.monthLabel;
|
|
1753
|
+
}
|
|
1754
|
+
lastLabel = index;
|
|
1755
|
+
});
|
|
1756
|
+
return columns;
|
|
1757
|
+
}
|
|
1758
|
+
function getHeatColorIndex(value, domain, count) {
|
|
1759
|
+
if (value === null || value === void 0 || !Number.isFinite(value)) return -1;
|
|
1760
|
+
const [min, max] = domain;
|
|
1761
|
+
if (max <= min) return count - 1;
|
|
1762
|
+
const ratio = Math.min(Math.max((value - min) / (max - min), 0), 1);
|
|
1763
|
+
return Math.min(count - 1, Math.floor(ratio * count));
|
|
1764
|
+
}
|
|
1765
|
+
function Heatmap({
|
|
1766
|
+
data,
|
|
1767
|
+
startDate,
|
|
1768
|
+
endDate,
|
|
1769
|
+
colors = DEFAULT_COLORS,
|
|
1770
|
+
domain,
|
|
1771
|
+
firstDayOfWeek = 1,
|
|
1772
|
+
rectSize = 10,
|
|
1773
|
+
gap = 1,
|
|
1774
|
+
rectRadius = 2,
|
|
1775
|
+
fontSize = 12,
|
|
1776
|
+
withMonthLabels = false,
|
|
1777
|
+
monthLabels = DEFAULT_MONTHS,
|
|
1778
|
+
monthLabelsPosition = "top",
|
|
1779
|
+
monthsLabelsHeight = 14,
|
|
1780
|
+
withWeekdayLabels = false,
|
|
1781
|
+
weekdayLabels = DEFAULT_WEEKDAYS,
|
|
1782
|
+
weekdaysLabelsWidth = 30,
|
|
1783
|
+
splitMonths = false,
|
|
1784
|
+
withOutsideDates = false,
|
|
1785
|
+
withTooltip = false,
|
|
1786
|
+
getTooltipLabel,
|
|
1787
|
+
getRectProps,
|
|
1788
|
+
withLegend = false,
|
|
1789
|
+
legendLabels = ["Less", "More"],
|
|
1790
|
+
className,
|
|
1791
|
+
classNames,
|
|
1792
|
+
style,
|
|
1793
|
+
"aria-label": ariaLabel = "Heatmap"
|
|
1794
|
+
}) {
|
|
1795
|
+
const [hover, setHover] = useState6(null);
|
|
1796
|
+
const end = endDate !== void 0 ? toUtcDay(endDate) : toUtcDay(/* @__PURE__ */ new Date());
|
|
1797
|
+
const start = startDate !== void 0 ? toUtcDay(startDate) : Date.UTC(
|
|
1798
|
+
new Date(end).getUTCFullYear() - 1,
|
|
1799
|
+
new Date(end).getUTCMonth(),
|
|
1800
|
+
new Date(end).getUTCDate() + 1
|
|
1801
|
+
);
|
|
1802
|
+
const columns = useMemo4(
|
|
1803
|
+
() => getHeatmapColumns({
|
|
1804
|
+
startDate: start,
|
|
1805
|
+
endDate: end,
|
|
1806
|
+
firstDayOfWeek,
|
|
1807
|
+
splitMonths,
|
|
1808
|
+
withOutsideDates
|
|
1809
|
+
}),
|
|
1810
|
+
[start, end, firstDayOfWeek, splitMonths, withOutsideDates]
|
|
1811
|
+
);
|
|
1812
|
+
const resolvedDomain = useMemo4(() => {
|
|
1813
|
+
if (domain) return domain;
|
|
1814
|
+
const values = Object.values(data).filter((value) => Number.isFinite(value));
|
|
1815
|
+
return values.length ? [Math.min(...values), Math.max(...values)] : [0, 0];
|
|
1816
|
+
}, [data, domain]);
|
|
1817
|
+
const palette = colors.map((color) => getThemeColor(color));
|
|
1818
|
+
const step = rectSize + gap;
|
|
1819
|
+
const left = withWeekdayLabels ? weekdaysLabelsWidth : 0;
|
|
1820
|
+
const top = withMonthLabels && monthLabelsPosition === "top" ? monthsLabelsHeight : 0;
|
|
1821
|
+
const gridHeight = 7 * step - gap;
|
|
1822
|
+
const width = left + columns.length * step - gap;
|
|
1823
|
+
const height = top + gridHeight + (withMonthLabels && monthLabelsPosition === "bottom" ? monthsLabelsHeight : 0);
|
|
1824
|
+
const tooltipEnabled = withTooltip && !!getTooltipLabel;
|
|
1825
|
+
const rowLabels = Array.from(
|
|
1826
|
+
{ length: 7 },
|
|
1827
|
+
(_, rowIndex) => weekdayLabels[(rowIndex + firstDayOfWeek) % 7]
|
|
1828
|
+
);
|
|
1829
|
+
return /* @__PURE__ */ jsxs9("div", { className: cx("wello-chart", "wello-heatmap", className, classNames?.root), style, children: [
|
|
1830
|
+
/* @__PURE__ */ jsxs9(
|
|
1831
|
+
"svg",
|
|
1832
|
+
{
|
|
1833
|
+
className: classNames?.chart,
|
|
1834
|
+
width,
|
|
1835
|
+
height,
|
|
1836
|
+
role: "img",
|
|
1837
|
+
"aria-label": ariaLabel,
|
|
1838
|
+
onMouseLeave: () => setHover(null),
|
|
1839
|
+
children: [
|
|
1840
|
+
withWeekdayLabels && rowLabels.map(
|
|
1841
|
+
(label, rowIndex) => label ? /* @__PURE__ */ jsx13(
|
|
1842
|
+
"text",
|
|
1843
|
+
{
|
|
1844
|
+
className: "wello-heatmap-label",
|
|
1845
|
+
x: 0,
|
|
1846
|
+
y: top + rowIndex * step + rectSize / 2,
|
|
1847
|
+
dominantBaseline: "central",
|
|
1848
|
+
fontSize,
|
|
1849
|
+
children: label
|
|
1850
|
+
},
|
|
1851
|
+
rowIndex
|
|
1852
|
+
) : null
|
|
1853
|
+
),
|
|
1854
|
+
withMonthLabels && columns.map(
|
|
1855
|
+
(column, index) => column.monthLabel !== void 0 ? /* @__PURE__ */ jsx13(
|
|
1856
|
+
"text",
|
|
1857
|
+
{
|
|
1858
|
+
className: "wello-heatmap-label",
|
|
1859
|
+
x: left + index * step,
|
|
1860
|
+
y: monthLabelsPosition === "top" ? monthsLabelsHeight - 4 : top + gridHeight + monthsLabelsHeight - 2,
|
|
1861
|
+
fontSize,
|
|
1862
|
+
children: monthLabels[column.monthLabel]
|
|
1863
|
+
},
|
|
1864
|
+
`m-${index}`
|
|
1865
|
+
) : null
|
|
1866
|
+
),
|
|
1867
|
+
columns.map(
|
|
1868
|
+
(column, columnIndex) => column.cells.map((cell, rowIndex) => {
|
|
1869
|
+
if (!cell) return null;
|
|
1870
|
+
const value = cell.outside ? null : data[cell.date] ?? null;
|
|
1871
|
+
const rect = { date: cell.date, value };
|
|
1872
|
+
const colorIndex = getHeatColorIndex(value, resolvedDomain, palette.length);
|
|
1873
|
+
return /* @__PURE__ */ jsx13(
|
|
1874
|
+
"rect",
|
|
1875
|
+
{
|
|
1876
|
+
className: cx("wello-heatmap-rect", cell.outside && "wello-heatmap-rect--outside"),
|
|
1877
|
+
x: left + columnIndex * step,
|
|
1878
|
+
y: top + rowIndex * step,
|
|
1879
|
+
width: rectSize,
|
|
1880
|
+
height: rectSize,
|
|
1881
|
+
rx: rectRadius,
|
|
1882
|
+
fill: colorIndex === -1 ? "var(--wello-chart-heatmap-empty)" : palette[colorIndex],
|
|
1883
|
+
"data-date": cell.date,
|
|
1884
|
+
"data-value": value ?? void 0,
|
|
1885
|
+
onMouseEnter: tooltipEnabled && !cell.outside ? (event) => {
|
|
1886
|
+
const own = event.currentTarget.getBoundingClientRect();
|
|
1887
|
+
setHover({
|
|
1888
|
+
rect,
|
|
1889
|
+
x: own.left + own.width / 2,
|
|
1890
|
+
y: own.top,
|
|
1891
|
+
size: own.height,
|
|
1892
|
+
source: event.currentTarget.ownerSVGElement.parentElement
|
|
1893
|
+
});
|
|
1894
|
+
} : void 0,
|
|
1895
|
+
...getRectProps?.(rect)
|
|
1896
|
+
},
|
|
1897
|
+
cell.date
|
|
1898
|
+
);
|
|
1899
|
+
})
|
|
1900
|
+
)
|
|
1901
|
+
]
|
|
1902
|
+
}
|
|
1903
|
+
),
|
|
1904
|
+
tooltipEnabled && hover && /* @__PURE__ */ jsx13(
|
|
1905
|
+
FloatingTooltip,
|
|
1906
|
+
{
|
|
1907
|
+
clientX: hover.x,
|
|
1908
|
+
clientY: hover.y,
|
|
1909
|
+
side: "top",
|
|
1910
|
+
gap: 6,
|
|
1911
|
+
anchorHeight: hover.size,
|
|
1912
|
+
themeSource: hover.source,
|
|
1913
|
+
children: /* @__PURE__ */ jsx13("div", { className: "wello-tooltip wello-heatmap-tooltip", children: getTooltipLabel(hover.rect) })
|
|
1914
|
+
}
|
|
1915
|
+
),
|
|
1916
|
+
withLegend && /* @__PURE__ */ jsxs9(
|
|
1917
|
+
"div",
|
|
1918
|
+
{
|
|
1919
|
+
className: cx("wello-heatmap-legend", classNames?.legend),
|
|
1920
|
+
style: { paddingInlineStart: left, fontSize },
|
|
1921
|
+
children: [
|
|
1922
|
+
/* @__PURE__ */ jsx13("span", { children: legendLabels[0] }),
|
|
1923
|
+
palette.map((color) => /* @__PURE__ */ jsx13(
|
|
1924
|
+
"span",
|
|
1925
|
+
{
|
|
1926
|
+
className: "wello-heatmap-legend-rect",
|
|
1927
|
+
style: {
|
|
1928
|
+
width: rectSize,
|
|
1929
|
+
height: rectSize,
|
|
1930
|
+
borderRadius: rectRadius,
|
|
1931
|
+
background: color
|
|
1932
|
+
}
|
|
1933
|
+
},
|
|
1934
|
+
color
|
|
1935
|
+
)),
|
|
1936
|
+
/* @__PURE__ */ jsx13("span", { children: legendLabels[1] })
|
|
1937
|
+
]
|
|
1938
|
+
}
|
|
1939
|
+
)
|
|
1940
|
+
] });
|
|
1941
|
+
}
|
|
1942
|
+
export {
|
|
1943
|
+
AreaChart,
|
|
1944
|
+
BarChart,
|
|
1945
|
+
CHART_COLORS,
|
|
1946
|
+
ChartLegend,
|
|
1947
|
+
ChartSliceTooltip,
|
|
1948
|
+
ChartTooltip,
|
|
1949
|
+
DEFAULT_CHART_COLORS,
|
|
1950
|
+
DonutChart,
|
|
1951
|
+
Heatmap,
|
|
1952
|
+
LineChart,
|
|
1953
|
+
PieChart,
|
|
1954
|
+
RadialBarChart,
|
|
1955
|
+
formatUtcDay,
|
|
1956
|
+
getHeatColorIndex,
|
|
1957
|
+
getHeatmapColumns,
|
|
1958
|
+
getPercent,
|
|
1959
|
+
getSplitOffset,
|
|
1960
|
+
getThemeColor,
|
|
1961
|
+
getWaterfallData,
|
|
1962
|
+
seriesColor,
|
|
1963
|
+
toUtcDay
|
|
1964
|
+
};
|
|
1965
|
+
//# sourceMappingURL=index.js.map
|