@wello-dev/charts 0.0.0-stage → 1.0.4

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,2043 @@
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: color-mix(in srgb, currentColor 50%, transparent);\n --wello-chart-legend-color: color-mix(in srgb, currentColor 85%, transparent);\n --wello-chart-bright-color: currentColor;\n --wello-chart-dimmed-color: color-mix(in srgb, currentColor 50%, transparent);\n --wello-chart-grid-color: color-mix(in srgb, currentColor 22%, transparent);\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 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-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-cartesian-grid line {\n shape-rendering: crispEdges;\n}\n.wello-chart .recharts-surface,\n.wello-heatmap svg {\n direction: ltr;\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 12px;\n box-sizing: border-box;\n max-width: 100%;\n padding-bottom: 14px;\n font-size: 12.5px;\n font-weight: 500;\n color: var(--wello-chart-legend-color);\n}\n.wello-legend--start,\n.wello-legend--left {\n justify-content: flex-start;\n}\n.wello-legend--center {\n justify-content: center;\n}\n.wello-legend--end,\n.wello-legend--right {\n justify-content: flex-end;\n}\n[dir=rtl] .wello-legend--left {\n justify-content: flex-end;\n}\n[dir=rtl] .wello-legend--right {\n justify-content: flex-start;\n}\n.wello-legend .wello-legend-swatch {\n width: 10px;\n height: 10px;\n}\n.wello-legend-item {\n display: flex;\n align-items: center;\n gap: 8px;\n padding: 3px 8px;\n border-radius: 999px;\n cursor: default;\n transition: background-color 120ms ease;\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 color: var(--wello-chart-text-color);\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-bright-color);\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 = "start", 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 renderGridLine(props) {
536
+ const snap = (value) => Math.round(value) + 0.5;
537
+ const horizontal = props.y1 === props.y2;
538
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
539
+ "line",
540
+ {
541
+ x1: horizontal ? props.x1 : snap(props.x1),
542
+ x2: horizontal ? props.x2 : snap(props.x2),
543
+ y1: horizontal ? snap(props.y1) : props.y1,
544
+ y2: horizontal ? snap(props.y2) : props.y2,
545
+ stroke: props.stroke,
546
+ strokeWidth: props.strokeWidth,
547
+ strokeOpacity: props.strokeOpacity,
548
+ strokeDasharray: props.strokeDasharray,
549
+ fill: "none",
550
+ shapeRendering: "crispEdges"
551
+ },
552
+ props.key
553
+ );
554
+ }
555
+ function tickFormatter(props) {
556
+ return (value) => `${props.valueFormatter ? props.valueFormatter(value) : value}${props.unit ?? ""}`;
557
+ }
558
+ function axisLabel(value, axis) {
559
+ if (!value) return void 0;
560
+ if (axis === "x")
561
+ return {
562
+ value,
563
+ position: "insideBottom",
564
+ offset: -16,
565
+ fontSize: 12,
566
+ fill: "var(--wello-chart-text-color)"
567
+ };
568
+ return {
569
+ value,
570
+ angle: axis === "y" ? -90 : 90,
571
+ position: axis === "y" ? "insideLeft" : "insideRight",
572
+ fontSize: 12,
573
+ fill: "var(--wello-chart-text-color)",
574
+ style: { textAnchor: "middle" }
575
+ };
576
+ }
577
+ function cartesianElements(props, { onHighlight, cursor, valueTickFormatter, rtl = false }) {
578
+ const {
579
+ dataKey,
580
+ series,
581
+ orientation = "horizontal",
582
+ withLegend = false,
583
+ legendProps,
584
+ withTooltip = true,
585
+ tooltipProps,
586
+ tooltipAnimationDuration = 0,
587
+ withXAxis = true,
588
+ withYAxis = true,
589
+ xAxisProps,
590
+ yAxisProps,
591
+ xAxisLabel,
592
+ yAxisLabel,
593
+ withRightYAxis = false,
594
+ rightYAxisProps,
595
+ rightYAxisLabel,
596
+ gridAxis = "x",
597
+ gridProps,
598
+ tickLine = "none",
599
+ strokeDasharray = "5 5",
600
+ gridColor,
601
+ unit,
602
+ valueFormatter,
603
+ referenceLines
604
+ } = props;
605
+ const vertical = orientation === "vertical";
606
+ const gridStroke = getThemeColor(gridColor, "var(--wello-chart-grid-color)");
607
+ const valueTicks = valueTickFormatter ?? tickFormatter(props);
608
+ const tickBase = { fill: "var(--wello-chart-text-color)", fontSize: 12 };
609
+ const xTick = { ...tickBase, transform: "translate(0, 10)" };
610
+ const yTick = { ...tickBase, transform: rtl ? "translate(10, 0)" : "translate(-10, 0)" };
611
+ const rightYTick = { ...tickBase, transform: rtl ? "translate(-10, 0)" : "translate(10, 0)" };
612
+ const xTickLine = tickLine === "x" || tickLine === "xy" ? { stroke: "var(--wello-chart-grid-color)" } : false;
613
+ const yTickLine = tickLine === "y" || tickLine === "xy" ? { stroke: "var(--wello-chart-grid-color)" } : false;
614
+ const categoryAxis = { dataKey, type: "category" };
615
+ const valueAxis = {
616
+ type: "number",
617
+ tickFormatter: valueTicks,
618
+ unit: void 0,
619
+ tickCount: 7,
620
+ // Keep every tick. With recharts' default ("preserveEnd") the grid re-thins the ticks using
621
+ // its own label-size guess, so a short chart shows 7 labels but only every other grid line.
622
+ interval: 0
623
+ };
624
+ const valueGrid = gridAxis === "x" || gridAxis === "xy";
625
+ const categoryGrid = gridAxis === "y" || gridAxis === "xy";
626
+ const elements = [
627
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
628
+ import_recharts.CartesianGrid,
629
+ {
630
+ yAxisId: "left",
631
+ strokeDasharray,
632
+ stroke: gridStroke,
633
+ horizontal: (vertical ? categoryGrid : valueGrid) ? renderGridLine : false,
634
+ vertical: (vertical ? valueGrid : categoryGrid) ? renderGridLine : false,
635
+ ...gridProps
636
+ },
637
+ "grid"
638
+ ),
639
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
640
+ import_recharts.XAxis,
641
+ {
642
+ hide: !withXAxis,
643
+ ...vertical ? valueAxis : categoryAxis,
644
+ reversed: rtl,
645
+ tick: xTick,
646
+ tickLine: xTickLine,
647
+ axisLine: false,
648
+ minTickGap: 5,
649
+ interval: "preserveStartEnd",
650
+ label: axisLabel(xAxisLabel, "x"),
651
+ ...xAxisProps
652
+ },
653
+ "x"
654
+ ),
655
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
656
+ import_recharts.YAxis,
657
+ {
658
+ yAxisId: "left",
659
+ orientation: rtl ? "right" : "left",
660
+ hide: !withYAxis,
661
+ ...vertical ? categoryAxis : valueAxis,
662
+ tick: yTick,
663
+ tickLine: yTickLine,
664
+ axisLine: false,
665
+ width: vertical ? 80 : 60,
666
+ label: axisLabel(yAxisLabel, "y"),
667
+ ...yAxisProps
668
+ },
669
+ "y"
670
+ )
671
+ ];
672
+ if (withRightYAxis) {
673
+ elements.push(
674
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
675
+ import_recharts.YAxis,
676
+ {
677
+ yAxisId: "right",
678
+ orientation: rtl ? "left" : "right",
679
+ ...vertical ? categoryAxis : valueAxis,
680
+ tick: rightYTick,
681
+ tickLine: yTickLine,
682
+ axisLine: false,
683
+ width: 60,
684
+ label: axisLabel(rightYAxisLabel, "right"),
685
+ ...rightYAxisProps
686
+ },
687
+ "y-right"
688
+ )
689
+ );
690
+ }
691
+ if (withTooltip) {
692
+ elements.push(
693
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
694
+ import_recharts.Tooltip,
695
+ {
696
+ isAnimationActive: tooltipAnimationDuration !== 0,
697
+ animationDuration: tooltipAnimationDuration,
698
+ cursor: cursor === "fill" ? { fill: "var(--wello-chart-cursor-fill)" } : (
699
+ // Dashed like the grid (Mantine style).
700
+ { stroke: gridStroke, strokeWidth: 1, strokeDasharray }
701
+ ),
702
+ wrapperStyle: { zIndex: 50, outline: "none" },
703
+ offset: 14,
704
+ content: renderCartesianTooltip({ series, unit, valueFormatter }),
705
+ ...tooltipProps
706
+ },
707
+ "tooltip"
708
+ )
709
+ );
710
+ }
711
+ if (withLegend) {
712
+ elements.push(
713
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
714
+ import_recharts.Legend,
715
+ {
716
+ verticalAlign: legendProps?.verticalAlign ?? "top",
717
+ content: () => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
718
+ ChartLegend,
719
+ {
720
+ series,
721
+ align: legendProps?.align,
722
+ className: props.classNames?.legend,
723
+ onHighlight: legendProps?.highlightOnHover === false ? void 0 : onHighlight
724
+ }
725
+ )
726
+ },
727
+ "legend"
728
+ )
729
+ );
730
+ }
731
+ referenceLines?.forEach((line, index) => {
732
+ const color = getThemeColor(line.color, "var(--wello-chart-text-color)");
733
+ elements.push(
734
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
735
+ import_recharts.ReferenceLine,
736
+ {
737
+ yAxisId: line.yAxisId ?? "left",
738
+ x: line.x,
739
+ y: line.y,
740
+ stroke: color,
741
+ strokeDasharray: line.strokeDasharray,
742
+ label: line.label === void 0 ? void 0 : {
743
+ value: line.label,
744
+ fill: color,
745
+ fontSize: 12,
746
+ position: line.y !== void 0 ? "insideBottomLeft" : "insideTopRight"
747
+ },
748
+ ifOverflow: "extendDomain"
749
+ },
750
+ `ref-${index}`
751
+ )
752
+ );
753
+ });
754
+ return elements;
755
+ }
756
+
757
+ // src/components/chart-canvas.tsx
758
+ var import_jsx_runtime4 = require("react/jsx-runtime");
759
+ function ChartCanvas({
760
+ empty,
761
+ loading = false,
762
+ emptyLabel = "No data",
763
+ height,
764
+ className,
765
+ style,
766
+ children
767
+ }) {
768
+ if (loading)
769
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
770
+ "div",
771
+ {
772
+ className: cx("wello-chart", "wello-chart-skeleton", className),
773
+ style: { height, ...style },
774
+ "aria-busy": true
775
+ }
776
+ );
777
+ if (empty)
778
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
779
+ "div",
780
+ {
781
+ className: cx("wello-chart", "wello-chart-empty", className),
782
+ style: { height, ...style },
783
+ children: emptyLabel
784
+ }
785
+ );
786
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_jsx_runtime4.Fragment, { children });
787
+ }
788
+ function isCartesianEmpty(data, keys) {
789
+ return !data.length || !keys.length || !data.some((row) => keys.some((key) => Number(row[key]) !== 0 && row[key] != null));
790
+ }
791
+
792
+ // src/charts/area-chart.tsx
793
+ var import_jsx_runtime5 = require("react/jsx-runtime");
794
+ function getSplitOffset(data, key) {
795
+ const values = data.map((item) => Number(item[key])).filter((value) => Number.isFinite(value));
796
+ if (!values.length) return 0.5;
797
+ const max = Math.max(...values);
798
+ const min = Math.min(...values);
799
+ if (max <= 0) return 0;
800
+ if (min >= 0) return 1;
801
+ return max / (max - min);
802
+ }
803
+ function AreaChart(props) {
804
+ const {
805
+ data,
806
+ series,
807
+ h = 300,
808
+ w = "100%",
809
+ className,
810
+ classNames,
811
+ style,
812
+ orientation = "horizontal",
813
+ type = "default",
814
+ curveType = "monotone",
815
+ withGradient = true,
816
+ fillOpacity = 0.2,
817
+ strokeWidth = 2,
818
+ withDots = true,
819
+ dotProps,
820
+ activeDotProps,
821
+ connectNulls = true,
822
+ withPointLabels = false,
823
+ splitColors = ["green-700", "red-700"],
824
+ splitOffset,
825
+ areaChartProps,
826
+ areaProps,
827
+ textColor,
828
+ animationDuration = 650,
829
+ loading,
830
+ emptyLabel,
831
+ children
832
+ } = props;
833
+ const ref = (0, import_react3.useRef)(null);
834
+ const rtl = useIsRtl(ref);
835
+ const resolved = resolveSeries(props);
836
+ const chartProps = { ...props, series: resolved };
837
+ const [highlighted, setHighlighted] = useHighlight();
838
+ const id = useSvgId("wello-area");
839
+ const stacked = type === "stacked" || type === "percent";
840
+ const areas = resolved.map((item, index) => {
841
+ const color = getThemeColor(item.color);
842
+ const gradientId = `${id}-${index}`;
843
+ const dimmed = isDimmed(highlighted, item.name);
844
+ const extra = typeof areaProps === "function" ? areaProps(item) : areaProps;
845
+ const split = type === "split";
846
+ const offset = splitOffset ?? getSplitOffset(data, item.name);
847
+ return [
848
+ /* @__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: [
849
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
850
+ "stop",
851
+ {
852
+ offset,
853
+ stopColor: getThemeColor(splitColors[0]),
854
+ stopOpacity: fillOpacity
855
+ }
856
+ ),
857
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
858
+ "stop",
859
+ {
860
+ offset,
861
+ stopColor: getThemeColor(splitColors[1]),
862
+ stopOpacity: fillOpacity
863
+ }
864
+ )
865
+ ] }) : withGradient ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
866
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("stop", { offset: "0%", stopColor: color, stopOpacity: fillOpacity }),
867
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("stop", { offset: "100%", stopColor: color, stopOpacity: 0.01 })
868
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("stop", { offset: "0%", stopColor: color, stopOpacity: fillOpacity }) }) }, `defs-${item.name}`),
869
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
870
+ import_recharts2.Area,
871
+ {
872
+ yAxisId: item.yAxisId ?? "left",
873
+ name: item.name,
874
+ dataKey: item.name,
875
+ type: curveType,
876
+ stroke: color,
877
+ strokeWidth,
878
+ strokeDasharray: item.strokeDasharray,
879
+ fill: `url(#${gradientId})`,
880
+ fillOpacity: dimmed ? 0.1 : 1,
881
+ strokeOpacity: dimmed ? 0.3 : 1,
882
+ stackId: stacked ? "stack" : void 0,
883
+ connectNulls,
884
+ dot: withDots ? {
885
+ fill: color,
886
+ fillOpacity: dimmed ? 0 : 1,
887
+ strokeWidth: 2,
888
+ r: 4,
889
+ // Solid dot in the series color (no surface-colored ring), as in Mantine.
890
+ stroke: color,
891
+ strokeOpacity: dimmed ? 0 : 1,
892
+ ...dotProps
893
+ } : false,
894
+ activeDot: {
895
+ fill: "#fff",
896
+ stroke: color,
897
+ strokeWidth: 2,
898
+ r: 4,
899
+ ...activeDotProps
900
+ },
901
+ isAnimationActive: animationDuration > 0,
902
+ animationDuration,
903
+ animationEasing: "ease-out",
904
+ ...extra,
905
+ children: withPointLabels && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
906
+ import_recharts2.LabelList,
907
+ {
908
+ position: "top",
909
+ fontSize: 12,
910
+ fill: "var(--wello-chart-text-color)",
911
+ formatter: props.valueFormatter
912
+ }
913
+ )
914
+ },
915
+ item.name
916
+ )
917
+ ];
918
+ });
919
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
920
+ ChartCanvas,
921
+ {
922
+ empty: isCartesianEmpty(
923
+ data,
924
+ series.map((item) => item.name)
925
+ ),
926
+ loading,
927
+ emptyLabel,
928
+ height: h,
929
+ className: cx(className, classNames?.root),
930
+ style,
931
+ children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
932
+ "div",
933
+ {
934
+ ref,
935
+ className: cx("wello-chart", className, classNames?.root),
936
+ style: {
937
+ height: h,
938
+ width: w,
939
+ color: textColor ? getThemeColor(textColor) : void 0,
940
+ ...style
941
+ },
942
+ children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_recharts2.ResponsiveContainer, { className: classNames?.chart, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
943
+ import_recharts2.AreaChart,
944
+ {
945
+ data,
946
+ layout: orientation,
947
+ stackOffset: type === "percent" ? "expand" : void 0,
948
+ margin: { top: 10, right: 10, bottom: props.xAxisLabel ? 20 : 0, left: 0 },
949
+ ...areaChartProps,
950
+ children: [
951
+ cartesianElements(withPointLabels ? withLabelPadding(chartProps) : chartProps, {
952
+ highlighted,
953
+ onHighlight: setHighlighted,
954
+ cursor: "line",
955
+ rtl,
956
+ valueTickFormatter: type === "percent" ? (value) => `${Math.round(value * 100)}%` : void 0
957
+ }),
958
+ areas,
959
+ children
960
+ ]
961
+ }
962
+ ) })
963
+ }
964
+ )
965
+ }
966
+ );
967
+ }
968
+
969
+ // src/charts/bar-chart.tsx
970
+ var import_react4 = require("react");
971
+ var import_recharts3 = require("recharts");
972
+ var import_jsx_runtime6 = require("react/jsx-runtime");
973
+ function getWaterfallData(data, key) {
974
+ let total = 0;
975
+ return data.map((item) => {
976
+ const value = Number(item[key]) || 0;
977
+ if (item.standalone) {
978
+ total = value;
979
+ return { ...item, [key]: [0, value], __value: value };
980
+ }
981
+ const start = total;
982
+ total += value;
983
+ return { ...item, [key]: [start, total], __value: value };
984
+ });
985
+ }
986
+ function BarChart(props) {
987
+ const {
988
+ data,
989
+ series,
990
+ h = 300,
991
+ w = "100%",
992
+ className,
993
+ classNames,
994
+ style,
995
+ orientation = "horizontal",
996
+ type = "default",
997
+ fillOpacity = 1,
998
+ maxBarWidth = 26,
999
+ minBarSize,
1000
+ withBarValueLabel = false,
1001
+ valueLabelProps,
1002
+ getBarColor,
1003
+ barChartProps,
1004
+ barProps,
1005
+ valueFormatter,
1006
+ textColor,
1007
+ animationDuration = 650,
1008
+ loading,
1009
+ emptyLabel,
1010
+ children
1011
+ } = props;
1012
+ const ref = (0, import_react4.useRef)(null);
1013
+ const rtl = useIsRtl(ref);
1014
+ const [highlighted, setHighlighted] = useHighlight();
1015
+ const waterfall = type === "waterfall";
1016
+ const stacked = type === "stacked" || type === "percent";
1017
+ const resolved = resolveSeries(props);
1018
+ const visibleSeries = waterfall ? resolved.slice(0, 1) : resolved;
1019
+ const chartData = (0, import_react4.useMemo)(
1020
+ () => waterfall && series[0] ? getWaterfallData(data, series[0].name) : data,
1021
+ [waterfall, data, series]
1022
+ );
1023
+ const bars = visibleSeries.map((item) => {
1024
+ const color = getThemeColor(item.color);
1025
+ const dimmed = isDimmed(highlighted, item.name);
1026
+ const extra = typeof barProps === "function" ? barProps(item) : barProps;
1027
+ const radius = orientation === "vertical" ? [0, 7, 7, 0] : [7, 7, 0, 0];
1028
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
1029
+ import_recharts3.Bar,
1030
+ {
1031
+ yAxisId: item.yAxisId ?? "left",
1032
+ name: item.name,
1033
+ dataKey: item.name,
1034
+ fill: color,
1035
+ fillOpacity: dimmed ? 0.2 : fillOpacity,
1036
+ stroke: color,
1037
+ strokeOpacity: dimmed ? 0.2 : fillOpacity,
1038
+ strokeWidth: 0,
1039
+ stackId: stacked ? "stack" : void 0,
1040
+ maxBarSize: maxBarWidth,
1041
+ minPointSize: minBarSize,
1042
+ radius: stacked || waterfall ? 0 : radius,
1043
+ isAnimationActive: animationDuration > 0,
1044
+ animationDuration,
1045
+ animationEasing: "ease-out",
1046
+ ...extra,
1047
+ children: [
1048
+ (waterfall || getBarColor) && chartData.map((row, index) => {
1049
+ const value = waterfall ? row.__value : row[item.name];
1050
+ const custom = getBarColor?.(value, item) ?? (waterfall ? row.color : void 0);
1051
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1052
+ import_recharts3.Cell,
1053
+ {
1054
+ fill: custom ? getThemeColor(custom) : color,
1055
+ stroke: custom ? getThemeColor(custom) : color
1056
+ },
1057
+ index
1058
+ );
1059
+ }),
1060
+ withBarValueLabel && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1061
+ import_recharts3.LabelList,
1062
+ {
1063
+ position: orientation === "vertical" ? "right" : "top",
1064
+ fontSize: 12,
1065
+ fill: "var(--wello-chart-text-color)",
1066
+ valueAccessor: (entry) => waterfall ? entry.payload.__value : entry.value,
1067
+ formatter: (value) => valueFormatter && typeof value === "number" ? valueFormatter(value) : value,
1068
+ ...valueLabelProps
1069
+ }
1070
+ )
1071
+ ]
1072
+ },
1073
+ item.name
1074
+ );
1075
+ });
1076
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1077
+ ChartCanvas,
1078
+ {
1079
+ empty: isCartesianEmpty(
1080
+ data,
1081
+ visibleSeries.map((item) => item.name)
1082
+ ),
1083
+ loading,
1084
+ emptyLabel,
1085
+ height: h,
1086
+ className: cx(className, classNames?.root),
1087
+ style,
1088
+ children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1089
+ "div",
1090
+ {
1091
+ ref,
1092
+ className: cx("wello-chart", className, classNames?.root),
1093
+ style: {
1094
+ height: h,
1095
+ width: w,
1096
+ color: textColor ? getThemeColor(textColor) : void 0,
1097
+ ...style
1098
+ },
1099
+ children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_recharts3.ResponsiveContainer, { className: classNames?.chart, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
1100
+ import_recharts3.BarChart,
1101
+ {
1102
+ data: chartData,
1103
+ layout: orientation,
1104
+ stackOffset: type === "percent" ? "expand" : void 0,
1105
+ margin: {
1106
+ top: withBarValueLabel ? 20 : 10,
1107
+ right: 10,
1108
+ bottom: props.xAxisLabel ? 20 : 0,
1109
+ left: 0
1110
+ },
1111
+ ...barChartProps,
1112
+ children: [
1113
+ cartesianElements(
1114
+ { ...props, series: visibleSeries },
1115
+ {
1116
+ highlighted,
1117
+ onHighlight: setHighlighted,
1118
+ cursor: "fill",
1119
+ rtl,
1120
+ valueTickFormatter: type === "percent" ? (value) => `${Math.round(value * 100)}%` : void 0
1121
+ }
1122
+ ),
1123
+ bars,
1124
+ children
1125
+ ]
1126
+ }
1127
+ ) })
1128
+ }
1129
+ )
1130
+ }
1131
+ );
1132
+ }
1133
+
1134
+ // src/charts/line-chart.tsx
1135
+ var import_recharts4 = require("recharts");
1136
+ var import_react5 = require("react");
1137
+ var import_jsx_runtime7 = require("react/jsx-runtime");
1138
+ var DEFAULT_GRADIENT = [
1139
+ { offset: 0, color: "red" },
1140
+ { offset: 50, color: "yellow" },
1141
+ { offset: 100, color: "teal" }
1142
+ ];
1143
+ function LineChart(props) {
1144
+ const {
1145
+ data,
1146
+ series,
1147
+ h = 300,
1148
+ w = "100%",
1149
+ className,
1150
+ classNames,
1151
+ style,
1152
+ orientation = "horizontal",
1153
+ type = "default",
1154
+ gradientStops = DEFAULT_GRADIENT,
1155
+ curveType = "monotone",
1156
+ strokeWidth = 2.75,
1157
+ withDots = false,
1158
+ dotProps,
1159
+ activeDotProps,
1160
+ connectNulls = true,
1161
+ withPointLabels = false,
1162
+ lineChartProps,
1163
+ lineProps,
1164
+ valueFormatter,
1165
+ textColor,
1166
+ animationDuration = 650,
1167
+ loading,
1168
+ emptyLabel,
1169
+ children
1170
+ } = props;
1171
+ const ref = (0, import_react5.useRef)(null);
1172
+ const rtl = useIsRtl(ref);
1173
+ const [highlighted, setHighlighted] = useHighlight();
1174
+ const gradientId = useSvgId("wello-line");
1175
+ const gradient = type === "gradient";
1176
+ const resolved = resolveSeries(props);
1177
+ const visibleSeries = gradient ? resolved.slice(0, 1) : resolved;
1178
+ const lines = visibleSeries.map((item) => {
1179
+ const color = gradient ? `url(#${gradientId})` : getThemeColor(item.color);
1180
+ const dotColor = gradient ? "var(--wello-chart-text-color)" : color;
1181
+ const dimmed = isDimmed(highlighted, item.name);
1182
+ const extra = typeof lineProps === "function" ? lineProps(item) : lineProps;
1183
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1184
+ import_recharts4.Line,
1185
+ {
1186
+ yAxisId: item.yAxisId ?? "left",
1187
+ name: item.name,
1188
+ dataKey: item.name,
1189
+ type: curveType,
1190
+ stroke: color,
1191
+ strokeWidth,
1192
+ strokeDasharray: item.strokeDasharray,
1193
+ strokeOpacity: dimmed ? 0.2 : 1,
1194
+ connectNulls,
1195
+ dot: withDots ? {
1196
+ fill: dotColor,
1197
+ fillOpacity: dimmed ? 0 : 1,
1198
+ strokeWidth: 2,
1199
+ r: 4,
1200
+ stroke: "var(--wello-chart-bg)",
1201
+ ...dotProps
1202
+ } : false,
1203
+ activeDot: {
1204
+ fill: "var(--wello-chart-bg)",
1205
+ stroke: dotColor,
1206
+ strokeWidth: 2,
1207
+ r: 4,
1208
+ ...activeDotProps
1209
+ },
1210
+ isAnimationActive: animationDuration > 0,
1211
+ animationDuration,
1212
+ animationEasing: "ease-out",
1213
+ ...extra,
1214
+ children: withPointLabels && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1215
+ import_recharts4.LabelList,
1216
+ {
1217
+ position: "top",
1218
+ fontSize: 12,
1219
+ fill: "var(--wello-chart-text-color)",
1220
+ formatter: (value) => valueFormatter && typeof value === "number" ? valueFormatter(value) : value
1221
+ }
1222
+ )
1223
+ },
1224
+ item.name
1225
+ );
1226
+ });
1227
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1228
+ ChartCanvas,
1229
+ {
1230
+ empty: isCartesianEmpty(
1231
+ data,
1232
+ visibleSeries.map((item) => item.name)
1233
+ ),
1234
+ loading,
1235
+ emptyLabel,
1236
+ height: h,
1237
+ className: cx(className, classNames?.root),
1238
+ style,
1239
+ children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1240
+ "div",
1241
+ {
1242
+ ref,
1243
+ className: cx("wello-chart", className, classNames?.root),
1244
+ style: {
1245
+ height: h,
1246
+ width: w,
1247
+ color: textColor ? getThemeColor(textColor) : void 0,
1248
+ ...style
1249
+ },
1250
+ children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_recharts4.ResponsiveContainer, { className: classNames?.chart, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
1251
+ import_recharts4.LineChart,
1252
+ {
1253
+ data,
1254
+ layout: orientation,
1255
+ margin: {
1256
+ top: withPointLabels ? 20 : 10,
1257
+ right: 10,
1258
+ bottom: props.xAxisLabel ? 20 : 0,
1259
+ left: 0
1260
+ },
1261
+ ...lineChartProps,
1262
+ children: [
1263
+ gradient && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("defs", { children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1264
+ "linearGradient",
1265
+ {
1266
+ id: gradientId,
1267
+ gradientUnits: "userSpaceOnUse",
1268
+ x1: "0",
1269
+ y1: "0%",
1270
+ x2: "0",
1271
+ y2: "100%",
1272
+ children: gradientStops.map((stop) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1273
+ "stop",
1274
+ {
1275
+ offset: `${stop.offset}%`,
1276
+ stopColor: getThemeColor(stop.color)
1277
+ },
1278
+ stop.offset
1279
+ ))
1280
+ }
1281
+ ) }),
1282
+ cartesianElements(
1283
+ withPointLabels ? withLabelPadding({ ...props, series: visibleSeries }) : { ...props, series: visibleSeries },
1284
+ { highlighted, onHighlight: setHighlighted, cursor: "line", rtl }
1285
+ ),
1286
+ lines,
1287
+ children
1288
+ ]
1289
+ }
1290
+ ) })
1291
+ }
1292
+ )
1293
+ }
1294
+ );
1295
+ }
1296
+
1297
+ // src/shared/pie-base.tsx
1298
+ var import_react7 = require("react");
1299
+ var import_recharts5 = require("recharts");
1300
+
1301
+ // src/components/floating-tooltip.tsx
1302
+ var import_react6 = require("react");
1303
+ var import_react_dom = require("react-dom");
1304
+ var import_jsx_runtime8 = require("react/jsx-runtime");
1305
+ var GAP = 18;
1306
+ var EDGE = 8;
1307
+ var THEME_VARS = ["--wello-chart-tooltip-bg", "--wello-chart-tooltip-fg", "--wello-chart-font"];
1308
+ function FloatingTooltip({
1309
+ clientX,
1310
+ clientY,
1311
+ side,
1312
+ gap = GAP,
1313
+ anchorHeight = 0,
1314
+ themeSource,
1315
+ children
1316
+ }) {
1317
+ const ref = (0, import_react6.useRef)(null);
1318
+ const [position, setPosition] = (0, import_react6.useState)(null);
1319
+ const [scrolledAt, setScrolledAt] = (0, import_react6.useState)(null);
1320
+ const hidden = scrolledAt !== null && scrolledAt.x === clientX && scrolledAt.y === clientY;
1321
+ (0, import_react6.useEffect)(() => {
1322
+ const onScroll = () => setScrolledAt({ x: clientX, y: clientY });
1323
+ window.addEventListener("scroll", onScroll, { capture: true, passive: true });
1324
+ return () => window.removeEventListener("scroll", onScroll, { capture: true });
1325
+ }, [clientX, clientY]);
1326
+ (0, import_react6.useLayoutEffect)(() => {
1327
+ const element = ref.current;
1328
+ if (!element) return;
1329
+ const { width, height } = element.getBoundingClientRect();
1330
+ const clampX = (value) => Math.min(Math.max(value, EDGE), Math.max(EDGE, window.innerWidth - width - EDGE));
1331
+ const clampY = (value) => Math.min(Math.max(value, EDGE), Math.max(EDGE, window.innerHeight - height - EDGE));
1332
+ let x;
1333
+ let y;
1334
+ if (side === "top") {
1335
+ const above = clientY - gap - height;
1336
+ x = clampX(clientX - width / 2);
1337
+ y = above >= EDGE ? above : clampY(clientY + anchorHeight + gap);
1338
+ } else {
1339
+ const right = clientX + gap;
1340
+ const left = clientX - gap - width;
1341
+ const fitsRight = right + width <= window.innerWidth - EDGE;
1342
+ const fitsLeft = left >= EDGE;
1343
+ x = clampX(
1344
+ side === "right" ? fitsRight || !fitsLeft ? right : left : fitsLeft || !fitsRight ? left : right
1345
+ );
1346
+ y = clampY(clientY - height / 2);
1347
+ }
1348
+ setPosition(
1349
+ (current) => current && current.left === x && current.top === y ? current : { left: x, top: y }
1350
+ );
1351
+ }, [clientX, clientY, side, gap, anchorHeight, children]);
1352
+ const theme = {};
1353
+ if (themeSource) {
1354
+ const styles = getComputedStyle(themeSource);
1355
+ for (const name of THEME_VARS) theme[name] = styles.getPropertyValue(name);
1356
+ }
1357
+ const style = {
1358
+ ...theme,
1359
+ position: "fixed",
1360
+ left: position?.left ?? 0,
1361
+ top: position?.top ?? 0,
1362
+ visibility: position && !hidden ? "visible" : "hidden"
1363
+ };
1364
+ return (0, import_react_dom.createPortal)(
1365
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { ref, className: "wello-floating-tooltip", style, children }),
1366
+ document.body
1367
+ );
1368
+ }
1369
+ function createPointerStore() {
1370
+ let state = null;
1371
+ const listeners = /* @__PURE__ */ new Set();
1372
+ return {
1373
+ get: () => state,
1374
+ set: (next) => {
1375
+ state = next;
1376
+ listeners.forEach((listener) => listener());
1377
+ },
1378
+ subscribe: (listener) => {
1379
+ listeners.add(listener);
1380
+ return () => listeners.delete(listener);
1381
+ }
1382
+ };
1383
+ }
1384
+ function PointerTooltip({ store, children }) {
1385
+ const pointer = (0, import_react6.useSyncExternalStore)(store.subscribe, store.get, () => null);
1386
+ if (!pointer) return null;
1387
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1388
+ FloatingTooltip,
1389
+ {
1390
+ clientX: pointer.clientX,
1391
+ clientY: pointer.clientY,
1392
+ side: pointer.side,
1393
+ themeSource: pointer.source,
1394
+ children
1395
+ }
1396
+ );
1397
+ }
1398
+
1399
+ // src/shared/pie-base.tsx
1400
+ var import_jsx_runtime9 = require("react/jsx-runtime");
1401
+ var RADIAN = Math.PI / 180;
1402
+ var OUTSIDE_LABEL_SPACE = 80;
1403
+ var HOVER_GROWTH = 6;
1404
+ function getPercent(value, data) {
1405
+ const total = data.reduce((sum, item) => sum + (Number(item.value) || 0), 0);
1406
+ return total > 0 ? value / total * 100 : 0;
1407
+ }
1408
+ function ActiveSlice(props) {
1409
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1410
+ import_recharts5.Sector,
1411
+ {
1412
+ ...props,
1413
+ outerRadius: props.outerRadius + HOVER_GROWTH,
1414
+ stroke: props.fill,
1415
+ strokeWidth: 2,
1416
+ style: { filter: `drop-shadow(0 0 7px color-mix(in srgb, ${props.fill} 45%, transparent))` }
1417
+ }
1418
+ );
1419
+ }
1420
+ function PieBase({
1421
+ data,
1422
+ size = 160,
1423
+ colors,
1424
+ withLabels = false,
1425
+ withLabelsLine = true,
1426
+ labelsType = "value",
1427
+ labelColor,
1428
+ labelsPosition,
1429
+ paddingAngle = 2,
1430
+ startAngle = 0,
1431
+ endAngle = 360,
1432
+ cornerRadius = 6,
1433
+ strokeWidth = 3,
1434
+ strokeColor,
1435
+ withTooltip = false,
1436
+ tooltipDataSource = "segment",
1437
+ tooltipProps,
1438
+ tooltipAnimationDuration = 0,
1439
+ withLegend = false,
1440
+ legendPosition = "bottom",
1441
+ valueFormatter,
1442
+ animationDuration = 650,
1443
+ pieProps,
1444
+ pieChartProps,
1445
+ loading,
1446
+ emptyLabel,
1447
+ className,
1448
+ classNames,
1449
+ style,
1450
+ children,
1451
+ innerRadius,
1452
+ center,
1453
+ emptyRing = false,
1454
+ rootClassName
1455
+ }) {
1456
+ const [highlighted, setHighlighted] = (0, import_react7.useState)(null);
1457
+ const [pointer] = (0, import_react7.useState)(createPointerStore);
1458
+ const cells = (0, import_react7.useMemo)(
1459
+ () => data.map((item, index) => ({ ...item, color: seriesColor(item.color, index, colors) })).filter((item) => Number(item.value) > 0),
1460
+ [data, colors]
1461
+ );
1462
+ const total = cells.reduce((sum, item) => sum + Number(item.value), 0);
1463
+ const ring = total <= 0 && emptyRing && data.length > 0;
1464
+ const outside = withLabels && labelsPosition === "outside";
1465
+ const height = size + (outside ? OUTSIDE_LABEL_SPACE : 0) + HOVER_GROWTH * 2;
1466
+ const outerRadius = size / 2;
1467
+ const text = (value) => labelsType === "percent" ? `${getPercent(value, cells).toFixed(0)}%` : formatValue(value, valueFormatter);
1468
+ const renderLabel = (entry) => {
1469
+ const { cx: x0, cy: y0, midAngle, outerRadius: r, innerRadius: ri, value } = entry;
1470
+ const radius = outside ? r + 16 : ri + (r - ri) / 2 || r / 2;
1471
+ const x = x0 + radius * Math.cos(-midAngle * RADIAN);
1472
+ const y = y0 + radius * Math.sin(-midAngle * RADIAN);
1473
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1474
+ "text",
1475
+ {
1476
+ x,
1477
+ y,
1478
+ fill: outside ? getThemeColor(labelColor, "var(--wello-chart-text-color)") : getThemeColor(labelColor, "#fff"),
1479
+ textAnchor: outside ? x > x0 ? "start" : "end" : "middle",
1480
+ dominantBaseline: "central",
1481
+ fontSize: 11,
1482
+ fontWeight: outside ? 500 : 700,
1483
+ children: text(value)
1484
+ }
1485
+ );
1486
+ };
1487
+ const legend = withLegend && !ring && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1488
+ ChartLegend,
1489
+ {
1490
+ series: cells.map(({ name, color }) => ({ name, color })),
1491
+ align: "center",
1492
+ className: classNames?.legend,
1493
+ onHighlight: setHighlighted
1494
+ }
1495
+ );
1496
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1497
+ ChartCanvas,
1498
+ {
1499
+ empty: !cells.length && !ring,
1500
+ loading,
1501
+ emptyLabel,
1502
+ height,
1503
+ className: cx(className, classNames?.root),
1504
+ style,
1505
+ children: /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: cx("wello-chart", "wello-pie", rootClassName, className, classNames?.root), style: { minWidth: height, ...style }, children: [
1506
+ legendPosition === "top" && legend,
1507
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
1508
+ "div",
1509
+ {
1510
+ className: cx("wello-pie-area", classNames?.chart),
1511
+ style: { height },
1512
+ onMouseMove: (event) => {
1513
+ const area = event.currentTarget;
1514
+ const box = area.getBoundingClientRect();
1515
+ const side = event.clientX >= box.left + box.width / 2 ? "right" : "left";
1516
+ pointer.set({ clientX: event.clientX, clientY: event.clientY, side, source: area });
1517
+ },
1518
+ onMouseLeave: () => pointer.set(null),
1519
+ children: [
1520
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_recharts5.ResponsiveContainer, { children: /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_recharts5.PieChart, { ...pieChartProps, children: [
1521
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1522
+ import_recharts5.Pie,
1523
+ {
1524
+ data: ring ? [{ name: "empty", value: 1 }] : cells,
1525
+ dataKey: "value",
1526
+ nameKey: "name",
1527
+ innerRadius,
1528
+ outerRadius,
1529
+ paddingAngle: ring ? 0 : paddingAngle,
1530
+ startAngle,
1531
+ endAngle,
1532
+ cornerRadius,
1533
+ stroke: strokeColor ? getThemeColor(strokeColor) : "none",
1534
+ strokeWidth: ring || !strokeColor ? 0 : strokeWidth,
1535
+ label: withLabels && !ring ? renderLabel : false,
1536
+ labelLine: outside && withLabelsLine && !ring ? { stroke: "var(--wello-chart-label-line-color)" } : false,
1537
+ activeShape: ring ? void 0 : ActiveSlice,
1538
+ isAnimationActive: animationDuration > 0,
1539
+ animationDuration,
1540
+ animationEasing: "ease-out",
1541
+ ...pieProps,
1542
+ 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)(
1543
+ import_recharts5.Cell,
1544
+ {
1545
+ fill: item.color,
1546
+ fillOpacity: highlighted !== null && highlighted !== item.name ? 0.2 : 1
1547
+ },
1548
+ item.name
1549
+ ))
1550
+ }
1551
+ ),
1552
+ withTooltip && !ring && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1553
+ import_recharts5.Tooltip,
1554
+ {
1555
+ cursor: false,
1556
+ isAnimationActive: false,
1557
+ content: ({ active, payload }) => {
1558
+ const hovered = payload?.[0]?.payload;
1559
+ if (!active || !hovered) return null;
1560
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(PointerTooltip, { store: pointer, children: tooltipDataSource === "all" ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1561
+ ChartTooltip,
1562
+ {
1563
+ valueFormatter,
1564
+ items: cells.map((item) => ({
1565
+ name: item.name,
1566
+ value: item.value,
1567
+ color: item.color
1568
+ }))
1569
+ }
1570
+ ) : /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1571
+ ChartSliceTooltip,
1572
+ {
1573
+ name: hovered.name,
1574
+ value: hovered.value,
1575
+ color: hovered.color,
1576
+ percent: getPercent(hovered.value, cells),
1577
+ valueFormatter
1578
+ }
1579
+ ) });
1580
+ },
1581
+ ...tooltipProps
1582
+ }
1583
+ ),
1584
+ children
1585
+ ] }) }),
1586
+ center !== void 0 && center !== null && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "wello-donut-label", children: center })
1587
+ ]
1588
+ }
1589
+ ),
1590
+ legendPosition === "bottom" && legend
1591
+ ] })
1592
+ }
1593
+ );
1594
+ }
1595
+
1596
+ // src/charts/pie-chart.tsx
1597
+ var import_jsx_runtime10 = require("react/jsx-runtime");
1598
+ function PieChart({ labelsPosition = "outside", ...props }) {
1599
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
1600
+ PieBase,
1601
+ {
1602
+ ...props,
1603
+ innerRadius: 0,
1604
+ labelsPosition,
1605
+ rootClassName: "wello-pie-chart"
1606
+ }
1607
+ );
1608
+ }
1609
+
1610
+ // src/charts/donut-chart.tsx
1611
+ var import_jsx_runtime11 = require("react/jsx-runtime");
1612
+ function DonutChart({
1613
+ thickness,
1614
+ chartLabel,
1615
+ chartSubLabel,
1616
+ emptyRing,
1617
+ withTooltip = true,
1618
+ ...props
1619
+ }) {
1620
+ const size = props.size ?? 160;
1621
+ const radius = size / 2;
1622
+ const ring = thickness ?? Math.round(radius * 0.26);
1623
+ const hasCenter = (chartLabel ?? null) !== null || (chartSubLabel ?? null) !== null;
1624
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
1625
+ PieBase,
1626
+ {
1627
+ ...props,
1628
+ withTooltip,
1629
+ innerRadius: Math.max(radius - ring, 0),
1630
+ labelsPosition: "outside",
1631
+ emptyRing,
1632
+ center: hasCenter ? /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "wello-donut-label-inner", children: [
1633
+ chartLabel !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("span", { className: "wello-donut-label-main", children: chartLabel }),
1634
+ chartSubLabel !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("span", { className: "wello-donut-label-sub", children: chartSubLabel })
1635
+ ] }) : void 0,
1636
+ rootClassName: "wello-donut-chart"
1637
+ }
1638
+ );
1639
+ }
1640
+
1641
+ // src/charts/radial-bar-chart.tsx
1642
+ var import_react8 = require("react");
1643
+ var import_recharts6 = require("recharts");
1644
+ var import_jsx_runtime12 = require("react/jsx-runtime");
1645
+ function RadialBarChart({
1646
+ data,
1647
+ dataKey,
1648
+ h = 300,
1649
+ w = "100%",
1650
+ colors,
1651
+ animationDuration = 650,
1652
+ barSize = 20,
1653
+ withBackground = true,
1654
+ emptyBackgroundColor,
1655
+ startAngle = 90,
1656
+ endAngle = -270,
1657
+ withLabels = false,
1658
+ withLegend = false,
1659
+ legendPosition = "bottom",
1660
+ withTooltip = true,
1661
+ tooltipProps,
1662
+ valueFormatter,
1663
+ radialBarProps,
1664
+ radialBarChartProps,
1665
+ className,
1666
+ classNames,
1667
+ style,
1668
+ children
1669
+ }) {
1670
+ const [highlighted, setHighlighted] = (0, import_react8.useState)(null);
1671
+ const chartData = (0, import_react8.useMemo)(
1672
+ () => data.map((item, index) => ({
1673
+ ...item,
1674
+ fill: seriesColor(item.color, index, colors),
1675
+ fillOpacity: highlighted !== null && highlighted !== item.name ? 0.2 : 1
1676
+ })),
1677
+ [data, colors, highlighted]
1678
+ );
1679
+ const legend = withLegend && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
1680
+ ChartLegend,
1681
+ {
1682
+ series: chartData.map((item, index) => ({
1683
+ name: String(data[index].name),
1684
+ color: item.fill
1685
+ })),
1686
+ align: "center",
1687
+ className: classNames?.legend,
1688
+ onHighlight: setHighlighted
1689
+ }
1690
+ );
1691
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
1692
+ "div",
1693
+ {
1694
+ className: cx("wello-chart", "wello-radial-bar", className, classNames?.root),
1695
+ style: { width: w, ...style },
1696
+ children: [
1697
+ legendPosition === "top" && legend,
1698
+ /* @__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)(
1699
+ import_recharts6.RadialBarChart,
1700
+ {
1701
+ data: chartData,
1702
+ barSize,
1703
+ startAngle,
1704
+ endAngle,
1705
+ innerRadius: "10%",
1706
+ outerRadius: "100%",
1707
+ ...radialBarChartProps,
1708
+ children: [
1709
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
1710
+ import_recharts6.RadialBar,
1711
+ {
1712
+ dataKey,
1713
+ background: withBackground ? { fill: getThemeColor(emptyBackgroundColor, "var(--wello-chart-radial-bg)") } : false,
1714
+ cornerRadius: barSize / 2,
1715
+ isAnimationActive: animationDuration > 0,
1716
+ animationDuration,
1717
+ animationEasing: "ease-out",
1718
+ ...radialBarProps,
1719
+ children: withLabels && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
1720
+ import_recharts6.LabelList,
1721
+ {
1722
+ position: "insideStart",
1723
+ dataKey: "name",
1724
+ fill: "#fff",
1725
+ fontSize: 12,
1726
+ fontWeight: 600
1727
+ }
1728
+ )
1729
+ }
1730
+ ),
1731
+ withTooltip && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
1732
+ import_recharts6.Tooltip,
1733
+ {
1734
+ isAnimationActive: false,
1735
+ cursor: false,
1736
+ content: ({ active, payload }) => {
1737
+ if (!active || !payload?.length) return null;
1738
+ const item = payload[0].payload;
1739
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
1740
+ ChartTooltip,
1741
+ {
1742
+ valueFormatter,
1743
+ items: [{ name: String(item.name), value: item[dataKey], color: item.fill }]
1744
+ }
1745
+ );
1746
+ },
1747
+ ...tooltipProps
1748
+ }
1749
+ ),
1750
+ children
1751
+ ]
1752
+ }
1753
+ ) }) }),
1754
+ legendPosition === "bottom" && legend
1755
+ ]
1756
+ }
1757
+ );
1758
+ }
1759
+
1760
+ // src/charts/heatmap.tsx
1761
+ var import_react9 = require("react");
1762
+ var import_jsx_runtime13 = require("react/jsx-runtime");
1763
+ var DAY = 864e5;
1764
+ var DEFAULT_COLORS = ["green-200", "green-400", "green-600", "green-800"];
1765
+ var DEFAULT_MONTHS = [
1766
+ "Jan",
1767
+ "Feb",
1768
+ "Mar",
1769
+ "Apr",
1770
+ "May",
1771
+ "Jun",
1772
+ "Jul",
1773
+ "Aug",
1774
+ "Sep",
1775
+ "Oct",
1776
+ "Nov",
1777
+ "Dec"
1778
+ ];
1779
+ var DEFAULT_WEEKDAYS = ["", "Mon", "", "Wed", "", "Fri", ""];
1780
+ function toUtcDay(value) {
1781
+ if (typeof value === "string") {
1782
+ const [y, m, d] = value.slice(0, 10).split("-").map(Number);
1783
+ return Date.UTC(y, m - 1, d);
1784
+ }
1785
+ return Date.UTC(value.getFullYear(), value.getMonth(), value.getDate());
1786
+ }
1787
+ function formatUtcDay(time) {
1788
+ return new Date(time).toISOString().slice(0, 10);
1789
+ }
1790
+ function getHeatmapColumns({
1791
+ startDate,
1792
+ endDate,
1793
+ firstDayOfWeek = 1,
1794
+ splitMonths = false,
1795
+ withOutsideDates = false
1796
+ }) {
1797
+ const columns = [];
1798
+ if (endDate < startDate) return columns;
1799
+ const row = (time) => (new Date(time).getUTCDay() - firstDayOfWeek + 7) % 7;
1800
+ const month = (time) => new Date(time).getUTCMonth();
1801
+ let column = { cells: Array(7).fill(null) };
1802
+ const push = () => {
1803
+ if (column.cells.some(Boolean)) columns.push(column);
1804
+ column = { cells: Array(7).fill(null) };
1805
+ };
1806
+ const first = withOutsideDates ? startDate - row(startDate) * DAY : startDate;
1807
+ const last = withOutsideDates ? endDate + (6 - row(endDate)) * DAY : endDate;
1808
+ let previousMonth = null;
1809
+ for (let time = first; time <= last; time += DAY) {
1810
+ const outside = time < startDate || time > endDate;
1811
+ const currentMonth = month(time);
1812
+ if (time !== first && row(time) === 0) push();
1813
+ if (splitMonths && !outside && previousMonth !== null && currentMonth !== previousMonth) {
1814
+ push();
1815
+ columns.push({ cells: Array(7).fill(null), spacer: true });
1816
+ }
1817
+ if (!outside && previousMonth !== currentMonth) {
1818
+ column.monthLabel = currentMonth;
1819
+ previousMonth = currentMonth;
1820
+ }
1821
+ column.cells[row(time)] = { date: formatUtcDay(time), outside };
1822
+ }
1823
+ push();
1824
+ let lastLabel = -Infinity;
1825
+ columns.forEach((item, index) => {
1826
+ if (item.monthLabel === void 0) return;
1827
+ if (index - lastLabel < 3) {
1828
+ const previous = columns[lastLabel];
1829
+ if (previous) delete previous.monthLabel;
1830
+ }
1831
+ lastLabel = index;
1832
+ });
1833
+ return columns;
1834
+ }
1835
+ function getHeatColorIndex(value, domain, count) {
1836
+ if (value === null || value === void 0 || !Number.isFinite(value)) return -1;
1837
+ const [min, max] = domain;
1838
+ if (max <= min) return count - 1;
1839
+ const ratio = Math.min(Math.max((value - min) / (max - min), 0), 1);
1840
+ return Math.min(count - 1, Math.floor(ratio * count));
1841
+ }
1842
+ function Heatmap({
1843
+ data,
1844
+ startDate,
1845
+ endDate,
1846
+ colors = DEFAULT_COLORS,
1847
+ domain,
1848
+ firstDayOfWeek = 1,
1849
+ rectSize = 10,
1850
+ gap = 1,
1851
+ rectRadius = 2,
1852
+ fontSize = 12,
1853
+ withMonthLabels = false,
1854
+ monthLabels = DEFAULT_MONTHS,
1855
+ monthLabelsPosition = "top",
1856
+ monthsLabelsHeight = 14,
1857
+ withWeekdayLabels = false,
1858
+ weekdayLabels = DEFAULT_WEEKDAYS,
1859
+ weekdaysLabelsWidth = 30,
1860
+ splitMonths = false,
1861
+ withOutsideDates = false,
1862
+ withTooltip = false,
1863
+ getTooltipLabel,
1864
+ getRectProps,
1865
+ withLegend = false,
1866
+ legendLabels = ["Less", "More"],
1867
+ className,
1868
+ classNames,
1869
+ style,
1870
+ "aria-label": ariaLabel = "Heatmap"
1871
+ }) {
1872
+ const [hover, setHover] = (0, import_react9.useState)(null);
1873
+ const end = endDate !== void 0 ? toUtcDay(endDate) : toUtcDay(/* @__PURE__ */ new Date());
1874
+ const start = startDate !== void 0 ? toUtcDay(startDate) : Date.UTC(
1875
+ new Date(end).getUTCFullYear() - 1,
1876
+ new Date(end).getUTCMonth(),
1877
+ new Date(end).getUTCDate() + 1
1878
+ );
1879
+ const columns = (0, import_react9.useMemo)(
1880
+ () => getHeatmapColumns({
1881
+ startDate: start,
1882
+ endDate: end,
1883
+ firstDayOfWeek,
1884
+ splitMonths,
1885
+ withOutsideDates
1886
+ }),
1887
+ [start, end, firstDayOfWeek, splitMonths, withOutsideDates]
1888
+ );
1889
+ const resolvedDomain = (0, import_react9.useMemo)(() => {
1890
+ if (domain) return domain;
1891
+ const values = Object.values(data).filter((value) => Number.isFinite(value));
1892
+ return values.length ? [Math.min(...values), Math.max(...values)] : [0, 0];
1893
+ }, [data, domain]);
1894
+ const palette = colors.map((color) => getThemeColor(color));
1895
+ const step = rectSize + gap;
1896
+ const left = withWeekdayLabels ? weekdaysLabelsWidth : 0;
1897
+ const top = withMonthLabels && monthLabelsPosition === "top" ? monthsLabelsHeight : 0;
1898
+ const gridHeight = 7 * step - gap;
1899
+ const width = left + columns.length * step - gap;
1900
+ const height = top + gridHeight + (withMonthLabels && monthLabelsPosition === "bottom" ? monthsLabelsHeight : 0);
1901
+ const tooltipEnabled = withTooltip && !!getTooltipLabel;
1902
+ const rowLabels = Array.from(
1903
+ { length: 7 },
1904
+ (_, rowIndex) => weekdayLabels[(rowIndex + firstDayOfWeek) % 7]
1905
+ );
1906
+ return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: cx("wello-chart", "wello-heatmap", className, classNames?.root), style, children: [
1907
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
1908
+ "svg",
1909
+ {
1910
+ className: classNames?.chart,
1911
+ width,
1912
+ height,
1913
+ role: "img",
1914
+ "aria-label": ariaLabel,
1915
+ onMouseLeave: () => setHover(null),
1916
+ children: [
1917
+ withWeekdayLabels && rowLabels.map(
1918
+ (label, rowIndex) => label ? /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
1919
+ "text",
1920
+ {
1921
+ className: "wello-heatmap-label",
1922
+ x: 0,
1923
+ y: top + rowIndex * step + rectSize / 2,
1924
+ dominantBaseline: "central",
1925
+ fontSize,
1926
+ children: label
1927
+ },
1928
+ rowIndex
1929
+ ) : null
1930
+ ),
1931
+ withMonthLabels && columns.map(
1932
+ (column, index) => column.monthLabel !== void 0 ? /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
1933
+ "text",
1934
+ {
1935
+ className: "wello-heatmap-label",
1936
+ x: left + index * step,
1937
+ y: monthLabelsPosition === "top" ? monthsLabelsHeight - 4 : top + gridHeight + monthsLabelsHeight - 2,
1938
+ fontSize,
1939
+ children: monthLabels[column.monthLabel]
1940
+ },
1941
+ `m-${index}`
1942
+ ) : null
1943
+ ),
1944
+ columns.map(
1945
+ (column, columnIndex) => column.cells.map((cell, rowIndex) => {
1946
+ if (!cell) return null;
1947
+ const value = cell.outside ? null : data[cell.date] ?? null;
1948
+ const rect = { date: cell.date, value };
1949
+ const colorIndex = getHeatColorIndex(value, resolvedDomain, palette.length);
1950
+ return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
1951
+ "rect",
1952
+ {
1953
+ className: cx("wello-heatmap-rect", cell.outside && "wello-heatmap-rect--outside"),
1954
+ x: left + columnIndex * step,
1955
+ y: top + rowIndex * step,
1956
+ width: rectSize,
1957
+ height: rectSize,
1958
+ rx: rectRadius,
1959
+ fill: colorIndex === -1 ? "var(--wello-chart-heatmap-empty)" : palette[colorIndex],
1960
+ "data-date": cell.date,
1961
+ "data-value": value ?? void 0,
1962
+ onMouseEnter: tooltipEnabled && !cell.outside ? (event) => {
1963
+ const own = event.currentTarget.getBoundingClientRect();
1964
+ setHover({
1965
+ rect,
1966
+ x: own.left + own.width / 2,
1967
+ y: own.top,
1968
+ size: own.height,
1969
+ source: event.currentTarget.ownerSVGElement.parentElement
1970
+ });
1971
+ } : void 0,
1972
+ ...getRectProps?.(rect)
1973
+ },
1974
+ cell.date
1975
+ );
1976
+ })
1977
+ )
1978
+ ]
1979
+ }
1980
+ ),
1981
+ tooltipEnabled && hover && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
1982
+ FloatingTooltip,
1983
+ {
1984
+ clientX: hover.x,
1985
+ clientY: hover.y,
1986
+ side: "top",
1987
+ gap: 6,
1988
+ anchorHeight: hover.size,
1989
+ themeSource: hover.source,
1990
+ children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { className: "wello-tooltip wello-heatmap-tooltip", children: getTooltipLabel(hover.rect) })
1991
+ }
1992
+ ),
1993
+ withLegend && /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
1994
+ "div",
1995
+ {
1996
+ className: cx("wello-heatmap-legend", classNames?.legend),
1997
+ style: { paddingInlineStart: left, fontSize },
1998
+ children: [
1999
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { children: legendLabels[0] }),
2000
+ palette.map((color) => /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
2001
+ "span",
2002
+ {
2003
+ className: "wello-heatmap-legend-rect",
2004
+ style: {
2005
+ width: rectSize,
2006
+ height: rectSize,
2007
+ borderRadius: rectRadius,
2008
+ background: color
2009
+ }
2010
+ },
2011
+ color
2012
+ )),
2013
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { children: legendLabels[1] })
2014
+ ]
2015
+ }
2016
+ )
2017
+ ] });
2018
+ }
2019
+ // Annotate the CommonJS export names for ESM import in node:
2020
+ 0 && (module.exports = {
2021
+ AreaChart,
2022
+ BarChart,
2023
+ CHART_COLORS,
2024
+ ChartLegend,
2025
+ ChartSliceTooltip,
2026
+ ChartTooltip,
2027
+ DEFAULT_CHART_COLORS,
2028
+ DonutChart,
2029
+ Heatmap,
2030
+ LineChart,
2031
+ PieChart,
2032
+ RadialBarChart,
2033
+ formatUtcDay,
2034
+ getHeatColorIndex,
2035
+ getHeatmapColumns,
2036
+ getPercent,
2037
+ getSplitOffset,
2038
+ getThemeColor,
2039
+ getWaterfallData,
2040
+ seriesColor,
2041
+ toUtcDay
2042
+ });
2043
+ //# sourceMappingURL=index.cjs.map