@mui/x-charts 7.3.1 → 7.4.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 (147) hide show
  1. package/BarChart/BarChart.d.ts +4 -3
  2. package/BarChart/BarChart.js +22 -6
  3. package/BarChart/BarClipPath.d.ts +14 -0
  4. package/BarChart/BarClipPath.js +50 -0
  5. package/BarChart/BarPlot.d.ts +4 -0
  6. package/BarChart/BarPlot.js +108 -36
  7. package/BarChart/getRadius.d.ts +15 -0
  8. package/BarChart/getRadius.js +37 -0
  9. package/BarChart/types.d.ts +25 -0
  10. package/BarChart/types.js +5 -0
  11. package/CHANGELOG.md +141 -5
  12. package/ChartsAxis/axisClasses.d.ts +1 -1
  13. package/ChartsGrid/ChartsGrid.js +22 -11
  14. package/ChartsOverlay/ChartsLoadingOverlay.d.ts +3 -0
  15. package/ChartsOverlay/ChartsLoadingOverlay.js +43 -0
  16. package/ChartsOverlay/ChartsNoDataOverlay.d.ts +3 -0
  17. package/ChartsOverlay/ChartsNoDataOverlay.js +43 -0
  18. package/ChartsOverlay/ChartsOverlay.d.ts +35 -0
  19. package/ChartsOverlay/ChartsOverlay.js +41 -0
  20. package/ChartsOverlay/index.d.ts +3 -0
  21. package/ChartsOverlay/index.js +26 -0
  22. package/ChartsOverlay/package.json +6 -0
  23. package/ChartsReferenceLine/ChartsReferenceLine.js +1 -1
  24. package/ChartsReferenceLine/common.d.ts +1 -1
  25. package/ChartsTooltip/ChartsAxisTooltipContent.d.ts +1 -1
  26. package/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
  27. package/ChartsTooltip/ChartsTooltip.d.ts +2 -2
  28. package/ChartsTooltip/ChartsTooltip.js +2 -2
  29. package/ChartsTooltip/DefaultChartsAxisTooltipContent.js +1 -1
  30. package/ChartsXAxis/ChartsXAxis.d.ts +1 -1
  31. package/ChartsXAxis/ChartsXAxis.js +7 -0
  32. package/ChartsYAxis/ChartsYAxis.d.ts +1 -1
  33. package/ChartsYAxis/ChartsYAxis.js +7 -0
  34. package/Gauge/Gauge.js +1 -1
  35. package/Gauge/GaugeContainer.js +1 -1
  36. package/Gauge/GaugeProvider.d.ts +2 -2
  37. package/Gauge/GaugeProvider.js +1 -1
  38. package/Gauge/gaugeClasses.d.ts +2 -2
  39. package/Gauge/utils.d.ts +1 -1
  40. package/Gauge/utils.js +4 -4
  41. package/LineChart/AreaElement.d.ts +1 -1
  42. package/LineChart/LineChart.d.ts +4 -3
  43. package/LineChart/LineChart.js +12 -2
  44. package/LineChart/LineElement.d.ts +1 -1
  45. package/LineChart/MarkElement.d.ts +1 -1
  46. package/PieChart/PieArc.d.ts +1 -1
  47. package/PieChart/PieArcLabel.d.ts +1 -1
  48. package/PieChart/PieArcLabel.js +1 -1
  49. package/PieChart/PieArcLabelPlot.d.ts +1 -1
  50. package/PieChart/PieArcLabelPlot.js +3 -3
  51. package/PieChart/PieArcPlot.d.ts +1 -1
  52. package/PieChart/PieArcPlot.js +3 -3
  53. package/PieChart/PieChart.d.ts +4 -3
  54. package/PieChart/PieChart.js +15 -2
  55. package/ScatterChart/ScatterChart.d.ts +4 -3
  56. package/ScatterChart/ScatterChart.js +12 -2
  57. package/context/SeriesContextProvider.js +1 -1
  58. package/esm/BarChart/BarChart.js +22 -6
  59. package/esm/BarChart/BarClipPath.js +42 -0
  60. package/esm/BarChart/BarPlot.js +109 -37
  61. package/esm/BarChart/getRadius.js +30 -0
  62. package/esm/BarChart/types.js +1 -0
  63. package/esm/ChartsGrid/ChartsGrid.js +23 -12
  64. package/esm/ChartsOverlay/ChartsLoadingOverlay.js +34 -0
  65. package/esm/ChartsOverlay/ChartsNoDataOverlay.js +34 -0
  66. package/esm/ChartsOverlay/ChartsOverlay.js +31 -0
  67. package/esm/ChartsOverlay/index.js +3 -0
  68. package/esm/ChartsReferenceLine/ChartsReferenceLine.js +1 -1
  69. package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
  70. package/esm/ChartsTooltip/ChartsTooltip.js +2 -2
  71. package/esm/ChartsTooltip/DefaultChartsAxisTooltipContent.js +1 -1
  72. package/esm/ChartsXAxis/ChartsXAxis.js +7 -0
  73. package/esm/ChartsYAxis/ChartsYAxis.js +7 -0
  74. package/esm/Gauge/Gauge.js +1 -1
  75. package/esm/Gauge/GaugeContainer.js +1 -1
  76. package/esm/Gauge/GaugeProvider.js +1 -1
  77. package/esm/Gauge/utils.js +4 -4
  78. package/esm/LineChart/LineChart.js +12 -2
  79. package/esm/PieChart/PieArcLabel.js +1 -1
  80. package/esm/PieChart/PieArcLabelPlot.js +3 -3
  81. package/esm/PieChart/PieArcPlot.js +3 -3
  82. package/esm/PieChart/PieChart.js +15 -2
  83. package/esm/ScatterChart/ScatterChart.js +12 -2
  84. package/esm/context/SeriesContextProvider.js +1 -1
  85. package/esm/hooks/useReducedMotion.js +1 -1
  86. package/esm/hooks/useScale.js +1 -1
  87. package/esm/hooks/useTicks.js +4 -0
  88. package/esm/internals/components/ChartsAxesGradients/ChartsAxesGradients.js +5 -5
  89. package/esm/internals/components/ChartsAxesGradients/ChartsContinuousGradient.js +3 -3
  90. package/esm/internals/components/ChartsAxesGradients/ChartsPiecewiseGradient.js +3 -3
  91. package/esm/internals/utils.js +1 -1
  92. package/hooks/useReducedMotion.d.ts +1 -1
  93. package/hooks/useReducedMotion.js +1 -1
  94. package/hooks/useScale.d.ts +4 -4
  95. package/hooks/useScale.js +1 -1
  96. package/hooks/useTicks.js +4 -0
  97. package/index.js +1 -1
  98. package/internals/components/ChartsAxesGradients/ChartsAxesGradients.js +5 -5
  99. package/internals/components/ChartsAxesGradients/ChartsContinuousGradient.d.ts +1 -1
  100. package/internals/components/ChartsAxesGradients/ChartsContinuousGradient.js +3 -3
  101. package/internals/components/ChartsAxesGradients/ChartsPiecewiseGradient.d.ts +1 -1
  102. package/internals/components/ChartsAxesGradients/ChartsPiecewiseGradient.js +3 -3
  103. package/internals/utils.d.ts +1 -1
  104. package/internals/utils.js +1 -1
  105. package/models/axis.d.ts +1 -1
  106. package/models/seriesType/bar.d.ts +1 -1
  107. package/models/seriesType/line.d.ts +1 -1
  108. package/models/seriesType/pie.d.ts +4 -4
  109. package/modern/BarChart/BarChart.js +22 -6
  110. package/modern/BarChart/BarClipPath.js +42 -0
  111. package/modern/BarChart/BarPlot.js +109 -37
  112. package/modern/BarChart/getRadius.js +30 -0
  113. package/modern/BarChart/types.js +1 -0
  114. package/modern/ChartsGrid/ChartsGrid.js +23 -12
  115. package/modern/ChartsOverlay/ChartsLoadingOverlay.js +34 -0
  116. package/modern/ChartsOverlay/ChartsNoDataOverlay.js +34 -0
  117. package/modern/ChartsOverlay/ChartsOverlay.js +31 -0
  118. package/modern/ChartsOverlay/index.js +3 -0
  119. package/modern/ChartsReferenceLine/ChartsReferenceLine.js +1 -1
  120. package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
  121. package/modern/ChartsTooltip/ChartsTooltip.js +2 -2
  122. package/modern/ChartsTooltip/DefaultChartsAxisTooltipContent.js +1 -1
  123. package/modern/ChartsXAxis/ChartsXAxis.js +7 -0
  124. package/modern/ChartsYAxis/ChartsYAxis.js +7 -0
  125. package/modern/Gauge/Gauge.js +1 -1
  126. package/modern/Gauge/GaugeContainer.js +1 -1
  127. package/modern/Gauge/GaugeProvider.js +1 -1
  128. package/modern/Gauge/utils.js +4 -4
  129. package/modern/LineChart/LineChart.js +12 -2
  130. package/modern/PieChart/PieArcLabel.js +1 -1
  131. package/modern/PieChart/PieArcLabelPlot.js +3 -3
  132. package/modern/PieChart/PieArcPlot.js +3 -3
  133. package/modern/PieChart/PieChart.js +15 -2
  134. package/modern/ScatterChart/ScatterChart.js +12 -2
  135. package/modern/context/SeriesContextProvider.js +1 -1
  136. package/modern/hooks/useReducedMotion.js +1 -1
  137. package/modern/hooks/useScale.js +1 -1
  138. package/modern/hooks/useTicks.js +4 -0
  139. package/modern/index.js +1 -1
  140. package/modern/internals/components/ChartsAxesGradients/ChartsAxesGradients.js +5 -5
  141. package/modern/internals/components/ChartsAxesGradients/ChartsContinuousGradient.js +3 -3
  142. package/modern/internals/components/ChartsAxesGradients/ChartsPiecewiseGradient.js +3 -3
  143. package/modern/internals/utils.js +1 -1
  144. package/package.json +2 -2
  145. package/themeAugmentation/components.d.ts +4 -0
  146. package/themeAugmentation/overrides.d.ts +2 -0
  147. package/themeAugmentation/props.d.ts +2 -0
