@lobehub/charts 1.4.1 → 1.6.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.
@@ -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", "customCategories"];
8
+ var _excluded = ["data", "categories", "index", "stack", "colors", "valueFormatter", "xAxisLabelFormatter", "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";
@@ -36,14 +39,17 @@ var AreaChart = /*#__PURE__*/forwardRef(function (props, ref) {
36
39
  colors = _props$colors === void 0 ? themeColorRange : _props$colors,
37
40
  _props$valueFormatter = props.valueFormatter,
38
41
  valueFormatter = _props$valueFormatter === void 0 ? defaultValueFormatter : _props$valueFormatter,
42
+ _props$xAxisLabelForm = props.xAxisLabelFormatter,
43
+ xAxisLabelFormatter = _props$xAxisLabelForm === void 0 ? defaultValueFormatter : _props$xAxisLabelForm,
39
44
  _props$startEndOnly = props.startEndOnly,
40
45
  startEndOnly = _props$startEndOnly === void 0 ? false : _props$startEndOnly,
41
46
  _props$showXAxis = props.showXAxis,
42
47
  showXAxis = _props$showXAxis === void 0 ? true : _props$showXAxis,
43
48
  _props$showYAxis = props.showYAxis,
44
49
  showYAxis = _props$showYAxis === void 0 ? true : _props$showYAxis,
45
- _props$yAxisWidth = props.yAxisWidth,
46
- yAxisWidth = _props$yAxisWidth === void 0 ? 56 : _props$yAxisWidth,
50
+ _props$yAxisAlign = props.yAxisAlign,
51
+ yAxisAlign = _props$yAxisAlign === void 0 ? 'left' : _props$yAxisAlign,
52
+ yAxisWidth = props.yAxisWidth,
47
53
  _props$intervalType = props.intervalType,
48
54
  intervalType = _props$intervalType === void 0 ? 'equidistantPreserveStart' : _props$intervalType,
49
55
  _props$showAnimation = props.showAnimation,
@@ -77,6 +83,7 @@ var AreaChart = /*#__PURE__*/forwardRef(function (props, ref) {
77
83
  rotateLabelX = props.rotateLabelX,
78
84
  _props$tickGap = props.tickGap,
79
85
  tickGap = _props$tickGap === void 0 ? 5 : _props$tickGap,
86
+ loading = props.loading,
80
87
  xAxisLabel = props.xAxisLabel,
81
88
  yAxisLabel = props.yAxisLabel,
82
89
  _props$width = props.width,
@@ -86,8 +93,6 @@ var AreaChart = /*#__PURE__*/forwardRef(function (props, ref) {
86
93
  style = props.style,
87
94
  customCategories = props.customCategories,
88
95
  rest = _objectWithoutProperties(props, _excluded);
89
- var CustomTooltip = customTooltip;
90
- var paddingValue = !showXAxis && !showYAxis || startEndOnly && !showYAxis ? 0 : 20;
91
96
  var _useState = useState(60),
92
97
  _useState2 = _slicedToArray(_useState, 2),
93
98
  legendHeight = _useState2[0],
@@ -100,6 +105,25 @@ var AreaChart = /*#__PURE__*/forwardRef(function (props, ref) {
100
105
  _useState6 = _slicedToArray(_useState5, 2),
101
106
  activeLegend = _useState6[0],
102
107
  setActiveLegend = _useState6[1];
108
+ var calculatedYAxisWidth = useMemo(function () {
109
+ if (yAxisWidth) return yAxisWidth;
110
+ return getMaxLabelLength({
111
+ data: data,
112
+ index: index,
113
+ margin: 16,
114
+ valueFormatter: valueFormatter
115
+ });
116
+ }, [yAxisWidth, data, valueFormatter, index]);
117
+ if (loading || !data) return /*#__PURE__*/_jsx(Skeleton.Button, {
118
+ active: true,
119
+ block: true,
120
+ style: {
121
+ height: height,
122
+ width: width
123
+ }
124
+ });
125
+ var CustomTooltip = customTooltip;
126
+ var paddingValue = !showXAxis && !showYAxis || startEndOnly && !showYAxis ? 0 : 20;
103
127
  var categoryColors = constructCategoryColors(categories, colors);
104
128
  var yAxisDomain = getYAxisDomain(autoMinValue, minValue, maxValue);
105
129
  var hasOnValueChange = !!onValueChange;
@@ -182,6 +206,7 @@ var AreaChart = /*#__PURE__*/forwardRef(function (props, ref) {
182
206
  tick: {
183
207
  transform: 'translate(0, 6)'
184
208
  },
209
+ tickFormatter: xAxisLabelFormatter,
185
210
  tickLine: false,
186
211
  ticks: startEndOnly ? [data[0][index], data.at(-1)[index]] : undefined,
187
212
  children: xAxisLabel && /*#__PURE__*/_jsx(Label, {
@@ -198,13 +223,18 @@ var AreaChart = /*#__PURE__*/forwardRef(function (props, ref) {
198
223
  fill: "",
199
224
  hide: !showYAxis,
200
225
  stroke: "",
201
- tick: {
202
- transform: 'translate(-3, 0)'
226
+ tick: function tick(props) {
227
+ return /*#__PURE__*/_jsx(CustomYAxisTick, _objectSpread(_objectSpread({}, props), {}, {
228
+ align: yAxisAlign,
229
+ formatter: valueFormatter,
230
+ textAnchor: yAxisAlign === 'left' ? 'start' : 'end',
231
+ yAxisLabel: Boolean(yAxisLabel)
232
+ }));
203
233
  },
204
234
  tickFormatter: valueFormatter,
205
235
  tickLine: false,
206
236
  type: "number",
207
- width: yAxisWidth,
237
+ width: calculatedYAxisWidth,
208
238
  children: yAxisLabel && /*#__PURE__*/_jsx(Label, {
209
239
  angle: -90,
210
240
  className: cx(styles.strongLabel, styles.emphasis),
@@ -217,6 +247,7 @@ var AreaChart = /*#__PURE__*/forwardRef(function (props, ref) {
217
247
  })
218
248
  }), /*#__PURE__*/_jsx(Tooltip, {
219
249
  content: showTooltip ? function (_ref) {
250
+ var _ref2;
220
251
  var active = _ref.active,
221
252
  payload = _ref.payload,
222
253
  label = _ref.label;
@@ -224,7 +255,7 @@ var AreaChart = /*#__PURE__*/forwardRef(function (props, ref) {
224
255
  active: active,
225
256
  customCategories: customCategories,
226
257
  label: label,
227
- payload: payload === null || payload === void 0 ? void 0 : payload.map(function (payloadItem) {
258
+ payload: (_ref2 = stack ? payload === null || payload === void 0 ? void 0 : payload.reverse() : payload) === null || _ref2 === void 0 ? void 0 : _ref2.map(function (payloadItem) {
228
259
  var _categoryColors$get;
229
260
  return _objectSpread(_objectSpread({}, payloadItem), {}, {
230
261
  color: (_categoryColors$get = categoryColors.get(payloadItem.dataKey)) !== null && _categoryColors$get !== void 0 ? _categoryColors$get : theme.colorPrimary
@@ -235,7 +266,7 @@ var AreaChart = /*#__PURE__*/forwardRef(function (props, ref) {
235
266
  categoryColors: categoryColors,
236
267
  customCategories: customCategories,
237
268
  label: label,
238
- payload: payload,
269
+ payload: stack ? payload === null || payload === void 0 ? void 0 : payload.reverse() : payload,
239
270
  valueFormatter: valueFormatter
240
271
  });
241
272
  } : undefined,
@@ -251,8 +282,8 @@ var AreaChart = /*#__PURE__*/forwardRef(function (props, ref) {
251
282
  outline: 'none'
252
283
  }
253
284
  }), showLegend ? /*#__PURE__*/_jsx(Legend, {
254
- content: function content(_ref2) {
255
- var payload = _ref2.payload;
285
+ content: function content(_ref3) {
286
+ var payload = _ref3.payload;
256
287
  return ChartLegend({
257
288
  payload: payload
258
289
  }, categoryColors, setLegendHeight, activeLegend, hasOnValueChange ? function (clickedLegendItem) {
@@ -3,7 +3,6 @@ import BaseChartProps from "../common/BaseChartProps";
3
3
  export interface BarChartProps extends BaseChartProps {
4
4
  barCategoryGap?: string | number;
5
5
  layout?: 'vertical' | 'horizontal';
6
- relative?: boolean;
7
6
  stack?: boolean;
8
7
  }
9
8
  declare const BarChart: import("react").ForwardRefExoticComponent<BarChartProps & import("react").RefAttributes<HTMLDivElement>>;
@@ -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", "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"];
8
+ var _excluded = ["data", "categories", "customCategories", "index", "yAxisAlign", "colors", "valueFormatter", "xAxisLabelFormatter", "layout", "stack", "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";
@@ -32,16 +35,18 @@ var BarChart = /*#__PURE__*/forwardRef(function (props, ref) {
32
35
  categories = _props$categories === void 0 ? [] : _props$categories,
33
36
  customCategories = props.customCategories,
34
37
  index = props.index,
38
+ _props$yAxisAlign = props.yAxisAlign,
39
+ yAxisAlign = _props$yAxisAlign === void 0 ? 'left' : _props$yAxisAlign,
35
40
  _props$colors = props.colors,
36
41
  colors = _props$colors === void 0 ? themeColorRange : _props$colors,
37
42
  _props$valueFormatter = props.valueFormatter,
38
43
  valueFormatter = _props$valueFormatter === void 0 ? defaultValueFormatter : _props$valueFormatter,
44
+ _props$xAxisLabelForm = props.xAxisLabelFormatter,
45
+ xAxisLabelFormatter = _props$xAxisLabelForm === void 0 ? defaultValueFormatter : _props$xAxisLabelForm,
39
46
  _props$layout = props.layout,
40
47
  layout = _props$layout === void 0 ? 'horizontal' : _props$layout,
41
48
  _props$stack = props.stack,
42
49
  stack = _props$stack === void 0 ? false : _props$stack,
43
- _props$relative = props.relative,
44
- relative = _props$relative === void 0 ? false : _props$relative,
45
50
  _props$startEndOnly = props.startEndOnly,
46
51
  startEndOnly = _props$startEndOnly === void 0 ? false : _props$startEndOnly,
47
52
  _props$animationDurat = props.animationDuration,
@@ -52,8 +57,7 @@ var BarChart = /*#__PURE__*/forwardRef(function (props, ref) {
52
57
  showXAxis = _props$showXAxis === void 0 ? true : _props$showXAxis,
53
58
  _props$showYAxis = props.showYAxis,
54
59
  showYAxis = _props$showYAxis === void 0 ? true : _props$showYAxis,
55
- _props$yAxisWidth = props.yAxisWidth,
56
- yAxisWidth = _props$yAxisWidth === void 0 ? 56 : _props$yAxisWidth,
60
+ yAxisWidth = props.yAxisWidth,
57
61
  _props$intervalType = props.intervalType,
58
62
  intervalType = _props$intervalType === void 0 ? 'equidistantPreserveStart' : _props$intervalType,
59
63
  _props$showTooltip = props.showTooltip,
@@ -77,6 +81,7 @@ var BarChart = /*#__PURE__*/forwardRef(function (props, ref) {
77
81
  barCategoryGap = props.barCategoryGap,
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
  className = props.className,
@@ -86,21 +91,38 @@ var BarChart = /*#__PURE__*/forwardRef(function (props, ref) {
86
91
  height = _props$height === void 0 ? '20rem' : _props$height,
87
92
  style = props.style,
88
93
  rest = _objectWithoutProperties(props, _excluded);
89
- var CustomTooltip = customTooltip;
90
- var paddingValue = !showXAxis && !showYAxis ? 0 : 20;
91
- var _useState = useState(60),
94
+ var _useState = useState(),
92
95
  _useState2 = _slicedToArray(_useState, 2),
93
- legendHeight = _useState2[0],
94
- setLegendHeight = _useState2[1];
95
- var categoryColors = constructCategoryColors(categories, colors);
96
+ activeBar = _useState2[0],
97
+ setActiveBar = _useState2[1];
96
98
  var _useState3 = useState(),
97
99
  _useState4 = _slicedToArray(_useState3, 2),
98
- activeBar = _useState4[0],
99
- setActiveBar = _useState4[1];
100
- var _useState5 = useState(),
100
+ activeLegend = _useState4[0],
101
+ setActiveLegend = _useState4[1];
102
+ var _useState5 = useState(60),
101
103
  _useState6 = _slicedToArray(_useState5, 2),
102
- activeLegend = _useState6[0],
103
- setActiveLegend = _useState6[1];
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
+ valueFormatter: valueFormatter
113
+ });
114
+ }, [yAxisWidth, layout, 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 ? 0 : 20;
125
+ var categoryColors = constructCategoryColors(categories, colors);
104
126
  var hasOnValueChange = !!onValueChange;
105
127
  var onBarClick = function onBarClick(data, idx, event) {
106
128
  event.stopPropagation();
@@ -163,7 +185,7 @@ var BarChart = /*#__PURE__*/forwardRef(function (props, ref) {
163
185
  setActiveLegend(undefined);
164
186
  onValueChange === null || onValueChange === void 0 || onValueChange(null);
165
187
  } : undefined,
166
- stackOffset: stack ? 'sign' : relative ? 'expand' : 'none',
188
+ stackOffset: stack ? 'sign' : 'none',
167
189
  children: [showGridLines ? /*#__PURE__*/_jsx(CartesianGrid, {
168
190
  className: styles.gridLines,
169
191
  horizontal: layout !== 'vertical',
@@ -216,6 +238,7 @@ var BarChart = /*#__PURE__*/forwardRef(function (props, ref) {
216
238
  tick: {
217
239
  transform: 'translate(0, 6)'
218
240
  },
241
+ tickFormatter: xAxisLabelFormatter,
219
242
  tickLine: false,
220
243
  ticks: startEndOnly ? [data[0][index], data.at(-1)[index]] : undefined,
221
244
  children: xAxisLabel && /*#__PURE__*/_jsx(Label, {
@@ -237,13 +260,19 @@ var BarChart = /*#__PURE__*/forwardRef(function (props, ref) {
237
260
  hide: !showYAxis,
238
261
  interval: "preserveStartEnd",
239
262
  stroke: "",
240
- tick: {
241
- transform: 'translate(0, 6)'
263
+ tick: function tick(props) {
264
+ return /*#__PURE__*/_jsx(CustomYAxisTick, _objectSpread(_objectSpread({}, props), {}, {
265
+ align: yAxisAlign,
266
+ formatter: xAxisLabelFormatter,
267
+ textAnchor: yAxisAlign === 'left' ? 'start' : 'end',
268
+ yAxisLabel: Boolean(yAxisLabel)
269
+ }));
242
270
  },
271
+ tickFormatter: xAxisLabelFormatter,
243
272
  tickLine: false,
244
273
  ticks: startEndOnly ? [data[0][index], data.at(-1)[index]] : undefined,
245
274
  type: "category",
246
- width: yAxisWidth,
275
+ width: calculatedYAxisWidth,
247
276
  children: yAxisLabel && /*#__PURE__*/_jsx(Label, {
248
277
  angle: -90,
249
278
  className: styles.emphasis,
@@ -264,15 +293,18 @@ var BarChart = /*#__PURE__*/forwardRef(function (props, ref) {
264
293
  fill: "",
265
294
  hide: !showYAxis,
266
295
  stroke: "",
267
- tick: {
268
- transform: 'translate(-3, 0)'
296
+ tick: function tick(props) {
297
+ return /*#__PURE__*/_jsx(CustomYAxisTick, _objectSpread(_objectSpread({}, props), {}, {
298
+ align: yAxisAlign,
299
+ formatter: valueFormatter,
300
+ textAnchor: yAxisAlign === 'left' ? 'start' : 'end',
301
+ yAxisLabel: Boolean(yAxisLabel)
302
+ }));
269
303
  },
270
- tickFormatter: relative ? function (value) {
271
- return "".concat((value * 100).toString(), " %");
272
- } : valueFormatter,
304
+ tickFormatter: valueFormatter,
273
305
  tickLine: false,
274
306
  type: "number",
275
- width: yAxisWidth,
307
+ width: calculatedYAxisWidth,
276
308
  children: yAxisLabel && /*#__PURE__*/_jsx(Label, {
277
309
  angle: -90,
278
310
  className: styles.emphasis,
@@ -287,6 +319,7 @@ var BarChart = /*#__PURE__*/forwardRef(function (props, ref) {
287
319
  })
288
320
  }), /*#__PURE__*/_jsx(Tooltip, {
289
321
  content: showTooltip ? function (_ref) {
322
+ var _ref2;
290
323
  var active = _ref.active,
291
324
  payload = _ref.payload,
292
325
  label = _ref.label;
@@ -294,7 +327,7 @@ var BarChart = /*#__PURE__*/forwardRef(function (props, ref) {
294
327
  active: active,
295
328
  customCategories: customCategories,
296
329
  label: label,
297
- payload: payload === null || payload === void 0 ? void 0 : payload.map(function (payloadItem) {
330
+ payload: (_ref2 = stack ? payload === null || payload === void 0 ? void 0 : payload.reverse() : payload) === null || _ref2 === void 0 ? void 0 : _ref2.map(function (payloadItem) {
298
331
  var _categoryColors$get;
299
332
  return _objectSpread(_objectSpread({}, payloadItem), {}, {
300
333
  color: (_categoryColors$get = categoryColors.get(payloadItem.dataKey)) !== null && _categoryColors$get !== void 0 ? _categoryColors$get : theme.colorPrimary
@@ -305,7 +338,7 @@ var BarChart = /*#__PURE__*/forwardRef(function (props, ref) {
305
338
  categoryColors: categoryColors,
306
339
  customCategories: customCategories,
307
340
  label: label,
308
- payload: payload,
341
+ payload: stack ? payload === null || payload === void 0 ? void 0 : payload.reverse() : payload,
309
342
  valueFormatter: valueFormatter
310
343
  });
311
344
  } : undefined,
@@ -320,8 +353,8 @@ var BarChart = /*#__PURE__*/forwardRef(function (props, ref) {
320
353
  outline: 'none'
321
354
  }
322
355
  }), showLegend ? /*#__PURE__*/_jsx(Legend, {
323
- content: function content(_ref2) {
324
- var payload = _ref2.payload;
356
+ content: function content(_ref3) {
357
+ var payload = _ref3.payload;
325
358
  return ChartLegend({
326
359
  payload: payload
327
360
  }, categoryColors, setLegendHeight, activeLegend, hasOnValueChange ? function (clickedLegendItem) {
@@ -343,7 +376,7 @@ var BarChart = /*#__PURE__*/forwardRef(function (props, ref) {
343
376
  shape: function shape(props) {
344
377
  return renderShape(props, activeBar, activeLegend, layout);
345
378
  },
346
- stackId: stack || relative ? 'a' : undefined,
379
+ stackId: stack ? 'a' : undefined,
347
380
  style: {
348
381
  cursor: onValueChange ? 'pointer' : undefined
349
382
  },
@@ -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", "customCategories"];
8
+ var _excluded = ["data", "categories", "index", "colors", "valueFormatter", "xAxisLabelFormatter", "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";
@@ -34,20 +37,23 @@ var LineChart = /*#__PURE__*/forwardRef(function (props, ref) {
34
37
  colors = _props$colors === void 0 ? themeColorRange : _props$colors,
35
38
  _props$valueFormatter = props.valueFormatter,
36
39
  valueFormatter = _props$valueFormatter === void 0 ? defaultValueFormatter : _props$valueFormatter,
40
+ _props$xAxisLabelForm = props.xAxisLabelFormatter,
41
+ xAxisLabelFormatter = _props$xAxisLabelForm === void 0 ? defaultValueFormatter : _props$xAxisLabelForm,
37
42
  _props$startEndOnly = props.startEndOnly,
38
43
  startEndOnly = _props$startEndOnly === void 0 ? false : _props$startEndOnly,
39
44
  _props$showXAxis = props.showXAxis,
40
45
  showXAxis = _props$showXAxis === void 0 ? true : _props$showXAxis,
41
46
  _props$showYAxis = props.showYAxis,
42
47
  showYAxis = _props$showYAxis === void 0 ? true : _props$showYAxis,
43
- _props$yAxisWidth = props.yAxisWidth,
44
- yAxisWidth = _props$yAxisWidth === void 0 ? 56 : _props$yAxisWidth,
48
+ yAxisWidth = props.yAxisWidth,
45
49
  _props$intervalType = props.intervalType,
46
50
  intervalType = _props$intervalType === void 0 ? 'equidistantPreserveStart' : _props$intervalType,
47
51
  _props$animationDurat = props.animationDuration,
48
52
  animationDuration = _props$animationDurat === void 0 ? 900 : _props$animationDurat,
49
53
  _props$showAnimation = props.showAnimation,
50
54
  showAnimation = _props$showAnimation === void 0 ? false : _props$showAnimation,
55
+ _props$yAxisAlign = props.yAxisAlign,
56
+ yAxisAlign = _props$yAxisAlign === void 0 ? 'left' : _props$yAxisAlign,
51
57
  _props$showTooltip = props.showTooltip,
52
58
  showTooltip = _props$showTooltip === void 0 ? true : _props$showTooltip,
53
59
  _props$showLegend = props.showLegend,
@@ -81,9 +87,8 @@ var LineChart = /*#__PURE__*/forwardRef(function (props, ref) {
81
87
  height = _props$height === void 0 ? '20rem' : _props$height,
82
88
  style = props.style,
83
89
  customCategories = props.customCategories,
90
+ loading = props.loading,
84
91
  rest = _objectWithoutProperties(props, _excluded);
85
- var CustomTooltip = customTooltip;
86
- var paddingValue = !showXAxis && !showYAxis ? 0 : 20;
87
92
  var _useState = useState(60),
88
93
  _useState2 = _slicedToArray(_useState, 2),
89
94
  legendHeight = _useState2[0],
@@ -96,6 +101,25 @@ var LineChart = /*#__PURE__*/forwardRef(function (props, ref) {
96
101
  _useState6 = _slicedToArray(_useState5, 2),
97
102
  activeLegend = _useState6[0],
98
103
  setActiveLegend = _useState6[1];
104
+ var calculatedYAxisWidth = useMemo(function () {
105
+ if (yAxisWidth) return yAxisWidth;
106
+ return getMaxLabelLength({
107
+ data: data,
108
+ index: index,
109
+ margin: 16,
110
+ valueFormatter: valueFormatter
111
+ });
112
+ }, [yAxisWidth, data, valueFormatter, index]);
113
+ if (loading || !data) return /*#__PURE__*/_jsx(Skeleton.Button, {
114
+ active: true,
115
+ block: true,
116
+ style: {
117
+ height: height,
118
+ width: width
119
+ }
120
+ });
121
+ var CustomTooltip = customTooltip;
122
+ var paddingValue = !showXAxis && !showYAxis ? 0 : 20;
99
123
  var categoryColors = constructCategoryColors(categories, colors);
100
124
  var yAxisDomain = getYAxisDomain(autoMinValue, minValue, maxValue);
101
125
  var hasOnValueChange = !!onValueChange;
@@ -178,6 +202,7 @@ var LineChart = /*#__PURE__*/forwardRef(function (props, ref) {
178
202
  tick: {
179
203
  transform: 'translate(0, 6)'
180
204
  },
205
+ tickFormatter: xAxisLabelFormatter,
181
206
  tickLine: false,
182
207
  ticks: startEndOnly ? [data[0][index], data.at(-1)[index]] : undefined,
183
208
  children: xAxisLabel && /*#__PURE__*/_jsx(Label, {
@@ -194,13 +219,18 @@ var LineChart = /*#__PURE__*/forwardRef(function (props, ref) {
194
219
  fill: "",
195
220
  hide: !showYAxis,
196
221
  stroke: "",
197
- tick: {
198
- transform: 'translate(-3, 0)'
222
+ tick: function tick(props) {
223
+ return /*#__PURE__*/_jsx(CustomYAxisTick, _objectSpread(_objectSpread({}, props), {}, {
224
+ align: yAxisAlign,
225
+ formatter: valueFormatter,
226
+ textAnchor: yAxisAlign === 'left' ? 'start' : 'end',
227
+ yAxisLabel: Boolean(yAxisLabel)
228
+ }));
199
229
  },
200
230
  tickFormatter: valueFormatter,
201
231
  tickLine: false,
202
232
  type: "number",
203
- width: yAxisWidth,
233
+ width: calculatedYAxisWidth,
204
234
  children: yAxisLabel && /*#__PURE__*/_jsx(Label, {
205
235
  angle: -90,
206
236
  className: cx(styles.strongLabel, styles.emphasis),
@@ -22,6 +22,7 @@ export interface ScatterChartProps extends BaseAnimationTimingProps, HTMLAttribu
22
22
  data: any[];
23
23
  enableLegendSlider?: boolean;
24
24
  intervalType?: IntervalType;
25
+ loading?: boolean;
25
26
  maxXValue?: number;
26
27
  maxYValue?: number;
27
28
  minXValue?: number;
@@ -47,6 +48,7 @@ export interface ScatterChartProps extends BaseAnimationTimingProps, HTMLAttribu
47
48
  x: string;
48
49
  xAxisLabel?: string;
49
50
  y: string;
51
+ yAxisAlign?: 'left' | 'right';
50
52
  yAxisLabel?: string;
51
53
  yAxisWidth?: number;
52
54
  }
@@ -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", "customCategories"];
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
- _props$yAxisWidth = props.yAxisWidth,
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,
@@ -92,7 +97,6 @@ var ScatterChart = /*#__PURE__*/forwardRef(function (props, ref) {
92
97
  style = props.style,
93
98
  customCategories = props.customCategories,
94
99
  rest = _objectWithoutProperties(props, _excluded);
95
- var CustomTooltip = customTooltip;
96
100
  var _useState = useState(60),
97
101
  _useState2 = _slicedToArray(_useState, 2),
98
102
  legendHeight = _useState2[0],
@@ -105,6 +109,25 @@ var ScatterChart = /*#__PURE__*/forwardRef(function (props, ref) {
105
109
  _useState6 = _slicedToArray(_useState5, 2),
106
110
  activeLegend = _useState6[0],
107
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;
108
131
  var hasOnValueChange = !!onValueChange;
109
132
  var onNodeClick = function onNodeClick(data, index, event) {
110
133
  event.stopPropagation();
@@ -207,13 +230,18 @@ var ScatterChart = /*#__PURE__*/forwardRef(function (props, ref) {
207
230
  hide: !showYAxis,
208
231
  name: y,
209
232
  stroke: "",
210
- tick: {
211
- transform: 'translate(-3, 0)'
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
+ }));
212
240
  },
213
241
  tickFormatter: valueFormatter.y,
214
242
  tickLine: false,
215
243
  type: "number",
216
- width: yAxisWidth,
244
+ width: calculatedYAxisWidth,
217
245
  children: yAxisLabel && /*#__PURE__*/_jsx(Label, {
218
246
  angle: -90,
219
247
  className: cx(styles.strongLabel, styles.emphasis),
@@ -4,6 +4,7 @@ import { CurveType } from "../types";
4
4
  export interface SparkAreaChartProps extends BaseSparkChartProps {
5
5
  connectNulls?: boolean;
6
6
  curveType?: CurveType;
7
+ loading?: boolean;
7
8
  showGradient?: boolean;
8
9
  stack?: boolean;
9
10
  }
@@ -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({
@@ -1,6 +1,7 @@
1
1
  /// <reference types="react" />
2
2
  import BaseSparkChartProps from "../common/BaseSparkChartProps";
3
3
  export interface SparkBarChartProps extends BaseSparkChartProps {
4
+ loading?: boolean;
4
5
  relative?: boolean;
5
6
  stack?: boolean;
6
7
  }
@@ -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({
@@ -1,6 +1,6 @@
1
1
  import { ComponentType, HTMLAttributes } from 'react';
2
2
  import type { NoDataProps } from "./NoData";
3
- import { IntervalType, ValueFormatter } from "../types";
3
+ import { IntervalType, LabelFormatter, ValueFormatter } from "../types";
4
4
  import type BaseAnimationTimingProps from './BaseAnimationTimingProps';
5
5
  import { CustomTooltipProps } from './CustomTooltipProps';
6
6
  type FixedProps = {
@@ -25,6 +25,7 @@ interface BaseChartProps extends BaseAnimationTimingProps, HTMLAttributes<HTMLDi
25
25
  height?: string | number;
26
26
  index: string;
27
27
  intervalType?: IntervalType;
28
+ loading?: boolean;
28
29
  maxValue?: number;
29
30
  minValue?: number;
30
31
  noDataText?: NoDataProps['noDataText'];
@@ -44,6 +45,8 @@ interface BaseChartProps extends BaseAnimationTimingProps, HTMLAttributes<HTMLDi
44
45
  valueFormatter?: ValueFormatter;
45
46
  width?: string | number;
46
47
  xAxisLabel?: string;
48
+ xAxisLabelFormatter?: LabelFormatter;
49
+ yAxisAlign?: 'left' | 'right';
47
50
  yAxisLabel?: string;
48
51
  yAxisWidth?: number;
49
52
  }
@@ -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;
package/es/types.d.ts CHANGED
@@ -37,6 +37,9 @@ export type CurveType = 'linear' | 'natural' | 'monotone' | 'step';
37
37
  export type ValueFormatter = {
38
38
  (value: number): string;
39
39
  };
40
+ export type LabelFormatter = {
41
+ (value: number | string): string;
42
+ };
40
43
  export type ScatterChartValueFormatter = {
41
44
  size?: ValueFormatter;
42
45
  x?: ValueFormatter;
@@ -0,0 +1,10 @@
1
+ import { ValueFormatter } from "../types";
2
+ export declare const getTextWidth: (text: string) => number;
3
+ export declare const getMaxLabelLength: ({ data, valueFormatter, 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
+ valueFormatter?: ValueFormatter | undefined;
10
+ }) => number;
@@ -0,0 +1,107 @@
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
+ index = _ref.index,
31
+ _ref$layout = _ref.layout,
32
+ layout = _ref$layout === void 0 ? 'horizontal' : _ref$layout,
33
+ _ref$margin = _ref.margin,
34
+ margin = _ref$margin === void 0 ? 24 : _ref$margin,
35
+ isScatterChart = _ref.isScatterChart;
36
+ var maxLength = 0;
37
+ var maxLabel = '';
38
+ if (isScatterChart) {
39
+ var _iterator = _createForOfIteratorHelper(data),
40
+ _step;
41
+ try {
42
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
43
+ var item = _step.value;
44
+ var formattedValue = valueFormatter(item[index]);
45
+ if (formattedValue.length > maxLength) {
46
+ maxLength = formattedValue.length;
47
+ maxLabel = formattedValue;
48
+ }
49
+ }
50
+ } catch (err) {
51
+ _iterator.e(err);
52
+ } finally {
53
+ _iterator.f();
54
+ }
55
+ } else if (layout === 'vertical') {
56
+ var _iterator2 = _createForOfIteratorHelper(data),
57
+ _step2;
58
+ try {
59
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
60
+ var _item = _step2.value;
61
+ if (_item[index].length > maxLength) {
62
+ maxLength = _item[index].length;
63
+ maxLabel = _item[index];
64
+ }
65
+ }
66
+ } catch (err) {
67
+ _iterator2.e(err);
68
+ } finally {
69
+ _iterator2.f();
70
+ }
71
+ } else {
72
+ var _iterator3 = _createForOfIteratorHelper(data),
73
+ _step3;
74
+ try {
75
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
76
+ var _item2 = _step3.value;
77
+ var categories = Object.keys(_item2).filter(function (key) {
78
+ return key !== index;
79
+ });
80
+ var _iterator4 = _createForOfIteratorHelper(categories),
81
+ _step4;
82
+ try {
83
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
84
+ var category = _step4.value;
85
+ var value = _item2[category];
86
+ if (value === undefined) continue; // Skip null or undefined values
87
+ var _formattedValue = valueFormatter(value);
88
+ if (_formattedValue.length > maxLength) {
89
+ maxLength = _formattedValue.length;
90
+ maxLabel = _formattedValue;
91
+ }
92
+ }
93
+ } catch (err) {
94
+ _iterator4.e(err);
95
+ } finally {
96
+ _iterator4.f();
97
+ }
98
+ }
99
+ } catch (err) {
100
+ _iterator3.e(err);
101
+ } finally {
102
+ _iterator3.f();
103
+ }
104
+ }
105
+ console.log(maxLabel);
106
+ return getTextWidth(maxLabel) + margin;
107
+ };
package/es/utils/index.js CHANGED
@@ -1,7 +1,5 @@
1
1
  import { DeltaTypes } from "../types";
2
- export var defaultValueFormatter = function defaultValueFormatter(value) {
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.4.1",
3
+ "version": "1.6.0",
4
4
  "description": "React modern charts components built on recharts",
5
5
  "keywords": [
6
6
  "lobehub",
@@ -88,6 +88,7 @@
88
88
  "commitlint": "^19.3.0",
89
89
  "concurrently": "^8.2.2",
90
90
  "cross-env": "^7.0.3",
91
+ "dayjs": "^1.11.13",
91
92
  "dumi": "2.2.17",
92
93
  "dumi-theme-lobehub": "^1.8.1",
93
94
  "eslint": "^8.57.0",