@lobehub/charts 6.0.1 → 6.1.0
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/README.md +8 -10
- package/es/AccuracyBarChart/index.d.mts +7 -5
- package/es/AccuracyBarChart/index.mjs +36 -37
- package/es/AccuracyBarChart/index.mjs.map +1 -1
- package/es/AccuracyBarChart/styles.d.mts +1 -4
- package/es/AccuracyBarChart/styles.mjs +6 -7
- package/es/AccuracyBarChart/styles.mjs.map +1 -1
- package/es/AreaChart/index.d.mts +11 -7
- package/es/AreaChart/index.mjs +100 -60
- package/es/AreaChart/index.mjs.map +1 -1
- package/es/AreaChart/styles.d.mts +1 -4
- package/es/AreaChart/styles.mjs +1 -2
- package/es/BarChart/A2uiBarChart.d.mts +56 -0
- package/es/BarChart/A2uiBarChart.mjs +368 -0
- package/es/BarChart/A2uiBarChart.mjs.map +1 -0
- package/es/BarChart/index.d.mts +10 -6
- package/es/BarChart/index.mjs +70 -33
- package/es/BarChart/index.mjs.map +1 -1
- package/es/BarChart/renderShape.d.mts +1 -4
- package/es/BarChart/renderShape.mjs +5 -6
- package/es/BarChart/renderShape.mjs.map +1 -1
- package/es/BarChart/styles.d.mts +1 -4
- package/es/BarChart/styles.mjs +1 -2
- package/es/BarList/index.d.mts +8 -6
- package/es/BarList/index.mjs +13 -14
- package/es/BarList/index.mjs.map +1 -1
- package/es/BarList/styles.d.mts +1 -4
- package/es/BarList/styles.mjs +3 -5
- package/es/BarList/styles.mjs.map +1 -1
- package/es/BenchmarkColumnChart/index.d.mts +8 -6
- package/es/BenchmarkColumnChart/index.mjs +38 -39
- package/es/BenchmarkColumnChart/index.mjs.map +1 -1
- package/es/BenchmarkColumnChart/styles.d.mts +1 -4
- package/es/BenchmarkColumnChart/styles.mjs +6 -8
- package/es/BenchmarkColumnChart/styles.mjs.map +1 -1
- package/es/BenchmarkRankingChart/index.d.mts +8 -6
- package/es/BenchmarkRankingChart/index.mjs +16 -17
- package/es/BenchmarkRankingChart/index.mjs.map +1 -1
- package/es/BenchmarkRankingChart/styles.d.mts +1 -4
- package/es/BenchmarkRankingChart/styles.mjs +25 -27
- package/es/BenchmarkRankingChart/styles.mjs.map +1 -1
- package/es/BenchmarkScatterChart/index.d.mts +7 -5
- package/es/BenchmarkScatterChart/index.mjs +22 -23
- package/es/BenchmarkScatterChart/index.mjs.map +1 -1
- package/es/BenchmarkScatterChart/styles.d.mts +1 -4
- package/es/BenchmarkScatterChart/styles.mjs +3 -2
- package/es/BenchmarkScatterChart/styles.mjs.map +1 -1
- package/es/BenchmarkScatterChart/utils.d.mts +1 -4
- package/es/BenchmarkScatterChart/utils.mjs +4 -5
- package/es/BenchmarkScatterChart/utils.mjs.map +1 -1
- package/es/CandlestickChart/index.d.mts +52 -0
- package/es/CandlestickChart/index.mjs +205 -0
- package/es/CandlestickChart/index.mjs.map +1 -0
- package/es/CandlestickChart/styles.d.mts +5 -0
- package/es/CandlestickChart/styles.mjs +24 -0
- package/es/CandlestickChart/styles.mjs.map +1 -0
- package/es/CandlestickChart/utils.d.mts +17 -0
- package/es/CandlestickChart/utils.mjs +56 -0
- package/es/CandlestickChart/utils.mjs.map +1 -0
- package/es/ChartFrame/index.d.mts +40 -0
- package/es/ChartFrame/index.mjs +18 -0
- package/es/ChartFrame/index.mjs.map +1 -0
- package/es/ComposedChart/index.d.mts +7 -5
- package/es/ComposedChart/index.mjs +37 -38
- package/es/ComposedChart/index.mjs.map +1 -1
- package/es/ComposedChart/styles.d.mts +1 -4
- package/es/ComposedChart/styles.mjs +1 -2
- package/es/ComposedChart/types.d.mts +3 -6
- package/es/DataBars/CategoryBar.d.mts +8 -6
- package/es/DataBars/CategoryBar.mjs +13 -14
- package/es/DataBars/CategoryBar.mjs.map +1 -1
- package/es/DataBars/DeltaBar.d.mts +7 -5
- package/es/DataBars/DeltaBar.mjs +10 -12
- package/es/DataBars/DeltaBar.mjs.map +1 -1
- package/es/DataBars/MarkerBar.d.mts +7 -5
- package/es/DataBars/MarkerBar.mjs +10 -12
- package/es/DataBars/MarkerBar.mjs.map +1 -1
- package/es/DataBars/ProgressBar.d.mts +7 -5
- package/es/DataBars/ProgressBar.mjs +10 -12
- package/es/DataBars/ProgressBar.mjs.map +1 -1
- package/es/DataBars/styles.d.mts +1 -4
- package/es/DataBars/styles.mjs +2 -3
- package/es/DataBars/styles.mjs.map +1 -1
- package/es/DonutChart/A2uiDonutChart.d.mts +35 -0
- package/es/DonutChart/A2uiDonutChart.mjs +189 -0
- package/es/DonutChart/A2uiDonutChart.mjs.map +1 -0
- package/es/DonutChart/DonutChartTooltip.d.mts +2 -5
- package/es/DonutChart/DonutChartTooltip.mjs +3 -4
- package/es/DonutChart/DonutChartTooltip.mjs.map +1 -1
- package/es/DonutChart/a2uiStyles.d.mts +13 -0
- package/es/DonutChart/a2uiStyles.mjs +90 -0
- package/es/DonutChart/a2uiStyles.mjs.map +1 -0
- package/es/DonutChart/index.d.mts +42 -9
- package/es/DonutChart/index.mjs +48 -16
- package/es/DonutChart/index.mjs.map +1 -1
- package/es/DonutChart/inputParser.d.mts +1 -4
- package/es/DonutChart/inputParser.mjs +1 -2
- package/es/DonutChart/inputParser.mjs.map +1 -1
- package/es/DonutChart/renderInactiveShape.d.mts +1 -4
- package/es/DonutChart/renderInactiveShape.mjs +1 -2
- package/es/DonutChart/styles.d.mts +1 -4
- package/es/DonutChart/styles.mjs +1 -2
- package/es/FunnelChart/ArrowRightIcon.d.mts +1 -4
- package/es/FunnelChart/ArrowRightIcon.mjs +1 -2
- package/es/FunnelChart/index.d.mts +7 -5
- package/es/FunnelChart/index.mjs +43 -44
- package/es/FunnelChart/index.mjs.map +1 -1
- package/es/FunnelChart/styles.d.mts +1 -4
- package/es/FunnelChart/styles.mjs +1 -2
- package/es/FunnelChart/types.d.mts +1 -4
- package/es/GaugeChart/index.d.mts +49 -0
- package/es/GaugeChart/index.mjs +77 -0
- package/es/GaugeChart/index.mjs.map +1 -0
- package/es/GaugeChart/styles.d.mts +9 -0
- package/es/GaugeChart/styles.mjs +73 -0
- package/es/GaugeChart/styles.mjs.map +1 -0
- package/es/GaugeChart/utils.d.mts +5 -0
- package/es/GaugeChart/utils.mjs +32 -0
- package/es/GaugeChart/utils.mjs.map +1 -0
- package/es/HeatmapChart/index.d.mts +68 -0
- package/es/HeatmapChart/index.mjs +162 -0
- package/es/HeatmapChart/index.mjs.map +1 -0
- package/es/HeatmapChart/styles.d.mts +4 -0
- package/es/HeatmapChart/styles.mjs +24 -0
- package/es/HeatmapChart/styles.mjs.map +1 -0
- package/es/HeatmapChart/utils.d.mts +18 -0
- package/es/HeatmapChart/utils.mjs +40 -0
- package/es/HeatmapChart/utils.mjs.map +1 -0
- package/es/Heatmaps/Calendar.d.mts +2 -5
- package/es/Heatmaps/Calendar.mjs +8 -9
- package/es/Heatmaps/Calendar.mjs.map +1 -1
- package/es/Heatmaps/ChartLabels.d.mts +2 -5
- package/es/Heatmaps/ChartLabels.mjs +3 -4
- package/es/Heatmaps/ChartLabels.mjs.map +1 -1
- package/es/Heatmaps/Footer.d.mts +1 -4
- package/es/Heatmaps/Footer.mjs +3 -4
- package/es/Heatmaps/index.d.mts +10 -8
- package/es/Heatmaps/index.mjs +10 -11
- package/es/Heatmaps/index.mjs.map +1 -1
- package/es/Heatmaps/styles.d.mts +1 -4
- package/es/Heatmaps/styles.mjs +2 -3
- package/es/Heatmaps/styles.mjs.map +1 -1
- package/es/Legend/LegendItem.d.mts +1 -4
- package/es/Legend/LegendItem.mjs +7 -8
- package/es/Legend/LegendItem.mjs.map +1 -1
- package/es/Legend/ScrollButton.d.mts +1 -4
- package/es/Legend/ScrollButton.mjs +6 -7
- package/es/Legend/ScrollButton.mjs.map +1 -1
- package/es/Legend/index.d.mts +7 -5
- package/es/Legend/index.mjs +13 -18
- package/es/Legend/index.mjs.map +1 -1
- package/es/LineChart/index.d.mts +11 -7
- package/es/LineChart/index.mjs +91 -53
- package/es/LineChart/index.mjs.map +1 -1
- package/es/LineChart/styles.d.mts +1 -4
- package/es/LineChart/styles.mjs +1 -2
- package/es/RadarChart/A2uiRadarChart.d.mts +37 -0
- package/es/RadarChart/A2uiRadarChart.mjs +203 -0
- package/es/RadarChart/A2uiRadarChart.mjs.map +1 -0
- package/es/RadarChart/index.d.mts +11 -7
- package/es/RadarChart/index.mjs +51 -18
- package/es/RadarChart/index.mjs.map +1 -1
- package/es/RadarChart/styles.d.mts +1 -4
- package/es/RadarChart/styles.mjs +1 -2
- package/es/SankeyChart/index.d.mts +73 -0
- package/es/SankeyChart/index.mjs +156 -0
- package/es/SankeyChart/index.mjs.map +1 -0
- package/es/SankeyChart/utils.d.mts +54 -0
- package/es/SankeyChart/utils.mjs +270 -0
- package/es/SankeyChart/utils.mjs.map +1 -0
- package/es/ScatterChart/A2uiScatterChart.d.mts +41 -0
- package/es/ScatterChart/A2uiScatterChart.mjs +259 -0
- package/es/ScatterChart/A2uiScatterChart.mjs.map +1 -0
- package/es/ScatterChart/ScatterChartTooltip.d.mts +2 -5
- package/es/ScatterChart/ScatterChartTooltip.mjs +7 -8
- package/es/ScatterChart/ScatterChartTooltip.mjs.map +1 -1
- package/es/ScatterChart/ScatterChartTooltipRow.d.mts +1 -4
- package/es/ScatterChart/ScatterChartTooltipRow.mjs +3 -4
- package/es/ScatterChart/ScatterChartTooltipRow.mjs.map +1 -1
- package/es/ScatterChart/index.d.mts +15 -9
- package/es/ScatterChart/index.mjs +70 -33
- package/es/ScatterChart/index.mjs.map +1 -1
- package/es/ScatterChart/renderShape.d.mts +1 -4
- package/es/ScatterChart/renderShape.mjs +4 -5
- package/es/ScatterChart/renderShape.mjs.map +1 -1
- package/es/ScatterChart/styles.d.mts +1 -4
- package/es/ScatterChart/styles.mjs +1 -2
- package/es/SparkChart/A2uiSparkChart.d.mts +41 -0
- package/es/SparkChart/A2uiSparkChart.mjs +179 -0
- package/es/SparkChart/A2uiSparkChart.mjs.map +1 -0
- package/es/SparkChart/SparkAreaChart.d.mts +12 -7
- package/es/SparkChart/SparkAreaChart.mjs +47 -22
- package/es/SparkChart/SparkAreaChart.mjs.map +1 -1
- package/es/SparkChart/SparkBarChart.d.mts +11 -6
- package/es/SparkChart/SparkBarChart.mjs +39 -16
- package/es/SparkChart/SparkBarChart.mjs.map +1 -1
- package/es/SparkChart/SparkLineChart.d.mts +12 -7
- package/es/SparkChart/SparkLineChart.mjs +41 -16
- package/es/SparkChart/SparkLineChart.mjs.map +1 -1
- package/es/SparkChart/index.d.mts +2 -1
- package/es/Tracker/TrackerBlock.d.mts +5 -5
- package/es/Tracker/TrackerBlock.mjs +8 -9
- package/es/Tracker/TrackerBlock.mjs.map +1 -1
- package/es/Tracker/index.d.mts +8 -6
- package/es/Tracker/index.mjs +11 -13
- package/es/Tracker/index.mjs.map +1 -1
- package/es/Tracker/styles.d.mts +1 -4
- package/es/Tracker/styles.mjs +1 -2
- package/es/TreemapChart/index.d.mts +64 -0
- package/es/TreemapChart/index.mjs +140 -0
- package/es/TreemapChart/index.mjs.map +1 -0
- package/es/TreemapChart/utils.d.mts +23 -0
- package/es/TreemapChart/utils.mjs +175 -0
- package/es/TreemapChart/utils.mjs.map +1 -0
- package/es/common/BaseAnimationTimingProps.d.mts +1 -4
- package/es/common/BaseChartProps.d.mts +3 -6
- package/es/common/BaseSparkChartProps.d.mts +2 -5
- package/es/common/ChartLegend.d.mts +1 -4
- package/es/common/ChartLegend.mjs +4 -5
- package/es/common/ChartLegend.mjs.map +1 -1
- package/es/common/ChartTooltip/ChartTooltipFrame.d.mts +1 -4
- package/es/common/ChartTooltip/ChartTooltipFrame.mjs +1 -2
- package/es/common/ChartTooltip/ChartTooltipFrame.mjs.map +1 -1
- package/es/common/ChartTooltip/ChartTooltipRow.d.mts +1 -4
- package/es/common/ChartTooltip/ChartTooltipRow.mjs +5 -6
- package/es/common/ChartTooltip/ChartTooltipRow.mjs.map +1 -1
- package/es/common/ChartTooltip/index.d.mts +2 -5
- package/es/common/ChartTooltip/index.mjs +3 -4
- package/es/common/ChartTooltip/index.mjs.map +1 -1
- package/es/common/CustomTooltipProps.d.mts +3 -6
- package/es/common/CustomYAxisTick.d.mts +2 -5
- package/es/common/CustomYAxisTick.mjs +1 -2
- package/es/common/CustomYAxisTick.mjs.map +1 -1
- package/es/common/NoData.d.mts +1 -4
- package/es/common/NoData.mjs +2 -3
- package/es/common/NoData.mjs.map +1 -1
- package/es/common/a2ui/A2uiTrendChart.d.mts +43 -0
- package/es/common/a2ui/A2uiTrendChart.mjs +353 -0
- package/es/common/a2ui/A2uiTrendChart.mjs.map +1 -0
- package/es/common/a2ui/Frame.d.mts +20 -0
- package/es/common/a2ui/Frame.mjs +43 -0
- package/es/common/a2ui/Frame.mjs.map +1 -0
- package/es/common/a2ui/HoverTooltip.d.mts +28 -0
- package/es/common/a2ui/HoverTooltip.mjs +36 -0
- package/es/common/a2ui/HoverTooltip.mjs.map +1 -0
- package/es/common/a2ui/Legend.d.mts +11 -0
- package/es/common/a2ui/Legend.mjs +33 -0
- package/es/common/a2ui/Legend.mjs.map +1 -0
- package/es/common/a2ui/PlacedTooltip.d.mts +22 -0
- package/es/common/a2ui/PlacedTooltip.mjs +58 -0
- package/es/common/a2ui/PlacedTooltip.mjs.map +1 -0
- package/es/common/a2ui/Tooltip.d.mts +13 -0
- package/es/common/a2ui/Tooltip.mjs +33 -0
- package/es/common/a2ui/Tooltip.mjs.map +1 -0
- package/es/common/a2ui/axis.d.mts +38 -0
- package/es/common/a2ui/axis.mjs +48 -0
- package/es/common/a2ui/axis.mjs.map +1 -0
- package/es/common/a2ui/curve.d.mts +20 -0
- package/es/common/a2ui/curve.mjs +58 -0
- package/es/common/a2ui/curve.mjs.map +1 -0
- package/es/common/a2ui/format.d.mts +17 -0
- package/es/common/a2ui/format.mjs +56 -0
- package/es/common/a2ui/format.mjs.map +1 -0
- package/es/common/a2ui/index.d.mts +16 -0
- package/es/common/a2ui/index.mjs +15 -0
- package/es/common/a2ui/scale.d.mts +20 -0
- package/es/common/a2ui/scale.mjs +112 -0
- package/es/common/a2ui/scale.mjs.map +1 -0
- package/es/common/a2ui/styles.d.mts +35 -0
- package/es/common/a2ui/styles.mjs +254 -0
- package/es/common/a2ui/styles.mjs.map +1 -0
- package/es/common/a2ui/tokens.d.mts +20 -0
- package/es/common/a2ui/tokens.mjs +103 -0
- package/es/common/a2ui/tokens.mjs.map +1 -0
- package/es/common/a2ui/types.d.mts +25 -0
- package/es/common/a2ui/types.mjs +0 -0
- package/es/common/a2ui/useA2uiTheme.d.mts +2 -0
- package/es/common/a2ui/useA2uiTheme.mjs +11 -0
- package/es/common/a2ui/useA2uiTheme.mjs.map +1 -0
- package/es/common/a2ui/useElementWidth.d.mts +2 -0
- package/es/common/a2ui/useElementWidth.mjs +31 -0
- package/es/common/a2ui/useElementWidth.mjs.map +1 -0
- package/es/common/benchmark/types.d.mts +2 -5
- package/es/common/benchmark/utils.d.mts +1 -4
- package/es/common/benchmark/utils.mjs +1 -2
- package/es/common/utils.d.mts +1 -4
- package/es/common/utils.mjs +1 -2
- package/es/hooks/useOnWindowResize.d.mts +1 -4
- package/es/hooks/useOnWindowResize.mjs +2 -3
- package/es/hooks/usePrefersReducedMotion.d.mts +1 -4
- package/es/hooks/usePrefersReducedMotion.mjs +2 -3
- package/es/hooks/useThemeColorRange.d.mts +1 -4
- package/es/hooks/useThemeColorRange.mjs +1 -2
- package/es/index.d.mts +20 -9
- package/es/index.mjs +15 -9
- package/es/types/charts.d.mts +1 -4
- package/es/types/charts.mjs +1 -2
- package/es/utils/calendar.d.mts +2 -5
- package/es/utils/calendar.mjs +2 -3
- package/es/utils/getMaxLabelLength.d.mts +1 -4
- package/es/utils/getMaxLabelLength.mjs +1 -2
- package/es/utils/getMaxLabelLength.mjs.map +1 -1
- package/es/utils/index.d.mts +1 -4
- package/es/utils/index.mjs +1 -2
- package/es/utils/index.mjs.map +1 -1
- package/es/utils/theme.d.mts +1 -4
- package/es/utils/theme.mjs +1 -2
- package/package.json +32 -8
|
@@ -1,20 +1,39 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import { CSSProperties, ComponentType } from "react";
|
|
2
|
+
import "../common/a2ui/index.mjs";
|
|
3
3
|
import BaseAnimationTimingProps from "../common/BaseAnimationTimingProps.mjs";
|
|
4
4
|
import { CustomTooltipProps } from "../common/CustomTooltipProps.mjs";
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
import { ChartNumberFormat } from "../common/a2ui/format.mjs";
|
|
6
|
+
import { NoDataProps } from "../common/NoData.mjs";
|
|
7
|
+
import { EventProps, ValueFormatter } from "../types/charts.mjs";
|
|
8
|
+
/** `a2ui` draws the A2UI look: a framed donut (or pie, with `donut={false}`) beside a value list. */
|
|
9
|
+
type DonutChartVariant = 'donut' | 'pie' | 'a2ui';
|
|
8
10
|
export interface DonutChartProps extends BaseAnimationTimingProps {
|
|
9
11
|
category?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Caption under the centre total (a2ui only).
|
|
14
|
+
* @default 'Total'
|
|
15
|
+
*/
|
|
16
|
+
centerLabel?: string;
|
|
10
17
|
className?: string;
|
|
11
18
|
colors?: string[];
|
|
19
|
+
/**
|
|
20
|
+
* ISO 4217 code used when `format` is `currency` (a2ui only).
|
|
21
|
+
* @default 'USD'
|
|
22
|
+
*/
|
|
23
|
+
currency?: string;
|
|
12
24
|
customCategories?: {
|
|
13
25
|
[key: string]: string;
|
|
14
26
|
};
|
|
15
27
|
customTooltip?: ComponentType<CustomTooltipProps>;
|
|
16
28
|
data: any[];
|
|
29
|
+
/**
|
|
30
|
+
* Draw a ring with the total in the centre; `false` draws a pie (a2ui only).
|
|
31
|
+
* @default true
|
|
32
|
+
*/
|
|
33
|
+
donut?: boolean;
|
|
17
34
|
donutLabel?: string;
|
|
35
|
+
/** How values read in the a2ui look. `percent` expects 0-100. */
|
|
36
|
+
format?: ChartNumberFormat;
|
|
18
37
|
index?: string;
|
|
19
38
|
label?: string;
|
|
20
39
|
loading?: boolean;
|
|
@@ -23,11 +42,25 @@ export interface DonutChartProps extends BaseAnimationTimingProps {
|
|
|
23
42
|
showAnimation?: boolean;
|
|
24
43
|
showLabel?: boolean;
|
|
25
44
|
showTooltip?: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Diameter of the donut in px (a2ui only).
|
|
47
|
+
* @default 200
|
|
48
|
+
*/
|
|
49
|
+
size?: number;
|
|
26
50
|
style?: CSSProperties;
|
|
51
|
+
/** Secondary line under the title (a2ui only). */
|
|
52
|
+
subtitle?: string;
|
|
53
|
+
/** Card title (a2ui only). */
|
|
54
|
+
title?: string;
|
|
55
|
+
/** Unit appended to values (a2ui only). */
|
|
56
|
+
unit?: string;
|
|
27
57
|
valueFormatter?: ValueFormatter;
|
|
28
58
|
variant?: DonutChartVariant;
|
|
29
59
|
}
|
|
30
|
-
declare const DonutChart:
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
60
|
+
declare const DonutChart: {
|
|
61
|
+
({ centerLabel, currency, donut, format, size, subtitle, title, unit, ref, ...props }: DonutChartProps & {
|
|
62
|
+
ref?: React.Ref<HTMLDivElement>;
|
|
63
|
+
}): import("react").JSX.Element;
|
|
64
|
+
displayName: string;
|
|
65
|
+
};
|
|
66
|
+
export { DonutChart as default };
|
package/es/DonutChart/index.mjs
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { Flexbox, Skeleton, css, cssVar, cx, useThemeMode } from "@lobehub/ui";
|
|
3
|
+
import { useEffect, useState } from "react";
|
|
4
|
+
import { Pie, PieChart, ResponsiveContainer, Tooltip as Tooltip$1 } from "recharts";
|
|
5
|
+
import NoData from "../common/NoData.mjs";
|
|
2
6
|
import { useThemeColorRange } from "../hooks/useThemeColorRange.mjs";
|
|
3
7
|
import { defaultValueFormatter, isOnSeverSide } from "../utils/index.mjs";
|
|
4
|
-
import
|
|
8
|
+
import A2uiDonutChart from "./A2uiDonutChart.mjs";
|
|
5
9
|
import { DonutChartTooltip } from "./DonutChartTooltip.mjs";
|
|
6
10
|
import { parseLabelInput } from "./inputParser.mjs";
|
|
7
11
|
import { renderInactiveShape } from "./renderInactiveShape.mjs";
|
|
8
12
|
import { styles } from "./styles.mjs";
|
|
9
|
-
import { Flexbox, Skeleton, css, cssVar, cx, useThemeMode } from "@lobehub/ui";
|
|
10
|
-
import { forwardRef, useEffect, useState } from "react";
|
|
11
|
-
import { Pie, PieChart, ResponsiveContainer, Tooltip as Tooltip$1 } from "recharts";
|
|
12
13
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
13
|
-
|
|
14
|
-
const
|
|
14
|
+
// src/DonutChart/index.tsx
|
|
15
|
+
const DefaultDonutChart = ({ ref, ...props }) => {
|
|
15
16
|
const themeColorRange = useThemeColorRange();
|
|
16
17
|
const { data = [], category = "value", index = "name", colors = themeColorRange, variant = "donut", valueFormatter = defaultValueFormatter, label, showLabel = true, animationDuration = 900, showAnimation = false, showTooltip = true, noDataText, onValueChange, customTooltip, className, width = "100%", loading, height = "10rem", style, customCategories, donutLabel, ...rest } = props;
|
|
17
18
|
const { isDarkMode } = useThemeMode();
|
|
@@ -96,7 +97,6 @@ const DonutChart = forwardRef((props, ref) => {
|
|
|
96
97
|
innerRadius: isDonut ? "75%" : "0%",
|
|
97
98
|
isAnimationActive: showAnimation,
|
|
98
99
|
nameKey: index,
|
|
99
|
-
onClick: onShapeClick,
|
|
100
100
|
outerRadius: "100%",
|
|
101
101
|
startAngle: 90,
|
|
102
102
|
stroke: "",
|
|
@@ -105,14 +105,14 @@ const DonutChart = forwardRef((props, ref) => {
|
|
|
105
105
|
cursor: onValueChange ? "pointer" : void 0,
|
|
106
106
|
outline: "none",
|
|
107
107
|
stroke: cssVar.colorBgContainer
|
|
108
|
-
}
|
|
108
|
+
},
|
|
109
|
+
onClick: onShapeClick
|
|
109
110
|
}),
|
|
110
111
|
isDonut && /* @__PURE__ */ jsx(Pie, {
|
|
111
112
|
activeIndex,
|
|
112
113
|
animationDuration,
|
|
113
114
|
cx: "50%",
|
|
114
115
|
cy: "50%",
|
|
115
|
-
data: parseData([{ [category]: 1 }], [isDarkMode ? "color-mix(in srgb, #000000 33%, transparent)" : "color-mix(in srgb, #000000 10%, transparent)"]),
|
|
116
116
|
dataKey: category,
|
|
117
117
|
endAngle: -270,
|
|
118
118
|
inactiveShape: renderInactiveShape,
|
|
@@ -123,36 +123,68 @@ const DonutChart = forwardRef((props, ref) => {
|
|
|
123
123
|
startAngle: 90,
|
|
124
124
|
stroke: "",
|
|
125
125
|
strokeLinejoin: "round",
|
|
126
|
+
data: parseData([{ [category]: 1 }], [isDarkMode ? "color-mix(in srgb, #000000 33%, transparent)" : "color-mix(in srgb, #000000 10%, transparent)"]),
|
|
126
127
|
style: {
|
|
127
128
|
outline: "none",
|
|
128
129
|
pointerEvents: "none"
|
|
129
130
|
}
|
|
130
131
|
}),
|
|
131
132
|
/* @__PURE__ */ jsx(Tooltip$1, {
|
|
133
|
+
isAnimationActive: false,
|
|
134
|
+
wrapperStyle: { outline: "none" },
|
|
132
135
|
content: showTooltip ? ({ active, payload }) => CustomTooltip ? /* @__PURE__ */ jsx(CustomTooltip, {
|
|
133
136
|
active,
|
|
134
137
|
customCategories,
|
|
135
138
|
label: payload?.[0]?.name,
|
|
139
|
+
valueFormatter,
|
|
136
140
|
payload: payload?.map((payloadItem) => ({
|
|
137
141
|
...payloadItem,
|
|
138
142
|
color: payload?.[0]?.payload?.color ?? cssVar.colorPrimary
|
|
139
|
-
}))
|
|
140
|
-
valueFormatter
|
|
143
|
+
}))
|
|
141
144
|
}) : /* @__PURE__ */ jsx(DonutChartTooltip, {
|
|
142
145
|
active,
|
|
143
146
|
customCategories,
|
|
144
147
|
payload,
|
|
145
148
|
valueFormatter
|
|
146
|
-
}) : void 0
|
|
147
|
-
isAnimationActive: false,
|
|
148
|
-
wrapperStyle: { outline: "none" }
|
|
149
|
+
}) : void 0
|
|
149
150
|
})
|
|
150
151
|
]
|
|
151
152
|
}) : /* @__PURE__ */ jsx(NoData, { noDataText }) })
|
|
152
153
|
});
|
|
153
|
-
}
|
|
154
|
+
};
|
|
155
|
+
const DonutChart = ({ centerLabel = "Total", currency = "USD", donut = true, format, size = 200, subtitle, title, unit, ref, ...props }) => {
|
|
156
|
+
if (props.variant !== "a2ui") return /* @__PURE__ */ jsx(DefaultDonutChart, {
|
|
157
|
+
ref,
|
|
158
|
+
...props
|
|
159
|
+
});
|
|
160
|
+
return /* @__PURE__ */ jsx(A2uiDonutChart, {
|
|
161
|
+
category: props.category ?? "value",
|
|
162
|
+
centerLabel,
|
|
163
|
+
className: props.className,
|
|
164
|
+
colors: props.colors,
|
|
165
|
+
currency,
|
|
166
|
+
customCategories: props.customCategories,
|
|
167
|
+
data: props.data,
|
|
168
|
+
donut,
|
|
169
|
+
format,
|
|
170
|
+
index: props.index ?? "name",
|
|
171
|
+
label: props.label,
|
|
172
|
+
loading: props.loading,
|
|
173
|
+
noDataText: props.noDataText,
|
|
174
|
+
ref,
|
|
175
|
+
showAnimation: props.showAnimation,
|
|
176
|
+
showLabel: props.showLabel,
|
|
177
|
+
showTooltip: props.showTooltip,
|
|
178
|
+
size,
|
|
179
|
+
style: props.style,
|
|
180
|
+
subtitle,
|
|
181
|
+
title,
|
|
182
|
+
unit,
|
|
183
|
+
valueFormatter: props.valueFormatter,
|
|
184
|
+
onValueChange: props.onValueChange
|
|
185
|
+
});
|
|
186
|
+
};
|
|
154
187
|
DonutChart.displayName = "DonutChart";
|
|
155
|
-
//#endregion
|
|
156
188
|
export { DonutChart as default };
|
|
157
189
|
|
|
158
190
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["ReChartsDonutChart","Tooltip"],"sources":["../../src/DonutChart/index.tsx"],"sourcesContent":["'use client';\n\nimport { Flexbox, Skeleton, css, cssVar, cx, useThemeMode } from '@lobehub/ui';\nimport { CSSProperties, ComponentType, MouseEvent, forwardRef, useEffect, useState } from 'react';\nimport { Pie, PieChart as ReChartsDonutChart, ResponsiveContainer, Tooltip } from 'recharts';\n\nimport type BaseAnimationTimingProps from '@/common/BaseAnimationTimingProps';\nimport { CustomTooltipProps } from '@/common/CustomTooltipProps';\nimport NoData, { type NoDataProps } from '@/common/NoData';\nimport { useThemeColorRange } from '@/hooks/useThemeColorRange';\nimport type { EventProps } from '@/types/charts';\nimport { ValueFormatter } from '@/types/charts';\nimport { defaultValueFormatter, isOnSeverSide } from '@/utils';\n\nimport { DonutChartTooltip } from './DonutChartTooltip';\nimport { parseLabelInput } from './inputParser';\nimport { renderInactiveShape } from './renderInactiveShape';\nimport { styles } from './styles';\n\ntype DonutChartVariant = 'donut' | 'pie';\n\nexport interface DonutChartProps extends BaseAnimationTimingProps {\n category?: string;\n className?: string;\n colors?: string[];\n customCategories?: {\n [key: string]: string;\n };\n customTooltip?: ComponentType<CustomTooltipProps>;\n data: any[];\n donutLabel?: string;\n index?: string;\n label?: string;\n loading?: boolean;\n noDataText?: NoDataProps['noDataText'];\n onValueChange?: (value: EventProps) => void;\n showAnimation?: boolean;\n showLabel?: boolean;\n showTooltip?: boolean;\n style?: CSSProperties;\n valueFormatter?: ValueFormatter;\n variant?: DonutChartVariant;\n}\n\nconst DonutChart = forwardRef<HTMLDivElement, DonutChartProps>((props, ref) => {\n const themeColorRange = useThemeColorRange();\n const {\n data = [],\n category = 'value',\n index = 'name',\n colors = themeColorRange,\n variant = 'donut',\n valueFormatter = defaultValueFormatter,\n label,\n showLabel = true,\n animationDuration = 900,\n showAnimation = false,\n showTooltip = true,\n noDataText,\n onValueChange,\n customTooltip,\n className,\n width = '100%',\n loading,\n height = '10rem',\n style,\n customCategories,\n donutLabel,\n ...rest\n } = props;\n const { isDarkMode } = useThemeMode();\n const CustomTooltip = customTooltip;\n const isDonut = variant === 'donut';\n const parsedLabelInput = parseLabelInput(label, valueFormatter, data, category);\n\n const [activeIndex, setActiveIndex] = useState<number | undefined>();\n const hasOnValueChange = !!onValueChange;\n\n useEffect(() => {\n if (isOnSeverSide) return;\n const pieSectors = document.querySelectorAll('.recharts-pie-sector');\n if (pieSectors) {\n for (const sector of pieSectors) {\n sector.setAttribute('style', 'outline: none');\n }\n }\n }, [activeIndex]);\n\n if (loading || !data) return <Skeleton height={height} width={width} />;\n\n const onShapeClick = (data: any, index: number, event: MouseEvent) => {\n event.stopPropagation();\n\n if (!hasOnValueChange) return;\n if (activeIndex === index) {\n setActiveIndex(undefined);\n onValueChange?.(null);\n } else {\n setActiveIndex(index);\n onValueChange?.({\n eventType: 'slice',\n ...data.payload.payload,\n });\n }\n };\n\n const parseData = (data: any[], colors: string[]) =>\n data.map((dataPoint: any, idx: number) => {\n const baseColor = idx < colors.length ? colors[idx] : cssVar.colorPrimary;\n return {\n ...dataPoint,\n className: cx(css`\n fill: ${baseColor ?? cssVar.colorPrimary};\n `),\n color: baseColor,\n fill: '',\n };\n });\n\n return (\n <Flexbox\n className={className}\n height={height}\n ref={ref}\n style={{ position: 'relative', ...style }}\n width={width}\n {...rest}\n >\n <ResponsiveContainer>\n {data?.length ? (\n <ReChartsDonutChart\n margin={{ bottom: 0, left: 0, right: 0, top: 0 }}\n onClick={\n hasOnValueChange && activeIndex\n ? () => {\n setActiveIndex(undefined);\n onValueChange?.(null);\n }\n : undefined\n }\n >\n {showLabel && isDonut ? (\n <text\n className={cx(styles.strongLabel, styles.emphasis)}\n dominantBaseline=\"middle\"\n textAnchor=\"middle\"\n x=\"50%\"\n y=\"50%\"\n >\n {donutLabel ||\n (typeof activeIndex === 'number'\n ? valueFormatter(data?.[activeIndex as any]?.[category])\n : parsedLabelInput)}\n </text>\n ) : null}\n <Pie\n activeIndex={activeIndex}\n animationDuration={animationDuration}\n cx=\"50%\"\n cy=\"50%\"\n data={parseData(data, colors)}\n dataKey={category}\n endAngle={-270}\n inactiveShape={renderInactiveShape}\n innerRadius={isDonut ? '75%' : '0%'}\n isAnimationActive={showAnimation}\n nameKey={index}\n onClick={onShapeClick}\n outerRadius=\"100%\"\n startAngle={90}\n stroke=\"\"\n strokeLinejoin=\"round\"\n style={{\n cursor: onValueChange ? 'pointer' : undefined,\n outline: 'none',\n stroke: cssVar.colorBgContainer,\n }}\n />\n {isDonut && (\n <Pie\n activeIndex={activeIndex}\n animationDuration={animationDuration}\n cx=\"50%\"\n cy=\"50%\"\n data={parseData(\n [{ [category]: 1 }],\n [\n isDarkMode\n ? 'color-mix(in srgb, #000000 33%, transparent)'\n : 'color-mix(in srgb, #000000 10%, transparent)',\n ],\n )}\n dataKey={category}\n endAngle={-270}\n inactiveShape={renderInactiveShape}\n innerRadius={isDonut ? '75%' : '0%'}\n isAnimationActive={false}\n nameKey={index}\n outerRadius=\"80%\"\n startAngle={90}\n stroke=\"\"\n strokeLinejoin=\"round\"\n style={{\n outline: 'none',\n pointerEvents: 'none',\n }}\n />\n )}\n <Tooltip\n content={\n showTooltip\n ? ({ active, payload }) =>\n CustomTooltip ? (\n <CustomTooltip\n active={active}\n customCategories={customCategories}\n label={payload?.[0]?.name}\n payload={payload?.map((payloadItem) => ({\n ...payloadItem,\n color: payload?.[0]?.payload?.color ?? cssVar.colorPrimary,\n }))}\n valueFormatter={valueFormatter}\n />\n ) : (\n <DonutChartTooltip\n active={active}\n customCategories={customCategories}\n payload={payload}\n valueFormatter={valueFormatter}\n />\n )\n : undefined\n }\n isAnimationActive={false}\n wrapperStyle={{ outline: 'none' }}\n />\n </ReChartsDonutChart>\n ) : (\n <NoData noDataText={noDataText} />\n )}\n </ResponsiveContainer>\n </Flexbox>\n );\n});\n\nDonutChart.displayName = 'DonutChart';\n\nexport default DonutChart;\n"],"mappings":";;;;;;;;;;;;;AA4CA,MAAM,aAAa,YAA6C,OAAO,QAAQ;CAC7E,MAAM,kBAAkB,mBAAmB;CAC3C,MAAM,EACJ,OAAO,CAAC,GACR,WAAW,SACX,QAAQ,QACR,SAAS,iBACT,UAAU,SACV,iBAAiB,uBACjB,OACA,YAAY,MACZ,oBAAoB,KACpB,gBAAgB,OAChB,cAAc,MACd,YACA,eACA,eACA,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,mBAAmB;KACnB,cAAc,EAAE,SAAS,OAAO;IACjC,CAAA;GACiB;EAEpB,CAAA,IAAA,oBAAC,QAAD,EAAoB,WAAa,CAAA,EAEhB,CAAA;CACd,CAAA;AAEb,CAAC;AAED,WAAW,cAAc"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["ReChartsDonutChart","Tooltip"],"sources":["../../src/DonutChart/index.tsx"],"sourcesContent":["'use client';\n\nimport { css, cssVar, cx, Flexbox, Skeleton, useThemeMode } from '@lobehub/ui';\nimport type { ComponentType, CSSProperties, MouseEvent, ReactNode, Ref } from 'react';\nimport { useEffect, useState } from 'react';\nimport { Pie, PieChart as ReChartsDonutChart, ResponsiveContainer, Tooltip } from 'recharts';\n\nimport type { ChartNumberFormat } from '@/common/a2ui';\nimport type BaseAnimationTimingProps from '@/common/BaseAnimationTimingProps';\nimport type { CustomTooltipProps } from '@/common/CustomTooltipProps';\nimport NoData, { type NoDataProps } from '@/common/NoData';\nimport { useThemeColorRange } from '@/hooks/useThemeColorRange';\nimport type { EventProps, ValueFormatter } from '@/types/charts';\nimport { defaultValueFormatter, isOnSeverSide } from '@/utils';\n\nimport A2uiDonutChart from './A2uiDonutChart';\nimport { DonutChartTooltip } from './DonutChartTooltip';\nimport { parseLabelInput } from './inputParser';\nimport { renderInactiveShape } from './renderInactiveShape';\nimport { styles } from './styles';\n\n/** `a2ui` draws the A2UI look: a framed donut (or pie, with `donut={false}`) beside a value list. */\ntype DonutChartVariant = 'donut' | 'pie' | 'a2ui';\n\nexport interface DonutChartProps extends BaseAnimationTimingProps {\n category?: string;\n /**\n * Caption under the centre total (a2ui only).\n * @default 'Total'\n */\n centerLabel?: string;\n className?: string;\n colors?: string[];\n /**\n * ISO 4217 code used when `format` is `currency` (a2ui only).\n * @default 'USD'\n */\n currency?: string;\n customCategories?: {\n [key: string]: string;\n };\n customTooltip?: ComponentType<CustomTooltipProps>;\n data: any[];\n /**\n * Draw a ring with the total in the centre; `false` draws a pie (a2ui only).\n * @default true\n */\n donut?: boolean;\n donutLabel?: string;\n /** How values read in the a2ui look. `percent` expects 0-100. */\n format?: ChartNumberFormat;\n index?: string;\n label?: string;\n loading?: boolean;\n noDataText?: NoDataProps['noDataText'];\n onValueChange?: (value: EventProps) => void;\n showAnimation?: boolean;\n showLabel?: boolean;\n showTooltip?: boolean;\n /**\n * Diameter of the donut in px (a2ui only).\n * @default 200\n */\n size?: number;\n style?: CSSProperties;\n /** Secondary line under the title (a2ui only). */\n subtitle?: string;\n /** Card title (a2ui only). */\n title?: string;\n /** Unit appended to values (a2ui only). */\n unit?: string;\n valueFormatter?: ValueFormatter;\n variant?: DonutChartVariant;\n}\n\nconst DefaultDonutChart = ({\n ref,\n ...props\n}: DonutChartProps & { ref?: React.Ref<HTMLDivElement> }) => {\n const themeColorRange = useThemeColorRange();\n const {\n data = [],\n category = 'value',\n index = 'name',\n colors = themeColorRange,\n variant = 'donut',\n valueFormatter = defaultValueFormatter,\n label,\n showLabel = true,\n animationDuration = 900,\n showAnimation = false,\n showTooltip = true,\n noDataText,\n onValueChange,\n customTooltip,\n className,\n width = '100%',\n loading,\n height = '10rem',\n style,\n customCategories,\n donutLabel,\n ...rest\n } = props;\n const { isDarkMode } = useThemeMode();\n const CustomTooltip = customTooltip;\n const isDonut = variant === 'donut';\n const parsedLabelInput = parseLabelInput(label, valueFormatter, data, category);\n\n const [activeIndex, setActiveIndex] = useState<number | undefined>();\n const hasOnValueChange = !!onValueChange;\n\n useEffect(() => {\n if (isOnSeverSide) return;\n const pieSectors = document.querySelectorAll('.recharts-pie-sector');\n if (pieSectors) {\n for (const sector of pieSectors) {\n sector.setAttribute('style', 'outline: none');\n }\n }\n }, [activeIndex]);\n\n if (loading || !data) return <Skeleton height={height} width={width} />;\n\n const onShapeClick = (data: any, index: number, event: MouseEvent) => {\n event.stopPropagation();\n\n if (!hasOnValueChange) return;\n if (activeIndex === index) {\n setActiveIndex(undefined);\n onValueChange?.(null);\n } else {\n setActiveIndex(index);\n onValueChange?.({\n eventType: 'slice',\n ...data.payload.payload,\n });\n }\n };\n\n const parseData = (data: any[], colors: string[]) =>\n data.map((dataPoint: any, idx: number) => {\n const baseColor = idx < colors.length ? colors[idx] : cssVar.colorPrimary;\n return {\n ...dataPoint,\n className: cx(css`\n fill: ${baseColor ?? cssVar.colorPrimary};\n `),\n color: baseColor,\n fill: '',\n };\n });\n\n return (\n <Flexbox\n className={className}\n height={height}\n ref={ref}\n style={{ position: 'relative', ...style }}\n width={width}\n {...rest}\n >\n <ResponsiveContainer>\n {data?.length ? (\n <ReChartsDonutChart\n margin={{ bottom: 0, left: 0, right: 0, top: 0 }}\n onClick={\n hasOnValueChange && activeIndex\n ? () => {\n setActiveIndex(undefined);\n onValueChange?.(null);\n }\n : undefined\n }\n >\n {showLabel && isDonut ? (\n <text\n className={cx(styles.strongLabel, styles.emphasis)}\n dominantBaseline=\"middle\"\n textAnchor=\"middle\"\n x=\"50%\"\n y=\"50%\"\n >\n {donutLabel ||\n (typeof activeIndex === 'number'\n ? valueFormatter(data?.[activeIndex as any]?.[category])\n : parsedLabelInput)}\n </text>\n ) : null}\n <Pie\n activeIndex={activeIndex}\n animationDuration={animationDuration}\n cx=\"50%\"\n cy=\"50%\"\n data={parseData(data, colors)}\n dataKey={category}\n endAngle={-270}\n inactiveShape={renderInactiveShape}\n innerRadius={isDonut ? '75%' : '0%'}\n isAnimationActive={showAnimation}\n nameKey={index}\n outerRadius=\"100%\"\n startAngle={90}\n stroke=\"\"\n strokeLinejoin=\"round\"\n style={{\n cursor: onValueChange ? 'pointer' : undefined,\n outline: 'none',\n stroke: cssVar.colorBgContainer,\n }}\n onClick={onShapeClick}\n />\n {isDonut && (\n <Pie\n activeIndex={activeIndex}\n animationDuration={animationDuration}\n cx=\"50%\"\n cy=\"50%\"\n dataKey={category}\n endAngle={-270}\n inactiveShape={renderInactiveShape}\n innerRadius={isDonut ? '75%' : '0%'}\n isAnimationActive={false}\n nameKey={index}\n outerRadius=\"80%\"\n startAngle={90}\n stroke=\"\"\n strokeLinejoin=\"round\"\n data={parseData(\n [{ [category]: 1 }],\n [\n isDarkMode\n ? 'color-mix(in srgb, #000000 33%, transparent)'\n : 'color-mix(in srgb, #000000 10%, transparent)',\n ],\n )}\n style={{\n outline: 'none',\n pointerEvents: 'none',\n }}\n />\n )}\n <Tooltip\n isAnimationActive={false}\n wrapperStyle={{ outline: 'none' }}\n content={\n showTooltip\n ? ({ active, payload }) =>\n CustomTooltip ? (\n <CustomTooltip\n active={active}\n customCategories={customCategories}\n label={payload?.[0]?.name}\n valueFormatter={valueFormatter}\n payload={payload?.map((payloadItem) => ({\n ...payloadItem,\n color: payload?.[0]?.payload?.color ?? cssVar.colorPrimary,\n }))}\n />\n ) : (\n <DonutChartTooltip\n active={active}\n customCategories={customCategories}\n payload={payload}\n valueFormatter={valueFormatter}\n />\n )\n : undefined\n }\n />\n </ReChartsDonutChart>\n ) : (\n <NoData noDataText={noDataText} />\n )}\n </ResponsiveContainer>\n </Flexbox>\n );\n};\n\nconst DonutChart = ({\n centerLabel = 'Total',\n currency = 'USD',\n donut = true,\n format,\n size = 200,\n subtitle,\n title,\n unit,\n ref,\n ...props\n}: DonutChartProps & { ref?: React.Ref<HTMLDivElement> }) => {\n if (props.variant !== 'a2ui') return <DefaultDonutChart ref={ref} {...props} />;\n return (\n <A2uiDonutChart\n category={props.category ?? 'value'}\n centerLabel={centerLabel}\n className={props.className}\n colors={props.colors}\n currency={currency}\n customCategories={props.customCategories}\n data={props.data}\n donut={donut}\n format={format}\n index={props.index ?? 'name'}\n label={props.label}\n loading={props.loading}\n noDataText={props.noDataText as ReactNode}\n ref={ref as Ref<HTMLElement>}\n showAnimation={props.showAnimation}\n showLabel={props.showLabel}\n showTooltip={props.showTooltip}\n size={size}\n style={props.style}\n subtitle={subtitle}\n title={title}\n unit={unit}\n valueFormatter={props.valueFormatter}\n onValueChange={props.onValueChange}\n />\n );\n};\n\nDonutChart.displayName = 'DonutChart';\n\nexport default DonutChart;\n"],"mapp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B,cAAc,EAAE,SAAS,OAAO;KAChC,SACE,eACK,EAAE,QAAQ,cACT,gBACE,oBAAC,eAAD;MACU;MACU;MAClB,OAAO,UAAU,EAAE,EAAE;MACL;MAChB,SAAS,SAAS,KAAK,iBAAiB;OACtC,GAAG;OACH,OAAO,UAAU,EAAE,EAAE,SAAS,SAAS,OAAO;MAChD,EAAE;KACH,CAAA,IAED,oBAAC,mBAAD;MACU;MACU;MACT;MACO;KACjB,CAAA,IAEL,KAAA;IAEP,CAAA;GACiB;EAEpB,CAAA,IAAA,oBAAC,QAAD,EAAoB,WAAa,CAAA,EAEhB,CAAA;CACd,CAAA;AAEb;AAEA,MAAM,cAAc,EAClB,cAAc,SACd,WAAW,OACX,QAAQ,MACR,QACA,OAAO,KACP,UACA,OACA,MACA,KACA,GAAG,YACwD;CAC3D,IAAI,MAAM,YAAY,QAAQ,OAAO,oBAAC,mBAAD;EAAwB;EAAK,GAAI;CAAQ,CAAA;CAC9E,OACE,oBAAC,gBAAD;EACE,UAAU,MAAM,YAAY;EACf;EACb,WAAW,MAAM;EACjB,QAAQ,MAAM;EACJ;EACV,kBAAkB,MAAM;EACxB,MAAM,MAAM;EACL;EACC;EACR,OAAO,MAAM,SAAS;EACtB,OAAO,MAAM;EACb,SAAS,MAAM;EACf,YAAY,MAAM;EACb;EACL,eAAe,MAAM;EACrB,WAAW,MAAM;EACjB,aAAa,MAAM;EACb;EACN,OAAO,MAAM;EACH;EACH;EACD;EACN,gBAAgB,MAAM;EACtB,eAAe,MAAM;CACtB,CAAA;AAEL;AAEA,WAAW,cAAc"}
|
|
@@ -1,5 +1,2 @@
|
|
|
1
1
|
import { ValueFormatter } from "../types/charts.mjs";
|
|
2
|
-
|
|
3
|
-
export declare const parseLabelInput: (labelInput: string | undefined, valueFormatter: ValueFormatter, data: any[], category: string) => string;
|
|
4
|
-
//#endregion
|
|
5
|
-
//# sourceMappingURL=inputParser.d.mts.map
|
|
2
|
+
export declare const parseLabelInput: (labelInput: string | undefined, valueFormatter: ValueFormatter, data: any[], category: string) => string;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { sumNumericArray } from "../utils/index.mjs";
|
|
2
|
-
|
|
2
|
+
// src/DonutChart/inputParser.ts
|
|
3
3
|
const calculateDefaultLabel = (data, category) => sumNumericArray(data.map((dataPoint) => dataPoint[category]));
|
|
4
4
|
const parseLabelInput = (labelInput, valueFormatter, data, category) => labelInput ? labelInput : valueFormatter(calculateDefaultLabel(data, category));
|
|
5
|
-
//#endregion
|
|
6
5
|
export { parseLabelInput };
|
|
7
6
|
|
|
8
7
|
//# sourceMappingURL=inputParser.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inputParser.mjs","names":[],"sources":["../../src/DonutChart/inputParser.ts"],"sourcesContent":["import { ValueFormatter } from '@/types/charts';\nimport { sumNumericArray } from '@/utils';\n\nconst calculateDefaultLabel = (data: any[], category: string) =>\n sumNumericArray(data.map((dataPoint) => dataPoint[category]));\n\nexport const parseLabelInput = (\n labelInput: string | undefined,\n valueFormatter: ValueFormatter,\n data: any[],\n category: string,\n) => (labelInput ? labelInput : valueFormatter(calculateDefaultLabel(data, category)));\n"],"mappings":";;AAGA,MAAM,yBAAyB,MAAa,aAC1C,gBAAgB,KAAK,KAAK,cAAc,UAAU,SAAS,CAAC;AAE9D,MAAa,mBACX,YACA,gBACA,MACA,aACI,aAAa,aAAa,eAAe,sBAAsB,MAAM,QAAQ,CAAC"}
|
|
1
|
+
{"version":3,"file":"inputParser.mjs","names":[],"sources":["../../src/DonutChart/inputParser.ts"],"sourcesContent":["import type { ValueFormatter } from '@/types/charts';\nimport { sumNumericArray } from '@/utils';\n\nconst calculateDefaultLabel = (data: any[], category: string) =>\n sumNumericArray(data.map((dataPoint) => dataPoint[category]));\n\nexport const parseLabelInput = (\n labelInput: string | undefined,\n valueFormatter: ValueFormatter,\n data: any[],\n category: string,\n) => (labelInput ? labelInput : valueFormatter(calculateDefaultLabel(data, category)));\n"],"mappings":";;AAGA,MAAM,yBAAyB,MAAa,aAC1C,gBAAgB,KAAK,KAAK,cAAc,UAAU,SAAS,CAAC;AAE9D,MAAa,mBACX,YACA,gBACA,MACA,aACI,aAAa,aAAa,eAAe,sBAAsB,MAAM,QAAQ,CAAC"}
|
|
@@ -1,4 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const renderInactiveShape: (props: any) => import("react").JSX.Element;
|
|
3
|
-
//#endregion
|
|
4
|
-
//# sourceMappingURL=renderInactiveShape.d.mts.map
|
|
1
|
+
export declare const renderInactiveShape: (props: any) => import("react").JSX.Element;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Sector } from "recharts";
|
|
2
2
|
import { jsx } from "react/jsx-runtime";
|
|
3
|
-
|
|
3
|
+
// src/DonutChart/renderInactiveShape.tsx
|
|
4
4
|
const renderInactiveShape = (props) => {
|
|
5
5
|
const { cx, cy, innerRadius, outerRadius, startAngle, endAngle, className } = props;
|
|
6
6
|
return /* @__PURE__ */ jsx("g", { children: /* @__PURE__ */ jsx(Sector, {
|
|
@@ -16,7 +16,6 @@ const renderInactiveShape = (props) => {
|
|
|
16
16
|
style: { outline: "none" }
|
|
17
17
|
}) });
|
|
18
18
|
};
|
|
19
|
-
//#endregion
|
|
20
19
|
export { renderInactiveShape };
|
|
21
20
|
|
|
22
21
|
//# sourceMappingURL=renderInactiveShape.mjs.map
|
package/es/DonutChart/styles.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createStaticStyles } from "@lobehub/ui";
|
|
2
|
-
|
|
2
|
+
// src/DonutChart/styles.ts
|
|
3
3
|
const styles = createStaticStyles(({ css, cssVar }) => ({
|
|
4
4
|
emphasis: css`
|
|
5
5
|
overflow: hidden;
|
|
@@ -22,7 +22,6 @@ const styles = createStaticStyles(({ css, cssVar }) => ({
|
|
|
22
22
|
fill: ${cssVar.colorTextSecondary};
|
|
23
23
|
`
|
|
24
24
|
}));
|
|
25
|
-
//#endregion
|
|
26
25
|
export { styles };
|
|
27
26
|
|
|
28
27
|
//# sourceMappingURL=styles.mjs.map
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
//#region src/FunnelChart/ArrowRightIcon.d.ts
|
|
3
2
|
declare const ArrowRightIcon: ({ ...props }: {
|
|
4
3
|
[x: string]: any;
|
|
5
4
|
}) => React.JSX.Element;
|
|
6
|
-
|
|
7
|
-
export { ArrowRightIcon as default };
|
|
8
|
-
//# sourceMappingURL=ArrowRightIcon.d.mts.map
|
|
5
|
+
export { ArrowRightIcon as default };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "react";
|
|
2
2
|
import { jsx } from "react/jsx-runtime";
|
|
3
|
-
|
|
3
|
+
// src/FunnelChart/ArrowRightIcon.tsx
|
|
4
4
|
const ArrowRightIcon = ({ ...props }) => /* @__PURE__ */ jsx("svg", {
|
|
5
5
|
fill: "currentColor",
|
|
6
6
|
viewBox: "0 0 24 24",
|
|
@@ -8,7 +8,6 @@ const ArrowRightIcon = ({ ...props }) => /* @__PURE__ */ jsx("svg", {
|
|
|
8
8
|
...props,
|
|
9
9
|
children: /* @__PURE__ */ jsx("path", { d: "M16.1716 10.9999L10.8076 5.63589L12.2218 4.22168L20 11.9999L12.2218 19.778L10.8076 18.3638L16.1716 12.9999H4V10.9999H16.1716Z" })
|
|
10
10
|
});
|
|
11
|
-
//#endregion
|
|
12
11
|
export { ArrowRightIcon as default };
|
|
13
12
|
|
|
14
13
|
//# sourceMappingURL=ArrowRightIcon.mjs.map
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import BaseChartProps from "../common/BaseChartProps.mjs";
|
|
2
|
-
//#region src/FunnelChart/index.d.ts
|
|
3
2
|
type CalculateFrom = 'first' | 'previous';
|
|
4
3
|
type DataT = {
|
|
5
4
|
name: string;
|
|
@@ -15,7 +14,10 @@ export interface FunnelChartProps extends Omit<BaseChartProps, 'categories' | 'i
|
|
|
15
14
|
variant?: 'base' | 'center';
|
|
16
15
|
yAxisPadding?: number;
|
|
17
16
|
}
|
|
18
|
-
declare const FunnelChart:
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
declare const FunnelChart: {
|
|
18
|
+
({ ref, ...props }: FunnelChartProps & {
|
|
19
|
+
ref?: React.Ref<HTMLDivElement>;
|
|
20
|
+
}): import("react").JSX.Element;
|
|
21
|
+
displayName: string;
|
|
22
|
+
};
|
|
23
|
+
export { FunnelChart as default };
|
package/es/FunnelChart/index.mjs
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { Flexbox, Skeleton, css, cssVar, cx } from "@lobehub/ui";
|
|
3
|
+
import { useSize } from "ahooks";
|
|
4
|
+
import { Fragment, useEffect, useMemo, useRef, useState } from "react";
|
|
4
5
|
import ChartTooltip from "../common/ChartTooltip/index.mjs";
|
|
5
6
|
import NoData from "../common/NoData.mjs";
|
|
6
|
-
import { getMaxLabelLength } from "../utils/getMaxLabelLength.mjs";
|
|
7
7
|
import ArrowRightIcon from "./ArrowRightIcon.mjs";
|
|
8
|
+
import { useThemeColorRange } from "../hooks/useThemeColorRange.mjs";
|
|
9
|
+
import { defaultValueFormatter } from "../utils/index.mjs";
|
|
10
|
+
import { getMaxLabelLength } from "../utils/getMaxLabelLength.mjs";
|
|
8
11
|
import { styles } from "./styles.mjs";
|
|
9
|
-
import { Flexbox, Skeleton, css, cssVar, cx } from "@lobehub/ui";
|
|
10
|
-
import { Fragment, forwardRef, useEffect, useMemo, useRef, useState } from "react";
|
|
11
12
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
12
|
-
|
|
13
|
-
//#region src/FunnelChart/index.tsx
|
|
13
|
+
// src/FunnelChart/index.tsx
|
|
14
14
|
const GLOBAL_PADDING = 10;
|
|
15
15
|
const HALF_PADDING = GLOBAL_PADDING / 2;
|
|
16
16
|
const Y_AXIS_LABELS = [
|
|
@@ -27,7 +27,7 @@ const validateData = (data, calculatedFrom) => {
|
|
|
27
27
|
}
|
|
28
28
|
return null;
|
|
29
29
|
};
|
|
30
|
-
const FunnelChart =
|
|
30
|
+
const FunnelChart = ({ ref, ...props }) => {
|
|
31
31
|
const themeColorRange = useThemeColorRange();
|
|
32
32
|
const { data = [], evolutionGradient = true, gradient = false, valueFormatter = defaultValueFormatter, calculateFrom = "first", color = themeColorRange[0], variant = "base", showGridLines = true, showYAxis = calculateFrom === "previous" ? false : true, showXAxis = true, showArrow = true, xAxisLabel = "", yAxisLabel = "", yAxisAlign = "left", showTooltip = true, onValueChange, customTooltip, noDataText, rotateLabelX, barGap = "20%", loading, width = "100%", height = 280, className, style, yAxisWidth, ...rest } = props;
|
|
33
33
|
const svgRef = useRef(ref);
|
|
@@ -200,10 +200,19 @@ const FunnelChart = forwardRef((props, ref) => {
|
|
|
200
200
|
width,
|
|
201
201
|
...rest,
|
|
202
202
|
children: data?.length ? /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsxs("svg", {
|
|
203
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
204
|
+
style: {
|
|
205
|
+
height: "100%",
|
|
206
|
+
width: "100%"
|
|
207
|
+
},
|
|
203
208
|
onMouseLeave: () => setTooltip({
|
|
204
209
|
x: 0,
|
|
205
210
|
y: 0
|
|
206
211
|
}),
|
|
212
|
+
onTouchEnd: () => setTooltip({
|
|
213
|
+
x: 0,
|
|
214
|
+
y: 0
|
|
215
|
+
}),
|
|
207
216
|
onMouseMove: (e) => {
|
|
208
217
|
const fakeTouch = {
|
|
209
218
|
clientX: e.clientX,
|
|
@@ -213,19 +222,10 @@ const FunnelChart = forwardRef((props, ref) => {
|
|
|
213
222
|
};
|
|
214
223
|
handleTooltip(fakeTouch);
|
|
215
224
|
},
|
|
216
|
-
onTouchEnd: () => setTooltip({
|
|
217
|
-
x: 0,
|
|
218
|
-
y: 0
|
|
219
|
-
}),
|
|
220
225
|
onTouchMove: (e) => {
|
|
221
226
|
const touch = e.touches[0];
|
|
222
227
|
handleTooltip(touch);
|
|
223
228
|
},
|
|
224
|
-
style: {
|
|
225
|
-
height: "100%",
|
|
226
|
-
width: "100%"
|
|
227
|
-
},
|
|
228
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
229
229
|
children: [
|
|
230
230
|
Y_AXIS_LABELS.map((label, index) => /* @__PURE__ */ jsxs(Fragment, { children: [showGridLines && /* @__PURE__ */ jsx("line", {
|
|
231
231
|
className: styles.gridLines,
|
|
@@ -236,55 +236,55 @@ const FunnelChart = forwardRef((props, ref) => {
|
|
|
236
236
|
}), /* @__PURE__ */ jsx("text", {
|
|
237
237
|
className: styles.label,
|
|
238
238
|
textAnchor: yAxisAlign === "left" ? "start" : "end",
|
|
239
|
-
x: yAxisAlign === "left" ? yAxisLabel ? 24 : 0 : calculatedYAxisWidth - 10 + HALF_PADDING,
|
|
240
239
|
y: index * realHeight / 4 + 5 + HALF_PADDING,
|
|
240
|
+
x: yAxisAlign === "left" ? yAxisLabel ? 24 : 0 : calculatedYAxisWidth - 10 + HALF_PADDING,
|
|
241
241
|
children: label
|
|
242
242
|
})] }, `y-axis-${index}`)),
|
|
243
243
|
formattedData.map((item, index) => /* @__PURE__ */ jsxs("g", { children: [
|
|
244
244
|
/* @__PURE__ */ jsx("rect", {
|
|
245
245
|
height: realHeight,
|
|
246
|
+
width: barWidth + gap,
|
|
247
|
+
x: item.startX - gap * .5 + HALF_PADDING + calculatedYAxisWidth,
|
|
248
|
+
y: HALF_PADDING,
|
|
246
249
|
style: {
|
|
247
250
|
fill: tooltip.index === index ? cssVar.colorFillTertiary : "transparent",
|
|
248
251
|
zIndex: 0
|
|
249
|
-
}
|
|
250
|
-
width: barWidth + gap,
|
|
251
|
-
x: item.startX - gap * .5 + HALF_PADDING + calculatedYAxisWidth,
|
|
252
|
-
y: HALF_PADDING
|
|
252
|
+
}
|
|
253
253
|
}),
|
|
254
254
|
gradient && /* @__PURE__ */ jsx("rect", {
|
|
255
255
|
fill: `url(#base-gradient)`,
|
|
256
|
-
height: (realHeight - item.barHeight - (isPreviousCalculation ? realHeight - formattedData[index - 1]?.barHeight || 0 : 0)) / (isVariantCenter ? 2 : 1),
|
|
257
|
-
style: { opacity: activeBar && activeBar.index !== index ? .3 : 1 },
|
|
258
256
|
width: barWidth,
|
|
259
257
|
x: item.startX + HALF_PADDING + calculatedYAxisWidth,
|
|
258
|
+
height: (realHeight - item.barHeight - (isPreviousCalculation ? realHeight - formattedData[index - 1]?.barHeight || 0 : 0)) / (isVariantCenter ? 2 : 1),
|
|
259
|
+
style: { opacity: activeBar && activeBar.index !== index ? .3 : 1 },
|
|
260
260
|
y: realHeight - (isPreviousCalculation ? formattedData[index - 1]?.barHeight || realHeight : realHeight) + HALF_PADDING
|
|
261
261
|
}),
|
|
262
262
|
/* @__PURE__ */ jsx("rect", {
|
|
263
263
|
height: item.barHeight,
|
|
264
|
-
|
|
264
|
+
width: barWidth,
|
|
265
|
+
x: item.startX + HALF_PADDING + calculatedYAxisWidth,
|
|
265
266
|
style: {
|
|
266
267
|
cursor: onValueChange ? "pointer" : void 0,
|
|
267
268
|
fill: color ?? cssVar.colorPrimary,
|
|
268
269
|
opacity: activeBar && activeBar.index !== index ? .3 : 1
|
|
269
270
|
},
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
y: (isVariantCenter ? realHeight / 2 - item.barHeight / 2 : item.startY) + HALF_PADDING
|
|
271
|
+
y: (isVariantCenter ? realHeight / 2 - item.barHeight / 2 : item.startY) + HALF_PADDING,
|
|
272
|
+
onClick: (e) => onBarClick(item, index, e)
|
|
273
273
|
}),
|
|
274
274
|
gradient && isVariantCenter && /* @__PURE__ */ jsx("rect", {
|
|
275
275
|
fill: `url(#base-gradient-revert)`,
|
|
276
276
|
height: (realHeight - item.barHeight) / 2,
|
|
277
|
-
style: { opacity: activeBar && activeBar.index !== index ? .3 : 1 },
|
|
278
277
|
width: barWidth,
|
|
279
278
|
x: item.startX + HALF_PADDING + calculatedYAxisWidth,
|
|
280
|
-
y: realHeight / 2 + item.barHeight / 2 + HALF_PADDING
|
|
279
|
+
y: realHeight / 2 + item.barHeight / 2 + HALF_PADDING,
|
|
280
|
+
style: { opacity: activeBar && activeBar.index !== index ? .3 : 1 }
|
|
281
281
|
}),
|
|
282
282
|
showXAxis && /* @__PURE__ */ jsx("foreignObject", {
|
|
283
283
|
height: rotateLabelX?.xAxisHeight || DEFAULT_X_AXIS_HEIGHT,
|
|
284
|
-
transform: rotateLabelX ? `rotate(${rotateLabelX?.angle}, ${item.startX + barWidth / 2 + HALF_PADDING + calculatedYAxisWidth}, ${realHeight + (rotateLabelX?.xAxisHeight || DEFAULT_X_AXIS_HEIGHT) / 2 + HALF_PADDING + (rotateLabelX?.verticalShift || 0)})` : void 0,
|
|
285
284
|
width: barWidth,
|
|
286
285
|
x: item.startX + HALF_PADDING + calculatedYAxisWidth,
|
|
287
286
|
y: realHeight + HALF_PADDING + 10,
|
|
287
|
+
transform: rotateLabelX ? `rotate(${rotateLabelX?.angle}, ${item.startX + barWidth / 2 + HALF_PADDING + calculatedYAxisWidth}, ${realHeight + (rotateLabelX?.xAxisHeight || DEFAULT_X_AXIS_HEIGHT) / 2 + HALF_PADDING + (rotateLabelX?.verticalShift || 0)})` : void 0,
|
|
288
288
|
children: /* @__PURE__ */ jsx("div", {
|
|
289
289
|
className: cx(styles.strongLabel, styles.emphasis),
|
|
290
290
|
title: item.name,
|
|
@@ -336,16 +336,16 @@ const FunnelChart = forwardRef((props, ref) => {
|
|
|
336
336
|
children: /* @__PURE__ */ jsx(ArrowRightIcon, {})
|
|
337
337
|
})] }, `gradient-${index}`)),
|
|
338
338
|
/* @__PURE__ */ jsxs("linearGradient", {
|
|
339
|
-
className: cx(css`
|
|
340
|
-
stop {
|
|
341
|
-
stop-color: ${color ?? cssVar.colorPrimary};
|
|
342
|
-
}
|
|
343
|
-
`),
|
|
344
339
|
id: "base-gradient",
|
|
345
340
|
x1: "0%",
|
|
346
341
|
x2: "0%",
|
|
347
342
|
y1: "0%",
|
|
348
343
|
y2: "100%",
|
|
344
|
+
className: cx(css`
|
|
345
|
+
stop {
|
|
346
|
+
stop-color: ${color ?? cssVar.colorPrimary};
|
|
347
|
+
}
|
|
348
|
+
`),
|
|
349
349
|
children: [/* @__PURE__ */ jsx("stop", {
|
|
350
350
|
offset: "5%",
|
|
351
351
|
stopOpacity: .4
|
|
@@ -355,16 +355,16 @@ const FunnelChart = forwardRef((props, ref) => {
|
|
|
355
355
|
})]
|
|
356
356
|
}),
|
|
357
357
|
/* @__PURE__ */ jsxs("linearGradient", {
|
|
358
|
-
className: cx(css`
|
|
359
|
-
stop {
|
|
360
|
-
stop-color: ${color ?? cssVar.colorPrimary};
|
|
361
|
-
}
|
|
362
|
-
`),
|
|
363
358
|
id: "base-gradient-revert",
|
|
364
359
|
x1: "0%",
|
|
365
360
|
x2: "0%",
|
|
366
361
|
y1: "0%",
|
|
367
362
|
y2: "100%",
|
|
363
|
+
className: cx(css`
|
|
364
|
+
stop {
|
|
365
|
+
stop-color: ${color ?? cssVar.colorPrimary};
|
|
366
|
+
}
|
|
367
|
+
`),
|
|
368
368
|
children: [/* @__PURE__ */ jsx("stop", {
|
|
369
369
|
offset: "5%",
|
|
370
370
|
stopOpacity: 0
|
|
@@ -389,6 +389,7 @@ const FunnelChart = forwardRef((props, ref) => {
|
|
|
389
389
|
]
|
|
390
390
|
}), showTooltip && /* @__PURE__ */ jsx("div", {
|
|
391
391
|
ref: tooltipRef,
|
|
392
|
+
tabIndex: -1,
|
|
392
393
|
style: {
|
|
393
394
|
display: tooltip.data ? "block" : "none",
|
|
394
395
|
left: tooltip.x + barWidth * .66,
|
|
@@ -396,7 +397,6 @@ const FunnelChart = forwardRef((props, ref) => {
|
|
|
396
397
|
position: "absolute",
|
|
397
398
|
top: 0
|
|
398
399
|
},
|
|
399
|
-
tabIndex: -1,
|
|
400
400
|
children: CustomTooltip ? /* @__PURE__ */ jsx(CustomTooltip, {
|
|
401
401
|
active: !!tooltip.data,
|
|
402
402
|
label: tooltip.data?.name,
|
|
@@ -411,9 +411,8 @@ const FunnelChart = forwardRef((props, ref) => {
|
|
|
411
411
|
})
|
|
412
412
|
})] }) : /* @__PURE__ */ jsx(NoData, { noDataText })
|
|
413
413
|
});
|
|
414
|
-
}
|
|
414
|
+
};
|
|
415
415
|
FunnelChart.displayName = "FunnelChart";
|
|
416
|
-
//#endregion
|
|
417
416
|
export { FunnelChart as default };
|
|
418
417
|
|
|
419
418
|
//# sourceMappingURL=index.mjs.map
|