@@ -10,11 +10,12 @@ import { ChartsAxisHighlightProps } from '../ChartsAxisHighlight';
10
10
  import { ChartsAxisSlots, ChartsAxisSlotProps } from '../models/axis';
11
11
  import { ChartsGridProps } from '../ChartsGrid';
12
12
  import { ChartsOnAxisClickHandlerProps } from '../ChartsOnAxisClickHandler';
13
- export interface BarChartSlots extends ChartsAxisSlots, BarPlotSlots, ChartsLegendSlots, ChartsTooltipSlots {
13
+ import { ChartsOverlayProps, ChartsOverlaySlotProps, ChartsOverlaySlots } from '../ChartsOverlay/ChartsOverlay';
14
+ export interface BarChartSlots extends ChartsAxisSlots, BarPlotSlots, ChartsLegendSlots, ChartsTooltipSlots, ChartsOverlaySlots {
14
15
  }
15
- export interface BarChartSlotProps extends ChartsAxisSlotProps, BarPlotSlotProps, ChartsLegendSlotProps, ChartsTooltipSlotProps {
16
+ export interface BarChartSlotProps extends ChartsAxisSlotProps, BarPlotSlotProps, ChartsLegendSlotProps, ChartsTooltipSlotProps, ChartsOverlaySlotProps {
16
17
  }
17
- export interface BarChartProps extends Omit<ResponsiveChartContainerProps, 'series'>, Omit<ChartsAxisProps, 'slots' | 'slotProps'>, Omit<BarPlotProps, 'slots' | 'slotProps'>, ChartsOnAxisClickHandlerProps {
18
+ export interface BarChartProps extends Omit<ResponsiveChartContainerProps, 'series'>, Omit<ChartsAxisProps, 'slots' | 'slotProps'>, Omit<BarPlotProps, 'slots' | 'slotProps'>, Omit<ChartsOverlayProps, 'slots' | 'slotProps'>, ChartsOnAxisClickHandlerProps {
18
19
  /**
19
20
  * The series to display in the bar chart.
20
21
  * An array of [[BarSeriesType]] objects.
@@ -19,6 +19,7 @@ var _ChartsAxisHighlight = require("../ChartsAxisHighlight");
19
19
  var _ChartsClipPath = require("../ChartsClipPath");
20
20
  var _ChartsGrid = require("../ChartsGrid");
21
21
  var _ChartsOnAxisClickHandler = require("../ChartsOnAxisClickHandler");
22
+ var _ChartsOverlay = require("../ChartsOverlay/ChartsOverlay");
22
23
  var _jsxRuntime = require("react/jsx-runtime");
23
24
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
24
25
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
@@ -54,11 +55,13 @@ const BarChart = exports.BarChart = /*#__PURE__*/React.forwardRef(function BarCh
54
55
  rightAxis,
55
56
  bottomAxis,
56
57
  skipAnimation,
58
+ borderRadius,
57
59
  onItemClick,
58
60
  onAxisClick,
59
61
  children,
60
62
  slots,
61
- slotProps
63
+ slotProps,
64
+ loading
62
65
  } = props;
63
66
  const id = (0, _useId.default)();
64
67
  const clipPathId = `${id}-clip-path`;
@@ -99,14 +102,19 @@ const BarChart = exports.BarChart = /*#__PURE__*/React.forwardRef(function BarCh
99
102
  }), grid && /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsGrid.ChartsGrid, {
100
103
  vertical: grid.vertical,
101
104
  horizontal: grid.horizontal
102
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)("g", {
105
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)("g", {
103
106
  clipPath: `url(#${clipPathId})`,
104
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_BarPlot.BarPlot, {
107
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_BarPlot.BarPlot, {
105
108
  slots: slots,
106
109
  slotProps: slotProps,
107
110
  skipAnimation: skipAnimation,
108
- onItemClick: onItemClick
109
- })
111
+ onItemClick: onItemClick,
112
+ borderRadius: borderRadius
113
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsOverlay.ChartsOverlay, {
114
+ loading: loading,
115
+ slots: slots,
116
+ slotProps: slotProps
117
+ })]
110
118
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsAxis.ChartsAxis, {
111
119
  topAxis: topAxis,
112
120
  leftAxis: leftAxis,
@@ -117,7 +125,7 @@ const BarChart = exports.BarChart = /*#__PURE__*/React.forwardRef(function BarCh
117
125
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsLegend.ChartsLegend, (0, _extends2.default)({}, legend, {
118
126
  slots: slots,
119
127
  slotProps: slotProps
120
- })), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsAxisHighlight.ChartsAxisHighlight, (0, _extends2.default)({}, defaultizedAxisHighlight)), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsTooltip.ChartsTooltip, (0, _extends2.default)({}, tooltip, {
128
+ })), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsAxisHighlight.ChartsAxisHighlight, (0, _extends2.default)({}, defaultizedAxisHighlight)), !loading && /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsTooltip.ChartsTooltip, (0, _extends2.default)({}, tooltip, {
121
129
  slots: slots,
122
130
  slotProps: slotProps
123
131
  })), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsClipPath.ChartsClipPath, {
@@ -140,6 +148,10 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
140
148
  x: _propTypes.default.oneOf(['band', 'line', 'none']),
141
149
  y: _propTypes.default.oneOf(['band', 'line', 'none'])
142
150
  }),
