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