@lobehub/charts 1.5.0 → 1.6.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.
@@ -4,10 +4,8 @@ import { CurveType } from "../types";
4
4
  export interface AreaChartProps extends BaseChartProps {
5
5
  connectNulls?: boolean;
6
6
  curveType?: CurveType;
7
- loading?: boolean;
8
7
  showGradient?: boolean;
9
8
  stack?: boolean;
10
- yAxisAlign?: 'left' | 'right';
11
9
  }
12
10
  declare const AreaChart: import("react").ForwardRefExoticComponent<AreaChartProps & import("react").RefAttributes<HTMLDivElement>>;
13
11
  export default AreaChart;
@@ -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", "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"];
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
9
  import { Skeleton } from 'antd';
10
10
  import { css } from 'antd-style';
11
11
  import { Fragment, forwardRef, useMemo, useState } from 'react';
@@ -39,6 +39,8 @@ var AreaChart = /*#__PURE__*/forwardRef(function (props, ref) {
39
39
  colors = _props$colors === void 0 ? themeColorRange : _props$colors,
40
40
  _props$valueFormatter = props.valueFormatter,
41
41
  valueFormatter = _props$valueFormatter === void 0 ? defaultValueFormatter : _props$valueFormatter,
42
+ _props$xAxisLabelForm = props.xAxisLabelFormatter,
43
+ xAxisLabelFormatter = _props$xAxisLabelForm === void 0 ? defaultValueFormatter : _props$xAxisLabelForm,
42
44
  _props$startEndOnly = props.startEndOnly,
43
45
  startEndOnly = _props$startEndOnly === void 0 ? false : _props$startEndOnly,
44
46
  _props$showXAxis = props.showXAxis,
@@ -204,6 +206,7 @@ var AreaChart = /*#__PURE__*/forwardRef(function (props, ref) {
204
206
  tick: {
205
207
  transform: 'translate(0, 6)'
206
208
  },
209
+ tickFormatter: xAxisLabelFormatter,
207
210
  tickLine: false,
208
211
  ticks: startEndOnly ? [data[0][index], data.at(-1)[index]] : undefined,
209
212
  children: xAxisLabel && /*#__PURE__*/_jsx(Label, {
@@ -244,6 +247,7 @@ var AreaChart = /*#__PURE__*/forwardRef(function (props, ref) {
244
247
  })
245
248
  }), /*#__PURE__*/_jsx(Tooltip, {
246
249
  content: showTooltip ? function (_ref) {
250
+ var _ref2;
247
251
  var active = _ref.active,
248
252
  payload = _ref.payload,
249
253
  label = _ref.label;
@@ -251,7 +255,7 @@ var AreaChart = /*#__PURE__*/forwardRef(function (props, ref) {
251
255
  active: active,
252
256
  customCategories: customCategories,
253
257
  label: label,
254
- 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) {
255
259
  var _categoryColors$get;
256
260
  return _objectSpread(_objectSpread({}, payloadItem), {}, {
257
261
  color: (_categoryColors$get = categoryColors.get(payloadItem.dataKey)) !== null && _categoryColors$get !== void 0 ? _categoryColors$get : theme.colorPrimary
@@ -262,7 +266,7 @@ var AreaChart = /*#__PURE__*/forwardRef(function (props, ref) {
262
266
  categoryColors: categoryColors,
263
267
  customCategories: customCategories,
264
268
  label: label,
265
- payload: payload,
269
+ payload: stack ? payload === null || payload === void 0 ? void 0 : payload.reverse() : payload,
266
270
  valueFormatter: valueFormatter
267
271
  });
268
272
  } : undefined,
@@ -278,8 +282,8 @@ var AreaChart = /*#__PURE__*/forwardRef(function (props, ref) {
278
282
  outline: 'none'
279
283
  }
280
284
  }), showLegend ? /*#__PURE__*/_jsx(Legend, {
281
- content: function content(_ref2) {
282
- var payload = _ref2.payload;
285
+ content: function content(_ref3) {
286
+ var payload = _ref3.payload;
283
287
  return ChartLegend({
284
288
  payload: payload
285
289
  }, categoryColors, setLegendHeight, activeLegend, hasOnValueChange ? function (clickedLegendItem) {
@@ -3,10 +3,7 @@ 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;
7
- relative?: boolean;
8
6
  stack?: boolean;
9
- yAxisAlign?: 'left' | 'right';
10
7
  }
11
8
  declare const BarChart: import("react").ForwardRefExoticComponent<BarChartProps & import("react").RefAttributes<HTMLDivElement>>;
12
9
  export default BarChart;
@@ -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", "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"];
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
9
  import { Skeleton } from 'antd';
10
10
  import { css } from 'antd-style';
11
11
  import { forwardRef, useMemo, useState } from 'react';
@@ -41,12 +41,12 @@ var BarChart = /*#__PURE__*/forwardRef(function (props, ref) {
41
41
  colors = _props$colors === void 0 ? themeColorRange : _props$colors,
42
42
  _props$valueFormatter = props.valueFormatter,
43
43
  valueFormatter = _props$valueFormatter === void 0 ? defaultValueFormatter : _props$valueFormatter,
44
+ _props$xAxisLabelForm = props.xAxisLabelFormatter,
45
+ xAxisLabelFormatter = _props$xAxisLabelForm === void 0 ? defaultValueFormatter : _props$xAxisLabelForm,
44
46
  _props$layout = props.layout,
45
47
  layout = _props$layout === void 0 ? 'horizontal' : _props$layout,
46
48
  _props$stack = props.stack,
47
49
  stack = _props$stack === void 0 ? false : _props$stack,
48
- _props$relative = props.relative,
49
- relative = _props$relative === void 0 ? false : _props$relative,
50
50
  _props$startEndOnly = props.startEndOnly,
51
51
  startEndOnly = _props$startEndOnly === void 0 ? false : _props$startEndOnly,
52
52
  _props$animationDurat = props.animationDuration,
@@ -109,10 +109,9 @@ var BarChart = /*#__PURE__*/forwardRef(function (props, ref) {
109
109
  data: data,
110
110
  index: index,
111
111
  layout: layout,
112
- relative: relative,
113
112
  valueFormatter: valueFormatter
114
113
  });
115
- }, [yAxisWidth, layout, data, valueFormatter, relative, index]);
114
+ }, [yAxisWidth, layout, data, valueFormatter, index]);
116
115
  if (loading || !data) return /*#__PURE__*/_jsx(Skeleton.Button, {
117
116
  active: true,
118
117
  block: true,
@@ -186,7 +185,7 @@ var BarChart = /*#__PURE__*/forwardRef(function (props, ref) {
186
185
  setActiveLegend(undefined);
187
186
  onValueChange === null || onValueChange === void 0 || onValueChange(null);
188
187
  } : undefined,
189
- stackOffset: stack ? 'sign' : relative ? 'expand' : 'none',
188
+ stackOffset: stack ? 'sign' : 'none',
190
189
  children: [showGridLines ? /*#__PURE__*/_jsx(CartesianGrid, {
191
190
  className: styles.gridLines,
192
191
  horizontal: layout !== 'vertical',
@@ -239,6 +238,7 @@ var BarChart = /*#__PURE__*/forwardRef(function (props, ref) {
239
238
  tick: {
240
239
  transform: 'translate(0, 6)'
241
240
  },
241
+ tickFormatter: xAxisLabelFormatter,
242
242
  tickLine: false,
243
243
  ticks: startEndOnly ? [data[0][index], data.at(-1)[index]] : undefined,
244
244
  children: xAxisLabel && /*#__PURE__*/_jsx(Label, {
@@ -263,13 +263,12 @@ var BarChart = /*#__PURE__*/forwardRef(function (props, ref) {
263
263
  tick: function tick(props) {
264
264
  return /*#__PURE__*/_jsx(CustomYAxisTick, _objectSpread(_objectSpread({}, props), {}, {
265
265
  align: yAxisAlign,
266
- formatter: function formatter(v) {
267
- return v;
268
- },
266
+ formatter: xAxisLabelFormatter,
269
267
  textAnchor: yAxisAlign === 'left' ? 'start' : 'end',
270
268
  yAxisLabel: Boolean(yAxisLabel)
271
269
  }));
272
270
  },
271
+ tickFormatter: xAxisLabelFormatter,
273
272
  tickLine: false,
274
273
  ticks: startEndOnly ? [data[0][index], data.at(-1)[index]] : undefined,
275
274
  type: "category",
@@ -297,16 +296,12 @@ var BarChart = /*#__PURE__*/forwardRef(function (props, ref) {
297
296
  tick: function tick(props) {
298
297
  return /*#__PURE__*/_jsx(CustomYAxisTick, _objectSpread(_objectSpread({}, props), {}, {
299
298
  align: yAxisAlign,
300
- formatter: relative ? function (value) {
301
- return "".concat(Number(value) * 100, "%");
302
- } : valueFormatter,
299
+ formatter: valueFormatter,
303
300
  textAnchor: yAxisAlign === 'left' ? 'start' : 'end',
304
301
  yAxisLabel: Boolean(yAxisLabel)
305
302
  }));
306
303
  },
307
- tickFormatter: relative ? function (value) {
308
- return "".concat((value * 100).toString(), " %");
309
- } : valueFormatter,
304
+ tickFormatter: valueFormatter,
310
305
  tickLine: false,
311
306
  type: "number",
312
307
  width: calculatedYAxisWidth,
@@ -324,6 +319,7 @@ var BarChart = /*#__PURE__*/forwardRef(function (props, ref) {
324
319
  })
325
320
  }), /*#__PURE__*/_jsx(Tooltip, {
326
321
  content: showTooltip ? function (_ref) {
322
+ var _ref2;
327
323
  var active = _ref.active,
328
324
  payload = _ref.payload,
329
325
  label = _ref.label;
@@ -331,7 +327,7 @@ var BarChart = /*#__PURE__*/forwardRef(function (props, ref) {
331
327
  active: active,
332
328
  customCategories: customCategories,
333
329
  label: label,
334
- 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) {
335
331
  var _categoryColors$get;
336
332
  return _objectSpread(_objectSpread({}, payloadItem), {}, {
337
333
  color: (_categoryColors$get = categoryColors.get(payloadItem.dataKey)) !== null && _categoryColors$get !== void 0 ? _categoryColors$get : theme.colorPrimary
@@ -342,7 +338,7 @@ var BarChart = /*#__PURE__*/forwardRef(function (props, ref) {
342
338
  categoryColors: categoryColors,
343
339
  customCategories: customCategories,
344
340
  label: label,
345
- payload: payload,
341
+ payload: stack ? payload === null || payload === void 0 ? void 0 : payload.reverse() : payload,
346
342
  valueFormatter: valueFormatter
347
343
  });
348
344
  } : undefined,
@@ -357,8 +353,8 @@ var BarChart = /*#__PURE__*/forwardRef(function (props, ref) {
357
353
  outline: 'none'
358
354
  }
359
355
  }), showLegend ? /*#__PURE__*/_jsx(Legend, {
360
- content: function content(_ref2) {
361
- var payload = _ref2.payload;
356
+ content: function content(_ref3) {
357
+ var payload = _ref3.payload;
362
358
  return ChartLegend({
363
359
  payload: payload
364
360
  }, categoryColors, setLegendHeight, activeLegend, hasOnValueChange ? function (clickedLegendItem) {
@@ -380,7 +376,7 @@ var BarChart = /*#__PURE__*/forwardRef(function (props, ref) {
380
376
  shape: function shape(props) {
381
377
  return renderShape(props, activeBar, activeLegend, layout);
382
378
  },
383
- stackId: stack || relative ? 'a' : undefined,
379
+ stackId: stack ? 'a' : undefined,
384
380
  style: {
385
381
  cursor: onValueChange ? 'pointer' : undefined
386
382
  },
@@ -4,8 +4,6 @@ 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';
9
7
  }
10
8
  declare const LineChart: import("react").ForwardRefExoticComponent<LineChartProps & import("react").RefAttributes<HTMLDivElement>>;
11
9
  export default LineChart;
@@ -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", "yAxisAlign", "showTooltip", "showLegend", "showGridLines", "autoMinValue", "curveType", "minValue", "maxValue", "connectNulls", "allowDecimals", "noDataText", "className", "onValueChange", "enableLegendSlider", "customTooltip", "rotateLabelX", "tickGap", "xAxisLabel", "yAxisLabel", "width", "height", "style", "customCategories", "loading"];
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
9
  import { Skeleton } from 'antd';
10
10
  import { css } from 'antd-style';
11
11
  import { Fragment, forwardRef, useMemo, useState } from 'react';
@@ -37,6 +37,8 @@ var LineChart = /*#__PURE__*/forwardRef(function (props, ref) {
37
37
  colors = _props$colors === void 0 ? themeColorRange : _props$colors,
38
38
  _props$valueFormatter = props.valueFormatter,
39
39
  valueFormatter = _props$valueFormatter === void 0 ? defaultValueFormatter : _props$valueFormatter,
40
+ _props$xAxisLabelForm = props.xAxisLabelFormatter,
41
+ xAxisLabelFormatter = _props$xAxisLabelForm === void 0 ? defaultValueFormatter : _props$xAxisLabelForm,
40
42
  _props$startEndOnly = props.startEndOnly,
41
43
  startEndOnly = _props$startEndOnly === void 0 ? false : _props$startEndOnly,
42
44
  _props$showXAxis = props.showXAxis,
@@ -200,6 +202,7 @@ var LineChart = /*#__PURE__*/forwardRef(function (props, ref) {
200
202
  tick: {
201
203
  transform: 'translate(0, 6)'
202
204
  },
205
+ tickFormatter: xAxisLabelFormatter,
203
206
  tickLine: false,
204
207
  ticks: startEndOnly ? [data[0][index], data.at(-1)[index]] : undefined,
205
208
  children: xAxisLabel && /*#__PURE__*/_jsx(Label, {
@@ -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
  }
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;
@@ -1,11 +1,10 @@
1
1
  import { ValueFormatter } from "../types";
2
2
  export declare const getTextWidth: (text: string) => number;
3
- export declare const getMaxLabelLength: ({ data, valueFormatter, relative, index, layout, margin, isScatterChart, }: {
3
+ export declare const getMaxLabelLength: ({ data, valueFormatter, index, layout, margin, isScatterChart, }: {
4
4
  data: Array<Record<string, any>>;
5
5
  index: string;
6
6
  isScatterChart?: boolean | undefined;
7
7
  layout?: "horizontal" | "vertical" | undefined;
8
8
  margin?: number | undefined;
9
- relative?: boolean | undefined;
10
9
  valueFormatter?: ValueFormatter | undefined;
11
10
  }) => number;
@@ -27,7 +27,6 @@ export var getMaxLabelLength = function getMaxLabelLength(_ref) {
27
27
  var data = _ref.data,
28
28
  _ref$valueFormatter = _ref.valueFormatter,
29
29
  valueFormatter = _ref$valueFormatter === void 0 ? defaultValueFormatter : _ref$valueFormatter,
30
- relative = _ref.relative,
31
30
  index = _ref.index,
32
31
  _ref$layout = _ref.layout,
33
32
  layout = _ref$layout === void 0 ? 'horizontal' : _ref$layout,
@@ -85,7 +84,7 @@ export var getMaxLabelLength = function getMaxLabelLength(_ref) {
85
84
  var category = _step4.value;
86
85
  var value = _item2[category];
87
86
  if (value === undefined) continue; // Skip null or undefined values
88
- var _formattedValue = relative ? "".concat((value * 100).toFixed(2), "%") : valueFormatter(value);
87
+ var _formattedValue = valueFormatter(value);
89
88
  if (_formattedValue.length > maxLength) {
90
89
  maxLength = _formattedValue.length;
91
90
  maxLabel = _formattedValue;
@@ -103,6 +102,5 @@ export var getMaxLabelLength = function getMaxLabelLength(_ref) {
103
102
  _iterator3.f();
104
103
  }
105
104
  }
106
- console.log(maxLabel);
107
105
  return getTextWidth(maxLabel) + margin;
108
106
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/charts",
3
- "version": "1.5.0",
3
+ "version": "1.6.1",
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",