151
+ /**
152
+ * Defines the border radius of the bar element.
153
+ */
154
+ borderRadius: _propTypes.default.number,
143
155
  /**
144
156
  * Indicate which axis to display the bottom of the charts.
145
157
  * Can be a string (the id of the axis) or an object `ChartsXAxisProps`.
@@ -200,6 +212,10 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
200
212
  slotProps: _propTypes.default.object,
201
213
  slots: _propTypes.default.object
202
214
  }),
215
+ /**
216
+ * If `true`, a loading overlay is displayed.
217
+ */
218
+ loading: _propTypes.default.bool,
203
219
  /**
204
220
  * The margin between the SVG and the drawing area.
205
221
  * It's used for leaving some space for extra information such as the x- and y-axis or legend.
@@ -0,0 +1,14 @@
1
+ import * as React from 'react';
2
+ export interface BarClipPathProps {
3
+ maskId: string;
4
+ borderRadius?: number;
5
+ hasNegative: boolean;
6
+ hasPositive: boolean;
7
+ layout?: 'vertical' | 'horizontal';
8
+ style: {};
9
+ }
10
+ /**
11
+ * @ignore - internal component.
12
+ */
13
+ declare function BarClipPath(props: BarClipPathProps): React.JSX.Element | null;
14
+ export { BarClipPath };
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.BarClipPath = BarClipPath;
8
+ var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
9
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
10
+ var React = _interopRequireWildcard(require("react"));
11
+ var _web = require("@react-spring/web");
12
+ var _getRadius = require("./getRadius");
13
+ var _jsxRuntime = require("react/jsx-runtime");
14
+ const _excluded = ["style", "maskId"];
15
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
16
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
17
+ const buildInset = corners => `inset(0px round ${corners.topLeft}px ${corners.topRight}px ${corners.bottomRight}px ${corners.bottomLeft}px)`;
18
+ function BarClipRect(props) {
19
+ const radiusData = props.ownerState;
20
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_web.animated.rect, {
21
+ style: (0, _extends2.default)({}, props.style, {
22
+ clipPath: (props.ownerState.layout === 'vertical' ? props.style?.height : props.style?.width).to(value => buildInset({
23
+ topLeft: Math.min(value, (0, _getRadius.getRadius)('top-left', radiusData)),
24
+ topRight: Math.min(value, (0, _getRadius.getRadius)('top-right', radiusData)),
25
+ bottomRight: Math.min(value, (0, _getRadius.getRadius)('bottom-right', radiusData)),
26
+ bottomLeft: Math.min(value, (0, _getRadius.getRadius)('bottom-left', radiusData))
27
+ }))
28
+ })
29
+ });
30
+ }
31
+ /**
32
+ * @ignore - internal component.
33
+ */
34
+ function BarClipPath(props) {
35
+ const {
36
+ style,
37
+ maskId
38
+ } = props,
39
+ rest = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
40
+ if (!props.borderRadius || props.borderRadius <= 0) {
41
+ return null;
42
+ }
43
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("clipPath", {
44
+ id: maskId,
45
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(BarClipRect, {
46
+ ownerState: rest,
47
+ style: style
48
+ })
49
+ });
50
+ }
@@ -17,6 +17,10 @@ export interface BarPlotProps extends Pick<BarElementProps, 'slots' | 'slotProps
17
17
  * @param {BarItemIdentifier} barItemIdentifier The bar item identifier.
