@lobehub/charts 1.4.0 → 1.5.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/es/AreaChart/index.d.ts +2 -0
- package/es/AreaChart/index.js +40 -10
- package/es/BarChart/index.d.ts +2 -0
- package/es/BarChart/index.js +62 -22
- package/es/DonutChart/DonutChartTooltip.d.ts +4 -1
- package/es/DonutChart/DonutChartTooltip.js +3 -2
- package/es/DonutChart/index.d.ts +3 -0
- package/es/DonutChart/index.js +4 -1
- package/es/Legend/LegendItem.d.ts +1 -0
- package/es/Legend/LegendItem.js +3 -2
- package/es/Legend/index.d.ts +3 -0
- package/es/Legend/index.js +4 -2
- package/es/LineChart/index.d.ts +2 -0
- package/es/LineChart/index.js +40 -10
- package/es/ScatterChart/ScatterChartTooltip.d.ts +3 -0
- package/es/ScatterChart/ScatterChartTooltip.js +3 -2
- package/es/ScatterChart/index.d.ts +5 -0
- package/es/ScatterChart/index.js +40 -9
- package/es/SparkChart/SparkAreaChart.d.ts +1 -0
- package/es/SparkChart/SparkAreaChart.js +11 -1
- package/es/SparkChart/SparkBarChart.d.ts +1 -0
- package/es/SparkChart/SparkBarChart.js +11 -1
- package/es/SparkChart/SparkLineChart.d.ts +1 -0
- package/es/SparkChart/SparkLineChart.js +11 -1
- package/es/common/BaseChartProps.d.ts +3 -0
- package/es/common/ChartLegend.d.ts +3 -1
- package/es/common/ChartLegend.js +2 -1
- package/es/common/ChartTooltip/index.d.ts +4 -1
- package/es/common/ChartTooltip/index.js +3 -2
- package/es/common/CustomTooltipProps.d.ts +3 -0
- package/es/common/CustomYAxisTick.d.ts +14 -0
- package/es/common/CustomYAxisTick.js +26 -0
- package/es/utils/getMaxLabelLength.d.ts +11 -0
- package/es/utils/getMaxLabelLength.js +108 -0
- package/es/utils/index.js +1 -3
- package/package.json +3 -3
package/es/AreaChart/index.d.ts
CHANGED
|
@@ -4,8 +4,10 @@ import { CurveType } from "../types";
|
|
|
4
4
|
export interface AreaChartProps extends BaseChartProps {
|
|
5
5
|
connectNulls?: boolean;
|
|
6
6
|
curveType?: CurveType;
|
|
7
|
+
loading?: boolean;
|
|
7
8
|
showGradient?: boolean;
|
|
8
9
|
stack?: boolean;
|
|
10
|
+
yAxisAlign?: 'left' | 'right';
|
|
9
11
|
}
|
|
10
12
|
declare const AreaChart: import("react").ForwardRefExoticComponent<AreaChartProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
11
13
|
export default AreaChart;
|
package/es/AreaChart/index.js
CHANGED
|
@@ -5,17 +5,20 @@ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
|
5
5
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
6
6
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
7
7
|
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5;
|
|
8
|
-
var _excluded = ["data", "categories", "index", "stack", "colors", "valueFormatter", "startEndOnly", "showXAxis", "showYAxis", "yAxisWidth", "intervalType", "showAnimation", "animationDuration", "showTooltip", "showLegend", "showGridLines", "showGradient", "autoMinValue", "curveType", "minValue", "maxValue", "connectNulls", "allowDecimals", "noDataText", "className", "onValueChange", "enableLegendSlider", "customTooltip", "rotateLabelX", "tickGap", "xAxisLabel", "yAxisLabel", "width", "height", "style"];
|
|
8
|
+
var _excluded = ["data", "categories", "index", "stack", "colors", "valueFormatter", "startEndOnly", "showXAxis", "showYAxis", "yAxisAlign", "yAxisWidth", "intervalType", "showAnimation", "animationDuration", "showTooltip", "showLegend", "showGridLines", "showGradient", "autoMinValue", "curveType", "minValue", "maxValue", "connectNulls", "allowDecimals", "noDataText", "className", "onValueChange", "enableLegendSlider", "customTooltip", "rotateLabelX", "tickGap", "loading", "xAxisLabel", "yAxisLabel", "width", "height", "style", "customCategories"];
|
|
9
|
+
import { Skeleton } from 'antd';
|
|
9
10
|
import { css } from 'antd-style';
|
|
10
|
-
import { Fragment, forwardRef, useState } from 'react';
|
|
11
|
+
import { Fragment, forwardRef, useMemo, useState } from 'react';
|
|
11
12
|
import { Flexbox } from 'react-layout-kit';
|
|
12
13
|
import { Area, CartesianGrid, Dot, Label, Legend, Line, AreaChart as ReChartsAreaChart, ResponsiveContainer, Tooltip, XAxis, YAxis } from 'recharts';
|
|
13
14
|
import ChartLegend from "../common/ChartLegend";
|
|
14
15
|
import ChartTooltip from "../common/ChartTooltip";
|
|
16
|
+
import CustomYAxisTick from "../common/CustomYAxisTick";
|
|
15
17
|
import NoData from "../common/NoData";
|
|
16
18
|
import { constructCategoryColors, getYAxisDomain, hasOnlyOneValueForThisKey } from "../common/utils";
|
|
17
19
|
import { useThemeColorRange } from "../hooks/useThemeColorRange";
|
|
18
20
|
import { defaultValueFormatter } from "../utils";
|
|
21
|
+
import { getMaxLabelLength } from "../utils/getMaxLabelLength";
|
|
19
22
|
import { useStyles } from "./styles";
|
|
20
23
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
21
24
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
@@ -42,8 +45,9 @@ var AreaChart = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
42
45
|
showXAxis = _props$showXAxis === void 0 ? true : _props$showXAxis,
|
|
43
46
|
_props$showYAxis = props.showYAxis,
|
|
44
47
|
showYAxis = _props$showYAxis === void 0 ? true : _props$showYAxis,
|
|
45
|
-
_props$
|
|
46
|
-
|
|
48
|
+
_props$yAxisAlign = props.yAxisAlign,
|
|
49
|
+
yAxisAlign = _props$yAxisAlign === void 0 ? 'left' : _props$yAxisAlign,
|
|
50
|
+
yAxisWidth = props.yAxisWidth,
|
|
47
51
|
_props$intervalType = props.intervalType,
|
|
48
52
|
intervalType = _props$intervalType === void 0 ? 'equidistantPreserveStart' : _props$intervalType,
|
|
49
53
|
_props$showAnimation = props.showAnimation,
|
|
@@ -77,6 +81,7 @@ var AreaChart = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
77
81
|
rotateLabelX = props.rotateLabelX,
|
|
78
82
|
_props$tickGap = props.tickGap,
|
|
79
83
|
tickGap = _props$tickGap === void 0 ? 5 : _props$tickGap,
|
|
84
|
+
loading = props.loading,
|
|
80
85
|
xAxisLabel = props.xAxisLabel,
|
|
81
86
|
yAxisLabel = props.yAxisLabel,
|
|
82
87
|
_props$width = props.width,
|
|
@@ -84,9 +89,8 @@ var AreaChart = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
84
89
|
_props$height = props.height,
|
|
85
90
|
height = _props$height === void 0 ? '20rem' : _props$height,
|
|
86
91
|
style = props.style,
|
|
92
|
+
customCategories = props.customCategories,
|
|
87
93
|
rest = _objectWithoutProperties(props, _excluded);
|
|
88
|
-
var CustomTooltip = customTooltip;
|
|
89
|
-
var paddingValue = !showXAxis && !showYAxis || startEndOnly && !showYAxis ? 0 : 20;
|
|
90
94
|
var _useState = useState(60),
|
|
91
95
|
_useState2 = _slicedToArray(_useState, 2),
|
|
92
96
|
legendHeight = _useState2[0],
|
|
@@ -99,6 +103,25 @@ var AreaChart = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
99
103
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
100
104
|
activeLegend = _useState6[0],
|
|
101
105
|
setActiveLegend = _useState6[1];
|
|
106
|
+
var calculatedYAxisWidth = useMemo(function () {
|
|
107
|
+
if (yAxisWidth) return yAxisWidth;
|
|
108
|
+
return getMaxLabelLength({
|
|
109
|
+
data: data,
|
|
110
|
+
index: index,
|
|
111
|
+
margin: 16,
|
|
112
|
+
valueFormatter: valueFormatter
|
|
113
|
+
});
|
|
114
|
+
}, [yAxisWidth, data, valueFormatter, index]);
|
|
115
|
+
if (loading || !data) return /*#__PURE__*/_jsx(Skeleton.Button, {
|
|
116
|
+
active: true,
|
|
117
|
+
block: true,
|
|
118
|
+
style: {
|
|
119
|
+
height: height,
|
|
120
|
+
width: width
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
var CustomTooltip = customTooltip;
|
|
124
|
+
var paddingValue = !showXAxis && !showYAxis || startEndOnly && !showYAxis ? 0 : 20;
|
|
102
125
|
var categoryColors = constructCategoryColors(categories, colors);
|
|
103
126
|
var yAxisDomain = getYAxisDomain(autoMinValue, minValue, maxValue);
|
|
104
127
|
var hasOnValueChange = !!onValueChange;
|
|
@@ -197,13 +220,18 @@ var AreaChart = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
197
220
|
fill: "",
|
|
198
221
|
hide: !showYAxis,
|
|
199
222
|
stroke: "",
|
|
200
|
-
tick: {
|
|
201
|
-
|
|
223
|
+
tick: function tick(props) {
|
|
224
|
+
return /*#__PURE__*/_jsx(CustomYAxisTick, _objectSpread(_objectSpread({}, props), {}, {
|
|
225
|
+
align: yAxisAlign,
|
|
226
|
+
formatter: valueFormatter,
|
|
227
|
+
textAnchor: yAxisAlign === 'left' ? 'start' : 'end',
|
|
228
|
+
yAxisLabel: Boolean(yAxisLabel)
|
|
229
|
+
}));
|
|
202
230
|
},
|
|
203
231
|
tickFormatter: valueFormatter,
|
|
204
232
|
tickLine: false,
|
|
205
233
|
type: "number",
|
|
206
|
-
width:
|
|
234
|
+
width: calculatedYAxisWidth,
|
|
207
235
|
children: yAxisLabel && /*#__PURE__*/_jsx(Label, {
|
|
208
236
|
angle: -90,
|
|
209
237
|
className: cx(styles.strongLabel, styles.emphasis),
|
|
@@ -221,6 +249,7 @@ var AreaChart = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
221
249
|
label = _ref.label;
|
|
222
250
|
return CustomTooltip ? /*#__PURE__*/_jsx(CustomTooltip, {
|
|
223
251
|
active: active,
|
|
252
|
+
customCategories: customCategories,
|
|
224
253
|
label: label,
|
|
225
254
|
payload: payload === null || payload === void 0 ? void 0 : payload.map(function (payloadItem) {
|
|
226
255
|
var _categoryColors$get;
|
|
@@ -231,6 +260,7 @@ var AreaChart = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
231
260
|
}) : /*#__PURE__*/_jsx(ChartTooltip, {
|
|
232
261
|
active: active,
|
|
233
262
|
categoryColors: categoryColors,
|
|
263
|
+
customCategories: customCategories,
|
|
234
264
|
label: label,
|
|
235
265
|
payload: payload,
|
|
236
266
|
valueFormatter: valueFormatter
|
|
@@ -254,7 +284,7 @@ var AreaChart = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
254
284
|
payload: payload
|
|
255
285
|
}, categoryColors, setLegendHeight, activeLegend, hasOnValueChange ? function (clickedLegendItem) {
|
|
256
286
|
return onCategoryClick(clickedLegendItem);
|
|
257
|
-
} : undefined, enableLegendSlider);
|
|
287
|
+
} : undefined, enableLegendSlider, customCategories);
|
|
258
288
|
},
|
|
259
289
|
height: legendHeight,
|
|
260
290
|
verticalAlign: "top"
|
package/es/BarChart/index.d.ts
CHANGED
|
@@ -3,8 +3,10 @@ import BaseChartProps from "../common/BaseChartProps";
|
|
|
3
3
|
export interface BarChartProps extends BaseChartProps {
|
|
4
4
|
barCategoryGap?: string | number;
|
|
5
5
|
layout?: 'vertical' | 'horizontal';
|
|
6
|
+
loading?: boolean;
|
|
6
7
|
relative?: boolean;
|
|
7
8
|
stack?: boolean;
|
|
9
|
+
yAxisAlign?: 'left' | 'right';
|
|
8
10
|
}
|
|
9
11
|
declare const BarChart: import("react").ForwardRefExoticComponent<BarChartProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
10
12
|
export default BarChart;
|
package/es/BarChart/index.js
CHANGED
|
@@ -5,17 +5,20 @@ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
|
5
5
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
6
6
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
7
7
|
var _templateObject;
|
|
8
|
-
var _excluded = ["data", "categories", "index", "colors", "valueFormatter", "layout", "stack", "relative", "startEndOnly", "animationDuration", "showAnimation", "showXAxis", "showYAxis", "yAxisWidth", "intervalType", "showTooltip", "showLegend", "showGridLines", "autoMinValue", "minValue", "maxValue", "allowDecimals", "noDataText", "onValueChange", "enableLegendSlider", "customTooltip", "rotateLabelX", "barCategoryGap", "tickGap", "xAxisLabel", "yAxisLabel", "className", "width", "height", "style"];
|
|
8
|
+
var _excluded = ["data", "categories", "customCategories", "index", "yAxisAlign", "colors", "valueFormatter", "layout", "stack", "relative", "startEndOnly", "animationDuration", "showAnimation", "showXAxis", "showYAxis", "yAxisWidth", "intervalType", "showTooltip", "showLegend", "showGridLines", "autoMinValue", "minValue", "maxValue", "allowDecimals", "noDataText", "onValueChange", "enableLegendSlider", "customTooltip", "rotateLabelX", "barCategoryGap", "tickGap", "loading", "xAxisLabel", "yAxisLabel", "className", "width", "height", "style"];
|
|
9
|
+
import { Skeleton } from 'antd';
|
|
9
10
|
import { css } from 'antd-style';
|
|
10
|
-
import { forwardRef, useState } from 'react';
|
|
11
|
+
import { forwardRef, useMemo, useState } from 'react';
|
|
11
12
|
import { Flexbox } from 'react-layout-kit';
|
|
12
13
|
import { Bar, CartesianGrid, Label, Legend, BarChart as ReChartsBarChart, ResponsiveContainer, Tooltip, XAxis, YAxis } from 'recharts';
|
|
13
14
|
import ChartLegend from "../common/ChartLegend";
|
|
14
15
|
import ChartTooltip from "../common/ChartTooltip";
|
|
16
|
+
import CustomYAxisTick from "../common/CustomYAxisTick";
|
|
15
17
|
import NoData from "../common/NoData";
|
|
16
18
|
import { constructCategoryColors, deepEqual, getYAxisDomain } from "../common/utils";
|
|
17
19
|
import { useThemeColorRange } from "../hooks/useThemeColorRange";
|
|
18
20
|
import { defaultValueFormatter } from "../utils";
|
|
21
|
+
import { getMaxLabelLength } from "../utils/getMaxLabelLength";
|
|
19
22
|
import { renderShape } from "./renderShape";
|
|
20
23
|
import { useStyles } from "./styles";
|
|
21
24
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
@@ -30,7 +33,10 @@ var BarChart = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
30
33
|
data = _props$data === void 0 ? [] : _props$data,
|
|
31
34
|
_props$categories = props.categories,
|
|
32
35
|
categories = _props$categories === void 0 ? [] : _props$categories,
|
|
36
|
+
customCategories = props.customCategories,
|
|
33
37
|
index = props.index,
|
|
38
|
+
_props$yAxisAlign = props.yAxisAlign,
|
|
39
|
+
yAxisAlign = _props$yAxisAlign === void 0 ? 'left' : _props$yAxisAlign,
|
|
34
40
|
_props$colors = props.colors,
|
|
35
41
|
colors = _props$colors === void 0 ? themeColorRange : _props$colors,
|
|
36
42
|
_props$valueFormatter = props.valueFormatter,
|
|
@@ -51,8 +57,7 @@ var BarChart = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
51
57
|
showXAxis = _props$showXAxis === void 0 ? true : _props$showXAxis,
|
|
52
58
|
_props$showYAxis = props.showYAxis,
|
|
53
59
|
showYAxis = _props$showYAxis === void 0 ? true : _props$showYAxis,
|
|
54
|
-
|
|
55
|
-
yAxisWidth = _props$yAxisWidth === void 0 ? 56 : _props$yAxisWidth,
|
|
60
|
+
yAxisWidth = props.yAxisWidth,
|
|
56
61
|
_props$intervalType = props.intervalType,
|
|
57
62
|
intervalType = _props$intervalType === void 0 ? 'equidistantPreserveStart' : _props$intervalType,
|
|
58
63
|
_props$showTooltip = props.showTooltip,
|
|
@@ -76,6 +81,7 @@ var BarChart = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
76
81
|
barCategoryGap = props.barCategoryGap,
|
|
77
82
|
_props$tickGap = props.tickGap,
|
|
78
83
|
tickGap = _props$tickGap === void 0 ? 5 : _props$tickGap,
|
|
84
|
+
loading = props.loading,
|
|
79
85
|
xAxisLabel = props.xAxisLabel,
|
|
80
86
|
yAxisLabel = props.yAxisLabel,
|
|
81
87
|
className = props.className,
|
|
@@ -85,21 +91,39 @@ var BarChart = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
85
91
|
height = _props$height === void 0 ? '20rem' : _props$height,
|
|
86
92
|
style = props.style,
|
|
87
93
|
rest = _objectWithoutProperties(props, _excluded);
|
|
88
|
-
var
|
|
89
|
-
var paddingValue = !showXAxis && !showYAxis ? 0 : 20;
|
|
90
|
-
var _useState = useState(60),
|
|
94
|
+
var _useState = useState(),
|
|
91
95
|
_useState2 = _slicedToArray(_useState, 2),
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
var categoryColors = constructCategoryColors(categories, colors);
|
|
96
|
+
activeBar = _useState2[0],
|
|
97
|
+
setActiveBar = _useState2[1];
|
|
95
98
|
var _useState3 = useState(),
|
|
96
99
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
var _useState5 = useState(),
|
|
100
|
+
activeLegend = _useState4[0],
|
|
101
|
+
setActiveLegend = _useState4[1];
|
|
102
|
+
var _useState5 = useState(60),
|
|
100
103
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
101
|
-
|
|
102
|
-
|
|
104
|
+
legendHeight = _useState6[0],
|
|
105
|
+
setLegendHeight = _useState6[1];
|
|
106
|
+
var calculatedYAxisWidth = useMemo(function () {
|
|
107
|
+
if (yAxisWidth) return yAxisWidth;
|
|
108
|
+
return getMaxLabelLength({
|
|
109
|
+
data: data,
|
|
110
|
+
index: index,
|
|
111
|
+
layout: layout,
|
|
112
|
+
relative: relative,
|
|
113
|
+
valueFormatter: valueFormatter
|
|
114
|
+
});
|
|
115
|
+
}, [yAxisWidth, layout, data, valueFormatter, relative, index]);
|
|
116
|
+
if (loading || !data) return /*#__PURE__*/_jsx(Skeleton.Button, {
|
|
117
|
+
active: true,
|
|
118
|
+
block: true,
|
|
119
|
+
style: {
|
|
120
|
+
height: height,
|
|
121
|
+
width: width
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
var CustomTooltip = customTooltip;
|
|
125
|
+
var paddingValue = !showXAxis && !showYAxis ? 0 : 20;
|
|
126
|
+
var categoryColors = constructCategoryColors(categories, colors);
|
|
103
127
|
var hasOnValueChange = !!onValueChange;
|
|
104
128
|
var onBarClick = function onBarClick(data, idx, event) {
|
|
105
129
|
event.stopPropagation();
|
|
@@ -236,13 +260,20 @@ var BarChart = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
236
260
|
hide: !showYAxis,
|
|
237
261
|
interval: "preserveStartEnd",
|
|
238
262
|
stroke: "",
|
|
239
|
-
tick: {
|
|
240
|
-
|
|
263
|
+
tick: function tick(props) {
|
|
264
|
+
return /*#__PURE__*/_jsx(CustomYAxisTick, _objectSpread(_objectSpread({}, props), {}, {
|
|
265
|
+
align: yAxisAlign,
|
|
266
|
+
formatter: function formatter(v) {
|
|
267
|
+
return v;
|
|
268
|
+
},
|
|
269
|
+
textAnchor: yAxisAlign === 'left' ? 'start' : 'end',
|
|
270
|
+
yAxisLabel: Boolean(yAxisLabel)
|
|
271
|
+
}));
|
|
241
272
|
},
|
|
242
273
|
tickLine: false,
|
|
243
274
|
ticks: startEndOnly ? [data[0][index], data.at(-1)[index]] : undefined,
|
|
244
275
|
type: "category",
|
|
245
|
-
width:
|
|
276
|
+
width: calculatedYAxisWidth,
|
|
246
277
|
children: yAxisLabel && /*#__PURE__*/_jsx(Label, {
|
|
247
278
|
angle: -90,
|
|
248
279
|
className: styles.emphasis,
|
|
@@ -263,15 +294,22 @@ var BarChart = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
263
294
|
fill: "",
|
|
264
295
|
hide: !showYAxis,
|
|
265
296
|
stroke: "",
|
|
266
|
-
tick: {
|
|
267
|
-
|
|
297
|
+
tick: function tick(props) {
|
|
298
|
+
return /*#__PURE__*/_jsx(CustomYAxisTick, _objectSpread(_objectSpread({}, props), {}, {
|
|
299
|
+
align: yAxisAlign,
|
|
300
|
+
formatter: relative ? function (value) {
|
|
301
|
+
return "".concat(Number(value) * 100, "%");
|
|
302
|
+
} : valueFormatter,
|
|
303
|
+
textAnchor: yAxisAlign === 'left' ? 'start' : 'end',
|
|
304
|
+
yAxisLabel: Boolean(yAxisLabel)
|
|
305
|
+
}));
|
|
268
306
|
},
|
|
269
307
|
tickFormatter: relative ? function (value) {
|
|
270
308
|
return "".concat((value * 100).toString(), " %");
|
|
271
309
|
} : valueFormatter,
|
|
272
310
|
tickLine: false,
|
|
273
311
|
type: "number",
|
|
274
|
-
width:
|
|
312
|
+
width: calculatedYAxisWidth,
|
|
275
313
|
children: yAxisLabel && /*#__PURE__*/_jsx(Label, {
|
|
276
314
|
angle: -90,
|
|
277
315
|
className: styles.emphasis,
|
|
@@ -291,6 +329,7 @@ var BarChart = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
291
329
|
label = _ref.label;
|
|
292
330
|
return CustomTooltip ? /*#__PURE__*/_jsx(CustomTooltip, {
|
|
293
331
|
active: active,
|
|
332
|
+
customCategories: customCategories,
|
|
294
333
|
label: label,
|
|
295
334
|
payload: payload === null || payload === void 0 ? void 0 : payload.map(function (payloadItem) {
|
|
296
335
|
var _categoryColors$get;
|
|
@@ -301,6 +340,7 @@ var BarChart = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
301
340
|
}) : /*#__PURE__*/_jsx(ChartTooltip, {
|
|
302
341
|
active: active,
|
|
303
342
|
categoryColors: categoryColors,
|
|
343
|
+
customCategories: customCategories,
|
|
304
344
|
label: label,
|
|
305
345
|
payload: payload,
|
|
306
346
|
valueFormatter: valueFormatter
|
|
@@ -323,7 +363,7 @@ var BarChart = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
323
363
|
payload: payload
|
|
324
364
|
}, categoryColors, setLegendHeight, activeLegend, hasOnValueChange ? function (clickedLegendItem) {
|
|
325
365
|
return onCategoryClick(clickedLegendItem);
|
|
326
|
-
} : undefined, enableLegendSlider);
|
|
366
|
+
} : undefined, enableLegendSlider, customCategories);
|
|
327
367
|
},
|
|
328
368
|
height: legendHeight,
|
|
329
369
|
verticalAlign: "top"
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { ValueFormatter } from "../types";
|
|
2
2
|
export interface DonutChartTooltipProps {
|
|
3
3
|
active: boolean | undefined;
|
|
4
|
+
customCategories?: {
|
|
5
|
+
[key: string]: string;
|
|
6
|
+
};
|
|
4
7
|
payload: any;
|
|
5
8
|
valueFormatter: ValueFormatter;
|
|
6
9
|
}
|
|
7
|
-
export declare const DonutChartTooltip: ({ active, payload, valueFormatter }: DonutChartTooltipProps) => import("react/jsx-runtime").JSX.Element | null;
|
|
10
|
+
export declare const DonutChartTooltip: ({ customCategories, active, payload, valueFormatter, }: DonutChartTooltipProps) => import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -4,7 +4,8 @@ import ChartTooltipFrame from "../common/ChartTooltip/ChartTooltipFrame";
|
|
|
4
4
|
import ChartTooltipRow from "../common/ChartTooltip/ChartTooltipRow";
|
|
5
5
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
6
|
export var DonutChartTooltip = function DonutChartTooltip(_ref) {
|
|
7
|
-
var
|
|
7
|
+
var customCategories = _ref.customCategories,
|
|
8
|
+
active = _ref.active,
|
|
8
9
|
payload = _ref.payload,
|
|
9
10
|
valueFormatter = _ref.valueFormatter;
|
|
10
11
|
if (active && payload !== null && payload !== void 0 && payload[0]) {
|
|
@@ -15,7 +16,7 @@ export var DonutChartTooltip = function DonutChartTooltip(_ref) {
|
|
|
15
16
|
paddingInline: 16,
|
|
16
17
|
children: /*#__PURE__*/_jsx(ChartTooltipRow, {
|
|
17
18
|
color: payloadRow.payload.color,
|
|
18
|
-
name: payloadRow.name,
|
|
19
|
+
name: (customCategories === null || customCategories === void 0 ? void 0 : customCategories[payloadRow.name]) || payloadRow.name,
|
|
19
20
|
value: valueFormatter(payloadRow.value)
|
|
20
21
|
})
|
|
21
22
|
})
|
package/es/DonutChart/index.d.ts
CHANGED
|
@@ -9,6 +9,9 @@ export interface DonutChartProps extends BaseAnimationTimingProps {
|
|
|
9
9
|
category?: string;
|
|
10
10
|
className?: string;
|
|
11
11
|
colors?: string[];
|
|
12
|
+
customCategories?: {
|
|
13
|
+
[key: string]: string;
|
|
14
|
+
};
|
|
12
15
|
customTooltip?: ComponentType<CustomTooltipProps>;
|
|
13
16
|
data: any[];
|
|
14
17
|
index?: string;
|
package/es/DonutChart/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
|
6
6
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
7
7
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
8
8
|
var _templateObject;
|
|
9
|
-
var _excluded = ["data", "category", "index", "colors", "variant", "valueFormatter", "label", "showLabel", "animationDuration", "showAnimation", "showTooltip", "noDataText", "onValueChange", "customTooltip", "className", "width", "height", "style"];
|
|
9
|
+
var _excluded = ["data", "category", "index", "colors", "variant", "valueFormatter", "label", "showLabel", "animationDuration", "showAnimation", "showTooltip", "noDataText", "onValueChange", "customTooltip", "className", "width", "height", "style", "customCategories"];
|
|
10
10
|
import { css } from 'antd-style';
|
|
11
11
|
import { forwardRef, useEffect, useState } from 'react';
|
|
12
12
|
import { Flexbox } from 'react-layout-kit';
|
|
@@ -56,6 +56,7 @@ var DonutChart = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
56
56
|
_props$height = props.height,
|
|
57
57
|
height = _props$height === void 0 ? '10rem' : _props$height,
|
|
58
58
|
style = props.style,
|
|
59
|
+
customCategories = props.customCategories,
|
|
59
60
|
rest = _objectWithoutProperties(props, _excluded);
|
|
60
61
|
var CustomTooltip = customTooltip;
|
|
61
62
|
var isDonut = variant === 'donut';
|
|
@@ -162,6 +163,7 @@ var DonutChart = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
162
163
|
payload = _ref.payload;
|
|
163
164
|
return CustomTooltip ? /*#__PURE__*/_jsx(CustomTooltip, {
|
|
164
165
|
active: active,
|
|
166
|
+
customCategories: customCategories,
|
|
165
167
|
label: payload === null || payload === void 0 || (_payload$ = payload[0]) === null || _payload$ === void 0 ? void 0 : _payload$.name,
|
|
166
168
|
payload: payload === null || payload === void 0 ? void 0 : payload.map(function (payloadItem) {
|
|
167
169
|
var _payload$0$payload$co, _payload$2;
|
|
@@ -171,6 +173,7 @@ var DonutChart = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
171
173
|
})
|
|
172
174
|
}) : /*#__PURE__*/_jsx(DonutChartTooltip, {
|
|
173
175
|
active: active,
|
|
176
|
+
customCategories: customCategories,
|
|
174
177
|
payload: payload,
|
|
175
178
|
valueFormatter: valueFormatter
|
|
176
179
|
});
|
package/es/Legend/LegendItem.js
CHANGED
|
@@ -18,7 +18,8 @@ var useStyles = createStyles(function (_ref) {
|
|
|
18
18
|
};
|
|
19
19
|
});
|
|
20
20
|
var LegendItem = /*#__PURE__*/memo(function (_ref2) {
|
|
21
|
-
var
|
|
21
|
+
var label = _ref2.label,
|
|
22
|
+
name = _ref2.name,
|
|
22
23
|
color = _ref2.color,
|
|
23
24
|
_onClick = _ref2.onClick,
|
|
24
25
|
activeLegend = _ref2.activeLegend;
|
|
@@ -58,7 +59,7 @@ var LegendItem = /*#__PURE__*/memo(function (_ref2) {
|
|
|
58
59
|
margin: 0,
|
|
59
60
|
opacity: activeLegend && activeLegend !== name ? 0.4 : 1
|
|
60
61
|
},
|
|
61
|
-
children:
|
|
62
|
+
children: label
|
|
62
63
|
})]
|
|
63
64
|
});
|
|
64
65
|
});
|
package/es/Legend/index.d.ts
CHANGED
|
@@ -4,6 +4,9 @@ export interface LegendProps extends FlexboxProps {
|
|
|
4
4
|
activeLegend?: string;
|
|
5
5
|
categories: string[];
|
|
6
6
|
colors?: string[];
|
|
7
|
+
customCategories?: {
|
|
8
|
+
[key: string]: string;
|
|
9
|
+
};
|
|
7
10
|
enableLegendSlider?: boolean;
|
|
8
11
|
onClickLegendItem?: (category: string, color: string) => void;
|
|
9
12
|
}
|
package/es/Legend/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
|
2
2
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
3
3
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
4
4
|
import _taggedTemplateLiteral from "@babel/runtime/helpers/esm/taggedTemplateLiteral";
|
|
5
|
-
var _excluded = ["categories", "colors", "className", "onClickLegendItem", "activeLegend", "enableLegendSlider"];
|
|
5
|
+
var _excluded = ["customCategories", "categories", "colors", "className", "onClickLegendItem", "activeLegend", "enableLegendSlider"];
|
|
6
6
|
var _templateObject, _templateObject2, _templateObject3;
|
|
7
7
|
import { createStyles } from 'antd-style';
|
|
8
8
|
import { ChevronLeft, ChevronRight } from 'lucide-react';
|
|
@@ -26,7 +26,8 @@ var Legend = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
26
26
|
cx = _useStyles.cx,
|
|
27
27
|
styles = _useStyles.styles;
|
|
28
28
|
var themeColorRange = useThemeColorRange();
|
|
29
|
-
var
|
|
29
|
+
var customCategories = props.customCategories,
|
|
30
|
+
categories = props.categories,
|
|
30
31
|
_props$colors = props.colors,
|
|
31
32
|
colors = _props$colors === void 0 ? themeColorRange : _props$colors,
|
|
32
33
|
className = props.className,
|
|
@@ -139,6 +140,7 @@ var Legend = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
139
140
|
return /*#__PURE__*/_jsx(LegendItem, {
|
|
140
141
|
activeLegend: activeLegend,
|
|
141
142
|
color: colors[idx % colors.length],
|
|
143
|
+
label: (customCategories === null || customCategories === void 0 ? void 0 : customCategories[category]) || category,
|
|
142
144
|
name: category,
|
|
143
145
|
onClick: onClickLegendItem
|
|
144
146
|
}, "item-".concat(idx));
|
package/es/LineChart/index.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ import { CurveType } from "../types";
|
|
|
4
4
|
export interface LineChartProps extends BaseChartProps {
|
|
5
5
|
connectNulls?: boolean;
|
|
6
6
|
curveType?: CurveType;
|
|
7
|
+
loading?: boolean;
|
|
8
|
+
yAxisAlign?: 'left' | 'right';
|
|
7
9
|
}
|
|
8
10
|
declare const LineChart: import("react").ForwardRefExoticComponent<LineChartProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
9
11
|
export default LineChart;
|
package/es/LineChart/index.js
CHANGED
|
@@ -5,17 +5,20 @@ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
|
5
5
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
6
6
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
7
7
|
var _templateObject, _templateObject2, _templateObject3;
|
|
8
|
-
var _excluded = ["data", "categories", "index", "colors", "valueFormatter", "startEndOnly", "showXAxis", "showYAxis", "yAxisWidth", "intervalType", "animationDuration", "showAnimation", "showTooltip", "showLegend", "showGridLines", "autoMinValue", "curveType", "minValue", "maxValue", "connectNulls", "allowDecimals", "noDataText", "className", "onValueChange", "enableLegendSlider", "customTooltip", "rotateLabelX", "tickGap", "xAxisLabel", "yAxisLabel", "width", "height", "style"];
|
|
8
|
+
var _excluded = ["data", "categories", "index", "colors", "valueFormatter", "startEndOnly", "showXAxis", "showYAxis", "yAxisWidth", "intervalType", "animationDuration", "showAnimation", "yAxisAlign", "showTooltip", "showLegend", "showGridLines", "autoMinValue", "curveType", "minValue", "maxValue", "connectNulls", "allowDecimals", "noDataText", "className", "onValueChange", "enableLegendSlider", "customTooltip", "rotateLabelX", "tickGap", "xAxisLabel", "yAxisLabel", "width", "height", "style", "customCategories", "loading"];
|
|
9
|
+
import { Skeleton } from 'antd';
|
|
9
10
|
import { css } from 'antd-style';
|
|
10
|
-
import { Fragment, forwardRef, useState } from 'react';
|
|
11
|
+
import { Fragment, forwardRef, useMemo, useState } from 'react';
|
|
11
12
|
import { Flexbox } from 'react-layout-kit';
|
|
12
13
|
import { CartesianGrid, Dot, Label, Legend, Line, LineChart as ReChartsLineChart, ResponsiveContainer, Tooltip, XAxis, YAxis } from 'recharts';
|
|
13
14
|
import ChartLegend from "../common/ChartLegend";
|
|
14
15
|
import ChartTooltip from "../common/ChartTooltip";
|
|
16
|
+
import CustomYAxisTick from "../common/CustomYAxisTick";
|
|
15
17
|
import NoData from "../common/NoData";
|
|
16
18
|
import { constructCategoryColors, getYAxisDomain, hasOnlyOneValueForThisKey } from "../common/utils";
|
|
17
19
|
import { useThemeColorRange } from "../hooks/useThemeColorRange";
|
|
18
20
|
import { defaultValueFormatter } from "../utils";
|
|
21
|
+
import { getMaxLabelLength } from "../utils/getMaxLabelLength";
|
|
19
22
|
import { useStyles } from "./styles";
|
|
20
23
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
21
24
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
@@ -40,14 +43,15 @@ var LineChart = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
40
43
|
showXAxis = _props$showXAxis === void 0 ? true : _props$showXAxis,
|
|
41
44
|
_props$showYAxis = props.showYAxis,
|
|
42
45
|
showYAxis = _props$showYAxis === void 0 ? true : _props$showYAxis,
|
|
43
|
-
|
|
44
|
-
yAxisWidth = _props$yAxisWidth === void 0 ? 56 : _props$yAxisWidth,
|
|
46
|
+
yAxisWidth = props.yAxisWidth,
|
|
45
47
|
_props$intervalType = props.intervalType,
|
|
46
48
|
intervalType = _props$intervalType === void 0 ? 'equidistantPreserveStart' : _props$intervalType,
|
|
47
49
|
_props$animationDurat = props.animationDuration,
|
|
48
50
|
animationDuration = _props$animationDurat === void 0 ? 900 : _props$animationDurat,
|
|
49
51
|
_props$showAnimation = props.showAnimation,
|
|
50
52
|
showAnimation = _props$showAnimation === void 0 ? false : _props$showAnimation,
|
|
53
|
+
_props$yAxisAlign = props.yAxisAlign,
|
|
54
|
+
yAxisAlign = _props$yAxisAlign === void 0 ? 'left' : _props$yAxisAlign,
|
|
51
55
|
_props$showTooltip = props.showTooltip,
|
|
52
56
|
showTooltip = _props$showTooltip === void 0 ? true : _props$showTooltip,
|
|
53
57
|
_props$showLegend = props.showLegend,
|
|
@@ -80,9 +84,9 @@ var LineChart = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
80
84
|
_props$height = props.height,
|
|
81
85
|
height = _props$height === void 0 ? '20rem' : _props$height,
|
|
82
86
|
style = props.style,
|
|
87
|
+
customCategories = props.customCategories,
|
|
88
|
+
loading = props.loading,
|
|
83
89
|
rest = _objectWithoutProperties(props, _excluded);
|
|
84
|
-
var CustomTooltip = customTooltip;
|
|
85
|
-
var paddingValue = !showXAxis && !showYAxis ? 0 : 20;
|
|
86
90
|
var _useState = useState(60),
|
|
87
91
|
_useState2 = _slicedToArray(_useState, 2),
|
|
88
92
|
legendHeight = _useState2[0],
|
|
@@ -95,6 +99,25 @@ var LineChart = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
95
99
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
96
100
|
activeLegend = _useState6[0],
|
|
97
101
|
setActiveLegend = _useState6[1];
|
|
102
|
+
var calculatedYAxisWidth = useMemo(function () {
|
|
103
|
+
if (yAxisWidth) return yAxisWidth;
|
|
104
|
+
return getMaxLabelLength({
|
|
105
|
+
data: data,
|
|
106
|
+
index: index,
|
|
107
|
+
margin: 16,
|
|
108
|
+
valueFormatter: valueFormatter
|
|
109
|
+
});
|
|
110
|
+
}, [yAxisWidth, data, valueFormatter, index]);
|
|
111
|
+
if (loading || !data) return /*#__PURE__*/_jsx(Skeleton.Button, {
|
|
112
|
+
active: true,
|
|
113
|
+
block: true,
|
|
114
|
+
style: {
|
|
115
|
+
height: height,
|
|
116
|
+
width: width
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
var CustomTooltip = customTooltip;
|
|
120
|
+
var paddingValue = !showXAxis && !showYAxis ? 0 : 20;
|
|
98
121
|
var categoryColors = constructCategoryColors(categories, colors);
|
|
99
122
|
var yAxisDomain = getYAxisDomain(autoMinValue, minValue, maxValue);
|
|
100
123
|
var hasOnValueChange = !!onValueChange;
|
|
@@ -193,13 +216,18 @@ var LineChart = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
193
216
|
fill: "",
|
|
194
217
|
hide: !showYAxis,
|
|
195
218
|
stroke: "",
|
|
196
|
-
tick: {
|
|
197
|
-
|
|
219
|
+
tick: function tick(props) {
|
|
220
|
+
return /*#__PURE__*/_jsx(CustomYAxisTick, _objectSpread(_objectSpread({}, props), {}, {
|
|
221
|
+
align: yAxisAlign,
|
|
222
|
+
formatter: valueFormatter,
|
|
223
|
+
textAnchor: yAxisAlign === 'left' ? 'start' : 'end',
|
|
224
|
+
yAxisLabel: Boolean(yAxisLabel)
|
|
225
|
+
}));
|
|
198
226
|
},
|
|
199
227
|
tickFormatter: valueFormatter,
|
|
200
228
|
tickLine: false,
|
|
201
229
|
type: "number",
|
|
202
|
-
width:
|
|
230
|
+
width: calculatedYAxisWidth,
|
|
203
231
|
children: yAxisLabel && /*#__PURE__*/_jsx(Label, {
|
|
204
232
|
angle: -90,
|
|
205
233
|
className: cx(styles.strongLabel, styles.emphasis),
|
|
@@ -217,6 +245,7 @@ var LineChart = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
217
245
|
label = _ref.label;
|
|
218
246
|
return CustomTooltip ? /*#__PURE__*/_jsx(CustomTooltip, {
|
|
219
247
|
active: active,
|
|
248
|
+
customCategories: customCategories,
|
|
220
249
|
label: label,
|
|
221
250
|
payload: payload === null || payload === void 0 ? void 0 : payload.map(function (payloadItem) {
|
|
222
251
|
var _categoryColors$get;
|
|
@@ -227,6 +256,7 @@ var LineChart = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
227
256
|
}) : /*#__PURE__*/_jsx(ChartTooltip, {
|
|
228
257
|
active: active,
|
|
229
258
|
categoryColors: categoryColors,
|
|
259
|
+
customCategories: customCategories,
|
|
230
260
|
label: label,
|
|
231
261
|
payload: payload,
|
|
232
262
|
valueFormatter: valueFormatter
|
|
@@ -250,7 +280,7 @@ var LineChart = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
250
280
|
payload: payload
|
|
251
281
|
}, categoryColors, setLegendHeight, activeLegend, hasOnValueChange ? function (clickedLegendItem) {
|
|
252
282
|
return onCategoryClick(clickedLegendItem);
|
|
253
|
-
} : undefined, enableLegendSlider);
|
|
283
|
+
} : undefined, enableLegendSlider, customCategories);
|
|
254
284
|
},
|
|
255
285
|
height: legendHeight,
|
|
256
286
|
verticalAlign: "top"
|
|
@@ -20,7 +20,8 @@ var useStyles = createStyles(function (_ref) {
|
|
|
20
20
|
});
|
|
21
21
|
var ScatterChartTooltip = /*#__PURE__*/memo(function (_ref2) {
|
|
22
22
|
var _categoryColors$get, _payload$;
|
|
23
|
-
var
|
|
23
|
+
var customCategories = _ref2.customCategories,
|
|
24
|
+
label = _ref2.label,
|
|
24
25
|
active = _ref2.active,
|
|
25
26
|
payload = _ref2.payload,
|
|
26
27
|
valueFormatter = _ref2.valueFormatter,
|
|
@@ -71,7 +72,7 @@ var ScatterChartTooltip = /*#__PURE__*/memo(function (_ref2) {
|
|
|
71
72
|
})) !== null && _Object$keys$find !== void 0 ? _Object$keys$find : '';
|
|
72
73
|
var valueFormatterFn = (_valueFormatter = valueFormatter[valueFormatterKey]) !== null && _valueFormatter !== void 0 ? _valueFormatter : defaultValueFormatter;
|
|
73
74
|
return /*#__PURE__*/_jsx(ScatterChartTooltipRow, {
|
|
74
|
-
name: name,
|
|
75
|
+
name: (customCategories === null || customCategories === void 0 ? void 0 : customCategories[name]) || name,
|
|
75
76
|
value: valueFormatter && valueFormatterFn ? valueFormatterFn(value) : "".concat(value)
|
|
76
77
|
}, "id-".concat(idx));
|
|
77
78
|
})
|
|
@@ -15,10 +15,14 @@ export interface ScatterChartProps extends BaseAnimationTimingProps, HTMLAttribu
|
|
|
15
15
|
autoMinYValue?: boolean;
|
|
16
16
|
category: string;
|
|
17
17
|
colors?: string[];
|
|
18
|
+
customCategories?: {
|
|
19
|
+
[key: string]: string;
|
|
20
|
+
};
|
|
18
21
|
customTooltip?: ComponentType<CustomTooltipProps>;
|
|
19
22
|
data: any[];
|
|
20
23
|
enableLegendSlider?: boolean;
|
|
21
24
|
intervalType?: IntervalType;
|
|
25
|
+
loading?: boolean;
|
|
22
26
|
maxXValue?: number;
|
|
23
27
|
maxYValue?: number;
|
|
24
28
|
minXValue?: number;
|
|
@@ -44,6 +48,7 @@ export interface ScatterChartProps extends BaseAnimationTimingProps, HTMLAttribu
|
|
|
44
48
|
x: string;
|
|
45
49
|
xAxisLabel?: string;
|
|
46
50
|
y: string;
|
|
51
|
+
yAxisAlign?: 'left' | 'right';
|
|
47
52
|
yAxisLabel?: string;
|
|
48
53
|
yAxisWidth?: number;
|
|
49
54
|
}
|
package/es/ScatterChart/index.js
CHANGED
|
@@ -5,16 +5,19 @@ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
|
5
5
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
6
6
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
7
7
|
var _templateObject, _templateObject2;
|
|
8
|
-
var _excluded = ["data", "x", "y", "size", "category", "colors", "showOpacity", "sizeRange", "valueFormatter", "startEndOnly", "showXAxis", "showYAxis", "yAxisWidth", "intervalType", "animationDuration", "showAnimation", "showTooltip", "showLegend", "showGridLines", "autoMinXValue", "minXValue", "maxXValue", "autoMinYValue", "minYValue", "maxYValue", "allowDecimals", "noDataText", "onValueChange", "customTooltip", "rotateLabelX", "className", "enableLegendSlider", "tickGap", "xAxisLabel", "yAxisLabel", "width", "height", "style"];
|
|
8
|
+
var _excluded = ["data", "x", "y", "size", "category", "colors", "showOpacity", "yAxisAlign", "sizeRange", "valueFormatter", "startEndOnly", "showXAxis", "showYAxis", "yAxisWidth", "intervalType", "animationDuration", "showAnimation", "showTooltip", "showLegend", "loading", "showGridLines", "autoMinXValue", "minXValue", "maxXValue", "autoMinYValue", "minYValue", "maxYValue", "allowDecimals", "noDataText", "onValueChange", "customTooltip", "rotateLabelX", "className", "enableLegendSlider", "tickGap", "xAxisLabel", "yAxisLabel", "width", "height", "style", "customCategories"];
|
|
9
|
+
import { Skeleton } from 'antd';
|
|
9
10
|
import { css } from 'antd-style';
|
|
10
|
-
import { forwardRef, useState } from 'react';
|
|
11
|
+
import { forwardRef, useMemo, useState } from 'react';
|
|
11
12
|
import { Flexbox } from 'react-layout-kit';
|
|
12
13
|
import { CartesianGrid, Label, Legend, ScatterChart as ReChartsScatterChart, ResponsiveContainer, Scatter, Tooltip, XAxis, YAxis, ZAxis } from 'recharts';
|
|
13
14
|
import { renderShape } from "./renderShape";
|
|
14
15
|
import ChartLegend from "../common/ChartLegend";
|
|
16
|
+
import CustomYAxisTick from "../common/CustomYAxisTick";
|
|
15
17
|
import { constructCategories, constructCategoryColors, deepEqual, getYAxisDomain } from "../common/utils";
|
|
16
18
|
import { useThemeColorRange } from "../hooks/useThemeColorRange";
|
|
17
19
|
import { defaultValueFormatter } from "../utils";
|
|
20
|
+
import { getMaxLabelLength } from "../utils/getMaxLabelLength";
|
|
18
21
|
import NoData from "../common/NoData";
|
|
19
22
|
import ScatterChartTooltip from "./ScatterChartTooltip";
|
|
20
23
|
import { useStyles } from "./styles";
|
|
@@ -36,6 +39,8 @@ var ScatterChart = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
36
39
|
colors = _props$colors === void 0 ? themeColorRange : _props$colors,
|
|
37
40
|
_props$showOpacity = props.showOpacity,
|
|
38
41
|
showOpacity = _props$showOpacity === void 0 ? false : _props$showOpacity,
|
|
42
|
+
_props$yAxisAlign = props.yAxisAlign,
|
|
43
|
+
yAxisAlign = _props$yAxisAlign === void 0 ? 'left' : _props$yAxisAlign,
|
|
39
44
|
_props$sizeRange = props.sizeRange,
|
|
40
45
|
sizeRange = _props$sizeRange === void 0 ? [1, 1000] : _props$sizeRange,
|
|
41
46
|
_props$valueFormatter = props.valueFormatter,
|
|
@@ -50,8 +55,7 @@ var ScatterChart = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
50
55
|
showXAxis = _props$showXAxis === void 0 ? true : _props$showXAxis,
|
|
51
56
|
_props$showYAxis = props.showYAxis,
|
|
52
57
|
showYAxis = _props$showYAxis === void 0 ? true : _props$showYAxis,
|
|
53
|
-
|
|
54
|
-
yAxisWidth = _props$yAxisWidth === void 0 ? 56 : _props$yAxisWidth,
|
|
58
|
+
yAxisWidth = props.yAxisWidth,
|
|
55
59
|
_props$intervalType = props.intervalType,
|
|
56
60
|
intervalType = _props$intervalType === void 0 ? 'equidistantPreserveStart' : _props$intervalType,
|
|
57
61
|
_props$animationDurat = props.animationDuration,
|
|
@@ -62,6 +66,7 @@ var ScatterChart = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
62
66
|
showTooltip = _props$showTooltip === void 0 ? true : _props$showTooltip,
|
|
63
67
|
_props$showLegend = props.showLegend,
|
|
64
68
|
showLegend = _props$showLegend === void 0 ? true : _props$showLegend,
|
|
69
|
+
loading = props.loading,
|
|
65
70
|
_props$showGridLines = props.showGridLines,
|
|
66
71
|
showGridLines = _props$showGridLines === void 0 ? true : _props$showGridLines,
|
|
67
72
|
_props$autoMinXValue = props.autoMinXValue,
|
|
@@ -90,8 +95,8 @@ var ScatterChart = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
90
95
|
_props$height = props.height,
|
|
91
96
|
height = _props$height === void 0 ? '20rem' : _props$height,
|
|
92
97
|
style = props.style,
|
|
98
|
+
customCategories = props.customCategories,
|
|
93
99
|
rest = _objectWithoutProperties(props, _excluded);
|
|
94
|
-
var CustomTooltip = customTooltip;
|
|
95
100
|
var _useState = useState(60),
|
|
96
101
|
_useState2 = _slicedToArray(_useState, 2),
|
|
97
102
|
legendHeight = _useState2[0],
|
|
@@ -104,6 +109,25 @@ var ScatterChart = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
104
109
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
105
110
|
activeLegend = _useState6[0],
|
|
106
111
|
setActiveLegend = _useState6[1];
|
|
112
|
+
var calculatedYAxisWidth = useMemo(function () {
|
|
113
|
+
if (yAxisWidth) return yAxisWidth;
|
|
114
|
+
return getMaxLabelLength({
|
|
115
|
+
data: data,
|
|
116
|
+
index: y,
|
|
117
|
+
isScatterChart: true,
|
|
118
|
+
margin: 0,
|
|
119
|
+
valueFormatter: valueFormatter === null || valueFormatter === void 0 ? void 0 : valueFormatter.y
|
|
120
|
+
});
|
|
121
|
+
}, [yAxisWidth, data, valueFormatter, y]);
|
|
122
|
+
if (loading || !data) return /*#__PURE__*/_jsx(Skeleton.Button, {
|
|
123
|
+
active: true,
|
|
124
|
+
block: true,
|
|
125
|
+
style: {
|
|
126
|
+
height: height,
|
|
127
|
+
width: width
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
var CustomTooltip = customTooltip;
|
|
107
131
|
var hasOnValueChange = !!onValueChange;
|
|
108
132
|
var onNodeClick = function onNodeClick(data, index, event) {
|
|
109
133
|
event.stopPropagation();
|
|
@@ -206,13 +230,18 @@ var ScatterChart = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
206
230
|
hide: !showYAxis,
|
|
207
231
|
name: y,
|
|
208
232
|
stroke: "",
|
|
209
|
-
tick: {
|
|
210
|
-
|
|
233
|
+
tick: function tick(props) {
|
|
234
|
+
return /*#__PURE__*/_jsx(CustomYAxisTick, _objectSpread(_objectSpread({}, props), {}, {
|
|
235
|
+
align: yAxisAlign,
|
|
236
|
+
formatter: valueFormatter.y,
|
|
237
|
+
textAnchor: yAxisAlign === 'left' ? 'start' : 'end',
|
|
238
|
+
yAxisLabel: Boolean(yAxisLabel)
|
|
239
|
+
}));
|
|
211
240
|
},
|
|
212
241
|
tickFormatter: valueFormatter.y,
|
|
213
242
|
tickLine: false,
|
|
214
243
|
type: "number",
|
|
215
|
-
width:
|
|
244
|
+
width: calculatedYAxisWidth,
|
|
216
245
|
children: yAxisLabel && /*#__PURE__*/_jsx(Label, {
|
|
217
246
|
angle: -90,
|
|
218
247
|
className: cx(styles.strongLabel, styles.emphasis),
|
|
@@ -232,6 +261,7 @@ var ScatterChart = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
232
261
|
var color = category ? payload === null || payload === void 0 || (_payload$ = payload[0]) === null || _payload$ === void 0 || (_payload$ = _payload$.payload) === null || _payload$ === void 0 ? void 0 : _payload$[category] : label;
|
|
233
262
|
return CustomTooltip ? /*#__PURE__*/_jsx(CustomTooltip, {
|
|
234
263
|
active: active,
|
|
264
|
+
customCategories: customCategories,
|
|
235
265
|
label: color,
|
|
236
266
|
payload: payload === null || payload === void 0 ? void 0 : payload.map(function (payloadItem) {
|
|
237
267
|
var _categoryColors$get;
|
|
@@ -248,6 +278,7 @@ var ScatterChart = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
248
278
|
},
|
|
249
279
|
category: category,
|
|
250
280
|
categoryColors: categoryColors,
|
|
281
|
+
customCategories: customCategories,
|
|
251
282
|
label: color,
|
|
252
283
|
payload: payload,
|
|
253
284
|
valueFormatter: valueFormatter
|
|
@@ -293,7 +324,7 @@ var ScatterChart = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
293
324
|
payload: payload
|
|
294
325
|
}, categoryColors, setLegendHeight, activeLegend, hasOnValueChange ? function (clickedLegendItem) {
|
|
295
326
|
return onCategoryClick(clickedLegendItem);
|
|
296
|
-
} : undefined, enableLegendSlider);
|
|
327
|
+
} : undefined, enableLegendSlider, customCategories);
|
|
297
328
|
},
|
|
298
329
|
height: legendHeight,
|
|
299
330
|
verticalAlign: "top"
|
|
@@ -4,7 +4,8 @@ import _taggedTemplateLiteral from "@babel/runtime/helpers/esm/taggedTemplateLit
|
|
|
4
4
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
5
5
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
6
6
|
var _templateObject, _templateObject2, _templateObject3;
|
|
7
|
-
var _excluded = ["data", "categories", "index", "stack", "colors", "showAnimation", "animationDuration", "showGradient", "curveType", "connectNulls", "noDataText", "autoMinValue", "minValue", "maxValue", "className", "width", "height", "style"];
|
|
7
|
+
var _excluded = ["data", "categories", "index", "stack", "colors", "showAnimation", "animationDuration", "showGradient", "curveType", "connectNulls", "noDataText", "autoMinValue", "loading", "minValue", "maxValue", "className", "width", "height", "style"];
|
|
8
|
+
import { Skeleton } from 'antd';
|
|
8
9
|
import { css } from 'antd-style';
|
|
9
10
|
import { forwardRef } from 'react';
|
|
10
11
|
import { Flexbox } from 'react-layout-kit';
|
|
@@ -43,6 +44,7 @@ var SparkAreaChart = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
43
44
|
noDataText = _props$noDataText === void 0 ? /*#__PURE__*/_jsx("div", {}) : _props$noDataText,
|
|
44
45
|
_props$autoMinValue = props.autoMinValue,
|
|
45
46
|
autoMinValue = _props$autoMinValue === void 0 ? false : _props$autoMinValue,
|
|
47
|
+
loading = props.loading,
|
|
46
48
|
minValue = props.minValue,
|
|
47
49
|
maxValue = props.maxValue,
|
|
48
50
|
className = props.className,
|
|
@@ -52,6 +54,14 @@ var SparkAreaChart = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
52
54
|
height = _props$height === void 0 ? 48 : _props$height,
|
|
53
55
|
style = props.style,
|
|
54
56
|
rest = _objectWithoutProperties(props, _excluded);
|
|
57
|
+
if (loading || !data) return /*#__PURE__*/_jsx(Skeleton.Button, {
|
|
58
|
+
active: true,
|
|
59
|
+
block: true,
|
|
60
|
+
style: {
|
|
61
|
+
height: height,
|
|
62
|
+
width: width
|
|
63
|
+
}
|
|
64
|
+
});
|
|
55
65
|
var categoryColors = constructCategoryColors(categories, colors);
|
|
56
66
|
var yAxisDomain = getYAxisDomain(autoMinValue, minValue, maxValue);
|
|
57
67
|
return /*#__PURE__*/_jsx(Flexbox, _objectSpread(_objectSpread({
|
|
@@ -4,7 +4,8 @@ import _taggedTemplateLiteral from "@babel/runtime/helpers/esm/taggedTemplateLit
|
|
|
4
4
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
5
5
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
6
6
|
var _templateObject;
|
|
7
|
-
var _excluded = ["data", "categories", "index", "colors", "stack", "relative", "animationDuration", "showAnimation", "noDataText", "autoMinValue", "minValue", "maxValue", "className", "width", "height", "style"];
|
|
7
|
+
var _excluded = ["data", "categories", "index", "colors", "stack", "relative", "animationDuration", "showAnimation", "noDataText", "loading", "autoMinValue", "minValue", "maxValue", "className", "width", "height", "style"];
|
|
8
|
+
import { Skeleton } from 'antd';
|
|
8
9
|
import { css } from 'antd-style';
|
|
9
10
|
import { forwardRef } from 'react';
|
|
10
11
|
import { Flexbox } from 'react-layout-kit';
|
|
@@ -37,6 +38,7 @@ var SparkBarChart = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
37
38
|
showAnimation = _props$showAnimation === void 0 ? false : _props$showAnimation,
|
|
38
39
|
_props$noDataText = props.noDataText,
|
|
39
40
|
noDataText = _props$noDataText === void 0 ? /*#__PURE__*/_jsx("div", {}) : _props$noDataText,
|
|
41
|
+
loading = props.loading,
|
|
40
42
|
_props$autoMinValue = props.autoMinValue,
|
|
41
43
|
autoMinValue = _props$autoMinValue === void 0 ? false : _props$autoMinValue,
|
|
42
44
|
minValue = props.minValue,
|
|
@@ -48,6 +50,14 @@ var SparkBarChart = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
48
50
|
height = _props$height === void 0 ? 48 : _props$height,
|
|
49
51
|
style = props.style,
|
|
50
52
|
rest = _objectWithoutProperties(props, _excluded);
|
|
53
|
+
if (loading || !data) return /*#__PURE__*/_jsx(Skeleton.Button, {
|
|
54
|
+
active: true,
|
|
55
|
+
block: true,
|
|
56
|
+
style: {
|
|
57
|
+
height: height,
|
|
58
|
+
width: width
|
|
59
|
+
}
|
|
60
|
+
});
|
|
51
61
|
var categoryColors = constructCategoryColors(categories, colors);
|
|
52
62
|
var yAxisDomain = getYAxisDomain(autoMinValue, minValue, maxValue);
|
|
53
63
|
return /*#__PURE__*/_jsx(Flexbox, _objectSpread(_objectSpread({
|
|
@@ -4,6 +4,7 @@ import { CurveType } from "../types";
|
|
|
4
4
|
export interface SparkLineChartProps extends BaseSparkChartProps {
|
|
5
5
|
connectNulls?: boolean;
|
|
6
6
|
curveType?: CurveType;
|
|
7
|
+
loading?: boolean;
|
|
7
8
|
}
|
|
8
9
|
declare const SparkLineChart: import("react").ForwardRefExoticComponent<SparkLineChartProps & import("react").RefAttributes<HTMLDivElement>>;
|
|
9
10
|
export default SparkLineChart;
|
|
@@ -4,7 +4,8 @@ import _taggedTemplateLiteral from "@babel/runtime/helpers/esm/taggedTemplateLit
|
|
|
4
4
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
5
5
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
6
6
|
var _templateObject;
|
|
7
|
-
var _excluded = ["data", "categories", "index", "colors", "animationDuration", "showAnimation", "curveType", "connectNulls", "noDataText", "autoMinValue", "minValue", "maxValue", "className", "width", "height", "style"];
|
|
7
|
+
var _excluded = ["data", "categories", "index", "colors", "animationDuration", "showAnimation", "curveType", "connectNulls", "noDataText", "autoMinValue", "minValue", "maxValue", "className", "width", "height", "style", "loading"];
|
|
8
|
+
import { Skeleton } from 'antd';
|
|
8
9
|
import { css } from 'antd-style';
|
|
9
10
|
import { forwardRef } from 'react';
|
|
10
11
|
import { Flexbox } from 'react-layout-kit';
|
|
@@ -47,7 +48,16 @@ var SparkLineChart = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
47
48
|
_props$height = props.height,
|
|
48
49
|
height = _props$height === void 0 ? 48 : _props$height,
|
|
49
50
|
style = props.style,
|
|
51
|
+
loading = props.loading,
|
|
50
52
|
rest = _objectWithoutProperties(props, _excluded);
|
|
53
|
+
if (loading || !data) return /*#__PURE__*/_jsx(Skeleton.Button, {
|
|
54
|
+
active: true,
|
|
55
|
+
block: true,
|
|
56
|
+
style: {
|
|
57
|
+
height: height,
|
|
58
|
+
width: width
|
|
59
|
+
}
|
|
60
|
+
});
|
|
51
61
|
var categoryColors = constructCategoryColors(categories, colors);
|
|
52
62
|
var yAxisDomain = getYAxisDomain(autoMinValue, minValue, maxValue);
|
|
53
63
|
return /*#__PURE__*/_jsx(Flexbox, _objectSpread(_objectSpread({
|
|
@@ -16,6 +16,9 @@ interface BaseChartProps extends BaseAnimationTimingProps, HTMLAttributes<HTMLDi
|
|
|
16
16
|
autoMinValue?: boolean;
|
|
17
17
|
categories: string[];
|
|
18
18
|
colors?: string[];
|
|
19
|
+
customCategories?: {
|
|
20
|
+
[key: string]: string;
|
|
21
|
+
};
|
|
19
22
|
customTooltip?: ComponentType<CustomTooltipProps>;
|
|
20
23
|
data: any[];
|
|
21
24
|
enableLegendSlider?: boolean;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import { Dispatch, SetStateAction } from 'react';
|
|
2
|
-
declare const ChartLegend: ({ payload }: any, categoryColors: Map<string, string>, setLegendHeight: Dispatch<SetStateAction<number>>, activeLegend: string | undefined, onClick?: ((category: string, color: string) => void) | undefined, enableLegendSlider?: boolean
|
|
2
|
+
declare const ChartLegend: ({ payload }: any, categoryColors: Map<string, string>, setLegendHeight: Dispatch<SetStateAction<number>>, activeLegend: string | undefined, onClick?: ((category: string, color: string) => void) | undefined, enableLegendSlider?: boolean, customCategories?: {
|
|
3
|
+
[key: string]: string;
|
|
4
|
+
} | undefined) => import("react/jsx-runtime").JSX.Element;
|
|
3
5
|
export default ChartLegend;
|
package/es/common/ChartLegend.js
CHANGED
|
@@ -8,7 +8,7 @@ var calculateHeight = function calculateHeight(height) {
|
|
|
8
8
|
: 60;
|
|
9
9
|
}; // default height
|
|
10
10
|
|
|
11
|
-
var ChartLegend = function ChartLegend(_ref, categoryColors, setLegendHeight, activeLegend, onClick, enableLegendSlider) {
|
|
11
|
+
var ChartLegend = function ChartLegend(_ref, categoryColors, setLegendHeight, activeLegend, onClick, enableLegendSlider, customCategories) {
|
|
12
12
|
var payload = _ref.payload;
|
|
13
13
|
var legendRef = useRef(null);
|
|
14
14
|
useOnWindowResize(function () {
|
|
@@ -31,6 +31,7 @@ var ChartLegend = function ChartLegend(_ref, categoryColors, setLegendHeight, ac
|
|
|
31
31
|
colors: filteredPayload.map(function (entry) {
|
|
32
32
|
return categoryColors.get(entry.value);
|
|
33
33
|
}),
|
|
34
|
+
customCategories: customCategories,
|
|
34
35
|
enableLegendSlider: enableLegendSlider,
|
|
35
36
|
onClickLegendItem: onClick
|
|
36
37
|
})
|
|
@@ -2,9 +2,12 @@ import { ValueFormatter } from "../../types";
|
|
|
2
2
|
export interface ChartTooltipProps {
|
|
3
3
|
active: boolean | undefined;
|
|
4
4
|
categoryColors: Map<string, string>;
|
|
5
|
+
customCategories?: {
|
|
6
|
+
[key: string]: string;
|
|
7
|
+
};
|
|
5
8
|
label: string;
|
|
6
9
|
payload: any;
|
|
7
10
|
valueFormatter: ValueFormatter;
|
|
8
11
|
}
|
|
9
|
-
declare const ChartTooltip: ({ active, payload, label, categoryColors, valueFormatter, }: ChartTooltipProps) => import("react/jsx-runtime").JSX.Element | null;
|
|
12
|
+
declare const ChartTooltip: ({ active, payload, label, categoryColors, valueFormatter, customCategories, }: ChartTooltipProps) => import("react/jsx-runtime").JSX.Element | null;
|
|
10
13
|
export default ChartTooltip;
|
|
@@ -19,7 +19,8 @@ var ChartTooltip = function ChartTooltip(_ref2) {
|
|
|
19
19
|
payload = _ref2.payload,
|
|
20
20
|
label = _ref2.label,
|
|
21
21
|
categoryColors = _ref2.categoryColors,
|
|
22
|
-
valueFormatter = _ref2.valueFormatter
|
|
22
|
+
valueFormatter = _ref2.valueFormatter,
|
|
23
|
+
customCategories = _ref2.customCategories;
|
|
23
24
|
var _useStyles = useStyles(),
|
|
24
25
|
cx = _useStyles.cx,
|
|
25
26
|
theme = _useStyles.theme,
|
|
@@ -53,7 +54,7 @@ var ChartTooltip = function ChartTooltip(_ref2) {
|
|
|
53
54
|
name = _ref3.name;
|
|
54
55
|
return /*#__PURE__*/_jsx(ChartTooltipRow, {
|
|
55
56
|
color: (_categoryColors$get = categoryColors.get(name)) !== null && _categoryColors$get !== void 0 ? _categoryColors$get : theme.colorPrimary,
|
|
56
|
-
name: name,
|
|
57
|
+
name: (customCategories === null || customCategories === void 0 ? void 0 : customCategories[name]) || name,
|
|
57
58
|
value: valueFormatter(value)
|
|
58
59
|
}, "id-".concat(idx));
|
|
59
60
|
})
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { NameType, Payload } from 'recharts/types/component/DefaultTooltipContent';
|
|
2
2
|
export type CustomTooltipProps = {
|
|
3
3
|
active: boolean | undefined;
|
|
4
|
+
customCategories?: {
|
|
5
|
+
[key: string]: string;
|
|
6
|
+
};
|
|
4
7
|
label: NameType | undefined;
|
|
5
8
|
payload: Payload<string | number | (string | number)[], string | number>[] | undefined;
|
|
6
9
|
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ValueFormatter } from "../types";
|
|
3
|
+
interface CustomYAxisTickProps {
|
|
4
|
+
align: 'left' | 'right';
|
|
5
|
+
formatter: ValueFormatter;
|
|
6
|
+
payload: {
|
|
7
|
+
value: number;
|
|
8
|
+
};
|
|
9
|
+
x: number;
|
|
10
|
+
y: number;
|
|
11
|
+
yAxisLabel?: boolean;
|
|
12
|
+
}
|
|
13
|
+
declare const CustomYAxisTick: React.NamedExoticComponent<CustomYAxisTickProps>;
|
|
14
|
+
export default CustomYAxisTick;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { useTheme } from 'antd-style';
|
|
2
|
+
import React, { memo } from 'react';
|
|
3
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
|
+
var CustomYAxisTick = /*#__PURE__*/memo(function (_ref) {
|
|
5
|
+
var yAxisLabel = _ref.yAxisLabel,
|
|
6
|
+
x = _ref.x,
|
|
7
|
+
y = _ref.y,
|
|
8
|
+
payload = _ref.payload,
|
|
9
|
+
align = _ref.align,
|
|
10
|
+
formatter = _ref.formatter;
|
|
11
|
+
var theme = useTheme();
|
|
12
|
+
var yAxisLabelWidth = yAxisLabel ? 24 : 0;
|
|
13
|
+
return /*#__PURE__*/_jsx("g", {
|
|
14
|
+
transform: "translate(".concat(align === 'left' ? yAxisLabelWidth : x + yAxisLabelWidth, ",").concat(y, ")"),
|
|
15
|
+
children: /*#__PURE__*/_jsx("text", {
|
|
16
|
+
dy: 4,
|
|
17
|
+
fill: theme.colorTextDescription,
|
|
18
|
+
fontSize: 14,
|
|
19
|
+
textAnchor: align === 'left' ? 'start' : 'end',
|
|
20
|
+
x: 0,
|
|
21
|
+
y: 0,
|
|
22
|
+
children: formatter(payload.value)
|
|
23
|
+
})
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
export default CustomYAxisTick;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ValueFormatter } from "../types";
|
|
2
|
+
export declare const getTextWidth: (text: string) => number;
|
|
3
|
+
export declare const getMaxLabelLength: ({ data, valueFormatter, relative, index, layout, margin, isScatterChart, }: {
|
|
4
|
+
data: Array<Record<string, any>>;
|
|
5
|
+
index: string;
|
|
6
|
+
isScatterChart?: boolean | undefined;
|
|
7
|
+
layout?: "horizontal" | "vertical" | undefined;
|
|
8
|
+
margin?: number | undefined;
|
|
9
|
+
relative?: boolean | undefined;
|
|
10
|
+
valueFormatter?: ValueFormatter | undefined;
|
|
11
|
+
}) => number;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
|
|
2
|
+
import { defaultValueFormatter } from "./index";
|
|
3
|
+
export var getTextWidth = function getTextWidth(text) {
|
|
4
|
+
// 创建临时 span 元素
|
|
5
|
+
var span = document.createElement('span');
|
|
6
|
+
|
|
7
|
+
// 设置样式使其不可见
|
|
8
|
+
span.style.fontSize = '14px';
|
|
9
|
+
span.style.position = 'absolute';
|
|
10
|
+
span.style.visibility = 'hidden';
|
|
11
|
+
span.style.whiteSpace = 'nowrap';
|
|
12
|
+
|
|
13
|
+
// 设置文本内容
|
|
14
|
+
span.textContent = text;
|
|
15
|
+
|
|
16
|
+
// 添加到 body
|
|
17
|
+
document.body.append(span);
|
|
18
|
+
|
|
19
|
+
// 获取宽度
|
|
20
|
+
var width = span.getBoundingClientRect().width;
|
|
21
|
+
|
|
22
|
+
// 移除临时元素
|
|
23
|
+
span.remove();
|
|
24
|
+
return width;
|
|
25
|
+
};
|
|
26
|
+
export var getMaxLabelLength = function getMaxLabelLength(_ref) {
|
|
27
|
+
var data = _ref.data,
|
|
28
|
+
_ref$valueFormatter = _ref.valueFormatter,
|
|
29
|
+
valueFormatter = _ref$valueFormatter === void 0 ? defaultValueFormatter : _ref$valueFormatter,
|
|
30
|
+
relative = _ref.relative,
|
|
31
|
+
index = _ref.index,
|
|
32
|
+
_ref$layout = _ref.layout,
|
|
33
|
+
layout = _ref$layout === void 0 ? 'horizontal' : _ref$layout,
|
|
34
|
+
_ref$margin = _ref.margin,
|
|
35
|
+
margin = _ref$margin === void 0 ? 24 : _ref$margin,
|
|
36
|
+
isScatterChart = _ref.isScatterChart;
|
|
37
|
+
var maxLength = 0;
|
|
38
|
+
var maxLabel = '';
|
|
39
|
+
if (isScatterChart) {
|
|
40
|
+
var _iterator = _createForOfIteratorHelper(data),
|
|
41
|
+
_step;
|
|
42
|
+
try {
|
|
43
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
44
|
+
var item = _step.value;
|
|
45
|
+
var formattedValue = valueFormatter(item[index]);
|
|
46
|
+
if (formattedValue.length > maxLength) {
|
|
47
|
+
maxLength = formattedValue.length;
|
|
48
|
+
maxLabel = formattedValue;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
} catch (err) {
|
|
52
|
+
_iterator.e(err);
|
|
53
|
+
} finally {
|
|
54
|
+
_iterator.f();
|
|
55
|
+
}
|
|
56
|
+
} else if (layout === 'vertical') {
|
|
57
|
+
var _iterator2 = _createForOfIteratorHelper(data),
|
|
58
|
+
_step2;
|
|
59
|
+
try {
|
|
60
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
61
|
+
var _item = _step2.value;
|
|
62
|
+
if (_item[index].length > maxLength) {
|
|
63
|
+
maxLength = _item[index].length;
|
|
64
|
+
maxLabel = _item[index];
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
} catch (err) {
|
|
68
|
+
_iterator2.e(err);
|
|
69
|
+
} finally {
|
|
70
|
+
_iterator2.f();
|
|
71
|
+
}
|
|
72
|
+
} else {
|
|
73
|
+
var _iterator3 = _createForOfIteratorHelper(data),
|
|
74
|
+
_step3;
|
|
75
|
+
try {
|
|
76
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
77
|
+
var _item2 = _step3.value;
|
|
78
|
+
var categories = Object.keys(_item2).filter(function (key) {
|
|
79
|
+
return key !== index;
|
|
80
|
+
});
|
|
81
|
+
var _iterator4 = _createForOfIteratorHelper(categories),
|
|
82
|
+
_step4;
|
|
83
|
+
try {
|
|
84
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
85
|
+
var category = _step4.value;
|
|
86
|
+
var value = _item2[category];
|
|
87
|
+
if (value === undefined) continue; // Skip null or undefined values
|
|
88
|
+
var _formattedValue = relative ? "".concat((value * 100).toFixed(2), "%") : valueFormatter(value);
|
|
89
|
+
if (_formattedValue.length > maxLength) {
|
|
90
|
+
maxLength = _formattedValue.length;
|
|
91
|
+
maxLabel = _formattedValue;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
} catch (err) {
|
|
95
|
+
_iterator4.e(err);
|
|
96
|
+
} finally {
|
|
97
|
+
_iterator4.f();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
} catch (err) {
|
|
101
|
+
_iterator3.e(err);
|
|
102
|
+
} finally {
|
|
103
|
+
_iterator3.f();
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
console.log(maxLabel);
|
|
107
|
+
return getTextWidth(maxLabel) + margin;
|
|
108
|
+
};
|
package/es/utils/index.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { DeltaTypes } from "../types";
|
|
2
|
-
export var defaultValueFormatter =
|
|
3
|
-
return value.toString();
|
|
4
|
-
};
|
|
2
|
+
export var defaultValueFormatter = String;
|
|
5
3
|
export var sumNumericArray = function sumNumericArray(arr) {
|
|
6
4
|
return arr.reduce(function (prefixSum, num) {
|
|
7
5
|
return prefixSum + num;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lobehub/charts",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "React modern charts components built on recharts",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"lobehub",
|
|
@@ -83,8 +83,8 @@
|
|
|
83
83
|
"@types/query-string": "^6.3.0",
|
|
84
84
|
"@types/react": "18.2.40",
|
|
85
85
|
"@types/react-dom": "^18.3.0",
|
|
86
|
-
"@vitest/coverage-v8": "
|
|
87
|
-
"babel-plugin-antd-style": "
|
|
86
|
+
"@vitest/coverage-v8": "~1.2.2",
|
|
87
|
+
"babel-plugin-antd-style": "^1.0.4",
|
|
88
88
|
"commitlint": "^19.3.0",
|
|
89
89
|
"concurrently": "^8.2.2",
|
|
90
90
|
"cross-env": "^7.0.3",
|