@lobehub/charts 5.1.0 → 5.2.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.
@@ -2,7 +2,7 @@
2
2
 
3
3
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
4
4
  var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5;
5
- 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"];
5
+ 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", "yAxisDomain", "width", "height", "style", "customCategories"];
6
6
  function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
7
7
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
8
8
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
@@ -92,6 +92,7 @@ var AreaChart = /*#__PURE__*/forwardRef(function (props, ref) {
92
92
  loading = props.loading,
93
93
  xAxisLabel = props.xAxisLabel,
94
94
  yAxisLabel = props.yAxisLabel,
95
+ yAxisDomainOverride = props.yAxisDomain,
95
96
  _props$width = props.width,
96
97
  width = _props$width === void 0 ? '100%' : _props$width,
97
98
  _props$height = props.height,
@@ -128,7 +129,7 @@ var AreaChart = /*#__PURE__*/forwardRef(function (props, ref) {
128
129
  var CustomTooltip = customTooltip;
129
130
  var paddingValue = !showXAxis && !showYAxis || startEndOnly && !showYAxis ? 0 : 20;
130
131
  var categoryColors = constructCategoryColors(categories, colors);
131
- var yAxisDomain = getYAxisDomain(autoMinValue, minValue, maxValue);
132
+ var yAxisDomain = yAxisDomainOverride !== null && yAxisDomainOverride !== void 0 ? yAxisDomainOverride : getYAxisDomain(autoMinValue, minValue, maxValue);
132
133
  var hasOnValueChange = !!onValueChange;
133
134
  var onDotClick = function onDotClick(itemData, event) {
134
135
  event.stopPropagation();
@@ -2,7 +2,7 @@
2
2
 
3
3
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
4
4
  var _templateObject;
5
- 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"];
5
+ 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", "yAxisDomain", "className", "width", "height", "style"];
6
6
  function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
7
7
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
8
8
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
@@ -89,6 +89,7 @@ var BarChart = /*#__PURE__*/forwardRef(function (props, ref) {
89
89
  loading = props.loading,
90
90
  xAxisLabel = props.xAxisLabel,
91
91
  yAxisLabel = props.yAxisLabel,
92
+ yAxisDomainOverride = props.yAxisDomain,
92
93
  className = props.className,
93
94
  _props$width = props.width,
94
95
  width = _props$width === void 0 ? '100%' : _props$width,
@@ -161,7 +162,7 @@ var BarChart = /*#__PURE__*/forwardRef(function (props, ref) {
161
162
  }
162
163
  setActiveBar(undefined);
163
164
  };
164
- var yAxisDomain = getYAxisDomain(autoMinValue, minValue, maxValue);
165
+ var yAxisDomain = yAxisDomainOverride !== null && yAxisDomainOverride !== void 0 ? yAxisDomainOverride : getYAxisDomain(autoMinValue, minValue, maxValue);
165
166
  return /*#__PURE__*/_jsx(Flexbox, _objectSpread(_objectSpread({
166
167
  className: className,
167
168
  height: height,
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
2
  import type { ComposedChartProps } from './types';
3
- export type { ComposedChartProps, SeriesItem } from './types';
3
+ export type { ComposedChartProps, SeriesItem, YAxisConfig } from './types';
4
4
  declare const ComposedChart: import("react").ForwardRefExoticComponent<ComposedChartProps & import("react").RefAttributes<HTMLDivElement>>;
5
5
  export default ComposedChart;
@@ -188,6 +188,7 @@ var ComposedChart = /*#__PURE__*/forwardRef(function (props, ref) {
188
188
  allowDecimals: allowDecimals,
189
189
  axisLine: false,
190
190
  className: styles.label,
191
+ domain: yAxisLeft === null || yAxisLeft === void 0 ? void 0 : yAxisLeft.domain,
191
192
  fill: "",
192
193
  hide: !showYAxis,
193
194
  orientation: "left",
@@ -197,7 +198,6 @@ var ComposedChart = /*#__PURE__*/forwardRef(function (props, ref) {
197
198
  return /*#__PURE__*/_jsx(CustomYAxisTick, _objectSpread(_objectSpread({}, tickProps), {}, {
198
199
  align: "left",
199
200
  formatter: (_yAxisLeft$valueForma2 = yAxisLeft === null || yAxisLeft === void 0 ? void 0 : yAxisLeft.valueFormatter) !== null && _yAxisLeft$valueForma2 !== void 0 ? _yAxisLeft$valueForma2 : defaultValueFormatter,
200
- textAnchor: "end",
201
201
  yAxisLabel: Boolean(yAxisLeft === null || yAxisLeft === void 0 ? void 0 : yAxisLeft.label)
202
202
  }));
203
203
  },
@@ -222,6 +222,7 @@ var ComposedChart = /*#__PURE__*/forwardRef(function (props, ref) {
222
222
  allowDecimals: allowDecimals,
223
223
  axisLine: false,
224
224
  className: styles.label,
225
+ domain: yAxisRight === null || yAxisRight === void 0 ? void 0 : yAxisRight.domain,
225
226
  fill: "",
226
227
  hide: !showYAxis,
227
228
  orientation: "right",
@@ -230,8 +231,8 @@ var ComposedChart = /*#__PURE__*/forwardRef(function (props, ref) {
230
231
  var _yAxisRight$valueForm2;
231
232
  return /*#__PURE__*/_jsx(CustomYAxisTick, _objectSpread(_objectSpread({}, tickProps), {}, {
232
233
  align: "right",
234
+ anchor: "start",
233
235
  formatter: (_yAxisRight$valueForm2 = yAxisRight === null || yAxisRight === void 0 ? void 0 : yAxisRight.valueFormatter) !== null && _yAxisRight$valueForm2 !== void 0 ? _yAxisRight$valueForm2 : defaultValueFormatter,
234
- textAnchor: "start",
235
236
  yAxisLabel: Boolean(yAxisRight === null || yAxisRight === void 0 ? void 0 : yAxisRight.label)
236
237
  }));
237
238
  },
@@ -1,4 +1,5 @@
1
1
  import type { HTMLAttributes } from 'react';
2
+ import type { AxisDomain } from 'recharts/types/util/types';
2
3
  import type { NoDataProps } from "../common/NoData";
3
4
  import type { IntervalType, LabelFormatter, ValueFormatter } from "../types/charts";
4
5
  import type BaseAnimationTimingProps from '../common/BaseAnimationTimingProps';
@@ -20,6 +21,11 @@ export interface SeriesItem {
20
21
  valueFormatter?: ValueFormatter;
21
22
  }
22
23
  export interface YAxisConfig {
24
+ /**
25
+ * Forward to recharts `YAxis.domain`.
26
+ * Accepts numbers or `'auto'` / `'dataMin'` / `'dataMax'` / `'dataMin - N'` etc.
27
+ */
28
+ domain?: AxisDomain;
23
29
  /** Label string rendered alongside the axis */
24
30
  label?: string;
25
31
  /** Custom tick formatter */
@@ -2,7 +2,7 @@
2
2
 
3
3
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
4
4
  var _templateObject, _templateObject2, _templateObject3;
5
- 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"];
5
+ 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", "yAxisDomain", "width", "height", "style", "customCategories", "loading"];
6
6
  function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
7
7
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
8
8
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
@@ -87,6 +87,7 @@ var LineChart = /*#__PURE__*/forwardRef(function (props, ref) {
87
87
  tickGap = _props$tickGap === void 0 ? 5 : _props$tickGap,
88
88
  xAxisLabel = props.xAxisLabel,
89
89
  yAxisLabel = props.yAxisLabel,
90
+ yAxisDomainOverride = props.yAxisDomain,
90
91
  _props$width = props.width,
91
92
  width = _props$width === void 0 ? '100%' : _props$width,
92
93
  _props$height = props.height,
@@ -124,7 +125,7 @@ var LineChart = /*#__PURE__*/forwardRef(function (props, ref) {
124
125
  var CustomTooltip = customTooltip;
125
126
  var paddingValue = !showXAxis && !showYAxis ? 0 : 20;
126
127
  var categoryColors = constructCategoryColors(categories, colors);
127
- var yAxisDomain = getYAxisDomain(autoMinValue, minValue, maxValue);
128
+ var yAxisDomain = yAxisDomainOverride !== null && yAxisDomainOverride !== void 0 ? yAxisDomainOverride : getYAxisDomain(autoMinValue, minValue, maxValue);
128
129
  var hasOnValueChange = !!onValueChange;
129
130
  var onDotClick = function onDotClick(itemData, event) {
130
131
  event.stopPropagation();
@@ -1,4 +1,5 @@
1
1
  import { ComponentType, HTMLAttributes } from 'react';
2
+ import type { AxisDomain } from 'recharts/types/util/types';
2
3
  import type { NoDataProps } from "./NoData";
3
4
  import { IntervalType, LabelFormatter, ValueFormatter } from "../types/charts";
4
5
  import type BaseAnimationTimingProps from './BaseAnimationTimingProps';
@@ -47,6 +48,10 @@ interface BaseChartProps extends BaseAnimationTimingProps, HTMLAttributes<HTMLDi
47
48
  xAxisLabel?: string;
48
49
  xAxisLabelFormatter?: LabelFormatter;
49
50
  yAxisAlign?: 'left' | 'right';
51
+ /**
52
+ * Forward to recharts `YAxis.domain`. When set, overrides `autoMinValue` / `minValue` / `maxValue`.
53
+ */
54
+ yAxisDomain?: AxisDomain;
50
55
  yAxisLabel?: string;
51
56
  yAxisWidth?: number;
52
57
  }
@@ -2,6 +2,7 @@ import React from 'react';
2
2
  import { ValueFormatter } from "../types/charts";
3
3
  interface CustomYAxisTickProps {
4
4
  align: 'left' | 'right';
5
+ anchor?: 'end' | 'middle' | 'start';
5
6
  formatter: ValueFormatter;
6
7
  payload: {
7
8
  value: number;
@@ -7,15 +7,17 @@ var CustomYAxisTick = /*#__PURE__*/memo(function (_ref) {
7
7
  y = _ref.y,
8
8
  payload = _ref.payload,
9
9
  align = _ref.align,
10
- formatter = _ref.formatter;
10
+ formatter = _ref.formatter,
11
+ anchor = _ref.anchor;
11
12
  var yAxisLabelWidth = yAxisLabel ? 24 : 0;
13
+ var resolvedTextAnchor = anchor !== null && anchor !== void 0 ? anchor : align === 'left' ? 'start' : 'end';
12
14
  return /*#__PURE__*/_jsx("g", {
13
15
  transform: "translate(".concat(align === 'left' ? yAxisLabelWidth : x + yAxisLabelWidth, ",").concat(y, ")"),
14
16
  children: /*#__PURE__*/_jsx("text", {
15
17
  dy: 4,
16
18
  fill: cssVar.colorTextDescription,
17
19
  fontSize: 12,
18
- textAnchor: align === 'left' ? 'start' : 'end',
20
+ textAnchor: resolvedTextAnchor,
19
21
  x: 0,
20
22
  y: 0,
21
23
  children: formatter(payload.value)
package/es/index.d.ts CHANGED
@@ -5,7 +5,7 @@ export { type Bar, default as BarList, type BarListProps } from './BarList';
5
5
  export { default as ChartTooltip, type ChartTooltipProps } from './common/ChartTooltip';
6
6
  export { default as ChartTooltipFrame } from './common/ChartTooltip/ChartTooltipFrame';
7
7
  export { default as ChartTooltipRow } from './common/ChartTooltip/ChartTooltipRow';
8
- export { default as ComposedChart, type ComposedChartProps, type SeriesItem } from './ComposedChart';
8
+ export { default as ComposedChart, type ComposedChartProps, type SeriesItem, type YAxisConfig, } from './ComposedChart';
9
9
  export * from './DataBars';
10
10
  export { default as DonutChart, type DonutChartProps } from './DonutChart';
11
11
  export { default as FunnelChart, type FunnelChartProps } from './FunnelChart';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/charts",
3
- "version": "5.1.0",
3
+ "version": "5.2.0",
4
4
  "description": "React modern charts components built on recharts",
5
5
  "keywords": [
6
6
  "lobehub",