@mui/x-charts 7.3.2 → 7.5.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.
Files changed (128) hide show
  1. package/BarChart/BarChart.js +18 -11
  2. package/BarChart/BarClipPath.d.ts +14 -0
  3. package/BarChart/BarClipPath.js +50 -0
  4. package/BarChart/BarElement.d.ts +10 -5
  5. package/BarChart/BarElement.js +3 -2
  6. package/BarChart/BarPlot.d.ts +4 -0
  7. package/BarChart/BarPlot.js +102 -30
  8. package/BarChart/getRadius.d.ts +15 -0
  9. package/BarChart/getRadius.js +37 -0
  10. package/BarChart/legend.js +13 -6
  11. package/BarChart/types.d.ts +25 -0
  12. package/BarChart/types.js +5 -0
  13. package/CHANGELOG.md +160 -2
  14. package/ChartContainer/ChartContainer.js +10 -10
  15. package/ChartsGrid/ChartsGrid.js +22 -11
  16. package/ChartsOverlay/ChartsLoadingOverlay.js +3 -3
  17. package/ChartsOverlay/ChartsNoDataOverlay.js +2 -2
  18. package/ChartsOverlay/ChartsOverlay.d.ts +9 -0
  19. package/ChartsTooltip/DefaultChartsAxisTooltipContent.js +4 -2
  20. package/ChartsTooltip/DefaultChartsItemTooltipContent.js +7 -3
  21. package/ChartsTooltip/utils.js +13 -8
  22. package/ChartsXAxis/ChartsXAxis.js +1 -2
  23. package/ChartsYAxis/ChartsYAxis.js +2 -2
  24. package/LineChart/AreaElement.d.ts +1 -1
  25. package/LineChart/AreaElement.js +3 -3
  26. package/LineChart/AreaPlot.js +3 -2
  27. package/LineChart/LineChart.js +11 -10
  28. package/LineChart/LineElement.d.ts +1 -1
  29. package/LineChart/LineElement.js +3 -3
  30. package/LineChart/LineHighlightElement.d.ts +1 -1
  31. package/LineChart/MarkElement.d.ts +1 -1
  32. package/LineChart/legend.js +13 -6
  33. package/PieChart/PieArc.d.ts +1 -1
  34. package/PieChart/PieArcLabel.d.ts +1 -1
  35. package/PieChart/PieArcLabel.js +3 -1
  36. package/PieChart/PieArcLabelPlot.js +14 -5
  37. package/PieChart/PieArcPlot.js +1 -1
  38. package/PieChart/PieChart.js +11 -10
  39. package/PieChart/formatter.js +4 -1
  40. package/PieChart/legend.js +15 -5
  41. package/ResponsiveChartContainer/ResponsiveChartContainer.js +10 -10
  42. package/ScatterChart/ScatterChart.js +16 -15
  43. package/ScatterChart/legend.js +13 -6
  44. package/SparkLineChart/SparkLineChart.js +5 -5
  45. package/context/ZAxisContextProvider.js +5 -5
  46. package/esm/BarChart/BarChart.js +18 -11
  47. package/esm/BarChart/BarClipPath.js +42 -0
  48. package/esm/BarChart/BarElement.js +3 -2
  49. package/esm/BarChart/BarPlot.js +103 -31
  50. package/esm/BarChart/getRadius.js +30 -0
  51. package/esm/BarChart/legend.js +13 -6
  52. package/esm/BarChart/types.js +1 -0
  53. package/esm/ChartContainer/ChartContainer.js +10 -10
  54. package/esm/ChartsGrid/ChartsGrid.js +23 -12
  55. package/esm/ChartsOverlay/ChartsLoadingOverlay.js +3 -3
  56. package/esm/ChartsOverlay/ChartsNoDataOverlay.js +2 -2
  57. package/esm/ChartsTooltip/DefaultChartsAxisTooltipContent.js +4 -2
  58. package/esm/ChartsTooltip/DefaultChartsItemTooltipContent.js +7 -3
  59. package/esm/ChartsTooltip/utils.js +13 -8
  60. package/esm/ChartsXAxis/ChartsXAxis.js +1 -2
  61. package/esm/ChartsYAxis/ChartsYAxis.js +2 -2
  62. package/esm/LineChart/AreaElement.js +3 -3
  63. package/esm/LineChart/AreaPlot.js +3 -2
  64. package/esm/LineChart/LineChart.js +11 -10
  65. package/esm/LineChart/LineElement.js +3 -3
  66. package/esm/LineChart/legend.js +13 -6
  67. package/esm/PieChart/PieArcLabel.js +3 -1
  68. package/esm/PieChart/PieArcLabelPlot.js +14 -5
  69. package/esm/PieChart/PieArcPlot.js +1 -1
  70. package/esm/PieChart/PieChart.js +11 -10
  71. package/esm/PieChart/formatter.js +4 -1
  72. package/esm/PieChart/legend.js +15 -5
  73. package/esm/ResponsiveChartContainer/ResponsiveChartContainer.js +10 -10
  74. package/esm/ScatterChart/ScatterChart.js +16 -15
  75. package/esm/ScatterChart/legend.js +13 -6
  76. package/esm/SparkLineChart/SparkLineChart.js +5 -5
  77. package/esm/context/ZAxisContextProvider.js +5 -5
  78. package/esm/hooks/useAxisEvents.js +12 -7
  79. package/esm/internals/getLabel.js +3 -0
  80. package/hooks/useAxisEvents.js +12 -7
  81. package/index.js +1 -1
  82. package/internals/defaultizeColor.d.ts +7 -5
  83. package/internals/getLabel.d.ts +1 -0
  84. package/internals/getLabel.js +9 -0
  85. package/internals/utils.d.ts +1 -1
  86. package/models/seriesType/bar.d.ts +4 -1
  87. package/models/seriesType/line.d.ts +4 -1
  88. package/models/seriesType/pie.d.ts +9 -4
  89. package/models/seriesType/scatter.d.ts +4 -1
  90. package/modern/BarChart/BarChart.js +18 -11
  91. package/modern/BarChart/BarClipPath.js +42 -0
  92. package/modern/BarChart/BarElement.js +3 -2
  93. package/modern/BarChart/BarPlot.js +103 -31
  94. package/modern/BarChart/getRadius.js +30 -0
  95. package/modern/BarChart/legend.js +13 -6
  96. package/modern/BarChart/types.js +1 -0
  97. package/modern/ChartContainer/ChartContainer.js +10 -10
  98. package/modern/ChartsGrid/ChartsGrid.js +23 -12
  99. package/modern/ChartsOverlay/ChartsLoadingOverlay.js +3 -3
  100. package/modern/ChartsOverlay/ChartsNoDataOverlay.js +2 -2
  101. package/modern/ChartsTooltip/DefaultChartsAxisTooltipContent.js +4 -2
  102. package/modern/ChartsTooltip/DefaultChartsItemTooltipContent.js +7 -3
  103. package/modern/ChartsTooltip/utils.js +13 -8
  104. package/modern/ChartsXAxis/ChartsXAxis.js +1 -2
  105. package/modern/ChartsYAxis/ChartsYAxis.js +2 -2
  106. package/modern/LineChart/AreaElement.js +3 -3
  107. package/modern/LineChart/AreaPlot.js +3 -2
  108. package/modern/LineChart/LineChart.js +11 -10
  109. package/modern/LineChart/LineElement.js +3 -3
  110. package/modern/LineChart/legend.js +13 -6
  111. package/modern/PieChart/PieArcLabel.js +3 -1
  112. package/modern/PieChart/PieArcLabelPlot.js +14 -5
  113. package/modern/PieChart/PieArcPlot.js +1 -1
  114. package/modern/PieChart/PieChart.js +11 -10
  115. package/modern/PieChart/formatter.js +4 -1
  116. package/modern/PieChart/legend.js +15 -5
  117. package/modern/ResponsiveChartContainer/ResponsiveChartContainer.js +10 -10
  118. package/modern/ScatterChart/ScatterChart.js +16 -15
  119. package/modern/ScatterChart/legend.js +13 -6
  120. package/modern/SparkLineChart/SparkLineChart.js +5 -5
  121. package/modern/context/ZAxisContextProvider.js +5 -5
  122. package/modern/hooks/useAxisEvents.js +12 -7
  123. package/modern/index.js +1 -1
  124. package/modern/internals/getLabel.js +3 -0
  125. package/package.json +3 -3
  126. package/themeAugmentation/components.d.ts +4 -0
  127. package/themeAugmentation/overrides.d.ts +2 -0
  128. package/themeAugmentation/props.d.ts +2 -0