18
18
  */
19
19
  onItemClick?: (event: React.MouseEvent<SVGElement, MouseEvent>, barItemIdentifier: BarItemIdentifier) => void;
20
+ /**
21
+ * Defines the border radius of the bar element.
22
+ */
23
+ borderRadius?: number;
20
24
  }
21
25
  /**
22
26
  * Demos:
@@ -16,8 +16,10 @@ var _BarElement = require("./BarElement");
16
16
  var _axis = require("../models/axis");
17
17
  var _constants = require("../constants");
18
18
  var _getColor = _interopRequireDefault(require("./getColor"));
19
+ var _hooks = require("../hooks");
20
+ var _BarClipPath = require("./BarClipPath");
19
21
  var _jsxRuntime = require("react/jsx-runtime");
20
- const _excluded = ["skipAnimation", "onItemClick"];
22
+ const _excluded = ["skipAnimation", "onItemClick", "borderRadius"];
21
23
  /**
22
24
  * Solution of the equations
23
25
  * W = barWidth * N + offset * (N-1)
@@ -54,6 +56,7 @@ const useAggregatedData = () => {
54
56
  seriesOrder: []
55
57
  };
56
58
  const axisData = React.useContext(_CartesianContextProvider.CartesianContext);
59
+ const chartId = (0, _hooks.useChartId)();
57
60
  const {
58
61
  series,
59
62
  stackingGroups
@@ -66,6 +69,7 @@ const useAggregatedData = () => {
66
69
  } = axisData;
67
70
  const defaultXAxisId = xAxisIds[0];
68
71
  const defaultYAxisId = yAxisIds[0];
72
+ const masks = {};
69
73
  const data = stackingGroups.flatMap(({
70
74
  ids: groupIds
71
75
  }, groupIndex) => {
@@ -78,25 +82,25 @@ const useAggregatedData = () => {
78
82
  let baseScaleConfig;
79
83
  if (verticalLayout) {
80
84
  if (!(0, _axis.isBandScaleConfig)(xAxisConfig)) {
81
- throw new Error(`MUI X Charts: ${xAxisKey === _constants.DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : `The x-axis with id "${xAxisKey}"`} shoud be of type "band" to display the bar series of id "${seriesId}".`);
85
+ throw new Error(`MUI X Charts: ${xAxisKey === _constants.DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : `The x-axis with id "${xAxisKey}"`} should be of type "band" to display the bar series of id "${seriesId}".`);
82
86
  }
83
87
  if (xAxis[xAxisKey].data === undefined) {
84
- throw new Error(`MUI X Charts: ${xAxisKey === _constants.DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : `The x-axis with id "${xAxisKey}"`} shoud have data property.`);
88
+ throw new Error(`MUI X Charts: ${xAxisKey === _constants.DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : `The x-axis with id "${xAxisKey}"`} should have data property.`);
85
89
  }
86
90
  baseScaleConfig = xAxisConfig;
87
91
  if ((0, _axis.isBandScaleConfig)(yAxisConfig) || (0, _axis.isPointScaleConfig)(yAxisConfig)) {
88
- throw new Error(`MUI X Charts: ${yAxisKey === _constants.DEFAULT_Y_AXIS_KEY ? 'The first `yAxis`' : `The y-axis with id "${yAxisKey}"`} shoud be a continuous type to display the bar series of id "${seriesId}".`);
92
+ throw new Error(`MUI X Charts: ${yAxisKey === _constants.DEFAULT_Y_AXIS_KEY ? 'The first `yAxis`' : `The y-axis with id "${yAxisKey}"`} should be a continuous type to display the bar series of id "${seriesId}".`);
89
93
  }
90
94
  } else {
91
95
  if (!(0, _axis.isBandScaleConfig)(yAxisConfig)) {
92
- throw new Error(`MUI X Charts: ${yAxisKey === _constants.DEFAULT_Y_AXIS_KEY ? 'The first `yAxis`' : `The y-axis with id "${yAxisKey}"`} shoud be of type "band" to display the bar series of id "${seriesId}".`);
96
+ throw new Error(`MUI X Charts: ${yAxisKey === _constants.DEFAULT_Y_AXIS_KEY ? 'The first `yAxis`' : `The y-axis with id "${yAxisKey}"`} should be of type "band" to display the bar series of id "${seriesId}".`);
93
97
  }
94
98
  if (yAxis[yAxisKey].data === undefined) {
95
- throw new Error(`MUI X Charts: ${yAxisKey === _constants.DEFAULT_Y_AXIS_KEY ? 'The first `yAxis`' : `The y-axis with id "${yAxisKey}"`} shoud have data property.`);
99
+ throw new Error(`MUI X Charts: ${yAxisKey === _constants.DEFAULT_Y_AXIS_KEY ? 'The first `yAxis`' : `The y-axis with id "${yAxisKey}"`} should have data property.`);
96
100
  }
97
101
  baseScaleConfig = yAxisConfig;
98
102
  if ((0, _axis.isBandScaleConfig)(xAxisConfig) || (0, _axis.isPointScaleConfig)(xAxisConfig)) {
99
- throw new Error(`MUI X Charts: ${xAxisKey === _constants.DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : `The x-axis with id "${xAxisKey}"`} shoud be a continuous type to display the bar series of id "${seriesId}".`);
103
+ throw new Error(`MUI X Charts: ${xAxisKey === _constants.DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : `The x-axis with id "${xAxisKey}"`} should be a continuous type to display the bar series of id "${seriesId}".`);
100
104
  }
101
105
  }
102
106
  const xScale = xAxisConfig.scale;
@@ -119,7 +123,8 @@ const useAggregatedData = () => {
119
123
  const valueCoordinates = values.map(v => verticalLayout ? yScale(v) : xScale(v));
120
124
  const minValueCoord = Math.round(Math.min(...valueCoordinates));
121
125
  const maxValueCoord = Math.round(Math.max(...valueCoordinates));
122
- return {
126
+ const stackId = series[seriesId].stack;
127
+ const result = {
123
128
  seriesId,
124
129
  dataIndex,
125
130
  layout: series[seriesId].layout,
@@ -130,14 +135,41 @@ const useAggregatedData = () => {
130
135
  height: verticalLayout ? maxValueCoord - minValueCoord : barWidth,
131
136
  width: verticalLayout ? barWidth : maxValueCoord - minValueCoord,
132
137
  color: colorGetter(dataIndex),
133
- highlightScope: series[seriesId].highlightScope
138
+ highlightScope: series[seriesId].highlightScope,
139
+ value: series[seriesId].data[dataIndex],
140
+ maskId: `${chartId}_${stackId || seriesId}_${groupIndex}_${dataIndex}`
134
141
  };
142
+ if (!masks[result.maskId]) {
143
+ masks[result.maskId] = {
144
+ id: result.maskId,
145
+ width: 0,
146
+ height: 0,
147
+ hasNegative: false,
148
+ hasPositive: false,
149
+ layout: result.layout,
150
+ xOrigin: xScale(0),
151
+ yOrigin: yScale(0),
152
+ x: 0,
153
+ y: 0
154
+ };
155
+ }
156
+ const mask = masks[result.maskId];
157
+ mask.width = result.layout === 'vertical' ? result.width : mask.width + result.width;
158
+ mask.height = result.layout === 'vertical' ? mask.height + result.height : result.height;
159
+ mask.x = Math.min(mask.x === 0 ? Infinity : mask.x, result.x);
160
+ mask.y = Math.min(mask.y === 0 ? Infinity : mask.y, result.y);
161
+ mask.hasNegative = mask.hasNegative || (result.value ?? 0) < 0;
162
+ mask.hasPositive = mask.hasPositive || (result.value ?? 0) > 0;
163
+ return result;
135
164
  });
136
165
  });
137
166
  });
138
- return data;
167
+ return {
168
+ completedData: data,
169
+ masksData: Object.values(masks)
170
+ };
139
171
  };
140
- const getOutStyle = ({
172
+ const leaveStyle = ({
141
173
  layout,
142
174
  yOrigin,
143
175
  x,
@@ -156,7 +188,7 @@ const getOutStyle = ({
156
188
  height,
157
189
  width: 0
158
190
  });
159
- const getInStyle = ({
191
+ const enterStyle = ({
160
192
  x,
161
193
  width,
162
194
  y,
@@ -180,41 +212,77 @@ const getInStyle = ({
180
212
  * - [BarPlot API](https://mui.com/x/api/charts/bar-plot/)
181
213
  */
