@lobehub/charts 1.3.0 → 1.4.1

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.
@@ -5,7 +5,7 @@ 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", "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", "customCategories"];
9
9
  import { css } from 'antd-style';
10
10
  import { Fragment, forwardRef, useState } from 'react';
11
11
  import { Flexbox } from 'react-layout-kit';
@@ -84,6 +84,7 @@ var AreaChart = /*#__PURE__*/forwardRef(function (props, ref) {
84
84
  _props$height = props.height,
85
85
  height = _props$height === void 0 ? '20rem' : _props$height,
86
86
  style = props.style,
87
+ customCategories = props.customCategories,
87
88
  rest = _objectWithoutProperties(props, _excluded);
88
89
  var CustomTooltip = customTooltip;
89
90
  var paddingValue = !showXAxis && !showYAxis || startEndOnly && !showYAxis ? 0 : 20;
@@ -221,6 +222,7 @@ var AreaChart = /*#__PURE__*/forwardRef(function (props, ref) {
221
222
  label = _ref.label;
222
223
  return CustomTooltip ? /*#__PURE__*/_jsx(CustomTooltip, {
223
224
  active: active,
225
+ customCategories: customCategories,
224
226
  label: label,
225
227
  payload: payload === null || payload === void 0 ? void 0 : payload.map(function (payloadItem) {
226
228
  var _categoryColors$get;
@@ -231,6 +233,7 @@ var AreaChart = /*#__PURE__*/forwardRef(function (props, ref) {
231
233
  }) : /*#__PURE__*/_jsx(ChartTooltip, {
232
234
  active: active,
233
235
  categoryColors: categoryColors,
236
+ customCategories: customCategories,
234
237
  label: label,
235
238
  payload: payload,
236
239
  valueFormatter: valueFormatter
@@ -254,7 +257,7 @@ var AreaChart = /*#__PURE__*/forwardRef(function (props, ref) {
254
257
  payload: payload
255
258
  }, categoryColors, setLegendHeight, activeLegend, hasOnValueChange ? function (clickedLegendItem) {
256
259
  return onCategoryClick(clickedLegendItem);
257
- } : undefined, enableLegendSlider);
260
+ } : undefined, enableLegendSlider, customCategories);
258
261
  },
259
262
  height: legendHeight,
260
263
  verticalAlign: "top"
@@ -5,7 +5,7 @@ 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", "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"];
9
9
  import { css } from 'antd-style';
10
10
  import { forwardRef, useState } from 'react';
11
11
  import { Flexbox } from 'react-layout-kit';
@@ -30,6 +30,7 @@ var BarChart = /*#__PURE__*/forwardRef(function (props, ref) {
30
30
  data = _props$data === void 0 ? [] : _props$data,
31
31
  _props$categories = props.categories,
32
32
  categories = _props$categories === void 0 ? [] : _props$categories,
33
+ customCategories = props.customCategories,
33
34
  index = props.index,
34
35
  _props$colors = props.colors,
35
36
  colors = _props$colors === void 0 ? themeColorRange : _props$colors,
@@ -291,6 +292,7 @@ var BarChart = /*#__PURE__*/forwardRef(function (props, ref) {
291
292
  label = _ref.label;
292
293
  return CustomTooltip ? /*#__PURE__*/_jsx(CustomTooltip, {
293
294
  active: active,
295
+ customCategories: customCategories,
294
296
  label: label,
295
297
  payload: payload === null || payload === void 0 ? void 0 : payload.map(function (payloadItem) {
296
298
  var _categoryColors$get;
@@ -301,6 +303,7 @@ var BarChart = /*#__PURE__*/forwardRef(function (props, ref) {
301
303
  }) : /*#__PURE__*/_jsx(ChartTooltip, {
302
304
  active: active,
303
305
  categoryColors: categoryColors,
306
+ customCategories: customCategories,
304
307
  label: label,
305
308
  payload: payload,
306
309
  valueFormatter: valueFormatter
@@ -323,7 +326,7 @@ var BarChart = /*#__PURE__*/forwardRef(function (props, ref) {
323
326
  payload: payload
324
327
  }, categoryColors, setLegendHeight, activeLegend, hasOnValueChange ? function (clickedLegendItem) {
325
328
  return onCategoryClick(clickedLegendItem);
326
- } : undefined, enableLegendSlider);
329
+ } : undefined, enableLegendSlider, customCategories);
327
330
  },
328
331
  height: legendHeight,
329
332
  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 active = _ref.active,
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
  })
@@ -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;
@@ -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
  });
@@ -2,6 +2,7 @@
2
2
  export interface LegendItemProps {
3
3
  activeLegend?: string;
4
4
  color: string;
5
+ label: string;
5
6
  name: string;
6
7
  onClick?: (name: string, color: string) => void;
7
8
  }
@@ -18,7 +18,8 @@ var useStyles = createStyles(function (_ref) {
18
18
  };
19
19
  });
20
20
  var LegendItem = /*#__PURE__*/memo(function (_ref2) {
21
- var name = _ref2.name,
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: name
62
+ children: label
62
63
  })]
63
64
  });
64
65
  });
@@ -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
  }
@@ -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';
@@ -22,12 +22,12 @@ var useStyles = createStyles(function (_ref) {
22
22
  };
23
23
  });
24
24
  var Legend = /*#__PURE__*/forwardRef(function (props, ref) {
25
- var _hasScroll$left, _hasScroll$right;
26
25
  var _useStyles = useStyles(),
27
26
  cx = _useStyles.cx,
28
27
  styles = _useStyles.styles;
29
28
  var themeColorRange = useThemeColorRange();
30
- var categories = props.categories,
29
+ var customCategories = props.customCategories,
30
+ categories = props.categories,
31
31
  _props$colors = props.colors,
32
32
  colors = _props$colors === void 0 ? themeColorRange : _props$colors,
33
33
  className = props.className,
@@ -117,6 +117,8 @@ var Legend = /*#__PURE__*/forwardRef(function (props, ref) {
117
117
  scrollable === null || scrollable === void 0 || scrollable.removeEventListener('keyup', keyUp);
118
118
  };
119
119
  }, [checkScroll, enableLegendSlider]);
120
+
121
+ // @ts-ignore
120
122
  return /*#__PURE__*/_jsxs(Flexbox, _objectSpread(_objectSpread({
121
123
  className: cx(styles.container, className),
122
124
  gap: 8,
@@ -138,6 +140,7 @@ var Legend = /*#__PURE__*/forwardRef(function (props, ref) {
138
140
  return /*#__PURE__*/_jsx(LegendItem, {
139
141
  activeLegend: activeLegend,
140
142
  color: colors[idx % colors.length],
143
+ label: (customCategories === null || customCategories === void 0 ? void 0 : customCategories[category]) || category,
141
144
  name: category,
142
145
  onClick: onClickLegendItem
143
146
  }, "item-".concat(idx));
@@ -152,14 +155,14 @@ var Legend = /*#__PURE__*/forwardRef(function (props, ref) {
152
155
  justify: 'center',
153
156
  ref: scrollButtonsRef,
154
157
  children: [/*#__PURE__*/_jsx(ScrollButton, {
155
- disabled: (_hasScroll$left = !(hasScroll !== null && hasScroll !== void 0 && hasScroll.left)) !== null && _hasScroll$left !== void 0 ? _hasScroll$left : true,
158
+ disabled: !(hasScroll !== null && hasScroll !== void 0 && hasScroll.left),
156
159
  icon: ChevronLeft,
157
160
  onClick: function onClick() {
158
161
  setIsKeyDowned(null);
159
162
  scrollToTest('left');
160
163
  }
161
164
  }), /*#__PURE__*/_jsx(ScrollButton, {
162
- disabled: (_hasScroll$right = !(hasScroll !== null && hasScroll !== void 0 && hasScroll.right)) !== null && _hasScroll$right !== void 0 ? _hasScroll$right : true,
165
+ disabled: !(hasScroll !== null && hasScroll !== void 0 && hasScroll.right),
163
166
  icon: ChevronRight,
164
167
  onClick: function onClick() {
165
168
  setIsKeyDowned(null);
@@ -5,7 +5,7 @@ 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", "showTooltip", "showLegend", "showGridLines", "autoMinValue", "curveType", "minValue", "maxValue", "connectNulls", "allowDecimals", "noDataText", "className", "onValueChange", "enableLegendSlider", "customTooltip", "rotateLabelX", "tickGap", "xAxisLabel", "yAxisLabel", "width", "height", "style", "customCategories"];
9
9
  import { css } from 'antd-style';
10
10
  import { Fragment, forwardRef, useState } from 'react';
11
11
  import { Flexbox } from 'react-layout-kit';
@@ -80,6 +80,7 @@ var LineChart = /*#__PURE__*/forwardRef(function (props, ref) {
80
80
  _props$height = props.height,
81
81
  height = _props$height === void 0 ? '20rem' : _props$height,
82
82
  style = props.style,
83
+ customCategories = props.customCategories,
83
84
  rest = _objectWithoutProperties(props, _excluded);
84
85
  var CustomTooltip = customTooltip;
85
86
  var paddingValue = !showXAxis && !showYAxis ? 0 : 20;
@@ -217,6 +218,7 @@ var LineChart = /*#__PURE__*/forwardRef(function (props, ref) {
217
218
  label = _ref.label;
218
219
  return CustomTooltip ? /*#__PURE__*/_jsx(CustomTooltip, {
219
220
  active: active,
221
+ customCategories: customCategories,
220
222
  label: label,
221
223
  payload: payload === null || payload === void 0 ? void 0 : payload.map(function (payloadItem) {
222
224
  var _categoryColors$get;
@@ -227,6 +229,7 @@ var LineChart = /*#__PURE__*/forwardRef(function (props, ref) {
227
229
  }) : /*#__PURE__*/_jsx(ChartTooltip, {
228
230
  active: active,
229
231
  categoryColors: categoryColors,
232
+ customCategories: customCategories,
230
233
  label: label,
231
234
  payload: payload,
232
235
  valueFormatter: valueFormatter
@@ -250,7 +253,7 @@ var LineChart = /*#__PURE__*/forwardRef(function (props, ref) {
250
253
  payload: payload
251
254
  }, categoryColors, setLegendHeight, activeLegend, hasOnValueChange ? function (clickedLegendItem) {
252
255
  return onCategoryClick(clickedLegendItem);
253
- } : undefined, enableLegendSlider);
256
+ } : undefined, enableLegendSlider, customCategories);
254
257
  },
255
258
  height: legendHeight,
256
259
  verticalAlign: "top"
@@ -5,6 +5,9 @@ export interface ScatterChartTooltipProps {
5
5
  axis: any;
6
6
  category?: string;
7
7
  categoryColors: Map<string, string>;
8
+ customCategories?: {
9
+ [key: string]: string;
10
+ };
8
11
  label: string;
9
12
  payload: any;
10
13
  valueFormatter: ScatterChartValueFormatter;
@@ -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 label = _ref2.label,
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,6 +15,9 @@ 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;
@@ -5,7 +5,7 @@ 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", "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", "customCategories"];
9
9
  import { css } from 'antd-style';
10
10
  import { forwardRef, useState } from 'react';
11
11
  import { Flexbox } from 'react-layout-kit';
@@ -90,6 +90,7 @@ var ScatterChart = /*#__PURE__*/forwardRef(function (props, ref) {
90
90
  _props$height = props.height,
91
91
  height = _props$height === void 0 ? '20rem' : _props$height,
92
92
  style = props.style,
93
+ customCategories = props.customCategories,
93
94
  rest = _objectWithoutProperties(props, _excluded);
94
95
  var CustomTooltip = customTooltip;
95
96
  var _useState = useState(60),
@@ -232,6 +233,7 @@ var ScatterChart = /*#__PURE__*/forwardRef(function (props, ref) {
232
233
  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
234
  return CustomTooltip ? /*#__PURE__*/_jsx(CustomTooltip, {
234
235
  active: active,
236
+ customCategories: customCategories,
235
237
  label: color,
236
238
  payload: payload === null || payload === void 0 ? void 0 : payload.map(function (payloadItem) {
237
239
  var _categoryColors$get;
@@ -248,6 +250,7 @@ var ScatterChart = /*#__PURE__*/forwardRef(function (props, ref) {
248
250
  },
249
251
  category: category,
250
252
  categoryColors: categoryColors,
253
+ customCategories: customCategories,
251
254
  label: color,
252
255
  payload: payload,
253
256
  valueFormatter: valueFormatter
@@ -293,7 +296,7 @@ var ScatterChart = /*#__PURE__*/forwardRef(function (props, ref) {
293
296
  payload: payload
294
297
  }, categoryColors, setLegendHeight, activeLegend, hasOnValueChange ? function (clickedLegendItem) {
295
298
  return onCategoryClick(clickedLegendItem);
296
- } : undefined, enableLegendSlider);
299
+ } : undefined, enableLegendSlider, customCategories);
297
300
  },
298
301
  height: legendHeight,
299
302
  verticalAlign: "top"
@@ -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) => import("react/jsx-runtime").JSX.Element;
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;
@@ -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
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/charts",
3
- "version": "1.3.0",
3
+ "version": "1.4.1",
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": "latest",
87
- "babel-plugin-antd-style": "latest",
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",