@lobehub/charts 5.0.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,
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ import type { ComposedChartProps } from './types';
3
+ export type { ComposedChartProps, SeriesItem, YAxisConfig } from './types';
4
+ declare const ComposedChart: import("react").ForwardRefExoticComponent<ComposedChartProps & import("react").RefAttributes<HTMLDivElement>>;
5
+ export default ComposedChart;
@@ -0,0 +1,334 @@
1
+ 'use client';
2
+
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
+ var _templateObject, _templateObject2;
5
+ var _excluded = ["data", "index", "series", "yAxisLeft", "yAxisRight", "colors", "xAxisLabelFormatter", "startEndOnly", "animationDuration", "showAnimation", "showXAxis", "showYAxis", "intervalType", "showTooltip", "showLegend", "showGridLines", "allowDecimals", "noDataText", "enableLegendSlider", "rotateLabelX", "tickGap", "loading", "xAxisLabel", "className", "width", "height", "style"];
6
+ function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
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
+ 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; }
9
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
10
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
11
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
12
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
13
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
14
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
15
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
16
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
17
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
18
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
19
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
20
+ import { Flexbox, Skeleton } from '@lobehub/ui';
21
+ import { css, cssVar, cx } from 'antd-style';
22
+ import { forwardRef, useMemo, useState } from 'react';
23
+ import { Bar, CartesianGrid, Label, Legend, Line, ComposedChart as ReChartsComposedChart, ResponsiveContainer, Tooltip, XAxis, YAxis } from 'recharts';
24
+ import ChartLegend from "../common/ChartLegend";
25
+ import ChartTooltip from "../common/ChartTooltip";
26
+ import CustomYAxisTick from "../common/CustomYAxisTick";
27
+ import NoData from "../common/NoData";
28
+ import { useThemeColorRange } from "../hooks/useThemeColorRange";
29
+ import { defaultValueFormatter } from "../utils";
30
+ import { getMaxLabelLength } from "../utils/getMaxLabelLength";
31
+ import { styles } from "./styles";
32
+ import { jsx as _jsx } from "react/jsx-runtime";
33
+ import { jsxs as _jsxs } from "react/jsx-runtime";
34
+ var ComposedChart = /*#__PURE__*/forwardRef(function (props, ref) {
35
+ var _data$at, _yAxisLeft$valueForma3, _yAxisRight$valueForm3;
36
+ var themeColorRange = useThemeColorRange();
37
+ var _props$data = props.data,
38
+ data = _props$data === void 0 ? [] : _props$data,
39
+ index = props.index,
40
+ _props$series = props.series,
41
+ series = _props$series === void 0 ? [] : _props$series,
42
+ yAxisLeft = props.yAxisLeft,
43
+ yAxisRight = props.yAxisRight,
44
+ _props$colors = props.colors,
45
+ colors = _props$colors === void 0 ? themeColorRange : _props$colors,
46
+ _props$xAxisLabelForm = props.xAxisLabelFormatter,
47
+ xAxisLabelFormatter = _props$xAxisLabelForm === void 0 ? defaultValueFormatter : _props$xAxisLabelForm,
48
+ _props$startEndOnly = props.startEndOnly,
49
+ startEndOnly = _props$startEndOnly === void 0 ? false : _props$startEndOnly,
50
+ _props$animationDurat = props.animationDuration,
51
+ animationDuration = _props$animationDurat === void 0 ? 900 : _props$animationDurat,
52
+ _props$showAnimation = props.showAnimation,
53
+ showAnimation = _props$showAnimation === void 0 ? false : _props$showAnimation,
54
+ _props$showXAxis = props.showXAxis,
55
+ showXAxis = _props$showXAxis === void 0 ? true : _props$showXAxis,
56
+ _props$showYAxis = props.showYAxis,
57
+ showYAxis = _props$showYAxis === void 0 ? true : _props$showYAxis,
58
+ _props$intervalType = props.intervalType,
59
+ intervalType = _props$intervalType === void 0 ? 'equidistantPreserveStart' : _props$intervalType,
60
+ _props$showTooltip = props.showTooltip,
61
+ showTooltip = _props$showTooltip === void 0 ? true : _props$showTooltip,
62
+ _props$showLegend = props.showLegend,
63
+ showLegend = _props$showLegend === void 0 ? true : _props$showLegend,
64
+ _props$showGridLines = props.showGridLines,
65
+ showGridLines = _props$showGridLines === void 0 ? true : _props$showGridLines,
66
+ _props$allowDecimals = props.allowDecimals,
67
+ allowDecimals = _props$allowDecimals === void 0 ? true : _props$allowDecimals,
68
+ noDataText = props.noDataText,
69
+ _props$enableLegendSl = props.enableLegendSlider,
70
+ enableLegendSlider = _props$enableLegendSl === void 0 ? false : _props$enableLegendSl,
71
+ rotateLabelX = props.rotateLabelX,
72
+ _props$tickGap = props.tickGap,
73
+ tickGap = _props$tickGap === void 0 ? 5 : _props$tickGap,
74
+ loading = props.loading,
75
+ xAxisLabel = props.xAxisLabel,
76
+ className = props.className,
77
+ _props$width = props.width,
78
+ width = _props$width === void 0 ? '100%' : _props$width,
79
+ _props$height = props.height,
80
+ height = _props$height === void 0 ? 280 : _props$height,
81
+ style = props.style,
82
+ rest = _objectWithoutProperties(props, _excluded);
83
+ var _useState = useState(60),
84
+ _useState2 = _slicedToArray(_useState, 2),
85
+ legendHeight = _useState2[0],
86
+ setLegendHeight = _useState2[1];
87
+ var seriesColorMap = useMemo(function () {
88
+ var map = new Map();
89
+ series.forEach(function (s, i) {
90
+ var _s$color;
91
+ map.set(s.key, (_s$color = s.color) !== null && _s$color !== void 0 ? _s$color : colors[i % colors.length]);
92
+ });
93
+ return map;
94
+ }, [series, colors]);
95
+ var categoryColors = seriesColorMap;
96
+ var customCategories = useMemo(function () {
97
+ return series.reduce(function (acc, item) {
98
+ if (item.name) acc[item.key] = item.name;
99
+ return acc;
100
+ }, {});
101
+ }, [series]);
102
+ var hasRightAxis = series.some(function (s) {
103
+ return s.axis === 'right';
104
+ });
105
+ var leftYAxisWidth = useMemo(function () {
106
+ var _yAxisLeft$valueForma;
107
+ if (yAxisLeft !== null && yAxisLeft !== void 0 && yAxisLeft.width) return yAxisLeft.width;
108
+ var leftFormatter = (_yAxisLeft$valueForma = yAxisLeft === null || yAxisLeft === void 0 ? void 0 : yAxisLeft.valueFormatter) !== null && _yAxisLeft$valueForma !== void 0 ? _yAxisLeft$valueForma : defaultValueFormatter;
109
+ return getMaxLabelLength({
110
+ data: data,
111
+ index: index,
112
+ layout: 'horizontal',
113
+ valueFormatter: leftFormatter
114
+ });
115
+ }, [yAxisLeft, data, index]);
116
+ var rightYAxisWidth = useMemo(function () {
117
+ var _yAxisRight$valueForm;
118
+ if (yAxisRight !== null && yAxisRight !== void 0 && yAxisRight.width) return yAxisRight.width;
119
+ var rightFormatter = (_yAxisRight$valueForm = yAxisRight === null || yAxisRight === void 0 ? void 0 : yAxisRight.valueFormatter) !== null && _yAxisRight$valueForm !== void 0 ? _yAxisRight$valueForm : defaultValueFormatter;
120
+ return getMaxLabelLength({
121
+ data: data,
122
+ index: index,
123
+ layout: 'horizontal',
124
+ valueFormatter: rightFormatter
125
+ });
126
+ }, [yAxisRight, data, index]);
127
+ if (loading || !data) return /*#__PURE__*/_jsx(Skeleton.Block, {
128
+ active: true,
129
+ height: height,
130
+ width: width
131
+ });
132
+ var paddingValue = !showXAxis && !showYAxis ? 0 : 20;
133
+ return /*#__PURE__*/_jsx(Flexbox, _objectSpread(_objectSpread({
134
+ className: className,
135
+ height: height,
136
+ ref: ref,
137
+ style: _objectSpread({
138
+ position: 'relative'
139
+ }, style),
140
+ width: width
141
+ }, rest), {}, {
142
+ children: /*#__PURE__*/_jsx(ResponsiveContainer, {
143
+ children: data !== null && data !== void 0 && data.length ? /*#__PURE__*/_jsxs(ReChartsComposedChart, {
144
+ data: data,
145
+ margin: {
146
+ bottom: xAxisLabel ? 30 : undefined,
147
+ left: yAxisLeft !== null && yAxisLeft !== void 0 && yAxisLeft.label ? 20 : undefined,
148
+ right: hasRightAxis ? yAxisRight !== null && yAxisRight !== void 0 && yAxisRight.label ? 20 : 5 : undefined,
149
+ top: 5
150
+ },
151
+ children: [showGridLines && /*#__PURE__*/_jsx(CartesianGrid, {
152
+ className: styles.gridLines,
153
+ horizontal: true,
154
+ vertical: false
155
+ }), /*#__PURE__*/_jsx(XAxis, {
156
+ angle: rotateLabelX === null || rotateLabelX === void 0 ? void 0 : rotateLabelX.angle,
157
+ axisLine: false,
158
+ className: styles.label,
159
+ dataKey: index,
160
+ dy: rotateLabelX === null || rotateLabelX === void 0 ? void 0 : rotateLabelX.verticalShift,
161
+ fill: "",
162
+ hide: !showXAxis,
163
+ interval: startEndOnly ? 'preserveStartEnd' : intervalType,
164
+ minTickGap: tickGap,
165
+ padding: {
166
+ left: paddingValue,
167
+ right: paddingValue
168
+ },
169
+ stroke: "",
170
+ tick: {
171
+ transform: 'translate(0, 6)'
172
+ },
173
+ tickFormatter: xAxisLabelFormatter,
174
+ tickLine: false,
175
+ ticks: startEndOnly ? [data[0][index], (_data$at = data.at(-1)) === null || _data$at === void 0 ? void 0 : _data$at[index]] : undefined,
176
+ children: xAxisLabel && /*#__PURE__*/_jsx(Label, {
177
+ className: cx(styles.strongLabel, styles.emphasis),
178
+ offset: -20,
179
+ position: "insideBottom",
180
+ style: {
181
+ fill: cssVar.colorTextSecondary,
182
+ fontWeight: 500,
183
+ textAnchor: 'middle'
184
+ },
185
+ children: xAxisLabel
186
+ })
187
+ }), /*#__PURE__*/_jsx(YAxis, {
188
+ allowDecimals: allowDecimals,
189
+ axisLine: false,
190
+ className: styles.label,
191
+ domain: yAxisLeft === null || yAxisLeft === void 0 ? void 0 : yAxisLeft.domain,
192
+ fill: "",
193
+ hide: !showYAxis,
194
+ orientation: "left",
195
+ stroke: "",
196
+ tick: function tick(tickProps) {
197
+ var _yAxisLeft$valueForma2;
198
+ return /*#__PURE__*/_jsx(CustomYAxisTick, _objectSpread(_objectSpread({}, tickProps), {}, {
199
+ align: "left",
200
+ formatter: (_yAxisLeft$valueForma2 = yAxisLeft === null || yAxisLeft === void 0 ? void 0 : yAxisLeft.valueFormatter) !== null && _yAxisLeft$valueForma2 !== void 0 ? _yAxisLeft$valueForma2 : defaultValueFormatter,
201
+ yAxisLabel: Boolean(yAxisLeft === null || yAxisLeft === void 0 ? void 0 : yAxisLeft.label)
202
+ }));
203
+ },
204
+ tickFormatter: (_yAxisLeft$valueForma3 = yAxisLeft === null || yAxisLeft === void 0 ? void 0 : yAxisLeft.valueFormatter) !== null && _yAxisLeft$valueForma3 !== void 0 ? _yAxisLeft$valueForma3 : defaultValueFormatter,
205
+ tickLine: false,
206
+ type: "number",
207
+ width: leftYAxisWidth,
208
+ yAxisId: "left",
209
+ children: (yAxisLeft === null || yAxisLeft === void 0 ? void 0 : yAxisLeft.label) && /*#__PURE__*/_jsx(Label, {
210
+ angle: -90,
211
+ className: styles.emphasis,
212
+ offset: -15,
213
+ position: "insideLeft",
214
+ style: {
215
+ fill: cssVar.colorTextSecondary,
216
+ fontWeight: 500,
217
+ textAnchor: 'middle'
218
+ },
219
+ children: yAxisLeft.label
220
+ })
221
+ }), hasRightAxis && /*#__PURE__*/_jsx(YAxis, {
222
+ allowDecimals: allowDecimals,
223
+ axisLine: false,
224
+ className: styles.label,
225
+ domain: yAxisRight === null || yAxisRight === void 0 ? void 0 : yAxisRight.domain,
226
+ fill: "",
227
+ hide: !showYAxis,
228
+ orientation: "right",
229
+ stroke: "",
230
+ tick: function tick(tickProps) {
231
+ var _yAxisRight$valueForm2;
232
+ return /*#__PURE__*/_jsx(CustomYAxisTick, _objectSpread(_objectSpread({}, tickProps), {}, {
233
+ align: "right",
234
+ anchor: "start",
235
+ formatter: (_yAxisRight$valueForm2 = yAxisRight === null || yAxisRight === void 0 ? void 0 : yAxisRight.valueFormatter) !== null && _yAxisRight$valueForm2 !== void 0 ? _yAxisRight$valueForm2 : defaultValueFormatter,
236
+ yAxisLabel: Boolean(yAxisRight === null || yAxisRight === void 0 ? void 0 : yAxisRight.label)
237
+ }));
238
+ },
239
+ tickFormatter: (_yAxisRight$valueForm3 = yAxisRight === null || yAxisRight === void 0 ? void 0 : yAxisRight.valueFormatter) !== null && _yAxisRight$valueForm3 !== void 0 ? _yAxisRight$valueForm3 : defaultValueFormatter,
240
+ tickLine: false,
241
+ type: "number",
242
+ width: rightYAxisWidth,
243
+ yAxisId: "right",
244
+ children: (yAxisRight === null || yAxisRight === void 0 ? void 0 : yAxisRight.label) && /*#__PURE__*/_jsx(Label, {
245
+ angle: 90,
246
+ className: styles.emphasis,
247
+ offset: -15,
248
+ position: "insideRight",
249
+ style: {
250
+ fill: cssVar.colorTextSecondary,
251
+ fontWeight: 500,
252
+ textAnchor: 'middle'
253
+ },
254
+ children: yAxisRight.label
255
+ })
256
+ }), /*#__PURE__*/_jsx(Tooltip, {
257
+ content: showTooltip ? function (_ref) {
258
+ var active = _ref.active,
259
+ payload = _ref.payload,
260
+ label = _ref.label;
261
+ return /*#__PURE__*/_jsx(ChartTooltip, {
262
+ active: active,
263
+ categoryColors: categoryColors,
264
+ customCategories: customCategories,
265
+ label: label,
266
+ payload: payload,
267
+ valueFormatter: function valueFormatter(value, name) {
268
+ var _ref2, _currentSeries$valueF;
269
+ var currentSeries = series.find(function (item) {
270
+ return item.key === name;
271
+ });
272
+ var formatter = (_ref2 = (_currentSeries$valueF = currentSeries === null || currentSeries === void 0 ? void 0 : currentSeries.valueFormatter) !== null && _currentSeries$valueF !== void 0 ? _currentSeries$valueF : (currentSeries === null || currentSeries === void 0 ? void 0 : currentSeries.axis) === 'right' ? yAxisRight === null || yAxisRight === void 0 ? void 0 : yAxisRight.valueFormatter : yAxisLeft === null || yAxisLeft === void 0 ? void 0 : yAxisLeft.valueFormatter) !== null && _ref2 !== void 0 ? _ref2 : defaultValueFormatter;
273
+ return formatter(value);
274
+ }
275
+ });
276
+ } : undefined,
277
+ cursor: {
278
+ fill: cssVar.colorFillTertiary
279
+ },
280
+ isAnimationActive: false,
281
+ position: {
282
+ y: 0
283
+ },
284
+ wrapperStyle: {
285
+ outline: 'none'
286
+ }
287
+ }), showLegend && /*#__PURE__*/_jsx(Legend, {
288
+ content: function content(_ref3) {
289
+ var payload = _ref3.payload;
290
+ return ChartLegend({
291
+ payload: payload
292
+ }, categoryColors, setLegendHeight, undefined, undefined, enableLegendSlider, customCategories);
293
+ },
294
+ height: legendHeight,
295
+ verticalAlign: "top"
296
+ }), series.map(function (s) {
297
+ var _seriesColorMap$get, _s$axis;
298
+ var color = (_seriesColorMap$get = seriesColorMap.get(s.key)) !== null && _seriesColorMap$get !== void 0 ? _seriesColorMap$get : cssVar.colorPrimary;
299
+ var axisId = (_s$axis = s.axis) !== null && _s$axis !== void 0 ? _s$axis : 'left';
300
+ if (s.type === 'bar') {
301
+ return /*#__PURE__*/_jsx(Bar, {
302
+ animationDuration: animationDuration,
303
+ className: cx(css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n fill: ", ";\n "])), color)),
304
+ dataKey: s.key,
305
+ fill: "",
306
+ isAnimationActive: showAnimation,
307
+ name: s.key,
308
+ yAxisId: axisId
309
+ }, s.key);
310
+ }
311
+ if (s.type === 'line') {
312
+ return /*#__PURE__*/_jsx(Line, {
313
+ animationDuration: animationDuration,
314
+ className: cx(css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n stroke: ", ";\n "])), color)),
315
+ dataKey: s.key,
316
+ dot: false,
317
+ isAnimationActive: showAnimation,
318
+ name: s.key,
319
+ stroke: "",
320
+ strokeWidth: 2,
321
+ type: "monotone",
322
+ yAxisId: axisId
323
+ }, s.key);
324
+ }
325
+ return null;
326
+ })]
327
+ }) : /*#__PURE__*/_jsx(NoData, {
328
+ noDataText: noDataText
329
+ })
330
+ })
331
+ }));
332
+ });
333
+ ComposedChart.displayName = 'ComposedChart';
334
+ export default ComposedChart;
@@ -0,0 +1,6 @@
1
+ export declare const styles: {
2
+ emphasis: string;
3
+ gridLines: string;
4
+ label: string;
5
+ strongLabel: string;
6
+ };
@@ -0,0 +1,13 @@
1
+ var _templateObject, _templateObject2, _templateObject3, _templateObject4;
2
+ function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
3
+ import { createStaticStyles } from 'antd-style';
4
+ export var styles = createStaticStyles(function (_ref) {
5
+ var css = _ref.css,
6
+ cssVar = _ref.cssVar;
7
+ return {
8
+ emphasis: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n overflow: hidden;\n text-overflow: ellipsis;\n white-space: nowrap;\n "]))),
9
+ gridLines: css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n stroke: ", ";\n stroke-width: 1;\n "])), cssVar.colorBorderSecondary),
10
+ label: css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n font-size: 12px;\n line-height: 16px;\n fill: ", ";\n "])), cssVar.colorTextDescription),
11
+ strongLabel: css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n font-size: 12px;\n font-weight: 500;\n line-height: 16px;\n fill: ", ";\n "])), cssVar.colorTextSecondary)
12
+ };
13
+ });
@@ -0,0 +1,68 @@
1
+ import type { HTMLAttributes } from 'react';
2
+ import type { AxisDomain } from 'recharts/types/util/types';
3
+ import type { NoDataProps } from "../common/NoData";
4
+ import type { IntervalType, LabelFormatter, ValueFormatter } from "../types/charts";
5
+ import type BaseAnimationTimingProps from '../common/BaseAnimationTimingProps';
6
+ export interface SeriesItem {
7
+ /**
8
+ * Which y-axis this series is bound to.
9
+ * @default 'left'
10
+ */
11
+ axis?: 'left' | 'right';
12
+ /** Override color for this series. Falls back to the chart-level `colors` array. */
13
+ color?: string;
14
+ /** Data key in the `data` array */
15
+ key: string;
16
+ /** Display name shown in legend / tooltip. Defaults to `key`. */
17
+ name?: string;
18
+ /** Chart type for this series */
19
+ type: 'bar' | 'line';
20
+ /** Per-series value formatter used in tooltip */
21
+ valueFormatter?: ValueFormatter;
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;
29
+ /** Label string rendered alongside the axis */
30
+ label?: string;
31
+ /** Custom tick formatter */
32
+ valueFormatter?: ValueFormatter;
33
+ /** Fixed axis width in pixels */
34
+ width?: number;
35
+ }
36
+ export interface ComposedChartProps extends BaseAnimationTimingProps, HTMLAttributes<HTMLDivElement> {
37
+ allowDecimals?: boolean;
38
+ colors?: string[];
39
+ data: any[];
40
+ enableLegendSlider?: boolean;
41
+ height?: string | number;
42
+ /** The key in `data` used as the shared x-axis category */
43
+ index: string;
44
+ intervalType?: IntervalType;
45
+ loading?: boolean;
46
+ noDataText?: NoDataProps['noDataText'];
47
+ rotateLabelX?: {
48
+ angle: number;
49
+ verticalShift?: number;
50
+ xAxisHeight?: number;
51
+ };
52
+ /** Series definitions — each item maps to a Bar or Line renderer */
53
+ series: SeriesItem[];
54
+ showGridLines?: boolean;
55
+ showLegend?: boolean;
56
+ showTooltip?: boolean;
57
+ showXAxis?: boolean;
58
+ showYAxis?: boolean;
59
+ startEndOnly?: boolean;
60
+ tickGap?: number;
61
+ width?: string | number;
62
+ xAxisLabel?: string;
63
+ xAxisLabelFormatter?: LabelFormatter;
64
+ /** Left y-axis configuration */
65
+ yAxisLeft?: YAxisConfig;
66
+ /** Right y-axis configuration */
67
+ yAxisRight?: YAxisConfig;
68
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -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
  }
@@ -9,7 +9,7 @@ export interface ChartTooltipProps {
9
9
  footer?: ReactNode;
10
10
  label: string;
11
11
  payload: any;
12
- valueFormatter: ValueFormatter;
12
+ valueFormatter: ValueFormatter | ((value: number, name?: string) => string);
13
13
  }
14
14
  declare const ChartTooltip: ({ active, payload, label, categoryColors, valueFormatter, customCategories, footer, }: ChartTooltipProps) => import("react/jsx-runtime").JSX.Element | null;
15
15
  export default ChartTooltip;
@@ -53,7 +53,7 @@ var ChartTooltip = function ChartTooltip(_ref2) {
53
53
  return /*#__PURE__*/_jsx(ChartTooltipRow, {
54
54
  color: (_categoryColors$get = categoryColors.get(name)) !== null && _categoryColors$get !== void 0 ? _categoryColors$get : cssVar.colorPrimary,
55
55
  name: (customCategories === null || customCategories === void 0 ? void 0 : customCategories[name]) || name,
56
- value: valueFormatter(value)
56
+ value: valueFormatter(value, name)
57
57
  }, "id-".concat(idx));
58
58
  })
59
59
  }), footer]
@@ -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,6 +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, type YAxisConfig, } from './ComposedChart';
8
9
  export * from './DataBars';
9
10
  export { default as DonutChart, type DonutChartProps } from './DonutChart';
10
11
  export { default as FunnelChart, type FunnelChartProps } from './FunnelChart';
package/es/index.js CHANGED
@@ -5,6 +5,7 @@ export { default as BarList } from "./BarList";
5
5
  export { default as ChartTooltip } 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 } from "./ComposedChart";
8
9
  export * from "./DataBars";
9
10
  export { default as DonutChart } from "./DonutChart";
10
11
  export { default as FunnelChart } from "./FunnelChart";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/charts",
3
- "version": "5.0.0",
3
+ "version": "5.2.0",
4
4
  "description": "React modern charts components built on recharts",
5
5
  "keywords": [
6
6
  "lobehub",