@mui/x-charts 7.9.0 → 7.11.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 (222) hide show
  1. package/BarChart/BarChart.js +2 -2
  2. package/BarChart/formatter.js +1 -1
  3. package/BarChart/useBarChartProps.js +38 -33
  4. package/CHANGELOG.md +159 -0
  5. package/ChartContainer/ChartContainer.d.ts +28 -2
  6. package/ChartContainer/ChartContainer.js +25 -66
  7. package/ChartContainer/useChartContainerHooks.d.ts +1 -1
  8. package/ChartContainer/useChartContainerHooks.js +2 -2
  9. package/ChartContainer/useChartContainerProps.d.ts +86 -0
  10. package/ChartContainer/useChartContainerProps.js +95 -0
  11. package/ChartContainer/useDefaultizeAxis.d.ts +36 -0
  12. package/ChartContainer/useDefaultizeAxis.js +29 -0
  13. package/ChartsLegend/ChartsLegend.d.ts +3 -12
  14. package/ChartsLegend/ContinuousColorLegend.d.ts +65 -0
  15. package/ChartsLegend/ContinuousColorLegend.js +398 -0
  16. package/ChartsLegend/DefaultChartsLegend.d.ts +7 -50
  17. package/ChartsLegend/DefaultChartsLegend.js +13 -198
  18. package/ChartsLegend/LegendPerItem.d.ts +61 -0
  19. package/ChartsLegend/LegendPerItem.js +151 -0
  20. package/ChartsLegend/PiecewiseColorLegend.d.ts +26 -0
  21. package/ChartsLegend/PiecewiseColorLegend.js +169 -0
  22. package/ChartsLegend/chartsLegend.types.d.ts +31 -0
  23. package/ChartsLegend/chartsLegend.types.js +5 -0
  24. package/ChartsLegend/index.d.ts +2 -0
  25. package/ChartsLegend/index.js +22 -0
  26. package/ChartsLegend/legend.types.d.ts +62 -0
  27. package/ChartsLegend/legend.types.js +5 -0
  28. package/ChartsLegend/legendItemsPlacement.d.ts +3 -0
  29. package/ChartsLegend/legendItemsPlacement.js +79 -0
  30. package/ChartsLegend/useAxis.d.ts +7 -0
  31. package/ChartsLegend/useAxis.js +47 -0
  32. package/ChartsLegend/utils.d.ts +1 -8
  33. package/ChartsReferenceLine/ChartsReferenceLine.d.ts +1 -1
  34. package/ChartsSurface.js +3 -1
  35. package/ChartsVoronoiHandler/ChartsVoronoiHandler.js +26 -18
  36. package/ChartsXAxis/ChartsXAxis.js +1 -1
  37. package/ChartsYAxis/ChartsYAxis.js +15 -3
  38. package/Gauge/Gauge.d.ts +1 -4
  39. package/Gauge/Gauge.js +9 -6
  40. package/Gauge/GaugeContainer.js +8 -4
  41. package/Gauge/GaugeProvider.js +9 -9
  42. package/LineChart/AnimatedArea.js +2 -2
  43. package/LineChart/AnimatedLine.js +2 -2
  44. package/LineChart/AreaPlot.js +7 -1
  45. package/LineChart/LineChart.js +2 -2
  46. package/LineChart/LineHighlightPlot.js +8 -0
  47. package/LineChart/MarkElement.js +2 -2
  48. package/LineChart/MarkPlot.js +4 -20
  49. package/LineChart/extremums.js +1 -1
  50. package/LineChart/formatter.js +1 -1
  51. package/LineChart/useLineChartProps.js +38 -33
  52. package/PieChart/PieChart.d.ts +1 -4
  53. package/PieChart/PieChart.js +40 -34
  54. package/PieChart/PiePlot.js +6 -6
  55. package/PieChart/getPieCoordinates.js +3 -3
  56. package/ResponsiveChartContainer/ResponsiveChartContainer.js +8 -20
  57. package/ResponsiveChartContainer/useChartContainerDimensions.d.ts +5 -1
  58. package/ResponsiveChartContainer/useChartContainerDimensions.js +6 -2
  59. package/ResponsiveChartContainer/useResponsiveChartContainerProps.d.ts +20 -0
  60. package/ResponsiveChartContainer/useResponsiveChartContainerProps.js +73 -0
  61. package/ScatterChart/Scatter.js +6 -9
  62. package/ScatterChart/useScatterChartProps.js +35 -30
  63. package/SparkLineChart/SparkLineChart.js +27 -22
  64. package/context/CartesianProvider/CartesianProvider.d.ts +2 -3
  65. package/context/CartesianProvider/CartesianProvider.js +18 -7
  66. package/context/CartesianProvider/computeValue.d.ts +32 -9
  67. package/context/CartesianProvider/computeValue.js +20 -16
  68. package/context/CartesianProvider/defaultizeAxis.d.ts +36 -0
  69. package/context/CartesianProvider/defaultizeAxis.js +21 -0
  70. package/context/CartesianProvider/index.d.ts +0 -1
  71. package/context/CartesianProvider/index.js +1 -3
  72. package/context/CartesianProvider/normalizeAxis.d.ts +1 -1
  73. package/context/CartesianProvider/normalizeAxis.js +1 -1
  74. package/context/DrawingProvider.d.ts +11 -0
  75. package/context/DrawingProvider.js +9 -2
  76. package/context/HighlightedProvider/HighlightedProvider.js +2 -2
  77. package/esm/BarChart/BarChart.js +2 -2
  78. package/esm/BarChart/formatter.js +1 -1
  79. package/esm/BarChart/useBarChartProps.js +38 -33
  80. package/esm/ChartContainer/ChartContainer.js +25 -66
  81. package/esm/ChartContainer/useChartContainerHooks.js +2 -2
  82. package/esm/ChartContainer/useChartContainerProps.js +87 -0
  83. package/esm/ChartContainer/useDefaultizeAxis.js +19 -0
  84. package/esm/ChartsLegend/ContinuousColorLegend.js +390 -0
  85. package/esm/ChartsLegend/DefaultChartsLegend.js +14 -198
  86. package/esm/ChartsLegend/LegendPerItem.js +141 -0
  87. package/esm/ChartsLegend/PiecewiseColorLegend.js +161 -0
  88. package/esm/ChartsLegend/chartsLegend.types.js +1 -0
  89. package/esm/ChartsLegend/index.js +2 -0
  90. package/esm/ChartsLegend/legend.types.js +1 -0
  91. package/esm/ChartsLegend/legendItemsPlacement.js +72 -0
  92. package/esm/ChartsLegend/useAxis.js +39 -0
  93. package/esm/ChartsSurface.js +3 -1
  94. package/esm/ChartsVoronoiHandler/ChartsVoronoiHandler.js +26 -18
  95. package/esm/ChartsXAxis/ChartsXAxis.js +1 -1
  96. package/esm/ChartsYAxis/ChartsYAxis.js +15 -3
  97. package/esm/Gauge/Gauge.js +8 -5
  98. package/esm/Gauge/GaugeContainer.js +8 -4
  99. package/esm/Gauge/GaugeProvider.js +1 -1
  100. package/esm/LineChart/AnimatedArea.js +1 -1
  101. package/esm/LineChart/AnimatedLine.js +1 -1
  102. package/esm/LineChart/AreaPlot.js +7 -1
  103. package/esm/LineChart/LineChart.js +2 -2
  104. package/esm/LineChart/LineHighlightPlot.js +8 -0
  105. package/esm/LineChart/MarkElement.js +1 -1
  106. package/esm/LineChart/MarkPlot.js +3 -19
  107. package/esm/LineChart/extremums.js +1 -1
  108. package/esm/LineChart/formatter.js +1 -1
  109. package/esm/LineChart/useLineChartProps.js +38 -33
  110. package/esm/PieChart/PieChart.js +39 -33
  111. package/esm/PieChart/PiePlot.js +1 -1
  112. package/esm/PieChart/getPieCoordinates.js +1 -1
  113. package/esm/ResponsiveChartContainer/ResponsiveChartContainer.js +8 -20
  114. package/esm/ResponsiveChartContainer/useChartContainerDimensions.js +6 -2
  115. package/esm/ResponsiveChartContainer/useResponsiveChartContainerProps.js +65 -0
  116. package/esm/ScatterChart/Scatter.js +6 -9
  117. package/esm/ScatterChart/useScatterChartProps.js +35 -30
  118. package/esm/SparkLineChart/SparkLineChart.js +27 -22
  119. package/esm/context/CartesianProvider/CartesianProvider.js +18 -7
  120. package/esm/context/CartesianProvider/computeValue.js +20 -16
  121. package/esm/context/CartesianProvider/defaultizeAxis.js +13 -0
  122. package/esm/context/CartesianProvider/index.js +1 -3
  123. package/esm/context/CartesianProvider/normalizeAxis.js +1 -1
  124. package/esm/context/DrawingProvider.js +9 -2
  125. package/esm/context/HighlightedProvider/HighlightedProvider.js +2 -2
  126. package/esm/hooks/useAxisEvents.js +3 -10
  127. package/esm/hooks/useDrawingArea.js +5 -3
  128. package/esm/hooks/useReducedMotion.js +4 -2
  129. package/esm/internals/cleanId.js +6 -0
  130. package/esm/internals/components/ChartsAxesGradients/ChartsContinuousGradient.js +3 -2
  131. package/esm/internals/{utils.js → getPercentageValue.js} +1 -13
  132. package/esm/internals/getSymbol.js +5 -0
  133. package/esm/internals/index.js +3 -1
  134. package/esm/internals/isDefined.js +3 -0
  135. package/esm/internals/notNull.js +3 -0
  136. package/esm/internals/ts-generic.js +1 -0
  137. package/hooks/useAxisEvents.js +3 -10
  138. package/hooks/useDrawingArea.js +5 -3
  139. package/hooks/useReducedMotion.js +4 -2
  140. package/index.js +1 -1
  141. package/internals/cleanId.d.ts +4 -0
  142. package/internals/cleanId.js +12 -0
  143. package/internals/components/ChartsAxesGradients/ChartsContinuousGradient.d.ts +6 -0
  144. package/internals/components/ChartsAxesGradients/ChartsContinuousGradient.js +3 -2
  145. package/internals/getPercentageValue.d.ts +7 -0
  146. package/internals/{utils.js → getPercentageValue.js} +1 -15
  147. package/internals/getSymbol.d.ts +2 -0
  148. package/internals/getSymbol.js +11 -0
  149. package/internals/index.d.ts +3 -1
  150. package/internals/index.js +25 -5
  151. package/internals/isDefined.d.ts +1 -0
  152. package/internals/isDefined.js +9 -0
  153. package/internals/notNull.d.ts +1 -0
  154. package/internals/notNull.js +9 -0
  155. package/internals/ts-generic.d.ts +5 -0
  156. package/internals/ts-generic.js +5 -0
  157. package/models/axis.d.ts +5 -2
  158. package/models/helpers.d.ts +1 -0
  159. package/models/seriesType/config.d.ts +2 -16
  160. package/modern/BarChart/BarChart.js +2 -2
  161. package/modern/BarChart/formatter.js +1 -1
  162. package/modern/BarChart/useBarChartProps.js +38 -33
  163. package/modern/ChartContainer/ChartContainer.js +25 -66
  164. package/modern/ChartContainer/useChartContainerHooks.js +2 -2
  165. package/modern/ChartContainer/useChartContainerProps.js +87 -0
  166. package/modern/ChartContainer/useDefaultizeAxis.js +19 -0
  167. package/modern/ChartsLegend/ContinuousColorLegend.js +390 -0
  168. package/modern/ChartsLegend/DefaultChartsLegend.js +14 -198
  169. package/modern/ChartsLegend/LegendPerItem.js +141 -0
  170. package/modern/ChartsLegend/PiecewiseColorLegend.js +161 -0
  171. package/modern/ChartsLegend/chartsLegend.types.js +1 -0
  172. package/modern/ChartsLegend/index.js +2 -0
  173. package/modern/ChartsLegend/legend.types.js +1 -0
  174. package/modern/ChartsLegend/legendItemsPlacement.js +72 -0
  175. package/modern/ChartsLegend/useAxis.js +39 -0
  176. package/modern/ChartsSurface.js +3 -1
  177. package/modern/ChartsVoronoiHandler/ChartsVoronoiHandler.js +26 -18
  178. package/modern/ChartsXAxis/ChartsXAxis.js +1 -1
  179. package/modern/ChartsYAxis/ChartsYAxis.js +15 -3
  180. package/modern/Gauge/Gauge.js +8 -5
  181. package/modern/Gauge/GaugeContainer.js +8 -4
  182. package/modern/Gauge/GaugeProvider.js +1 -1
  183. package/modern/LineChart/AnimatedArea.js +1 -1
  184. package/modern/LineChart/AnimatedLine.js +1 -1
  185. package/modern/LineChart/AreaPlot.js +7 -1
  186. package/modern/LineChart/LineChart.js +2 -2
  187. package/modern/LineChart/LineHighlightPlot.js +8 -0
  188. package/modern/LineChart/MarkElement.js +1 -1
  189. package/modern/LineChart/MarkPlot.js +3 -19
  190. package/modern/LineChart/extremums.js +1 -1
  191. package/modern/LineChart/formatter.js +1 -1
  192. package/modern/LineChart/useLineChartProps.js +38 -33
  193. package/modern/PieChart/PieChart.js +39 -33
  194. package/modern/PieChart/PiePlot.js +1 -1
  195. package/modern/PieChart/getPieCoordinates.js +1 -1
  196. package/modern/ResponsiveChartContainer/ResponsiveChartContainer.js +8 -20
  197. package/modern/ResponsiveChartContainer/useChartContainerDimensions.js +6 -2
  198. package/modern/ResponsiveChartContainer/useResponsiveChartContainerProps.js +65 -0
  199. package/modern/ScatterChart/Scatter.js +6 -9
  200. package/modern/ScatterChart/useScatterChartProps.js +35 -30
  201. package/modern/SparkLineChart/SparkLineChart.js +27 -22
  202. package/modern/context/CartesianProvider/CartesianProvider.js +18 -7
  203. package/modern/context/CartesianProvider/computeValue.js +20 -16
  204. package/modern/context/CartesianProvider/defaultizeAxis.js +13 -0
  205. package/modern/context/CartesianProvider/index.js +1 -3
  206. package/modern/context/CartesianProvider/normalizeAxis.js +1 -1
  207. package/modern/context/DrawingProvider.js +9 -2
  208. package/modern/context/HighlightedProvider/HighlightedProvider.js +2 -2
  209. package/modern/hooks/useAxisEvents.js +3 -10
  210. package/modern/hooks/useDrawingArea.js +5 -3
  211. package/modern/hooks/useReducedMotion.js +4 -2
  212. package/modern/index.js +1 -1
  213. package/modern/internals/cleanId.js +6 -0
  214. package/modern/internals/components/ChartsAxesGradients/ChartsContinuousGradient.js +3 -2
  215. package/modern/internals/{utils.js → getPercentageValue.js} +1 -13
  216. package/modern/internals/getSymbol.js +5 -0
  217. package/modern/internals/index.js +3 -1
  218. package/modern/internals/isDefined.js +3 -0
  219. package/modern/internals/notNull.js +3 -0
  220. package/modern/internals/ts-generic.js +1 -0
  221. package/package.json +4 -4
  222. package/internals/utils.d.ts +0 -18