@@ -8,7 +8,10 @@ export type PieValueType = {
8
8
  */
9
9
  id: PieItemId;
10
10
  value: number;
11
- label?: string;
11
+ /**
12
+ * The label to display on the tooltip, arc, or the legend. It can be a string or a function.
13
+ */
14
+ label?: string | ((location: 'tooltip' | 'legend' | 'arc') => string);
12
15
  color?: string;
13
16
  };
14
17
  export type DefaultizedPieValueType = PieValueType & Omit<D3PieArcDatum<any>, 'data'> & {
@@ -16,9 +19,9 @@ export type DefaultizedPieValueType = PieValueType & Omit<D3PieArcDatum<any>, 'd
16
19
  formattedValue: string;
17
20
  };
18
21
  export type ChartsPieSorting = 'none' | 'asc' | 'desc' | ((a: number, b: number) => number);
19
- export interface PieSeriesType<Tdata = PieValueType> extends CommonSeriesType<Tdata> {
22
+ export interface PieSeriesType<TData = PieValueType> extends CommonSeriesType<TData> {
20
23
  type: 'pie';
21
- data: Tdata[];
24
+ data: TData[];
22
25
  /**
23
26
  * The radius between circle center and the beginning of the arc.
24
27
  * Can be a number (in px) or a string with a percentage such as '50%'.
@@ -69,7 +72,9 @@ export interface PieSeriesType<Tdata = PieValueType> extends CommonSeriesType<Td
69
72
  /**
70
73
  * The label displayed into the arc.
71
74
  */
72
- arcLabel?: 'formattedValue' | 'label' | 'value' | ((item: DefaultizedPieValueType) => string);
75
+ arcLabel?: 'formattedValue' | 'label' | 'value' | ((item: Omit<DefaultizedPieValueType, 'label'> & {
76
+ label?: string;
77
+ }) => string);
73
78
  /**
74
79
  * The minimal angle required to display the arc label.
75
80
  * @default 0
@@ -13,7 +13,10 @@ export interface ScatterSeriesType extends CommonSeriesType<ScatterValueType>, C
13
13
  type: 'scatter';
14
14
  data: ScatterValueType[];
15
15
  markerSize?: number;
16
- label?: string;
16
+ /**
17
+ * The label to display on the tooltip or the legend. It can be a string or a function.
18
+ */
19
+ label?: string | ((location: 'tooltip' | 'legend') => string);
17
20
  /**
18
21
  * If true, the interaction will not use element hover for this series.
19
22
  * @default false
@@ -46,6 +46,7 @@ const BarChart = /*#__PURE__*/React.forwardRef(function BarChart(props, ref) {
46
46
  rightAxis,
47
47
  bottomAxis,
48
48
  skipAnimation,
49
+ borderRadius,
49
50
  onItemClick,
50
51
  onAxisClick,
51
52
  children,
@@ -98,7 +99,8 @@ const BarChart = /*#__PURE__*/React.forwardRef(function BarChart(props, ref) {
98
99
  slots: slots,
99
100
  slotProps: slotProps,
100
101
  skipAnimation: skipAnimation,
101
- onItemClick: onItemClick
102
+ onItemClick: onItemClick,
103
+ borderRadius: borderRadius
102
104
  }), /*#__PURE__*/_jsx(ChartsOverlay, {
103
105
  loading: loading,
104
106
  slots: slots,
@@ -137,6 +139,10 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
137
139
  x: PropTypes.oneOf(['band', 'line', 'none']),
138
140
  y: PropTypes.oneOf(['band', 'line', 'none'])
139
141
  }),
142
+ /**
143
+ * Defines the border radius of the bar element.
144
+ */
145
+ borderRadius: PropTypes.number,
140
146
  /**
141
147
  * Indicate which axis to display the bottom of the charts.
142
148
  * Can be a string (the id of the axis) or an object `ChartsXAxisProps`.
@@ -199,6 +205,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
199
205
  }),
200
206
  /**
201
207
  * If `true`, a loading overlay is displayed.
208
+ * @default false
202
209
  */
203
210
  loading: PropTypes.bool,
204
211
  /**
@@ -291,6 +298,11 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
291
298
  axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
292
299
  classes: PropTypes.object,
293
300
  colorMap: PropTypes.oneOfType([PropTypes.shape({
301
+ colors: PropTypes.arrayOf(PropTypes.string).isRequired,
302
+ type: PropTypes.oneOf(['ordinal']).isRequired,
303
+ unknownColor: PropTypes.string,
304
+ values: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired)
305
+ }), PropTypes.shape({
294
306
  color: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string.isRequired), PropTypes.func]).isRequired,
295
307
  max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
296
308
  min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
@@ -299,11 +311,6 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
299
311
  colors: PropTypes.arrayOf(PropTypes.string).isRequired,
300
312
  thresholds: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired).isRequired,
301
313
  type: PropTypes.oneOf(['piecewise']).isRequired
302
- }), PropTypes.shape({
303
- colors: PropTypes.arrayOf(PropTypes.string).isRequired,
304
- type: PropTypes.oneOf(['ordinal']).isRequired,
305
- unknownColor: PropTypes.string,
306
- values: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired)
307
314
  })]),
308
315
  data: PropTypes.array,
309
316
  dataKey: PropTypes.string,
@@ -344,6 +351,11 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
344
351
  axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
345
352
  classes: PropTypes.object,
346
353
  colorMap: PropTypes.oneOfType([PropTypes.shape({
354
+ colors: PropTypes.arrayOf(PropTypes.string).isRequired,
355
+ type: PropTypes.oneOf(['ordinal']).isRequired,
356
+ unknownColor: PropTypes.string,
357
+ values: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired)
358
+ }), PropTypes.shape({
347
359
  color: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string.isRequired), PropTypes.func]).isRequired,
348
360
  max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
349
361
  min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
@@ -352,11 +364,6 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
352
364
  colors: PropTypes.arrayOf(PropTypes.string).isRequired,
353
365
  thresholds: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired).isRequired,
354
366
  type: PropTypes.oneOf(['piecewise']).isRequired
355
- }), PropTypes.shape({
356
- colors: PropTypes.arrayOf(PropTypes.string).isRequired,
357
- type: PropTypes.oneOf(['ordinal']).isRequired,
358
- unknownColor: PropTypes.string,
359
- values: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired)
360
367
  })]),
361
368
  data: PropTypes.array,
362
369
  dataKey: PropTypes.string,
@@ -0,0 +1,42 @@
1
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
2
+ import _extends from "@babel/runtime/helpers/esm/extends";
3
+ const _excluded = ["style", "maskId"];
4
+ import * as React from 'react';
5
+ import { animated } from '@react-spring/web';
6
+ import { getRadius } from './getRadius';
7
+ import { jsx as _jsx } from "react/jsx-runtime";
8
+ const buildInset = corners => `inset(0px round ${corners.topLeft}px ${corners.topRight}px ${corners.bottomRight}px ${corners.bottomLeft}px)`;
9
+ function BarClipRect(props) {
10
+ const radiusData = props.ownerState;
11
+ return /*#__PURE__*/_jsx(animated.rect, {
12
+ style: _extends({}, props.style, {
13
+ clipPath: (props.ownerState.layout === 'vertical' ? props.style?.height : props.style?.width).to(value => buildInset({
14
+ topLeft: Math.min(value, getRadius('top-left', radiusData)),
15
+ topRight: Math.min(value, getRadius('top-right', radiusData)),
16
+ bottomRight: Math.min(value, getRadius('bottom-right', radiusData)),
17
+ bottomLeft: Math.min(value, getRadius('bottom-left', radiusData))
18
+ }))
19
+ })
20
+ });
21
+ }
22
+ /**
23
+ * @ignore - internal component.
24
+ */
25
+ function BarClipPath(props) {
26
+ const {
27
+ style,
28
+ maskId
29
+ } = props,
30
+ rest = _objectWithoutPropertiesLoose(props, _excluded);
31
+ if (!props.borderRadius || props.borderRadius <= 0) {
32
+ return null;
33
+ }
34
+ return /*#__PURE__*/_jsx("clipPath", {
35
+ id: maskId,
36
+ children: /*#__PURE__*/_jsx(BarClipRect, {
37
+ ownerState: rest,
38
+ style: style
39
+ })
40
+ });
41
+ }
42
+ export { BarClipPath };
@@ -79,16 +79,17 @@ function BarElement(props) {
79
79
  const barProps = useSlotProps({
80
80
  elementType: Bar,
81
81
  externalSlotProps: slotProps?.bar,
82
- additionalProps: _extends({}, other, getInteractionItemProps({
82
+ externalForwardedProps: other,
83
+ additionalProps: _extends({}, getInteractionItemProps({
83
84
  type: 'bar',
84
85
  seriesId: id,
85
86
  dataIndex
86
87
  }), {
87
88
  style,
88
- className: classes.root,
89
89
  onClick,
90
90
  cursor: onClick ? 'pointer' : 'unset'
91
91
  }),
92
+ className: classes.root,
92
93
  ownerState
93
94
  });
94
95
  return /*#__PURE__*/_jsx(Bar, _extends({}, barProps));
@@ -1,6 +1,6 @@
1
1
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
2
2
  import _extends from "@babel/runtime/helpers/esm/extends";
3
- const _excluded = ["skipAnimation", "onItemClick"];
3
+ const _excluded = ["skipAnimation", "onItemClick", "borderRadius"];
4
4
  import * as React from 'react';
5
5
  import PropTypes from 'prop-types';
6
6
  import { useTransition } from '@react-spring/web';
@@ -10,6 +10,8 @@ import { BarElement } from './BarElement';
10
10
  import { isBandScaleConfig, isPointScaleConfig } from '../models/axis';
11
11
  import { DEFAULT_X_AXIS_KEY, DEFAULT_Y_AXIS_KEY } from '../constants';
12
12
  import getColor from './getColor';
13
+ import { useChartId } from '../hooks';
14
+ import { BarClipPath } from './BarClipPath';
13
15
 
14
16
  /**
15
17
  * Solution of the equations
@@ -20,7 +22,7 @@ import getColor from './getColor';
20
22
  * @param gapRatio The ratio of the gap between bars over the bar width.
21
23
  * @returns The bar width and the offset between bars.
22
24
  */
23
- import { jsx as _jsx } from "react/jsx-runtime";
25
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
24
26
  function getBandSize({
25
27
  bandWidth: W,
26
28
  numberOfGroups: N,
@@ -46,6 +48,7 @@ const useAggregatedData = () => {
46
48
  seriesOrder: []
47
49
  };
48
50
  const axisData = React.useContext(CartesianContext);
51
+ const chartId = useChartId();
49
52
  const {
50
53
  series,
51
54
  stackingGroups
@@ -58,6 +61,7 @@ const useAggregatedData = () => {
58
61
  } = axisData;
59
62
  const defaultXAxisId = xAxisIds[0];
60
63
  const defaultYAxisId = yAxisIds[0];
64
+ const masks = {};
61
65
  const data = stackingGroups.flatMap(({
62
66
  ids: groupIds
63
67
  }, groupIndex) => {
@@ -111,7 +115,8 @@ const useAggregatedData = () => {
111
115
  const valueCoordinates = values.map(v => verticalLayout ? yScale(v) : xScale(v));
112
116
  const minValueCoord = Math.round(Math.min(...valueCoordinates));
113
117
  const maxValueCoord = Math.round(Math.max(...valueCoordinates));
114
- return {
118
+ const stackId = series[seriesId].stack;
119
+ const result = {
115
120
  seriesId,
116
121
  dataIndex,
117
122
  layout: series[seriesId].layout,
@@ -122,14 +127,41 @@ const useAggregatedData = () => {
122
127
  height: verticalLayout ? maxValueCoord - minValueCoord : barWidth,
123
128
  width: verticalLayout ? barWidth : maxValueCoord - minValueCoord,
124
129
  color: colorGetter(dataIndex),
125
- highlightScope: series[seriesId].highlightScope
130
+ highlightScope: series[seriesId].highlightScope,
131
+ value: series[seriesId].data[dataIndex],
132
+ maskId: `${chartId}_${stackId || seriesId}_${groupIndex}_${dataIndex}`
126
133
  };
134
+ if (!masks[result.maskId]) {
135
+ masks[result.maskId] = {
136
+ id: result.maskId,
137
+ width: 0,
138
+ height: 0,
139
+ hasNegative: false,
140
+ hasPositive: false,
141
+ layout: result.layout,
142
+ xOrigin: xScale(0),
143
+ yOrigin: yScale(0),
144
+ x: 0,
145
+ y: 0
146
+ };
147
+ }
148
+ const mask = masks[result.maskId];
149
+ mask.width = result.layout === 'vertical' ? result.width : mask.width + result.width;
150
+ mask.height = result.layout === 'vertical' ? mask.height + result.height : result.height;
151
+ mask.x = Math.min(mask.x === 0 ? Infinity : mask.x, result.x);
152
+ mask.y = Math.min(mask.y === 0 ? Infinity : mask.y, result.y);
153
+ mask.hasNegative = mask.hasNegative || (result.value ?? 0) < 0;
154
+ mask.hasPositive = mask.hasPositive || (result.value ?? 0) > 0;
155
+ return result;
127
156
  });
128
157
  });
129
158
  });
130
- return data;
159
+ return {
160
+ completedData: data,
161
+ masksData: Object.values(masks)
162
+ };
131
163
  };
132
- const getOutStyle = ({
164
+ const leaveStyle = ({
133
165
  layout,
134
166
  yOrigin,
135
167
  x,
@@ -148,7 +180,7 @@ const getOutStyle = ({
148
180
  height,
149
181
  width: 0
150
182
  });
151
- const getInStyle = ({
183
+ const enterStyle = ({
152
184
  x,
153
185
  width,
154
186
  y,
@@ -172,41 +204,77 @@ const getInStyle = ({
172
204
  * - [BarPlot API](https://mui.com/x/api/charts/bar-plot/)
173
205
  */
174
206
  function BarPlot(props) {
175
- const completedData = useAggregatedData();
207
+ const {
208
+ completedData,
209
+ masksData
210
+ } = useAggregatedData();
176
211
  const {
177
212
  skipAnimation,
178
- onItemClick
213
+ onItemClick,
214
+ borderRadius
179
215
  } = props,
180
216
  other = _objectWithoutPropertiesLoose(props, _excluded);
181
217
  const transition = useTransition(completedData, {
182
218
  keys: bar => `${bar.seriesId}-${bar.dataIndex}`,
183
- from: getOutStyle,
184
- leave: getOutStyle,
185
- enter: getInStyle,
186
- update: getInStyle,
219
+ from: leaveStyle,
220
+ leave: leaveStyle,
221
+ enter: enterStyle,
222
+ update: enterStyle,
223
+ immediate: skipAnimation
224
+ });
225
+ const maskTransition = useTransition(masksData, {
226
+ keys: v => v.id,
227
+ from: leaveStyle,
228
+ leave: leaveStyle,
229
+ enter: enterStyle,
230
+ update: enterStyle,
187
231
  immediate: skipAnimation
188
232
  });
189
- return /*#__PURE__*/_jsx(React.Fragment, {
190
- children: transition((style, {
233
+ return /*#__PURE__*/_jsxs(React.Fragment, {
234
+ children: [maskTransition((style, {
235
+ id,
236
+ hasPositive,
237
+ hasNegative,
238
+ layout
239
+ }) => {
240
+ return /*#__PURE__*/_jsx(BarClipPath, {
241
+ maskId: id,
242
+ borderRadius: borderRadius,
243
+ hasNegative: hasNegative,
244
+ hasPositive: hasPositive,
245
+ layout: layout,
246
+ style: style
247
+ });
248
+ }), transition((style, {
191
249
  seriesId,
192
250
  dataIndex,
193
251
  color,
194
- highlightScope
195
- }) => /*#__PURE__*/_jsx(BarElement, _extends({
196
- id: seriesId,
197
- dataIndex: dataIndex,
198
- highlightScope: highlightScope,
199
- color: color
200
- }, other, {
201
- onClick: onItemClick && (event => {
202
- onItemClick(event, {
203
- type: 'bar',
204
- seriesId,
205
- dataIndex
206
- });
207
- }),
208
- style: style
209
- })))
252
+ highlightScope,
253
+ maskId
254
+ }) => {
255
+ const barElement = /*#__PURE__*/_jsx(BarElement, _extends({
256
+ id: seriesId,
257
+ dataIndex: dataIndex,
258
+ color: color,
259
+ highlightScope: highlightScope
260
+ }, other, {
261
+ onClick: onItemClick && (event => {
262
+ onItemClick(event, {
263
+ type: 'bar',
264
+ seriesId,
265
+ dataIndex
266
+ });
267
+ }),
268
+ style: style
269
+ }));
270
+ if (!borderRadius || borderRadius <= 0) {
271
+ return barElement;
272
+ }
273
+ return /*#__PURE__*/_jsx("g", {
274
+ clipPath: `url(#${maskId})`,
275
+ children: barElement
276
+ });
277
+ })]
210
278
  });
211
279
  }
212
280
  process.env.NODE_ENV !== "production" ? BarPlot.propTypes = {
@@ -214,6 +282,10 @@ process.env.NODE_ENV !== "production" ? BarPlot.propTypes = {
214
282
  // | These PropTypes are generated from the TypeScript type definitions |
215
283
  // | To update them edit the TypeScript types and run "yarn proptypes" |
216
284
  // ----------------------------------------------------------------------
285
+ /**
286
+ * Defines the border radius of the bar element.
287
+ */
288
+ borderRadius: PropTypes.number,
217
289
  /**
218
290
  * Callback fired when a bar item is clicked.
219
291
  * @param {React.MouseEvent<SVGElement, MouseEvent>} event The event source of the callback.
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Returns if the corner should have a radius or not based on the layout and the data.
3
+ * @param {GetRadiusCorner} corner The corner to check.
4
+ * @param {GetRadiusData} cornerData The data for the corner.
5
+ * @returns {number} The radius for the corner.
6
+ */
7
+ export const getRadius = (corner, {
8
+ hasNegative,
9
+ hasPositive,
10
+ borderRadius,
11
+ layout
12
+ }) => {
13
+ if (!borderRadius) {
14
+ return 0;
15
+ }
16
+ const isVertical = layout === 'vertical';
17
+ if (corner === 'top-left' && (isVertical && hasPositive || !isVertical && hasNegative)) {
18
+ return borderRadius;
19
+ }
20
+ if (corner === 'top-right' && (isVertical && hasPositive || !isVertical && hasPositive)) {
21
+ return borderRadius;
22
+ }
23
+ if (corner === 'bottom-right' && (isVertical && hasNegative || !isVertical && hasPositive)) {
24
+ return borderRadius;
25
+ }
26
+ if (corner === 'bottom-left' && (isVertical && hasNegative || !isVertical && hasNegative)) {
27
+ return borderRadius;
28
+ }
29
+ return 0;
30
+ };
@@ -1,13 +1,20 @@
1
+ import { getLabel } from '../internals/getLabel';
1
2
  const legendGetter = params => {
2
3
  const {
3
4
  seriesOrder,
4
5
  series
5
6
  } = params;
6
- const data = seriesOrder.map(seriesId => ({
7
- color: series[seriesId].color,
8
- label: series[seriesId].label,
9
- id: seriesId
10
- }));
11
- return data.filter(item => item.label !== undefined);
7
+ return seriesOrder.reduce((acc, seriesId) => {
8
+ const formattedLabel = getLabel(series[seriesId].label, 'legend');
9
+ if (formattedLabel === undefined) {
10
+ return acc;
11
+ }
12
+ acc.push({
13
+ color: series[seriesId].color,
14
+ label: formattedLabel,
15
+ id: seriesId
16
+ });
17
+ return acc;
18
+ }, []);
12
19
  };
13
20
  export default legendGetter;
@@ -0,0 +1 @@
1
+ export {};
@@ -127,6 +127,11 @@ process.env.NODE_ENV !== "production" ? ChartContainer.propTypes = {
127
127
  axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
128
128
  classes: PropTypes.object,
129
129
  colorMap: PropTypes.oneOfType([PropTypes.shape({
130
+ colors: PropTypes.arrayOf(PropTypes.string).isRequired,
131
+ type: PropTypes.oneOf(['ordinal']).isRequired,
132
+ unknownColor: PropTypes.string,
133
+ values: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired)
134
+ }), PropTypes.shape({
130
135
  color: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string.isRequired), PropTypes.func]).isRequired,
131
136
  max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
132
137
  min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
@@ -135,11 +140,6 @@ process.env.NODE_ENV !== "production" ? ChartContainer.propTypes = {
135
140
  colors: PropTypes.arrayOf(PropTypes.string).isRequired,
136
141
  thresholds: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired).isRequired,
137
142
  type: PropTypes.oneOf(['piecewise']).isRequired
138
- }), PropTypes.shape({
139
- colors: PropTypes.arrayOf(PropTypes.string).isRequired,
140
- type: PropTypes.oneOf(['ordinal']).isRequired,
141
- unknownColor: PropTypes.string,
142
- values: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired)
143
143
  })]),
144
144
  data: PropTypes.array,
145
145
  dataKey: PropTypes.string,
@@ -180,6 +180,11 @@ process.env.NODE_ENV !== "production" ? ChartContainer.propTypes = {
180
180
  axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
181
181
  classes: PropTypes.object,
182
182
  colorMap: PropTypes.oneOfType([PropTypes.shape({
183
+ colors: PropTypes.arrayOf(PropTypes.string).isRequired,
184
+ type: PropTypes.oneOf(['ordinal']).isRequired,
185
+ unknownColor: PropTypes.string,
186
+ values: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired)
187
+ }), PropTypes.shape({
183
188
  color: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string.isRequired), PropTypes.func]).isRequired,
184
189
  max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
185
190
  min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
@@ -188,11 +193,6 @@ process.env.NODE_ENV !== "production" ? ChartContainer.propTypes = {
188
193
  colors: PropTypes.arrayOf(PropTypes.string).isRequired,
189
194
  thresholds: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired).isRequired,
190
195
  type: PropTypes.oneOf(['piecewise']).isRequired
191
- }), PropTypes.shape({
192
- colors: PropTypes.arrayOf(PropTypes.string).isRequired,
193
- type: PropTypes.oneOf(['ordinal']).isRequired,
194
- unknownColor: PropTypes.string,
195
- values: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired)
196
196
  })]),
197
197
  data: PropTypes.array,
198
198
  dataKey: PropTypes.string,
@@ -4,7 +4,7 @@ const _excluded = ["vertical", "horizontal"];
4
4
  import * as React from 'react';
5
5
  import PropTypes from 'prop-types';
6
6
  import composeClasses from '@mui/utils/composeClasses';
7
- import { styled } from '@mui/material/styles';
7
+ import { styled, useThemeProps } from '@mui/material/styles';
8
8
  import { CartesianContext } from '../context/CartesianContextProvider';
9
9
  import { useTicks } from '../hooks/useTicks';
10
10
  import { getChartsGridUtilityClass, chartsGridClasses } from './chartsGridClasses';
@@ -12,15 +12,22 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
12
12
  const GridRoot = styled('g', {
13
13
  name: 'MuiChartsGrid',
14
14
  slot: 'Root',
15
- overridesResolver: (props, styles) => styles.root
15
+ overridesResolver: (props, styles) => [{
16
+ [`&.${chartsGridClasses.verticalLine}`]: styles.verticalLine
17
+ }, {
18
+ [`&.${chartsGridClasses.horizontalLine}`]: styles.horizontalLine
19
+ }, styles.root]
20
+ })({});
21
+ const GridLine = styled('line', {
22
+ name: 'MuiChartsGrid',
23
+ slot: 'Line',
24
+ overridesResolver: (props, styles) => styles.line
16
25
  })(({
17
26
  theme
18
27
  }) => ({
19
- [`& .${chartsGridClasses.line}`]: {
20
- stroke: (theme.vars || theme).palette.divider,
21
- shapeRendering: 'crispEdges',
22
- strokeWidth: 1
23
- }
28
+ stroke: (theme.vars || theme).palette.divider,
29
+ shapeRendering: 'crispEdges',
30
+ strokeWidth: 1
24
31
  }));
25
32
  const useUtilityClasses = ({
26
33
  classes
@@ -42,18 +49,22 @@ const useUtilityClasses = ({
42
49
  * - [ChartsGrid API](https://mui.com/x/api/charts/charts-axis/)
43
50
  */
44
51
  function ChartsGrid(props) {
52
+ const themeProps = useThemeProps({
53
+ props,
54
+ name: 'MuiChartsGrid'
55
+ });
45
56
  const {
46
57
  vertical,
47
58
  horizontal
48
- } = props,
49
- other = _objectWithoutPropertiesLoose(props, _excluded);
59
+ } = themeProps,
60
+ other = _objectWithoutPropertiesLoose(themeProps, _excluded);
50
61
  const {
51
62
  xAxis,
52
63
  xAxisIds,
53
64
  yAxis,
54
65
  yAxisIds
55
66
  } = React.useContext(CartesianContext);
56
- const classes = useUtilityClasses(props);
67
+ const classes = useUtilityClasses(themeProps);
57
68
  const horizontalAxisId = yAxisIds[0];
58
69
  const verticalAxisId = xAxisIds[0];
59
70
  const {
@@ -81,7 +92,7 @@ function ChartsGrid(props) {
81
92
  children: [vertical && xTicks.map(({
82
93
  formattedValue,
83
94
  offset
84
- }) => /*#__PURE__*/_jsx("line", {
95
+ }) => /*#__PURE__*/_jsx(GridLine, {
85
96
  y1: yScale.range()[0],
86
97
  y2: yScale.range()[1],
87
98
  x1: offset,
@@ -90,7 +101,7 @@ function ChartsGrid(props) {
90
101
  }, `vertical-${formattedValue}`)), horizontal && yTicks.map(({
91
102
  formattedValue,
92
103
  offset
93
- }) => /*#__PURE__*/_jsx("line", {
104
+ }) => /*#__PURE__*/_jsx(GridLine, {
94
105
  y1: offset,
95
106
  y2: offset,
96
107
  x1: xScale.range()[0],
@@ -1,5 +1,5 @@
1
- import _extends from "@babel/runtime/helpers/esm/extends";
2
1
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
2
+ import _extends from "@babel/runtime/helpers/esm/extends";
3
3
  const _excluded = ["message"];
4
4
  import * as React from 'react';
5
5
  import { styled } from '@mui/material/styles';
@@ -7,7 +7,7 @@ import { useDrawingArea } from '../hooks/useDrawingArea';
7
7
  import { jsx as _jsx } from "react/jsx-runtime";
8
8
  const StyledText = styled('text')(({
9
9
  theme
10
- }) => ({
10
+ }) => _extends({}, theme.typography.body2, {
11
11
  stroke: 'none',
12
12
  fill: theme.palette.text.primary,
13
13
  shapeRendering: 'crispEdges',
@@ -29,6 +29,6 @@ export function ChartsLoadingOverlay(props) {
29
29
  x: left + width / 2,
30
30
  y: top + height / 2
31
31
  }, other, {
32
- children: message ?? 'Loading data ...'
32
+ children: message ?? 'Loading data'
33
33
  }));
34
34
  }
@@ -1,5 +1,5 @@
1
- import _extends from "@babel/runtime/helpers/esm/extends";
2
1
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
2
+ import _extends from "@babel/runtime/helpers/esm/extends";
3
3
  const _excluded = ["message"];
4
4
  import * as React from 'react';
5
5
  import { styled } from '@mui/material/styles';
@@ -7,7 +7,7 @@ import { useDrawingArea } from '../hooks/useDrawingArea';
7
7
  import { jsx as _jsx } from "react/jsx-runtime";
8
8
  const StyledText = styled('text')(({
9
9
  theme
10
- }) => ({
10
+ }) => _extends({}, theme.typography.body2, {
11
11
  stroke: 'none',
12
12
  fill: theme.palette.text.primary,
13
13
  shapeRendering: 'crispEdges',
@@ -4,6 +4,7 @@ import clsx from 'clsx';
4
4
  import Typography from '@mui/material/Typography';
5
5
  import { ChartsTooltipCell, ChartsTooltipPaper, ChartsTooltipTable, ChartsTooltipMark, ChartsTooltipRow } from './ChartsTooltipTable';
6
6
  import { isCartesianSeries, utcFormatter } from './utils';
7
+ import { getLabel } from '../internals/getLabel';
7
8
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
8
9
  function DefaultChartsAxisTooltipContent(props) {
9
10
  const {
@@ -50,6 +51,7 @@ function DefaultChartsAxisTooltipContent(props) {
50
51
  if (formattedValue == null) {
51
52
  return null;
52
53
  }
54
+ const formattedLabel = getLabel(label, 'tooltip');
53
55
  return /*#__PURE__*/_jsxs(ChartsTooltipRow, {
54
56
  className: classes.row,
55
57
  children: [/*#__PURE__*/_jsx(ChartsTooltipCell, {
@@ -60,8 +62,8 @@ function DefaultChartsAxisTooltipContent(props) {
60
62
  })
61
63
  }), /*#__PURE__*/_jsx(ChartsTooltipCell, {
62
64
  className: clsx(classes.labelCell, classes.cell),
63
- children: label ? /*#__PURE__*/_jsx(Typography, {
64
- children: label
65
+ children: formattedLabel ? /*#__PURE__*/_jsx(Typography, {
66
+ children: formattedLabel
65
67
  }) : null
66
68
  }), /*#__PURE__*/_jsx(ChartsTooltipCell, {
67
69
  className: clsx(classes.valueCell, classes.cell),