@classic-homes/charts-react 0.1.37 → 0.1.38
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 +328 -252
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +339 -255
- package/package.json +11 -6
package/dist/index.cjs
CHANGED
|
@@ -135,10 +135,11 @@ var ChartError = React2.forwardRef(
|
|
|
135
135
|
)
|
|
136
136
|
}
|
|
137
137
|
),
|
|
138
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "mb-2 text-sm font-medium text-
|
|
138
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "mb-2 text-sm font-medium text-foreground", children: message }),
|
|
139
139
|
onRetry && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
140
140
|
"button",
|
|
141
141
|
{
|
|
142
|
+
type: "button",
|
|
142
143
|
onClick: onRetry,
|
|
143
144
|
className: "rounded-md bg-destructive px-3 py-1.5 text-xs font-medium text-destructive-foreground transition-colors hover:bg-destructive/90",
|
|
144
145
|
children: "Retry"
|
|
@@ -214,6 +215,7 @@ var ChartContainer = React4.forwardRef(
|
|
|
214
215
|
...props
|
|
215
216
|
}, ref) => {
|
|
216
217
|
const heightStyle = typeof height === "number" ? `${height}px` : height;
|
|
218
|
+
const descriptionId = `${React4.useId()}-desc`;
|
|
217
219
|
if (loading) {
|
|
218
220
|
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ChartSkeleton, { height, className: wrapperClassName });
|
|
219
221
|
}
|
|
@@ -237,12 +239,12 @@ var ChartContainer = React4.forwardRef(
|
|
|
237
239
|
ref,
|
|
238
240
|
role: "img",
|
|
239
241
|
"aria-label": title,
|
|
240
|
-
"aria-describedby": description ?
|
|
242
|
+
"aria-describedby": description ? descriptionId : void 0,
|
|
241
243
|
"data-testid": "chart-container",
|
|
242
244
|
className: cn("rounded-lg border border-border bg-card", wrapperClassName),
|
|
243
245
|
...props,
|
|
244
246
|
children: [
|
|
245
|
-
description && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { id:
|
|
247
|
+
description && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { id: descriptionId, className: "sr-only", children: description }),
|
|
246
248
|
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: cn("h-full w-full", className), style: { height: heightStyle }, children })
|
|
247
249
|
]
|
|
248
250
|
}
|
|
@@ -257,11 +259,12 @@ var echarts3 = __toESM(require("echarts/core"), 1);
|
|
|
257
259
|
var import_charts = require("echarts/charts");
|
|
258
260
|
var import_components = require("echarts/components");
|
|
259
261
|
var import_renderers = require("echarts/renderers");
|
|
260
|
-
var
|
|
262
|
+
var import_charts_core3 = require("@classic-homes/charts-core");
|
|
261
263
|
|
|
262
264
|
// src/hooks/useChart.ts
|
|
263
265
|
var import_react4 = require("react");
|
|
264
266
|
var echarts2 = __toESM(require("echarts/core"), 1);
|
|
267
|
+
var import_charts_core2 = require("@classic-homes/charts-core");
|
|
265
268
|
|
|
266
269
|
// src/hooks/useChartTheme.ts
|
|
267
270
|
var import_react = require("react");
|
|
@@ -274,18 +277,18 @@ function registerClassicThemes() {
|
|
|
274
277
|
echarts.registerTheme(import_charts_core.THEME_DARK, import_charts_core.darkTheme);
|
|
275
278
|
themesRegistered = true;
|
|
276
279
|
}
|
|
280
|
+
function resolveTheme(preference) {
|
|
281
|
+
if (preference !== "auto") {
|
|
282
|
+
return preference === "dark" ? import_charts_core.THEME_DARK : import_charts_core.THEME_LIGHT;
|
|
283
|
+
}
|
|
284
|
+
if (typeof document === "undefined") return import_charts_core.THEME_LIGHT;
|
|
285
|
+
return document.documentElement.classList.contains("dark") ? import_charts_core.THEME_DARK : import_charts_core.THEME_LIGHT;
|
|
286
|
+
}
|
|
277
287
|
function useChartTheme(preference = "auto") {
|
|
278
|
-
const [currentTheme, setCurrentTheme] = (0, import_react.useState)(
|
|
279
|
-
const updateTheme = (0, import_react.useCallback)(() => {
|
|
280
|
-
if (preference !== "auto") {
|
|
281
|
-
setCurrentTheme(preference === "dark" ? import_charts_core.THEME_DARK : import_charts_core.THEME_LIGHT);
|
|
282
|
-
return;
|
|
283
|
-
}
|
|
284
|
-
const isDark = document.documentElement.classList.contains("dark");
|
|
285
|
-
setCurrentTheme(isDark ? import_charts_core.THEME_DARK : import_charts_core.THEME_LIGHT);
|
|
286
|
-
}, [preference]);
|
|
288
|
+
const [currentTheme, setCurrentTheme] = (0, import_react.useState)(() => resolveTheme(preference));
|
|
287
289
|
(0, import_react.useEffect)(() => {
|
|
288
290
|
registerClassicThemes();
|
|
291
|
+
const updateTheme = () => setCurrentTheme(resolveTheme(preference));
|
|
289
292
|
updateTheme();
|
|
290
293
|
if (preference !== "auto") return;
|
|
291
294
|
const observer = new MutationObserver((mutations) => {
|
|
@@ -299,26 +302,29 @@ function useChartTheme(preference = "auto") {
|
|
|
299
302
|
attributes: true,
|
|
300
303
|
attributeFilter: ["class"]
|
|
301
304
|
});
|
|
302
|
-
const mediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
|
|
303
|
-
const handleMediaChange = () => updateTheme();
|
|
304
|
-
mediaQuery.addEventListener("change", handleMediaChange);
|
|
305
305
|
return () => {
|
|
306
306
|
observer.disconnect();
|
|
307
|
-
mediaQuery.removeEventListener("change", handleMediaChange);
|
|
308
307
|
};
|
|
309
|
-
}, [preference
|
|
308
|
+
}, [preference]);
|
|
310
309
|
return currentTheme;
|
|
311
310
|
}
|
|
312
311
|
|
|
313
312
|
// src/hooks/useChartResize.ts
|
|
314
313
|
var import_react2 = require("react");
|
|
314
|
+
var useIsomorphicLayoutEffect = typeof window === "undefined" ? import_react2.useEffect : import_react2.useLayoutEffect;
|
|
315
|
+
function useRefElement(ref) {
|
|
316
|
+
const [element, setElement] = (0, import_react2.useState)(null);
|
|
317
|
+
useIsomorphicLayoutEffect(() => {
|
|
318
|
+
setElement(ref.current);
|
|
319
|
+
});
|
|
320
|
+
return element;
|
|
321
|
+
}
|
|
315
322
|
function useChartResize(chartRef, containerRef) {
|
|
316
|
-
const
|
|
323
|
+
const container = useRefElement(containerRef);
|
|
317
324
|
(0, import_react2.useEffect)(() => {
|
|
318
|
-
const container = containerRef.current;
|
|
319
325
|
if (!container) return;
|
|
320
326
|
let resizeTimeout;
|
|
321
|
-
|
|
327
|
+
const observer = new ResizeObserver(() => {
|
|
322
328
|
clearTimeout(resizeTimeout);
|
|
323
329
|
resizeTimeout = setTimeout(() => {
|
|
324
330
|
const chart = chartRef.current;
|
|
@@ -327,12 +333,12 @@ function useChartResize(chartRef, containerRef) {
|
|
|
327
333
|
}
|
|
328
334
|
}, 100);
|
|
329
335
|
});
|
|
330
|
-
|
|
336
|
+
observer.observe(container);
|
|
331
337
|
return () => {
|
|
332
338
|
clearTimeout(resizeTimeout);
|
|
333
|
-
|
|
339
|
+
observer.disconnect();
|
|
334
340
|
};
|
|
335
|
-
}, [chartRef,
|
|
341
|
+
}, [chartRef, container]);
|
|
336
342
|
}
|
|
337
343
|
|
|
338
344
|
// src/hooks/useReducedMotion.ts
|
|
@@ -354,7 +360,13 @@ function useReducedMotion() {
|
|
|
354
360
|
}
|
|
355
361
|
|
|
356
362
|
// src/hooks/useChart.ts
|
|
357
|
-
var
|
|
363
|
+
var isComponentType = (mainType) => echarts2.ComponentModel.hasClass(mainType);
|
|
364
|
+
function applyOption(chart, prev, next) {
|
|
365
|
+
chart.setOption(next, {
|
|
366
|
+
replaceMerge: (0, import_charts_core2.getReplaceMerge)(prev, next, isComponentType),
|
|
367
|
+
lazyUpdate: true
|
|
368
|
+
});
|
|
369
|
+
}
|
|
358
370
|
function useChart({
|
|
359
371
|
option,
|
|
360
372
|
theme = "auto",
|
|
@@ -362,6 +374,7 @@ function useChart({
|
|
|
362
374
|
onReady
|
|
363
375
|
}) {
|
|
364
376
|
const containerRef = (0, import_react4.useRef)(null);
|
|
377
|
+
const container = useRefElement(containerRef);
|
|
365
378
|
const chartRef = (0, import_react4.useRef)(null);
|
|
366
379
|
const currentTheme = useChartTheme(theme);
|
|
367
380
|
const reducedMotion = useReducedMotion();
|
|
@@ -370,13 +383,16 @@ function useChart({
|
|
|
370
383
|
const optionRef = (0, import_react4.useRef)(option);
|
|
371
384
|
optionRef.current = {
|
|
372
385
|
...option,
|
|
373
|
-
|
|
386
|
+
// Reduced motion always wins over the animation prop
|
|
387
|
+
animation: (animation ?? true) && !reducedMotion
|
|
374
388
|
};
|
|
389
|
+
const appliedRef = (0, import_react4.useRef)(null);
|
|
375
390
|
(0, import_react4.useEffect)(() => {
|
|
376
|
-
if (!
|
|
377
|
-
const chart = echarts2.init(
|
|
391
|
+
if (!container) return;
|
|
392
|
+
const chart = echarts2.init(container, currentTheme);
|
|
378
393
|
chartRef.current = chart;
|
|
379
|
-
chart
|
|
394
|
+
applyOption(chart, null, optionRef.current);
|
|
395
|
+
appliedRef.current = optionRef.current;
|
|
380
396
|
onReadyRef.current?.(chart);
|
|
381
397
|
return () => {
|
|
382
398
|
chart.dispose();
|
|
@@ -384,11 +400,12 @@ function useChart({
|
|
|
384
400
|
chartRef.current = null;
|
|
385
401
|
}
|
|
386
402
|
};
|
|
387
|
-
}, [currentTheme]);
|
|
403
|
+
}, [container, currentTheme]);
|
|
388
404
|
(0, import_react4.useEffect)(() => {
|
|
389
405
|
const chart = chartRef.current;
|
|
390
406
|
if (!chart || chart.isDisposed()) return;
|
|
391
|
-
chart.
|
|
407
|
+
applyOption(chart, appliedRef.current, optionRef.current);
|
|
408
|
+
appliedRef.current = optionRef.current;
|
|
392
409
|
}, [option, animation, reducedMotion]);
|
|
393
410
|
useChartResize(chartRef, containerRef);
|
|
394
411
|
return {
|
|
@@ -398,6 +415,14 @@ function useChart({
|
|
|
398
415
|
};
|
|
399
416
|
}
|
|
400
417
|
|
|
418
|
+
// src/hooks/useLatestRef.ts
|
|
419
|
+
var import_react5 = require("react");
|
|
420
|
+
function useLatestRef(value) {
|
|
421
|
+
const ref = (0, import_react5.useRef)(value);
|
|
422
|
+
ref.current = value;
|
|
423
|
+
return ref;
|
|
424
|
+
}
|
|
425
|
+
|
|
401
426
|
// src/components/core/LineChart.tsx
|
|
402
427
|
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
403
428
|
echarts3.use([
|
|
@@ -432,6 +457,8 @@ var LineChart = React5.forwardRef(
|
|
|
432
457
|
...props
|
|
433
458
|
}, ref) => {
|
|
434
459
|
const isEmpty = !data?.categories?.length || !data?.series?.length || data.series.every((s) => !s.data?.length);
|
|
460
|
+
const currentTheme = useChartTheme(theme);
|
|
461
|
+
const chartColors = (0, import_charts_core3.getChartColors)(currentTheme);
|
|
435
462
|
const option = React5.useMemo(() => {
|
|
436
463
|
if (isEmpty) return {};
|
|
437
464
|
return {
|
|
@@ -446,7 +473,7 @@ var LineChart = React5.forwardRef(
|
|
|
446
473
|
axisPointer: {
|
|
447
474
|
type: "cross",
|
|
448
475
|
label: {
|
|
449
|
-
backgroundColor:
|
|
476
|
+
backgroundColor: chartColors.axisPointerLabel
|
|
450
477
|
}
|
|
451
478
|
}
|
|
452
479
|
} : void 0,
|
|
@@ -492,44 +519,46 @@ var LineChart = React5.forwardRef(
|
|
|
492
519
|
smooth,
|
|
493
520
|
areaFilled,
|
|
494
521
|
showDataPoints,
|
|
495
|
-
stacked
|
|
522
|
+
stacked,
|
|
523
|
+
chartColors
|
|
496
524
|
]);
|
|
525
|
+
const latest = useLatestRef({ onClick, onHover });
|
|
497
526
|
const { containerRef } = useChart({
|
|
498
527
|
option,
|
|
499
|
-
theme,
|
|
528
|
+
theme: currentTheme === import_charts_core3.THEME_DARK ? "dark" : "light",
|
|
500
529
|
animation,
|
|
501
530
|
onReady: (chart) => {
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
531
|
+
chart.on("click", (params) => {
|
|
532
|
+
const { onClick: onClick2 } = latest.current;
|
|
533
|
+
if (!onClick2) return;
|
|
534
|
+
onClick2({
|
|
535
|
+
type: params.type || "click",
|
|
536
|
+
componentType: params.componentType || "series",
|
|
537
|
+
seriesIndex: params.seriesIndex,
|
|
538
|
+
seriesName: params.seriesName || "",
|
|
539
|
+
dataIndex: params.dataIndex || 0,
|
|
540
|
+
name: params.name || "",
|
|
541
|
+
value: params.value,
|
|
542
|
+
color: params.color
|
|
514
543
|
});
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
544
|
+
});
|
|
545
|
+
chart.on("mouseover", (params) => {
|
|
546
|
+
const { onHover: onHover2 } = latest.current;
|
|
547
|
+
if (!onHover2) return;
|
|
548
|
+
onHover2({
|
|
549
|
+
type: params.type || "mouseover",
|
|
550
|
+
componentType: params.componentType || "series",
|
|
551
|
+
seriesIndex: params.seriesIndex,
|
|
552
|
+
seriesName: params.seriesName || "",
|
|
553
|
+
dataIndex: params.dataIndex || 0,
|
|
554
|
+
name: params.name || "",
|
|
555
|
+
value: params.value,
|
|
556
|
+
color: params.color
|
|
528
557
|
});
|
|
529
|
-
}
|
|
558
|
+
});
|
|
530
559
|
}
|
|
531
560
|
});
|
|
532
|
-
const accessibilityDescription = description || (!isEmpty ? (0,
|
|
561
|
+
const accessibilityDescription = description || (!isEmpty ? (0, import_charts_core3.generateLineChartDescription)(title, data) : void 0);
|
|
533
562
|
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
534
563
|
ChartContainer,
|
|
535
564
|
{
|
|
@@ -556,7 +585,7 @@ var echarts4 = __toESM(require("echarts/core"), 1);
|
|
|
556
585
|
var import_charts2 = require("echarts/charts");
|
|
557
586
|
var import_components2 = require("echarts/components");
|
|
558
587
|
var import_renderers2 = require("echarts/renderers");
|
|
559
|
-
var
|
|
588
|
+
var import_charts_core4 = require("@classic-homes/charts-core");
|
|
560
589
|
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
561
590
|
echarts4.use([
|
|
562
591
|
import_charts2.BarChart,
|
|
@@ -639,28 +668,29 @@ var BarChart = React6.forwardRef(
|
|
|
639
668
|
}))
|
|
640
669
|
};
|
|
641
670
|
}, [data, isEmpty, showTooltip, showLegend, showGrid, isHorizontal, stacked, showValues]);
|
|
671
|
+
const latest = useLatestRef({ onClick });
|
|
642
672
|
const { containerRef } = useChart({
|
|
643
673
|
option,
|
|
644
674
|
theme,
|
|
645
675
|
animation,
|
|
646
676
|
onReady: (chart) => {
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
677
|
+
chart.on("click", (params) => {
|
|
678
|
+
const { onClick: onClick2 } = latest.current;
|
|
679
|
+
if (!onClick2) return;
|
|
680
|
+
onClick2({
|
|
681
|
+
type: params.type || "click",
|
|
682
|
+
componentType: params.componentType || "series",
|
|
683
|
+
seriesIndex: params.seriesIndex,
|
|
684
|
+
seriesName: params.seriesName || "",
|
|
685
|
+
dataIndex: params.dataIndex || 0,
|
|
686
|
+
name: params.name || "",
|
|
687
|
+
value: params.value,
|
|
688
|
+
color: params.color
|
|
659
689
|
});
|
|
660
|
-
}
|
|
690
|
+
});
|
|
661
691
|
}
|
|
662
692
|
});
|
|
663
|
-
const accessibilityDescription = description || (!isEmpty ? (0,
|
|
693
|
+
const accessibilityDescription = description || (!isEmpty ? (0, import_charts_core4.generateBarChartDescription)(title, data) : void 0);
|
|
664
694
|
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
665
695
|
ChartContainer,
|
|
666
696
|
{
|
|
@@ -687,7 +717,7 @@ var echarts5 = __toESM(require("echarts/core"), 1);
|
|
|
687
717
|
var import_charts3 = require("echarts/charts");
|
|
688
718
|
var import_components3 = require("echarts/components");
|
|
689
719
|
var import_renderers3 = require("echarts/renderers");
|
|
690
|
-
var
|
|
720
|
+
var import_charts_core5 = require("@classic-homes/charts-core");
|
|
691
721
|
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
692
722
|
echarts5.use([import_charts3.PieChart, import_components3.TooltipComponent, import_components3.LegendComponent, import_components3.TitleComponent, import_renderers3.CanvasRenderer]);
|
|
693
723
|
var PieChart = React7.forwardRef(
|
|
@@ -727,7 +757,7 @@ var PieChart = React7.forwardRef(
|
|
|
727
757
|
{
|
|
728
758
|
name: title,
|
|
729
759
|
type: "pie",
|
|
730
|
-
radius: innerRadius
|
|
760
|
+
radius: innerRadius ? [innerRadius, "70%"] : "70%",
|
|
731
761
|
center: ["50%", "45%"],
|
|
732
762
|
data: data.map((item) => ({
|
|
733
763
|
name: item.name,
|
|
@@ -752,26 +782,27 @@ var PieChart = React7.forwardRef(
|
|
|
752
782
|
]
|
|
753
783
|
};
|
|
754
784
|
}, [data, isEmpty, showTooltip, showLegend, showLabels, labelPosition, innerRadius, title]);
|
|
785
|
+
const latest = useLatestRef({ onClick });
|
|
755
786
|
const { containerRef } = useChart({
|
|
756
787
|
option,
|
|
757
788
|
theme,
|
|
758
789
|
animation,
|
|
759
790
|
onReady: (chart) => {
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
791
|
+
chart.on("click", (params) => {
|
|
792
|
+
const { onClick: onClick2 } = latest.current;
|
|
793
|
+
if (!onClick2) return;
|
|
794
|
+
onClick2({
|
|
795
|
+
type: params.type || "click",
|
|
796
|
+
componentType: params.componentType || "series",
|
|
797
|
+
name: params.name || "",
|
|
798
|
+
value: params.value,
|
|
799
|
+
percent: params.percent,
|
|
800
|
+
color: params.color
|
|
770
801
|
});
|
|
771
|
-
}
|
|
802
|
+
});
|
|
772
803
|
}
|
|
773
804
|
});
|
|
774
|
-
const accessibilityDescription = description || (!isEmpty ? (0,
|
|
805
|
+
const accessibilityDescription = description || (!isEmpty ? (0, import_charts_core5.generatePieChartDescription)(title, data, false) : void 0);
|
|
775
806
|
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
776
807
|
ChartContainer,
|
|
777
808
|
{
|
|
@@ -798,6 +829,7 @@ var echarts6 = __toESM(require("echarts/core"), 1);
|
|
|
798
829
|
var import_charts4 = require("echarts/charts");
|
|
799
830
|
var import_components4 = require("echarts/components");
|
|
800
831
|
var import_renderers4 = require("echarts/renderers");
|
|
832
|
+
var import_charts_core6 = require("@classic-homes/charts-core");
|
|
801
833
|
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
802
834
|
echarts6.use([
|
|
803
835
|
import_charts4.LineChart,
|
|
@@ -829,6 +861,8 @@ var AreaChart = React8.forwardRef(
|
|
|
829
861
|
...props
|
|
830
862
|
}, ref) => {
|
|
831
863
|
const isEmpty = !data?.categories?.length || !data?.series?.length || data.series.every((s) => !s.data?.length);
|
|
864
|
+
const currentTheme = useChartTheme(theme);
|
|
865
|
+
const chartColors = (0, import_charts_core6.getChartColors)(currentTheme);
|
|
832
866
|
const option = React8.useMemo(() => {
|
|
833
867
|
if (isEmpty) return {};
|
|
834
868
|
return {
|
|
@@ -843,7 +877,7 @@ var AreaChart = React8.forwardRef(
|
|
|
843
877
|
axisPointer: {
|
|
844
878
|
type: "cross",
|
|
845
879
|
label: {
|
|
846
|
-
backgroundColor:
|
|
880
|
+
backgroundColor: chartColors.axisPointerLabel
|
|
847
881
|
}
|
|
848
882
|
}
|
|
849
883
|
} : void 0,
|
|
@@ -862,52 +896,50 @@ var AreaChart = React8.forwardRef(
|
|
|
862
896
|
show: showGrid
|
|
863
897
|
}
|
|
864
898
|
},
|
|
865
|
-
series: data.series.map((series, index) =>
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
},
|
|
888
|
-
showSymbol: false
|
|
889
|
-
}))
|
|
899
|
+
series: data.series.map((series, index) => {
|
|
900
|
+
const base = series.color || chartColors.series[index % chartColors.series.length];
|
|
901
|
+
return {
|
|
902
|
+
name: series.name,
|
|
903
|
+
type: "line",
|
|
904
|
+
data: series.data,
|
|
905
|
+
smooth,
|
|
906
|
+
stack: stacked ? "Total" : void 0,
|
|
907
|
+
areaStyle: gradient ? {
|
|
908
|
+
opacity: 0.8,
|
|
909
|
+
color: new echarts6.graphic.LinearGradient(0, 0, 0, 1, [
|
|
910
|
+
{ offset: 0, color: (0, import_charts_core6.colorWithAlpha)(base, 0.8) },
|
|
911
|
+
{ offset: 1, color: (0, import_charts_core6.colorWithAlpha)(base, 0.1) }
|
|
912
|
+
])
|
|
913
|
+
} : { opacity: 0.5 },
|
|
914
|
+
itemStyle: series.color ? { color: series.color } : void 0,
|
|
915
|
+
emphasis: {
|
|
916
|
+
focus: "series"
|
|
917
|
+
},
|
|
918
|
+
showSymbol: false
|
|
919
|
+
};
|
|
920
|
+
})
|
|
890
921
|
};
|
|
891
|
-
}, [data, isEmpty, showTooltip, showLegend, showGrid, smooth, stacked, gradient]);
|
|
922
|
+
}, [data, isEmpty, showTooltip, showLegend, showGrid, smooth, stacked, gradient, chartColors]);
|
|
923
|
+
const latest = useLatestRef({ onClick });
|
|
892
924
|
const { containerRef } = useChart({
|
|
893
925
|
option,
|
|
894
|
-
theme,
|
|
926
|
+
theme: currentTheme === import_charts_core6.THEME_DARK ? "dark" : "light",
|
|
895
927
|
animation,
|
|
896
928
|
onReady: (chart) => {
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
929
|
+
chart.on("click", (params) => {
|
|
930
|
+
const { onClick: onClick2 } = latest.current;
|
|
931
|
+
if (!onClick2) return;
|
|
932
|
+
onClick2({
|
|
933
|
+
type: params.type || "click",
|
|
934
|
+
componentType: params.componentType || "series",
|
|
935
|
+
seriesIndex: params.seriesIndex,
|
|
936
|
+
seriesName: params.seriesName || "",
|
|
937
|
+
dataIndex: params.dataIndex || 0,
|
|
938
|
+
name: params.name || "",
|
|
939
|
+
value: params.value,
|
|
940
|
+
color: params.color
|
|
909
941
|
});
|
|
910
|
-
}
|
|
942
|
+
});
|
|
911
943
|
}
|
|
912
944
|
});
|
|
913
945
|
const accessibilityDescription = description || (!isEmpty ? `${title}. Area chart with ${data.categories.length} data points across ${data.series.length} series.` : void 0);
|
|
@@ -937,10 +969,12 @@ var echarts7 = __toESM(require("echarts/core"), 1);
|
|
|
937
969
|
var import_charts5 = require("echarts/charts");
|
|
938
970
|
var import_components5 = require("echarts/components");
|
|
939
971
|
var import_renderers5 = require("echarts/renderers");
|
|
940
|
-
var
|
|
972
|
+
var import_charts_core7 = require("@classic-homes/charts-core");
|
|
941
973
|
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
942
974
|
echarts7.use([
|
|
943
975
|
import_charts5.ScatterChart,
|
|
976
|
+
// Trend lines are line series
|
|
977
|
+
import_charts5.LineChart,
|
|
944
978
|
import_components5.GridComponent,
|
|
945
979
|
import_components5.TooltipComponent,
|
|
946
980
|
import_components5.LegendComponent,
|
|
@@ -997,9 +1031,12 @@ var ScatterChart = React9.forwardRef(
|
|
|
997
1031
|
});
|
|
998
1032
|
const slope = (n * sumXY - sumX * sumY) / (n * sumX2 - sumX * sumX);
|
|
999
1033
|
const intercept = (sumY - slope * sumX) / n;
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
const
|
|
1034
|
+
let minX = Infinity;
|
|
1035
|
+
let maxX = -Infinity;
|
|
1036
|
+
for (const [x] of s.data) {
|
|
1037
|
+
if (x < minX) minX = x;
|
|
1038
|
+
if (x > maxX) maxX = x;
|
|
1039
|
+
}
|
|
1003
1040
|
series.push({
|
|
1004
1041
|
name: `${s.name} Trend`,
|
|
1005
1042
|
type: "line",
|
|
@@ -1032,7 +1069,7 @@ var ScatterChart = React9.forwardRef(
|
|
|
1032
1069
|
formatter: (params) => {
|
|
1033
1070
|
const p = params;
|
|
1034
1071
|
if (!p.value) return "";
|
|
1035
|
-
return `${p.seriesName}<br/>X: ${p.value[0]}<br/>Y: ${p.value[1]}`;
|
|
1072
|
+
return `${(0, import_charts_core7.escapeHtml)(p.seriesName)}<br/>X: ${(0, import_charts_core7.escapeHtml)(p.value[0])}<br/>Y: ${(0, import_charts_core7.escapeHtml)(p.value[1])}`;
|
|
1036
1073
|
}
|
|
1037
1074
|
} : void 0,
|
|
1038
1075
|
legend: showLegend ? {
|
|
@@ -1054,28 +1091,29 @@ var ScatterChart = React9.forwardRef(
|
|
|
1054
1091
|
series
|
|
1055
1092
|
};
|
|
1056
1093
|
}, [data, isEmpty, showTooltip, showLegend, showGrid, showTrendLine, symbolSize]);
|
|
1094
|
+
const latest = useLatestRef({ onClick });
|
|
1057
1095
|
const { containerRef } = useChart({
|
|
1058
1096
|
option,
|
|
1059
1097
|
theme,
|
|
1060
1098
|
animation,
|
|
1061
1099
|
onReady: (chart) => {
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1100
|
+
chart.on("click", (params) => {
|
|
1101
|
+
const { onClick: onClick2 } = latest.current;
|
|
1102
|
+
if (!onClick2) return;
|
|
1103
|
+
onClick2({
|
|
1104
|
+
type: params.type || "click",
|
|
1105
|
+
componentType: params.componentType || "series",
|
|
1106
|
+
seriesIndex: params.seriesIndex,
|
|
1107
|
+
seriesName: params.seriesName || "",
|
|
1108
|
+
dataIndex: params.dataIndex || 0,
|
|
1109
|
+
name: params.name || "",
|
|
1110
|
+
value: params.value,
|
|
1111
|
+
color: params.color
|
|
1074
1112
|
});
|
|
1075
|
-
}
|
|
1113
|
+
});
|
|
1076
1114
|
}
|
|
1077
1115
|
});
|
|
1078
|
-
const accessibilityDescription = description || (!isEmpty ? (0,
|
|
1116
|
+
const accessibilityDescription = description || (!isEmpty ? (0, import_charts_core7.generateScatterChartDescription)(title, data) : void 0);
|
|
1079
1117
|
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
1080
1118
|
ChartContainer,
|
|
1081
1119
|
{
|
|
@@ -1102,7 +1140,7 @@ var echarts8 = __toESM(require("echarts/core"), 1);
|
|
|
1102
1140
|
var import_charts6 = require("echarts/charts");
|
|
1103
1141
|
var import_components6 = require("echarts/components");
|
|
1104
1142
|
var import_renderers6 = require("echarts/renderers");
|
|
1105
|
-
var
|
|
1143
|
+
var import_charts_core8 = require("@classic-homes/charts-core");
|
|
1106
1144
|
var import_jsx_runtime10 = require("react/jsx-runtime");
|
|
1107
1145
|
echarts8.use([import_charts6.PieChart, import_components6.TooltipComponent, import_components6.LegendComponent, import_components6.TitleComponent, import_renderers6.CanvasRenderer]);
|
|
1108
1146
|
var DonutChart = React10.forwardRef(
|
|
@@ -1128,6 +1166,8 @@ var DonutChart = React10.forwardRef(
|
|
|
1128
1166
|
...props
|
|
1129
1167
|
}, ref) => {
|
|
1130
1168
|
const isEmpty = !data?.length;
|
|
1169
|
+
const currentTheme = useChartTheme(theme);
|
|
1170
|
+
const chartColors = (0, import_charts_core8.getChartColors)(currentTheme);
|
|
1131
1171
|
const option = React10.useMemo(() => {
|
|
1132
1172
|
if (isEmpty) return {};
|
|
1133
1173
|
const graphicElements = [];
|
|
@@ -1144,7 +1184,7 @@ var DonutChart = React10.forwardRef(
|
|
|
1144
1184
|
text: String(centerValue),
|
|
1145
1185
|
fontSize: 28,
|
|
1146
1186
|
fontWeight: "bold",
|
|
1147
|
-
fill:
|
|
1187
|
+
fill: chartColors.foreground,
|
|
1148
1188
|
textAlign: "center"
|
|
1149
1189
|
},
|
|
1150
1190
|
top: 0,
|
|
@@ -1157,7 +1197,7 @@ var DonutChart = React10.forwardRef(
|
|
|
1157
1197
|
style: {
|
|
1158
1198
|
text: centerLabel,
|
|
1159
1199
|
fontSize: 14,
|
|
1160
|
-
fill:
|
|
1200
|
+
fill: chartColors.mutedForeground,
|
|
1161
1201
|
textAlign: "center"
|
|
1162
1202
|
},
|
|
1163
1203
|
top: centerValue !== void 0 ? 35 : 0,
|
|
@@ -1220,28 +1260,30 @@ var DonutChart = React10.forwardRef(
|
|
|
1220
1260
|
innerRadius,
|
|
1221
1261
|
centerLabel,
|
|
1222
1262
|
centerValue,
|
|
1223
|
-
title
|
|
1263
|
+
title,
|
|
1264
|
+
chartColors
|
|
1224
1265
|
]);
|
|
1266
|
+
const latest = useLatestRef({ onClick });
|
|
1225
1267
|
const { containerRef } = useChart({
|
|
1226
1268
|
option,
|
|
1227
|
-
theme,
|
|
1269
|
+
theme: currentTheme === import_charts_core8.THEME_DARK ? "dark" : "light",
|
|
1228
1270
|
animation,
|
|
1229
1271
|
onReady: (chart) => {
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1272
|
+
chart.on("click", (params) => {
|
|
1273
|
+
const { onClick: onClick2 } = latest.current;
|
|
1274
|
+
if (!onClick2) return;
|
|
1275
|
+
onClick2({
|
|
1276
|
+
type: params.type || "click",
|
|
1277
|
+
componentType: params.componentType || "series",
|
|
1278
|
+
name: params.name || "",
|
|
1279
|
+
value: params.value,
|
|
1280
|
+
percent: params.percent,
|
|
1281
|
+
color: params.color
|
|
1240
1282
|
});
|
|
1241
|
-
}
|
|
1283
|
+
});
|
|
1242
1284
|
}
|
|
1243
1285
|
});
|
|
1244
|
-
const accessibilityDescription = description || (!isEmpty ? (0,
|
|
1286
|
+
const accessibilityDescription = description || (!isEmpty ? (0, import_charts_core8.generatePieChartDescription)(title, data, true) : void 0);
|
|
1245
1287
|
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
1246
1288
|
ChartContainer,
|
|
1247
1289
|
{
|
|
@@ -1410,7 +1452,8 @@ var FunnelChart = React12.forwardRef(
|
|
|
1410
1452
|
bottom: 60,
|
|
1411
1453
|
width: "80%",
|
|
1412
1454
|
min: 0,
|
|
1413
|
-
|
|
1455
|
+
// reduce, not Math.max(...): spreading large arrays overflows the stack
|
|
1456
|
+
max: data.reduce((m, d) => d.value > m ? d.value : m, -Infinity),
|
|
1414
1457
|
minSize: "0%",
|
|
1415
1458
|
maxSize: "100%",
|
|
1416
1459
|
sort,
|
|
@@ -1440,22 +1483,23 @@ var FunnelChart = React12.forwardRef(
|
|
|
1440
1483
|
]
|
|
1441
1484
|
};
|
|
1442
1485
|
}, [data, isEmpty, showTooltip, showLegend, sort, orientation, showLabels, title]);
|
|
1486
|
+
const latest = useLatestRef({ onClick });
|
|
1443
1487
|
const { containerRef } = useChart({
|
|
1444
1488
|
option,
|
|
1445
1489
|
theme,
|
|
1446
1490
|
animation,
|
|
1447
1491
|
onReady: (chart) => {
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1492
|
+
chart.on("click", (params) => {
|
|
1493
|
+
const { onClick: onClick2 } = latest.current;
|
|
1494
|
+
if (!onClick2) return;
|
|
1495
|
+
onClick2({
|
|
1496
|
+
type: params.type || "click",
|
|
1497
|
+
componentType: params.componentType || "series",
|
|
1498
|
+
name: params.name || "",
|
|
1499
|
+
value: params.value,
|
|
1500
|
+
color: params.color
|
|
1457
1501
|
});
|
|
1458
|
-
}
|
|
1502
|
+
});
|
|
1459
1503
|
}
|
|
1460
1504
|
});
|
|
1461
1505
|
const accessibilityDescription = description || (!isEmpty ? `${title}. Funnel chart with ${data.length} stages.` : void 0);
|
|
@@ -1485,6 +1529,7 @@ var echarts11 = __toESM(require("echarts/core"), 1);
|
|
|
1485
1529
|
var import_charts9 = require("echarts/charts");
|
|
1486
1530
|
var import_components9 = require("echarts/components");
|
|
1487
1531
|
var import_renderers9 = require("echarts/renderers");
|
|
1532
|
+
var import_charts_core9 = require("@classic-homes/charts-core");
|
|
1488
1533
|
var import_jsx_runtime13 = require("react/jsx-runtime");
|
|
1489
1534
|
echarts11.use([import_charts9.GaugeChart, import_components9.TitleComponent, import_renderers9.CanvasRenderer]);
|
|
1490
1535
|
var GaugeChart = React13.forwardRef(
|
|
@@ -1506,6 +1551,9 @@ var GaugeChart = React13.forwardRef(
|
|
|
1506
1551
|
class: className,
|
|
1507
1552
|
...props
|
|
1508
1553
|
}, ref) => {
|
|
1554
|
+
const currentTheme = useChartTheme(theme);
|
|
1555
|
+
const chartColors = (0, import_charts_core9.getChartColors)(currentTheme);
|
|
1556
|
+
const reducedMotion = useReducedMotion();
|
|
1509
1557
|
const option = React13.useMemo(() => {
|
|
1510
1558
|
return {
|
|
1511
1559
|
series: [
|
|
@@ -1530,7 +1578,7 @@ var GaugeChart = React13.forwardRef(
|
|
|
1530
1578
|
splitNumber: 5,
|
|
1531
1579
|
lineStyle: {
|
|
1532
1580
|
width: 2,
|
|
1533
|
-
color:
|
|
1581
|
+
color: chartColors.mutedForeground
|
|
1534
1582
|
}
|
|
1535
1583
|
},
|
|
1536
1584
|
splitLine: {
|
|
@@ -1538,12 +1586,12 @@ var GaugeChart = React13.forwardRef(
|
|
|
1538
1586
|
length: 10,
|
|
1539
1587
|
lineStyle: {
|
|
1540
1588
|
width: 3,
|
|
1541
|
-
color:
|
|
1589
|
+
color: chartColors.mutedForeground
|
|
1542
1590
|
}
|
|
1543
1591
|
},
|
|
1544
1592
|
axisLabel: {
|
|
1545
1593
|
distance: -20,
|
|
1546
|
-
color:
|
|
1594
|
+
color: chartColors.mutedForeground,
|
|
1547
1595
|
fontSize: 12
|
|
1548
1596
|
},
|
|
1549
1597
|
anchor: {
|
|
@@ -1563,7 +1611,7 @@ var GaugeChart = React13.forwardRef(
|
|
|
1563
1611
|
fontSize: 14
|
|
1564
1612
|
},
|
|
1565
1613
|
detail: {
|
|
1566
|
-
valueAnimation: animation,
|
|
1614
|
+
valueAnimation: animation && !reducedMotion,
|
|
1567
1615
|
fontSize: 28,
|
|
1568
1616
|
fontWeight: "bold",
|
|
1569
1617
|
offsetCenter: [0, "40%"],
|
|
@@ -1578,10 +1626,21 @@ var GaugeChart = React13.forwardRef(
|
|
|
1578
1626
|
}
|
|
1579
1627
|
]
|
|
1580
1628
|
};
|
|
1581
|
-
}, [
|
|
1629
|
+
}, [
|
|
1630
|
+
value,
|
|
1631
|
+
min,
|
|
1632
|
+
max,
|
|
1633
|
+
splitNumber,
|
|
1634
|
+
showProgress,
|
|
1635
|
+
formatValue,
|
|
1636
|
+
title,
|
|
1637
|
+
animation,
|
|
1638
|
+
reducedMotion,
|
|
1639
|
+
chartColors
|
|
1640
|
+
]);
|
|
1582
1641
|
const { containerRef } = useChart({
|
|
1583
1642
|
option,
|
|
1584
|
-
theme,
|
|
1643
|
+
theme: currentTheme === import_charts_core9.THEME_DARK ? "dark" : "light",
|
|
1585
1644
|
animation
|
|
1586
1645
|
});
|
|
1587
1646
|
const accessibilityDescription = description || `${title}. Gauge showing value ${value} on scale from ${min} to ${max}.`;
|
|
@@ -1610,6 +1669,7 @@ var echarts12 = __toESM(require("echarts/core"), 1);
|
|
|
1610
1669
|
var import_charts10 = require("echarts/charts");
|
|
1611
1670
|
var import_components10 = require("echarts/components");
|
|
1612
1671
|
var import_renderers10 = require("echarts/renderers");
|
|
1672
|
+
var import_charts_core10 = require("@classic-homes/charts-core");
|
|
1613
1673
|
var import_jsx_runtime14 = require("react/jsx-runtime");
|
|
1614
1674
|
echarts12.use([
|
|
1615
1675
|
import_charts10.HeatmapChart,
|
|
@@ -1639,9 +1699,14 @@ var HeatmapChart = React14.forwardRef(
|
|
|
1639
1699
|
...props
|
|
1640
1700
|
}, ref) => {
|
|
1641
1701
|
const isEmpty = !data?.data?.length || !xAxis?.length || !yAxis?.length;
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
const
|
|
1702
|
+
let dataMin = Infinity;
|
|
1703
|
+
let dataMax = -Infinity;
|
|
1704
|
+
for (const [, , value] of data?.data ?? []) {
|
|
1705
|
+
if (value < dataMin) dataMin = value;
|
|
1706
|
+
if (value > dataMax) dataMax = value;
|
|
1707
|
+
}
|
|
1708
|
+
const minValue = data?.min ?? dataMin;
|
|
1709
|
+
const maxValue = data?.max ?? dataMax;
|
|
1645
1710
|
const option = React14.useMemo(() => {
|
|
1646
1711
|
if (isEmpty) return {};
|
|
1647
1712
|
return {
|
|
@@ -1651,7 +1716,7 @@ var HeatmapChart = React14.forwardRef(
|
|
|
1651
1716
|
const p = params;
|
|
1652
1717
|
if (!p.value) return "";
|
|
1653
1718
|
const [xIdx, yIdx, value] = p.value;
|
|
1654
|
-
return `${xAxis[xIdx]} / ${yAxis[yIdx]}: ${value}`;
|
|
1719
|
+
return `${(0, import_charts_core10.escapeHtml)(xAxis[xIdx])} / ${(0, import_charts_core10.escapeHtml)(yAxis[yIdx])}: ${(0, import_charts_core10.escapeHtml)(value)}`;
|
|
1655
1720
|
}
|
|
1656
1721
|
} : void 0,
|
|
1657
1722
|
grid: {
|
|
@@ -1700,25 +1765,26 @@ var HeatmapChart = React14.forwardRef(
|
|
|
1700
1765
|
]
|
|
1701
1766
|
};
|
|
1702
1767
|
}, [data, xAxis, yAxis, isEmpty, showTooltip, showValues, minValue, maxValue, title]);
|
|
1768
|
+
const latest = useLatestRef({ onClick, xAxis, yAxis });
|
|
1703
1769
|
const { containerRef } = useChart({
|
|
1704
1770
|
option,
|
|
1705
1771
|
theme,
|
|
1706
1772
|
animation,
|
|
1707
1773
|
onReady: (chart) => {
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1774
|
+
chart.on("click", (params) => {
|
|
1775
|
+
const { onClick: onClick2, xAxis: xAxis2, yAxis: yAxis2 } = latest.current;
|
|
1776
|
+
if (!onClick2) return;
|
|
1777
|
+
const [xIdx, yIdx, value] = params.value || [0, 0, 0];
|
|
1778
|
+
onClick2({
|
|
1779
|
+
type: params.type || "click",
|
|
1780
|
+
componentType: params.componentType || "series",
|
|
1781
|
+
xIndex: xIdx,
|
|
1782
|
+
yIndex: yIdx,
|
|
1783
|
+
xLabel: xAxis2[xIdx],
|
|
1784
|
+
yLabel: yAxis2[yIdx],
|
|
1785
|
+
value
|
|
1720
1786
|
});
|
|
1721
|
-
}
|
|
1787
|
+
});
|
|
1722
1788
|
}
|
|
1723
1789
|
});
|
|
1724
1790
|
const accessibilityDescription = description || (!isEmpty ? `${title}. Heatmap with ${xAxis.length} columns and ${yAxis.length} rows.` : void 0);
|
|
@@ -1748,6 +1814,7 @@ var echarts13 = __toESM(require("echarts/core"), 1);
|
|
|
1748
1814
|
var import_charts11 = require("echarts/charts");
|
|
1749
1815
|
var import_components11 = require("echarts/components");
|
|
1750
1816
|
var import_renderers11 = require("echarts/renderers");
|
|
1817
|
+
var import_charts_core11 = require("@classic-homes/charts-core");
|
|
1751
1818
|
var import_jsx_runtime15 = require("react/jsx-runtime");
|
|
1752
1819
|
echarts13.use([import_charts11.TreemapChart, import_components11.TooltipComponent, import_components11.TitleComponent, import_renderers11.CanvasRenderer]);
|
|
1753
1820
|
var TreemapChart = React15.forwardRef(
|
|
@@ -1768,13 +1835,15 @@ var TreemapChart = React15.forwardRef(
|
|
|
1768
1835
|
...props
|
|
1769
1836
|
}, ref) => {
|
|
1770
1837
|
const isEmpty = !data?.length;
|
|
1838
|
+
const currentTheme = useChartTheme(theme);
|
|
1839
|
+
const chartColors = (0, import_charts_core11.getChartColors)(currentTheme);
|
|
1771
1840
|
const option = React15.useMemo(() => {
|
|
1772
1841
|
if (isEmpty) return {};
|
|
1773
1842
|
return {
|
|
1774
1843
|
tooltip: showTooltip ? {
|
|
1775
1844
|
formatter: (params) => {
|
|
1776
1845
|
const p = params;
|
|
1777
|
-
return `${p.name}: ${p.value}`;
|
|
1846
|
+
return `${(0, import_charts_core11.escapeHtml)(p.name)}: ${(0, import_charts_core11.escapeHtml)(p.value)}`;
|
|
1778
1847
|
}
|
|
1779
1848
|
} : void 0,
|
|
1780
1849
|
series: [
|
|
@@ -1785,7 +1854,7 @@ var TreemapChart = React15.forwardRef(
|
|
|
1785
1854
|
levels: levels || [
|
|
1786
1855
|
{
|
|
1787
1856
|
itemStyle: {
|
|
1788
|
-
borderColor:
|
|
1857
|
+
borderColor: chartColors.divider,
|
|
1789
1858
|
borderWidth: 4,
|
|
1790
1859
|
gapWidth: 4
|
|
1791
1860
|
}
|
|
@@ -1823,25 +1892,26 @@ var TreemapChart = React15.forwardRef(
|
|
|
1823
1892
|
}
|
|
1824
1893
|
]
|
|
1825
1894
|
};
|
|
1826
|
-
}, [data, levels, isEmpty, showTooltip]);
|
|
1895
|
+
}, [data, levels, isEmpty, showTooltip, chartColors]);
|
|
1896
|
+
const latest = useLatestRef({ onClick });
|
|
1827
1897
|
const { containerRef } = useChart({
|
|
1828
1898
|
option,
|
|
1829
|
-
theme,
|
|
1899
|
+
theme: currentTheme === import_charts_core11.THEME_DARK ? "dark" : "light",
|
|
1830
1900
|
animation,
|
|
1831
1901
|
onReady: (chart) => {
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1902
|
+
chart.on("click", (params) => {
|
|
1903
|
+
const { onClick: onClick2 } = latest.current;
|
|
1904
|
+
if (!onClick2) return;
|
|
1905
|
+
const treePathInfo = params.treePathInfo || [];
|
|
1906
|
+
onClick2({
|
|
1907
|
+
type: params.type || "click",
|
|
1908
|
+
componentType: params.componentType || "series",
|
|
1909
|
+
name: params.name || "",
|
|
1910
|
+
value: params.value,
|
|
1911
|
+
path: treePathInfo.map((item) => item.name || ""),
|
|
1912
|
+
depth: treePathInfo.length - 1
|
|
1843
1913
|
});
|
|
1844
|
-
}
|
|
1914
|
+
});
|
|
1845
1915
|
}
|
|
1846
1916
|
});
|
|
1847
1917
|
const accessibilityDescription = description || (!isEmpty ? `${title}. Treemap chart showing hierarchical data.` : void 0);
|
|
@@ -1871,6 +1941,7 @@ var echarts14 = __toESM(require("echarts/core"), 1);
|
|
|
1871
1941
|
var import_charts12 = require("echarts/charts");
|
|
1872
1942
|
var import_components12 = require("echarts/components");
|
|
1873
1943
|
var import_renderers12 = require("echarts/renderers");
|
|
1944
|
+
var import_charts_core12 = require("@classic-homes/charts-core");
|
|
1874
1945
|
var import_jsx_runtime16 = require("react/jsx-runtime");
|
|
1875
1946
|
echarts14.use([
|
|
1876
1947
|
import_charts12.CandlestickChart,
|
|
@@ -1899,6 +1970,8 @@ var CandlestickChart = React16.forwardRef(
|
|
|
1899
1970
|
...props
|
|
1900
1971
|
}, ref) => {
|
|
1901
1972
|
const isEmpty = !data?.dates?.length || !data?.data?.length;
|
|
1973
|
+
const currentTheme = useChartTheme(theme);
|
|
1974
|
+
const chartColors = (0, import_charts_core12.getChartColors)(currentTheme);
|
|
1902
1975
|
const option = React16.useMemo(() => {
|
|
1903
1976
|
if (isEmpty) return {};
|
|
1904
1977
|
const candlestickData = data.data.map((item) => [item.open, item.close, item.low, item.high]);
|
|
@@ -1908,12 +1981,12 @@ var CandlestickChart = React16.forwardRef(
|
|
|
1908
1981
|
type: "candlestick",
|
|
1909
1982
|
data: candlestickData,
|
|
1910
1983
|
itemStyle: {
|
|
1911
|
-
color:
|
|
1984
|
+
color: chartColors.destructive,
|
|
1912
1985
|
// Up color (red for bearish in some markets)
|
|
1913
|
-
color0:
|
|
1986
|
+
color0: chartColors.success,
|
|
1914
1987
|
// Down color (green for bullish)
|
|
1915
|
-
borderColor:
|
|
1916
|
-
borderColor0:
|
|
1988
|
+
borderColor: chartColors.destructive,
|
|
1989
|
+
borderColor0: chartColors.success
|
|
1917
1990
|
}
|
|
1918
1991
|
}
|
|
1919
1992
|
];
|
|
@@ -1979,7 +2052,7 @@ var CandlestickChart = React16.forwardRef(
|
|
|
1979
2052
|
yAxisIndex: 1,
|
|
1980
2053
|
data: data.volume,
|
|
1981
2054
|
itemStyle: {
|
|
1982
|
-
color:
|
|
2055
|
+
color: chartColors.mutedForeground
|
|
1983
2056
|
}
|
|
1984
2057
|
});
|
|
1985
2058
|
}
|
|
@@ -2009,28 +2082,30 @@ var CandlestickChart = React16.forwardRef(
|
|
|
2009
2082
|
],
|
|
2010
2083
|
series: seriesArr
|
|
2011
2084
|
};
|
|
2012
|
-
}, [data, isEmpty, showTooltip, showVolume, title]);
|
|
2085
|
+
}, [data, isEmpty, showTooltip, showVolume, title, chartColors]);
|
|
2086
|
+
const latest = useLatestRef({ onClick, data });
|
|
2013
2087
|
const { containerRef } = useChart({
|
|
2014
2088
|
option,
|
|
2015
|
-
theme,
|
|
2089
|
+
theme: currentTheme === import_charts_core12.THEME_DARK ? "dark" : "light",
|
|
2016
2090
|
animation,
|
|
2017
2091
|
onReady: (chart) => {
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2092
|
+
chart.on("click", (params) => {
|
|
2093
|
+
const { onClick: onClick2, data: data2 } = latest.current;
|
|
2094
|
+
if (!onClick2) return;
|
|
2095
|
+
const dataIndex = params.dataIndex || 0;
|
|
2096
|
+
const item = data2.data[dataIndex];
|
|
2097
|
+
if (!item) return;
|
|
2098
|
+
onClick2({
|
|
2099
|
+
type: params.type || "click",
|
|
2100
|
+
componentType: params.componentType || "series",
|
|
2101
|
+
date: data2.dates[dataIndex],
|
|
2102
|
+
open: item.open,
|
|
2103
|
+
close: item.close,
|
|
2104
|
+
high: item.high,
|
|
2105
|
+
low: item.low,
|
|
2106
|
+
volume: data2.volume?.[dataIndex]
|
|
2032
2107
|
});
|
|
2033
|
-
}
|
|
2108
|
+
});
|
|
2034
2109
|
}
|
|
2035
2110
|
});
|
|
2036
2111
|
const accessibilityDescription = description || (!isEmpty ? `${title}. Candlestick chart with ${data.dates.length} data points.` : void 0);
|
|
@@ -2114,25 +2189,26 @@ var SankeyChart = React17.forwardRef(
|
|
|
2114
2189
|
]
|
|
2115
2190
|
};
|
|
2116
2191
|
}, [data, isEmpty, showTooltip, orient]);
|
|
2192
|
+
const latest = useLatestRef({ onClick });
|
|
2117
2193
|
const { containerRef } = useChart({
|
|
2118
2194
|
option,
|
|
2119
2195
|
theme,
|
|
2120
2196
|
animation,
|
|
2121
2197
|
onReady: (chart) => {
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2198
|
+
chart.on("click", (params) => {
|
|
2199
|
+
const { onClick: onClick2 } = latest.current;
|
|
2200
|
+
if (!onClick2) return;
|
|
2201
|
+
const isEdge = params.dataType === "edge";
|
|
2202
|
+
onClick2({
|
|
2203
|
+
type: params.type || "click",
|
|
2204
|
+
componentType: params.componentType || "series",
|
|
2205
|
+
dataType: isEdge ? "edge" : "node",
|
|
2206
|
+
name: params.name || "",
|
|
2207
|
+
value: isEdge ? params.value : void 0,
|
|
2208
|
+
source: isEdge ? params.data?.source : void 0,
|
|
2209
|
+
target: isEdge ? params.data?.target : void 0
|
|
2134
2210
|
});
|
|
2135
|
-
}
|
|
2211
|
+
});
|
|
2136
2212
|
}
|
|
2137
2213
|
});
|
|
2138
2214
|
const accessibilityDescription = description || (!isEmpty ? `${title}. Sankey diagram with ${data.nodes.length} nodes and ${data.links.length} links.` : void 0);
|