@@ -1,4 +1,6 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
+ const _excluded = ["xAxis", "yAxis", "width", "height", "margin", "colors", "sx", "showTooltip", "tooltip", "showHighlight", "axisHighlight", "children", "slots", "slotProps", "data", "plotType", "valueFormatter", "area", "curve", "className"];
2
4
  import * as React from 'react';
3
5
  import PropTypes from 'prop-types';
4
6
  import { BarPlot } from '../BarChart';
@@ -26,33 +28,35 @@ const SPARKLINE_DEFAULT_MARGIN = {
26
28
  */
27
29
  const SparkLineChart = /*#__PURE__*/React.forwardRef(function SparkLineChart(props, ref) {
28
30
  const {
29
- xAxis,
30
- yAxis,
31
- width,
32
- height,
33
- margin = SPARKLINE_DEFAULT_MARGIN,
34
- colors,
35
- sx,
36
- showTooltip,
37
- tooltip,
38
- showHighlight,
39
- axisHighlight: inAxisHighlight,
40
- children,
41
- slots,
42
- slotProps,
43
- data,
44
- plotType = 'line',
45
- valueFormatter = value => value === null ? '' : value.toString(),
46
- area,
47
- curve = 'linear'
48
- } = props;
31
+ xAxis,
32
+ yAxis,
33
+ width,
34
+ height,
35
+ margin = SPARKLINE_DEFAULT_MARGIN,
36
+ colors,
37
+ sx,
38
+ showTooltip,
39
+ tooltip,
40
+ showHighlight,
41
+ axisHighlight: inAxisHighlight,
42
+ children,
43
+ slots,
44
+ slotProps,
45
+ data,
46
+ plotType = 'line',
47
+ valueFormatter = value => value === null ? '' : value.toString(),
48
+ area,
49
+ curve = 'linear',
50
+ className
51
+ } = props,
52
+ other = _objectWithoutPropertiesLoose(props, _excluded);
49
53
  const defaultXHighlight = showHighlight && plotType === 'bar' ? {
50
54
  x: 'band'
51
55
  } : {
52
56
  x: 'none'
53
57
  };
54
58
  const axisHighlight = _extends({}, defaultXHighlight, inAxisHighlight);
55
- return /*#__PURE__*/_jsxs(ResponsiveChartContainer, {
59
+ return /*#__PURE__*/_jsxs(ResponsiveChartContainer, _extends({}, other, {
56
60
  ref: ref,
57
61
  series: [_extends({
58
62
  type: plotType,
@@ -66,6 +70,7 @@ const SparkLineChart = /*#__PURE__*/React.forwardRef(function SparkLineChart(pro
66
70
  width: width,
67
71
  height: height,
68
72
  margin: margin,
73
+ className: className,
69
74
  xAxis: [_extends({
70
75
  id: DEFAULT_X_AXIS_KEY,
71
76
  scaleType: plotType === 'bar' ? 'band' : 'point',
@@ -104,7 +109,7 @@ const SparkLineChart = /*#__PURE__*/React.forwardRef(function SparkLineChart(pro
104
109
  slotProps: slotProps,
105
110
  slots: slots
106
111
  })), children]
107
- });
112
+ }));
108
113
  });
109
114
  process.env.NODE_ENV !== "production" ? SparkLineChart.propTypes = {
110
115
  // ----------------------------- Warning --------------------------------
@@ -2,13 +2,12 @@ import * as React from 'react';
2
2
  import { useDrawingArea } from '../../hooks/useDrawingArea';
3
3
  import { useSeries } from '../../hooks/useSeries';
4
4
  import { CartesianContext } from './CartesianContext';
5
- import { normalizeAxis } from './normalizeAxis';
6
5
  import { computeValue } from './computeValue';
7
6
  import { jsx as _jsx } from "react/jsx-runtime";
8
7
  function CartesianContextProvider(props) {
9
8
  const {
10
- xAxis: inXAxis,
11
- yAxis: inYAxis,
9
+ xAxis,
10
+ yAxis,
12
11
  dataset,
13
12
  xExtremumGetters,
14
13
  yExtremumGetters,
@@ -16,10 +15,22 @@ function CartesianContextProvider(props) {
16
15
  } = props;
17
16
  const formattedSeries = useSeries();
18
17
  const drawingArea = useDrawingArea();
19
- const xAxis = React.useMemo(() => normalizeAxis(inXAxis, dataset, 'x'), [inXAxis, dataset]);
20
- const yAxis = React.useMemo(() => normalizeAxis(inYAxis, dataset, 'y'), [inYAxis, dataset]);
21
- const xValues = React.useMemo(() => computeValue(drawingArea, formattedSeries, xAxis, xExtremumGetters, 'x'), [drawingArea, formattedSeries, xAxis, xExtremumGetters]);
22
- const yValues = React.useMemo(() => computeValue(drawingArea, formattedSeries, yAxis, yExtremumGetters, 'y'), [drawingArea, formattedSeries, yAxis, yExtremumGetters]);
18
+ const xValues = React.useMemo(() => computeValue({
19
+ drawingArea,
20
+ formattedSeries,
21
+ axis: xAxis,
22
+ extremumGetters: xExtremumGetters,
23
+ dataset,
24
+ axisDirection: 'x'
25
+ }), [drawingArea, formattedSeries, xAxis, xExtremumGetters, dataset]);
26
+ const yValues = React.useMemo(() => computeValue({
27
+ drawingArea,
28
+ formattedSeries,
29
+ axis: yAxis,
30
+ extremumGetters: yExtremumGetters,
31
+ dataset,
32
+ axisDirection: 'y'
33
+ }), [drawingArea, formattedSeries, yAxis, yExtremumGetters, dataset]);
23
34
  const value = React.useMemo(() => ({
24
35
  isInitialized: true,
25
36
  data: {
@@ -1,13 +1,13 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import { scaleBand, scalePoint, scaleTime } from 'd3-scale';
3
- import { DEFAULT_X_AXIS_KEY, DEFAULT_Y_AXIS_KEY } from '../../constants';
4
3
  import { isBandScaleConfig, isPointScaleConfig } from '../../models/axis';
5
4
  import { getColorScale, getOrdinalColorScale } from '../../internals/colorScale';
6
5
  import { getTickNumber } from '../../hooks/useTicks';
7
6
  import { getScale } from '../../internals/getScale';
8
7
  import { getAxisExtremum } from './getAxisExtremum';
9
- const getRange = (drawingArea, axisName, isReverse) => {
10
- const range = axisName === 'x' ? [drawingArea.left, drawingArea.left + drawingArea.width] : [drawingArea.top + drawingArea.height, drawingArea.top];
8
+ import { normalizeAxis } from './normalizeAxis';
9
+ const getRange = (drawingArea, axisDirection, isReverse) => {
10
+ const range = axisDirection === 'x' ? [drawingArea.left, drawingArea.left + drawingArea.width] : [drawingArea.top + drawingArea.height, drawingArea.top];
11
11
  return isReverse ? range.reverse() : range;
12
12
  };
13
13
  const zoomedScaleRange = (scaleRange, zoomRange) => {
@@ -29,26 +29,30 @@ function createDateFormatter(axis, range) {
29
29
  }
30
30
  const DEFAULT_CATEGORY_GAP_RATIO = 0.2;
31
31
  const DEFAULT_BAR_GAP_RATIO = 0.1;
32
- export function computeValue(drawingArea, formattedSeries, inAxis, extremumGetters, axisName, zoomRange = [0, 100]) {
33
- const DEFAULT_AXIS_KEY = axisName === 'x' ? DEFAULT_X_AXIS_KEY : DEFAULT_Y_AXIS_KEY;
34
- const allAxis = [...(inAxis?.map((axis, index) => _extends({
35
- id: `defaultized-${axisName}-axis-${index}`
36
- }, axis)) ?? []), ...(inAxis === undefined || inAxis.findIndex(({
37
- id
38
- }) => id === DEFAULT_AXIS_KEY) === -1 ? [{
39
- id: DEFAULT_AXIS_KEY,
40
- scaleType: 'linear'
41
- }] : [])];
32
+ export function computeValue({
33
+ drawingArea,
34
+ formattedSeries,
35
+ axis: inAxis,
36
+ extremumGetters,
37
+ dataset,
38
+ axisDirection,
39
+ zoomData
40
+ }) {
41
+ const allAxis = normalizeAxis(inAxis, dataset, axisDirection);
42
42
  const completeAxis = {};
43
43
  allAxis.forEach((axis, axisIndex) => {
44
44
  const isDefaultAxis = axisIndex === 0;
45
45
  const [minData, maxData] = getAxisExtremum(axis, extremumGetters, isDefaultAxis, formattedSeries);
46
- const range = getRange(drawingArea, axisName, axis.reverse);
46
+ const zoom = zoomData?.find(({
47
+ axisId
48
+ }) => axisId === axis.id);
49
+ const zoomRange = zoom ? [zoom.start, zoom.end] : [0, 100];
50
+ const range = getRange(drawingArea, axisDirection, axis.reverse);
47
51
  if (isBandScaleConfig(axis)) {
48
52
  const categoryGapRatio = axis.categoryGapRatio ?? DEFAULT_CATEGORY_GAP_RATIO;
49
53
  const barGapRatio = axis.barGapRatio ?? DEFAULT_BAR_GAP_RATIO;
50
54
  // Reverse range because ordinal scales are presented from top to bottom on y-axis
51
- const scaleRange = axisName === 'x' ? range : [range[1], range[0]];
55
+ const scaleRange = axisDirection === 'x' ? range : [range[1], range[0]];
52
56
  const zoomedRange = zoomedScaleRange(scaleRange, zoomRange);
53
57
  completeAxis[axis.id] = _extends({
54
58
  categoryGapRatio,
@@ -66,7 +70,7 @@ export function computeValue(drawingArea, formattedSeries, inAxis, extremumGette
66
70
  }
67
71
  }
68
72
  if (isPointScaleConfig(axis)) {
69
- const scaleRange = axisName === 'x' ? range : [...range].reverse();
73
+ const scaleRange = axisDirection === 'x' ? range : [...range].reverse();
70
74
  const zoomedRange = zoomedScaleRange(scaleRange, zoomRange);
71
75
  completeAxis[axis.id] = _extends({}, axis, {
72
76
  scale: scalePoint(axis.data, zoomedRange),
@@ -0,0 +1,13 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import { DEFAULT_X_AXIS_KEY, DEFAULT_Y_AXIS_KEY } from '../../constants';
3
+ export const defaultizeAxis = (inAxis, axisName) => {
4
+ const DEFAULT_AXIS_KEY = axisName === 'x' ? DEFAULT_X_AXIS_KEY : DEFAULT_Y_AXIS_KEY;
5
+ return [...(inAxis?.map((axis, index) => _extends({
6
+ id: `defaultized-${axisName}-axis-${index}`
7
+ }, axis)) ?? []), ...(inAxis === undefined || inAxis.findIndex(({
8
+ id
9
+ }) => id === DEFAULT_AXIS_KEY) === -1 ? [{
10
+ id: DEFAULT_AXIS_KEY,
11
+ scaleType: 'linear'
12
+ }] : [])];
13
+ };
@@ -1,10 +1,8 @@
1
1
  import { computeValue } from './computeValue';
2
- import { normalizeAxis } from './normalizeAxis';
3
2
  export * from './CartesianProvider';
4
3
  export * from './CartesianContext';
5
4
  export * from './useCartesianContext';
6
5
  const cartesianProviderUtils = {
7
- computeValue,
8
- normalizeAxis
6
+ computeValue
9
7
  };
10
8
  export { cartesianProviderUtils };
@@ -11,5 +11,5 @@ export const normalizeAxis = (axis, dataset, axisName) => {
11
11
  return _extends({}, axisConfig, {
12
12
  data: dataset.map(d => d[dataKey])
13
13
  });
14
- });
14
+ }) ?? [];
15
15
  };
@@ -14,7 +14,8 @@ export const DrawingContext = /*#__PURE__*/React.createContext({
14
14
  right: 0,
15
15
  height: 300,
16
16
  width: 400,
17
- chartId: ''
17
+ chartId: '',
18
+ isPointInside: () => false
18
19
  });
19
20
  if (process.env.NODE_ENV !== 'production') {
20
21
  DrawingContext.displayName = 'DrawingContext';
@@ -38,9 +39,15 @@ export function DrawingProvider(props) {
38
39
  } = props;
39
40
  const drawingArea = useChartDimensions(width, height, margin);
40
41
  const chartId = useId();
42
+ const isPointInside = React.useCallback(({
43
+ x,
44
+ y
45
+ }) => x >= drawingArea.left && x <= drawingArea.left + drawingArea.width && y >= drawingArea.top && y <= drawingArea.top + drawingArea.height, [drawingArea]);
41
46
  const value = React.useMemo(() => _extends({
42
47
  chartId: chartId ?? ''
43
- }, drawingArea), [chartId, drawingArea]);
48
+ }, drawingArea, {
49
+ isPointInside
50
+ }), [chartId, drawingArea, isPointInside]);
44
51
  const refValue = React.useMemo(() => ({
45
52
  isInitialized: true,
46
53
  data: svgRef
@@ -15,11 +15,11 @@ const mergeDeprecatedOptions = options => {
15
15
  highlighted,
16
16
  faded
17
17
  } = _ref,
18
- rest = _objectWithoutPropertiesLoose(_ref, _excluded);
18
+ other = _objectWithoutPropertiesLoose(_ref, _excluded);
19
19
  return _extends({
20
20
  highlight: highlighted,
21
21
  fade: faded
22
- }, rest);
22
+ }, other);
23
23
  };
24
24
  function HighlightedProvider({
25
25
  children,
@@ -10,12 +10,7 @@ function getAsANumber(value) {
10
10
  }
11
11
  export const useAxisEvents = disableAxisListener => {
12
12
  const svgRef = useSvgRef();
13
- const {
14
- left,
15
- top,
16
- width,
17
- height
18
- } = useDrawingArea();
13
+ const drawingArea = useDrawingArea();
19
14
  const {
20
15
  xAxis,
21
16
  yAxis,
@@ -103,9 +98,7 @@ export const useAxisEvents = disableAxisListener => {
103
98
  x: svgPoint.x,
104
99
  y: svgPoint.y
105
100
  };
106
- const outsideX = svgPoint.x < left || svgPoint.x > left + width;
107
- const outsideY = svgPoint.y < top || svgPoint.y > top + height;
108
- if (outsideX || outsideY) {
101
+ if (!drawingArea.isPointInside(svgPoint)) {
109
102
  dispatch({
110
103
  type: 'exitChart'
111
104
  });
@@ -142,5 +135,5 @@ export const useAxisEvents = disableAxisListener => {
142
135
  element.removeEventListener('pointercancel', handleOut);
143
136
  element.removeEventListener('pointerleave', handleOut);
144
137
  };
145
- }, [svgRef, dispatch, left, width, top, height, usedYAxis, yAxis, usedXAxis, xAxis, disableAxisListener]);
138
+ }, [svgRef, dispatch, usedYAxis, yAxis, usedXAxis, xAxis, disableAxisListener, drawingArea]);
146
139
  };
@@ -7,7 +7,8 @@ export function useDrawingArea() {
7
7
  width,
8
8
  height,
9
9
  bottom,
10
- right
10
+ right,
11
+ isPointInside
11
12
  } = React.useContext(DrawingContext);
12
13
  return React.useMemo(() => ({
13
14
  left,
@@ -15,6 +16,7 @@ export function useDrawingArea() {
15
16
  width,
16
17
  height,
17
18
  bottom,
18
- right
19
- }), [height, left, top, width, bottom, right]);
19
+ right,
20
+ isPointInside
21
+ }), [height, left, top, width, bottom, right, isPointInside]);
20
22
  }
@@ -26,9 +26,11 @@ export const useReducedMotion = () => {
26
26
  });
27
27
  };
28
28
  handleMediaChange(mql);
29
- mql.addEventListener('change', handleMediaChange);
29
+
30
+ // MatchMedia is not fully supported in all environments, so we need to check if it exists before calling addEventListener
31
+ mql.addEventListener?.('change', handleMediaChange);
30
32
  return () => {
31
- mql.removeEventListener('change', handleMediaChange);
33
+ mql.removeEventListener?.('change', handleMediaChange);
32
34
  };
33
35
  }, []);
34
36
  };
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Remove spaces to have viable ids
3
+ */
4
+ export function cleanId(id) {
5
+ return id.replace(' ', '_');
6
+ }
@@ -4,6 +4,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
4
4
  const PX_PRECISION = 10;
5
5
  export default function ChartsContinuousGradient(props) {
6
6
  const {
7
+ gradientUnits,
7
8
  isReversed,
8
9
  gradientId,
9
10
  size,
@@ -26,8 +27,8 @@ export default function ChartsContinuousGradient(props) {
26
27
  x2: "0",
27
28
  y1: "0",
28
29
  y2: "0",
29
- [`${direction}${isReversed ? 1 : 2}`]: `${size}px`,
30
- gradientUnits: "userSpaceOnUse" // Use the SVG coordinate instead of the component ones.
30
+ [`${direction}${isReversed ? 1 : 2}`]: gradientUnits === 'objectBoundingBox' ? 1 : `${size}px`,
31
+ gradientUnits: gradientUnits ?? 'userSpaceOnUse' // Use the SVG coordinate instead of the component ones.
31
32
  ,
32
33
  children: Array.from({
33
34
  length: numberOfPoints + 1
@@ -1,8 +1,3 @@
1
- // Returns the index of a defined shape
2
- export function getSymbol(shape) {
3
- const symbolNames = 'circle cross diamond square star triangle wye'.split(/ /);
4
- return symbolNames.indexOf(shape) || 0;
5
- }
6
1
  /**
7
2
  * Helper that converts values and percentages into values.
8
3
  * @param value The value provided by the developer. Can either be a number or a string with '%' or 'px'.
@@ -29,12 +24,5 @@ export function getPercentageValue(value, refValue) {
29
24
  return val;
30
25
  }
31
26
  }
32
- throw Error(`MUI-Charts: Received an unknown value "${value}". It should be a number, or a string with a percentage value.`);
33
- }
34
-
35
- /**
36
- * Remove spaces to have viable ids
37
- */
38
- export function cleanId(id) {
39
- return id.replace(' ', '_');
27
+ throw Error(`MUI X Charts: Received an unknown value "${value}". It should be a number, or a string with a percentage value.`);
40
28
  }
@@ -0,0 +1,5 @@
1
+ // Returns the index of a defined shape
2
+ export function getSymbol(shape) {
3
+ const symbolNames = 'circle cross diamond square star triangle wye'.split(/ /);
4
+ return symbolNames.indexOf(shape) || 0;
5
+ }
@@ -8,16 +8,18 @@ export { useReducedMotion } from '../hooks/useReducedMotion';
8
8
  export { useSeries } from '../hooks/useSeries';
9
9
  export { useInteractionItemProps } from '../hooks/useInteractionItemProps';
10
10
  export { useDrawingArea } from '../hooks/useDrawingArea';
11
- export { useChartContainerHooks } from '../ChartContainer/useChartContainerHooks';
12
11
  export { useScatterChartProps } from '../ScatterChart/useScatterChartProps';
13
12
  export { useLineChartProps } from '../LineChart/useLineChartProps';
14
13
  export { useBarChartProps } from '../BarChart/useBarChartProps';
14
+ export { useResponsiveChartContainerProps } from '../ResponsiveChartContainer/useResponsiveChartContainerProps';
15
+ export { useChartContainerProps } from '../ChartContainer/useChartContainerProps';
15
16
 
16
17
  // utils
17
18
  export * from './defaultizeValueFormatter';
18
19
  export * from './configInit';
19
20
  export * from './getLabel';
20
21
  export * from './getSVGPoint';
22
+ export * from './isDefined';
21
23
 
22
24
  // contexts
23
25
 
@@ -0,0 +1,3 @@
1
+ export function isDefined(value) {
2
+ return value !== null && value !== undefined;
3
+ }
@@ -0,0 +1,3 @@
1
+ export function notNull(value) {
2
+ return value !== null;
3
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -18,12 +18,7 @@ function getAsANumber(value) {
18
18
  }
19
19
  const useAxisEvents = disableAxisListener => {
20
20
  const svgRef = (0, _useSvgRef.useSvgRef)();
21
- const {
22
- left,
23
- top,
24
- width,
25
- height
26
- } = (0, _useDrawingArea.useDrawingArea)();
21
+ const drawingArea = (0, _useDrawingArea.useDrawingArea)();
27
22
  const {
28
23
  xAxis,
29
24
  yAxis,
@@ -111,9 +106,7 @@ const useAxisEvents = disableAxisListener => {
111
106
  x: svgPoint.x,
112
107
  y: svgPoint.y
113
108
  };
114
- const outsideX = svgPoint.x < left || svgPoint.x > left + width;
115
- const outsideY = svgPoint.y < top || svgPoint.y > top + height;
116
- if (outsideX || outsideY) {
109
+ if (!drawingArea.isPointInside(svgPoint)) {
117
110
  dispatch({
118
111
  type: 'exitChart'
119
112
  });
@@ -150,6 +143,6 @@ const useAxisEvents = disableAxisListener => {
150
143
  element.removeEventListener('pointercancel', handleOut);
151
144
  element.removeEventListener('pointerleave', handleOut);
152
145
  };
153
- }, [svgRef, dispatch, left, width, top, height, usedYAxis, yAxis, usedXAxis, xAxis, disableAxisListener]);
146
+ }, [svgRef, dispatch, usedYAxis, yAxis, usedXAxis, xAxis, disableAxisListener, drawingArea]);
154
147
  };
155
148
  exports.useAxisEvents = useAxisEvents;
@@ -15,7 +15,8 @@ function useDrawingArea() {
15
15
  width,
16
16
  height,
17
17
  bottom,
18
- right
18
+ right,
19
+ isPointInside
19
20
  } = React.useContext(_DrawingProvider.DrawingContext);
20
21
  return React.useMemo(() => ({
21
22
  left,
@@ -23,6 +24,7 @@ function useDrawingArea() {
23
24
  width,
24
25
  height,
25
26
  bottom,
26
- right
27
- }), [height, left, top, width, bottom, right]);
27
+ right,
28
+ isPointInside
29
+ }), [height, left, top, width, bottom, right, isPointInside]);
28
30
  }
@@ -31,9 +31,11 @@ const useReducedMotion = () => {
31
31
  });
32
32
  };
33
33
  handleMediaChange(mql);
34
- mql.addEventListener('change', handleMediaChange);
34
+
35
+ // MatchMedia is not fully supported in all environments, so we need to check if it exists before calling addEventListener
36
+ mql.addEventListener?.('change', handleMediaChange);
35
37
  return () => {
36
- mql.removeEventListener('change', handleMediaChange);
38
+ mql.removeEventListener?.('change', handleMediaChange);
37
39
  };
38
40
  }, []);
39
41
  };
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-charts v7.9.0
2
+ * @mui/x-charts v7.11.0
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Remove spaces to have viable ids
3
+ */
4
+ export declare function cleanId(id: string): string;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.cleanId = cleanId;
7
+ /**
8
+ * Remove spaces to have viable ids
9
+ */
10
+ function cleanId(id) {
11
+ return id.replace(' ', '_');
12
+ }
@@ -8,6 +8,12 @@ type ChartsContinuousGradientProps = {
8
8
  scale: (value: any) => number | undefined;
9
9
  colorMap: ContinuousColorConfig;
10
10
  colorScale: (value: any) => string | null;
11
+ /**
12
+ * Defines the coordinate base to use:
13
+ * - 'userSpaceOnUse': uses the coordinate of the SVG (values in px).
14
+ * - 'objectBoundingBox': uses the coordinate ot the object on which gradient is applied (values from 0 to 1).
15
+ */
16
+ gradientUnits?: 'objectBoundingBox' | 'userSpaceOnUse';
11
17
  };
12
18
  export default function ChartsContinuousGradient(props: ChartsContinuousGradientProps): React.JSX.Element | null;
13
19
  export {};
@@ -12,6 +12,7 @@ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e;
12
12
  const PX_PRECISION = 10;
13
13
  function ChartsContinuousGradient(props) {
14
14
  const {
15
+ gradientUnits,
15
16
  isReversed,
16
17
  gradientId,
17
18
  size,
@@ -34,8 +35,8 @@ function ChartsContinuousGradient(props) {
34
35
  x2: "0",
35
36
  y1: "0",
36
37
  y2: "0",
37
- [`${direction}${isReversed ? 1 : 2}`]: `${size}px`,
38
- gradientUnits: "userSpaceOnUse" // Use the SVG coordinate instead of the component ones.
38
+ [`${direction}${isReversed ? 1 : 2}`]: gradientUnits === 'objectBoundingBox' ? 1 : `${size}px`,
39
+ gradientUnits: gradientUnits ?? 'userSpaceOnUse' // Use the SVG coordinate instead of the component ones.
39
40
  ,
40
41
  children: Array.from({
41
42
  length: numberOfPoints + 1
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Helper that converts values and percentages into values.
3
+ * @param value The value provided by the developer. Can either be a number or a string with '%' or 'px'.
4
+ * @param refValue The numerical value associated to 100%.
5
+ * @returns The numerical value associated to the provided value.
6
+ */
7
+ export declare function getPercentageValue(value: number | string, refValue: number): number;
@@ -3,14 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.cleanId = cleanId;
7
6
  exports.getPercentageValue = getPercentageValue;
8
- exports.getSymbol = getSymbol;
9
- // Returns the index of a defined shape
10
- function getSymbol(shape) {
11
- const symbolNames = 'circle cross diamond square star triangle wye'.split(/ /);
12
- return symbolNames.indexOf(shape) || 0;
13
- }
14
7
  /**
15
8
  * Helper that converts values and percentages into values.
16
9
  * @param value The value provided by the developer. Can either be a number or a string with '%' or 'px'.
@@ -37,12 +30,5 @@ function getPercentageValue(value, refValue) {
37
30
  return val;
38
31
  }
39
32
  }
40
- throw Error(`MUI-Charts: Received an unknown value "${value}". It should be a number, or a string with a percentage value.`);
41
- }
42
-
43
- /**
44
- * Remove spaces to have viable ids
45
- */
46
- function cleanId(id) {
47
- return id.replace(' ', '_');
33
+ throw Error(`MUI X Charts: Received an unknown value "${value}". It should be a number, or a string with a percentage value.`);
48
34
  }
@@ -0,0 +1,2 @@
1
+ export type SymbolsTypes = 'circle' | 'cross' | 'diamond' | 'square' | 'star' | 'triangle' | 'wye';
2
+ export declare function getSymbol(shape: SymbolsTypes): number;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getSymbol = getSymbol;
7
+ // Returns the index of a defined shape
8
+ function getSymbol(shape) {
9
+ const symbolNames = 'circle cross diamond square star triangle wye'.split(/ /);
10
+ return symbolNames.indexOf(shape) || 0;
11
+ }
@@ -5,14 +5,16 @@ export { useReducedMotion } from '../hooks/useReducedMotion';
5
5
  export { useSeries } from '../hooks/useSeries';
6
6
  export { useInteractionItemProps } from '../hooks/useInteractionItemProps';
7
7
  export { useDrawingArea } from '../hooks/useDrawingArea';
8
- export { useChartContainerHooks } from '../ChartContainer/useChartContainerHooks';
9
8
  export { useScatterChartProps } from '../ScatterChart/useScatterChartProps';
10
9
  export { useLineChartProps } from '../LineChart/useLineChartProps';
11
10
  export { useBarChartProps } from '../BarChart/useBarChartProps';
11
+ export { useResponsiveChartContainerProps } from '../ResponsiveChartContainer/useResponsiveChartContainerProps';
12
+ export { useChartContainerProps } from '../ChartContainer/useChartContainerProps';
12
13
  export * from './defaultizeValueFormatter';
13
14
  export * from './configInit';
14
15
  export * from './getLabel';
15
16
  export * from './getSVGPoint';
17
+ export * from './isDefined';
16
18
  export * from '../context/CartesianProvider';
17
19
  export * from '../context/DrawingProvider';
18
20
  export * from '../context/ColorProvider';