182
214
  function BarPlot(props) {
183
- const completedData = useAggregatedData();
215
+ const {
216
+ completedData,
217
+ masksData
218
+ } = useAggregatedData();
184
219
  const {
185
220
  skipAnimation,
186
- onItemClick
221
+ onItemClick,
222
+ borderRadius
187
223
  } = props,
188
224
  other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
189
225
  const transition = (0, _web.useTransition)(completedData, {
190
226
  keys: bar => `${bar.seriesId}-${bar.dataIndex}`,
191
- from: getOutStyle,
192
- leave: getOutStyle,
193
- enter: getInStyle,
194
- update: getInStyle,
227
+ from: leaveStyle,
228
+ leave: leaveStyle,
229
+ enter: enterStyle,
230
+ update: enterStyle,
231
+ immediate: skipAnimation
232
+ });
233
+ const maskTransition = (0, _web.useTransition)(masksData, {
234
+ keys: v => v.id,
235
+ from: leaveStyle,
236
+ leave: leaveStyle,
237
+ enter: enterStyle,
238
+ update: enterStyle,
195
239
  immediate: skipAnimation
196
240
  });
197
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(React.Fragment, {
198
- children: transition((style, {
241
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(React.Fragment, {
242
+ children: [maskTransition((style, {
243
+ id,
244
+ hasPositive,
245
+ hasNegative,
246
+ layout
247
+ }) => {
248
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_BarClipPath.BarClipPath, {
249
+ maskId: id,
250
+ borderRadius: borderRadius,
251
+ hasNegative: hasNegative,
252
+ hasPositive: hasPositive,
253
+ layout: layout,
254
+ style: style
255
+ });
256
+ }), transition((style, {
199
257
  seriesId,
200
258
  dataIndex,
201
259
  color,
202
- highlightScope
203
- }) => /*#__PURE__*/(0, _jsxRuntime.jsx)(_BarElement.BarElement, (0, _extends2.default)({
204
- id: seriesId,
205
- dataIndex: dataIndex,
206
- highlightScope: highlightScope,
207
- color: color
208
- }, other, {
209
- onClick: onItemClick && (event => {
210
- onItemClick(event, {
211
- type: 'bar',
212
- seriesId,
213
- dataIndex
214
- });
215
- }),
216
- style: style
217
- })))
260
+ highlightScope,
261
+ maskId
262
+ }) => {
263
+ const barElement = /*#__PURE__*/(0, _jsxRuntime.jsx)(_BarElement.BarElement, (0, _extends2.default)({
264
+ id: seriesId,
265
+ dataIndex: dataIndex,
266
+ color: color,
267
+ highlightScope: highlightScope
268
+ }, other, {
269
+ onClick: onItemClick && (event => {
270
+ onItemClick(event, {
271
+ type: 'bar',
272
+ seriesId,
273
+ dataIndex
274
+ });
275
+ }),
276
+ style: style
277
+ }));
278
+ if (!borderRadius || borderRadius <= 0) {
279
+ return barElement;
280
+ }
281
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("g", {
282
+ clipPath: `url(#${maskId})`,
283
+ children: barElement
284
+ });
285
+ })]
218
286
  });
219
287
  }
220
288
  process.env.NODE_ENV !== "production" ? BarPlot.propTypes = {
@@ -222,6 +290,10 @@ process.env.NODE_ENV !== "production" ? BarPlot.propTypes = {
222
290
  // | These PropTypes are generated from the TypeScript type definitions |
223
291
  // | To update them edit the TypeScript types and run "yarn proptypes" |
224
292
  // ----------------------------------------------------------------------
293
+ /**
294
+ * Defines the border radius of the bar element.
295
+ */
296
+ borderRadius: _propTypes.default.number,
225
297
  /**
226
298
  * Callback fired when a bar item is clicked.
227
299
  * @param {React.MouseEvent<SVGElement, MouseEvent>} event The event source of the callback.
@@ -0,0 +1,15 @@
1
+ type GetRadiusData = {
2
+ hasNegative: boolean;
3
+ hasPositive: boolean;
4
+ borderRadius?: number;
5
+ layout?: 'vertical' | 'horizontal';
6
+ };
7
+ type GetRadiusCorner = 'top-left' | 'top-right' | 'bottom-right' | 'bottom-left';
8
+ /**
9
+ * Returns if the corner should have a radius or not based on the layout and the data.
10
+ * @param {GetRadiusCorner} corner The corner to check.
11
+ * @param {GetRadiusData} cornerData The data for the corner.
12
+ * @returns {number} The radius for the corner.
13
+ */
14
+ export declare const getRadius: (corner: GetRadiusCorner, { hasNegative, hasPositive, borderRadius, layout }: GetRadiusData) => number;
15
+ export {};
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getRadius = void 0;
7
+ /**
8
+ * Returns if the corner should have a radius or not based on the layout and the data.
9
+ * @param {GetRadiusCorner} corner The corner to check.
10
+ * @param {GetRadiusData} cornerData The data for the corner.
11
+ * @returns {number} The radius for the corner.
12
+ */
13
+ const getRadius = (corner, {
14
+ hasNegative,
15
+ hasPositive,
16
+ borderRadius,
17
+ layout
18
+ }) => {
19
+ if (!borderRadius) {
20
+ return 0;
21
+ }
22
+ const isVertical = layout === 'vertical';
23
+ if (corner === 'top-left' && (isVertical && hasPositive || !isVertical && hasNegative)) {
24
+ return borderRadius;
25
+ }
26
+ if (corner === 'top-right' && (isVertical && hasPositive || !isVertical && hasPositive)) {
27
+ return borderRadius;
28
+ }
29
+ if (corner === 'bottom-right' && (isVertical && hasNegative || !isVertical && hasPositive)) {
30
+ return borderRadius;
31
+ }
32
+ if (corner === 'bottom-left' && (isVertical && hasNegative || !isVertical && hasNegative)) {
33
+ return borderRadius;
34
+ }
35
+ return 0;
36
+ };
37
+ exports.getRadius = getRadius;
@@ -0,0 +1,25 @@
1
+ import type { HighlightScope } from '../context';
2
+ import type { BarSeriesType } from '../models';
3
+ import type { SeriesId } from '../models/seriesType/common';
4
+ export type AnimationData = {
5
+ x: number;
6
+ y: number;
7
+ width: number;
8
+ height: number;
9
+ yOrigin: number;
10
+ xOrigin: number;
11
+ layout: BarSeriesType['layout'];
12
+ };
13
+ export interface CompletedBarData extends AnimationData {
14
+ seriesId: SeriesId;
15
+ dataIndex: number;
16
+ color: string;
17
+ value: number | null;
18
+ highlightScope?: Partial<HighlightScope>;
19
+ maskId: string;
20
+ }
21
+ export interface MaskData extends AnimationData {
22
+ id: string;
23
+ hasNegative: boolean;
24
+ hasPositive: boolean;
25
+ }
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });