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