@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
@@ -6,6 +6,8 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.useScatterChartProps = void 0;
8
8
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
+ var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
10
+ const _excluded = ["xAxis", "yAxis", "zAxis", "series", "tooltip", "axisHighlight", "voronoiMaxRadius", "disableVoronoi", "legend", "width", "height", "margin", "colors", "sx", "grid", "topAxis", "leftAxis", "rightAxis", "bottomAxis", "onItemClick", "children", "slots", "slotProps", "loading", "highlightedItem", "onHighlightChange", "className"];
9
11
  /**
10
12
  * A helper function that extracts ScatterChartProps from the input props
11
13
  * and returns an object with props for the children components of ScatterChart.
@@ -15,34 +17,36 @@ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")
15
17
  */
16
18
  const useScatterChartProps = props => {
17
19
  const {
18
- xAxis,
19
- yAxis,
20
- zAxis,
21
- series,
22
- tooltip,
23
- axisHighlight,
24
- voronoiMaxRadius,
25
- disableVoronoi,
26
- legend,
27
- width,
28
- height,
29
- margin,
30
- colors,
31
- sx,
32
- grid,
33
- topAxis,
34
- leftAxis,
35
- rightAxis,
36
- bottomAxis,
37
- onItemClick,
38
- children,
39
- slots,
40
- slotProps,
41
- loading,
42
- highlightedItem,
43
- onHighlightChange
44
- } = props;
45
- const chartContainerProps = {
20
+ xAxis,
21
+ yAxis,
22
+ zAxis,
23
+ series,
24
+ tooltip,
25
+ axisHighlight,
26
+ voronoiMaxRadius,
27
+ disableVoronoi,
28
+ legend,
29
+ width,
30
+ height,
31
+ margin,
32
+ colors,
33
+ sx,
34
+ grid,
35
+ topAxis,
36
+ leftAxis,
37
+ rightAxis,
38
+ bottomAxis,
39
+ onItemClick,
40
+ children,
41
+ slots,
42
+ slotProps,
43
+ loading,
44
+ highlightedItem,
45
+ onHighlightChange,
46
+ className
47
+ } = props,
48
+ other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
49
+ const chartContainerProps = (0, _extends2.default)({}, other, {
46
50
  series: series.map(s => (0, _extends2.default)({
47
51
  type: 'scatter'
48
52
  }, s)),
@@ -54,8 +58,9 @@ const useScatterChartProps = props => {
54
58
  yAxis,
55
59
  sx,
56
60
  highlightedItem,
57
- onHighlightChange
58
- };
61
+ onHighlightChange,
62
+ className
63
+ });
59
64
  const zAxisProps = {
60
65
  zAxis
61
66
  };
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.SparkLineChart = void 0;
8
8
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
+ var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
9
10
  var React = _interopRequireWildcard(require("react"));
10
11
  var _propTypes = _interopRequireDefault(require("prop-types"));
11
12
  var _BarChart = require("../BarChart");
@@ -15,6 +16,7 @@ var _constants = require("../constants");
15
16
  var _ChartsTooltip = require("../ChartsTooltip");
16
17
  var _ChartsAxisHighlight = require("../ChartsAxisHighlight");
17
18
  var _jsxRuntime = require("react/jsx-runtime");
19
+ const _excluded = ["xAxis", "yAxis", "width", "height", "margin", "colors", "sx", "showTooltip", "tooltip", "showHighlight", "axisHighlight", "children", "slots", "slotProps", "data", "plotType", "valueFormatter", "area", "curve", "className"];
18
20
  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); }
19
21
  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; }
20
22
  const SPARKLINE_DEFAULT_MARGIN = {
@@ -35,33 +37,35 @@ const SPARKLINE_DEFAULT_MARGIN = {
35
37
  */
36
38
  const SparkLineChart = exports.SparkLineChart = /*#__PURE__*/React.forwardRef(function SparkLineChart(props, ref) {
37
39
  const {
38
- xAxis,
39
- yAxis,
40
- width,
41
- height,
42
- margin = SPARKLINE_DEFAULT_MARGIN,
43
- colors,
44
- sx,
45
- showTooltip,
46
- tooltip,
47
- showHighlight,
48
- axisHighlight: inAxisHighlight,
49
- children,
50
- slots,
51
- slotProps,
52
- data,
53
- plotType = 'line',
54
- valueFormatter = value => value === null ? '' : value.toString(),
55
- area,
56
- curve = 'linear'
57
- } = props;
40
+ xAxis,
41
+ yAxis,
42
+ width,
43
+ height,
44
+ margin = SPARKLINE_DEFAULT_MARGIN,
45
+ colors,
46
+ sx,
47
+ showTooltip,
48
+ tooltip,
49
+ showHighlight,
50
+ axisHighlight: inAxisHighlight,
51
+ children,
52
+ slots,
53
+ slotProps,
54
+ data,
55
+ plotType = 'line',
56
+ valueFormatter = value => value === null ? '' : value.toString(),
57
+ area,
58
+ curve = 'linear',
59
+ className
60
+ } = props,
61
+ other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
58
62
  const defaultXHighlight = showHighlight && plotType === 'bar' ? {
59
63
  x: 'band'
60
64
  } : {
61
65
  x: 'none'
62
66
  };
63
67
  const axisHighlight = (0, _extends2.default)({}, defaultXHighlight, inAxisHighlight);
64
- return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_ResponsiveChartContainer.ResponsiveChartContainer, {
68
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_ResponsiveChartContainer.ResponsiveChartContainer, (0, _extends2.default)({}, other, {
65
69
  ref: ref,
66
70
  series: [(0, _extends2.default)({
67
71
  type: plotType,
@@ -75,6 +79,7 @@ const SparkLineChart = exports.SparkLineChart = /*#__PURE__*/React.forwardRef(fu
75
79
  width: width,
76
80
  height: height,
77
81
  margin: margin,
82
+ className: className,
78
83
  xAxis: [(0, _extends2.default)({
79
84
  id: _constants.DEFAULT_X_AXIS_KEY,
80
85
  scaleType: plotType === 'bar' ? 'band' : 'point',
@@ -113,7 +118,7 @@ const SparkLineChart = exports.SparkLineChart = /*#__PURE__*/React.forwardRef(fu
113
118
  slotProps: slotProps,
114
119
  slots: slots
115
120
  })), children]
116
- });
121
+ }));
117
122
  });
118
123
  process.env.NODE_ENV !== "production" ? SparkLineChart.propTypes = {
119
124
  // ----------------------------- Warning --------------------------------
@@ -1,7 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import { AxisConfig, ChartsXAxisProps, ChartsYAxisProps, ScaleName } from '../../models/axis';
3
3
  import { DatasetType } from '../../models/seriesType/config';
4
- import { MakeOptional } from '../../models/helpers';
5
4
  import { ExtremumGettersConfig } from '../../models';
6
5
  export type CartesianContextProviderProps = {
7
6
  /**
@@ -9,13 +8,13 @@ export type CartesianContextProviderProps = {
9
8
  * If not provided, a default axis config is used.
10
9
  * An array of [[AxisConfig]] objects.
11
10
  */
12
- xAxis?: MakeOptional<AxisConfig<ScaleName, any, ChartsXAxisProps>, 'id'>[];
11
+ xAxis: AxisConfig<ScaleName, any, ChartsXAxisProps>[];
13
12
  /**
14
13
  * The configuration of the y-axes.
15
14
  * If not provided, a default axis config is used.
16
15
  * An array of [[AxisConfig]] objects.
17
16
  */
18
- yAxis?: MakeOptional<AxisConfig<ScaleName, any, ChartsYAxisProps>, 'id'>[];
17
+ yAxis: AxisConfig<ScaleName, any, ChartsYAxisProps>[];
19
18
  /**
20
19
  * An array of objects that can be used to populate series and axes data using their `dataKey` property.
21
20
  */
@@ -8,15 +8,14 @@ var React = _interopRequireWildcard(require("react"));
8
8
  var _useDrawingArea = require("../../hooks/useDrawingArea");
9
9
  var _useSeries = require("../../hooks/useSeries");
10
10
  var _CartesianContext = require("./CartesianContext");
11
- var _normalizeAxis = require("./normalizeAxis");
12
11
  var _computeValue = require("./computeValue");
13
12
  var _jsxRuntime = require("react/jsx-runtime");
14
13
  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); }
15
14
  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; }
16
15
  function CartesianContextProvider(props) {
17
16
  const {
18
- xAxis: inXAxis,
19
- yAxis: inYAxis,
17
+ xAxis,
18
+ yAxis,
20
19
  dataset,
21
20
  xExtremumGetters,
22
21
  yExtremumGetters,
@@ -24,10 +23,22 @@ function CartesianContextProvider(props) {
24
23
  } = props;
25
24
  const formattedSeries = (0, _useSeries.useSeries)();
26
25
  const drawingArea = (0, _useDrawingArea.useDrawingArea)();
27
- const xAxis = React.useMemo(() => (0, _normalizeAxis.normalizeAxis)(inXAxis, dataset, 'x'), [inXAxis, dataset]);
28
- const yAxis = React.useMemo(() => (0, _normalizeAxis.normalizeAxis)(inYAxis, dataset, 'y'), [inYAxis, dataset]);
29
- const xValues = React.useMemo(() => (0, _computeValue.computeValue)(drawingArea, formattedSeries, xAxis, xExtremumGetters, 'x'), [drawingArea, formattedSeries, xAxis, xExtremumGetters]);
30
- const yValues = React.useMemo(() => (0, _computeValue.computeValue)(drawingArea, formattedSeries, yAxis, yExtremumGetters, 'y'), [drawingArea, formattedSeries, yAxis, yExtremumGetters]);
26
+ const xValues = React.useMemo(() => (0, _computeValue.computeValue)({
27
+ drawingArea,
28
+ formattedSeries,
29
+ axis: xAxis,
30
+ extremumGetters: xExtremumGetters,
31
+ dataset,
32
+ axisDirection: 'x'
33
+ }), [drawingArea, formattedSeries, xAxis, xExtremumGetters, dataset]);
34
+ const yValues = React.useMemo(() => (0, _computeValue.computeValue)({
35
+ drawingArea,
36
+ formattedSeries,
37
+ axis: yAxis,
38
+ extremumGetters: yExtremumGetters,
39
+ dataset,
40
+ axisDirection: 'y'
41
+ }), [drawingArea, formattedSeries, yAxis, yExtremumGetters, dataset]);
31
42
  const value = React.useMemo(() => ({
32
43
  isInitialized: true,
33
44
  data: {
@@ -1,19 +1,42 @@
1
1
  import { AxisConfig, ScaleName } from '../../models';
2
- import { ChartsXAxisProps, ChartsAxisProps, ChartsYAxisProps } from '../../models/axis';
3
- import { CartesianChartSeriesType, ExtremumGetter } from '../../models/seriesType/config';
2
+ import { ChartsXAxisProps, ChartsAxisProps, ChartsYAxisProps, AxisId } from '../../models/axis';
3
+ import { CartesianChartSeriesType, DatasetType, ExtremumGetter } from '../../models/seriesType/config';
4
4
  import { DefaultizedAxisConfig } from './CartesianContext';
5
5
  import { DrawingArea } from '../DrawingProvider';
6
6
  import { FormattedSeries } from '../SeriesContextProvider';
7
- import { MakeOptional } from '../../models/helpers';
8
- export declare function computeValue(drawingArea: DrawingArea, formattedSeries: FormattedSeries, axis: MakeOptional<AxisConfig<ScaleName, any, ChartsYAxisProps>, 'id'>[] | undefined, extremumGetters: {
9
- [K in CartesianChartSeriesType]?: ExtremumGetter<K>;
10
- }, axisName: 'y', zoomRange?: [number, number]): {
7
+ export declare function computeValue(options: {
8
+ drawingArea: DrawingArea;
9
+ formattedSeries: FormattedSeries;
10
+ axis: AxisConfig<ScaleName, any, ChartsYAxisProps>[] | undefined;
11
+ extremumGetters: {
12
+ [K in CartesianChartSeriesType]?: ExtremumGetter<K>;
13
+ };
14
+ axisDirection: 'y';
15
+ dataset: DatasetType | undefined;
16
+ zoomData?: {
17
+ axisId: AxisId;
18
+ start: number;
19
+ end: number;
20
+ }[];
21
+ }): {
11
22
  axis: DefaultizedAxisConfig<ChartsYAxisProps>;
12
23
  axisIds: string[];
13
24
  };
14
- export declare function computeValue(drawingArea: DrawingArea, formattedSeries: FormattedSeries, inAxis: MakeOptional<AxisConfig<ScaleName, any, ChartsXAxisProps>, 'id'>[] | undefined, extremumGetters: {
15
- [K in CartesianChartSeriesType]?: ExtremumGetter<K>;
16
- }, axisName: 'x', zoomRange?: [number, number]): {
25
+ export declare function computeValue(options: {
26
+ drawingArea: DrawingArea;
27
+ formattedSeries: FormattedSeries;
28
+ axis: AxisConfig<ScaleName, any, ChartsXAxisProps>[] | undefined;
29
+ extremumGetters: {
30
+ [K in CartesianChartSeriesType]?: ExtremumGetter<K>;
31
+ };
32
+ axisDirection: 'x';
33
+ dataset: DatasetType | undefined;
34
+ zoomData?: {
35
+ axisId: AxisId;
36
+ start: number;
37
+ end: number;
38
+ }[];
39
+ }): {
17
40
  axis: DefaultizedAxisConfig<ChartsAxisProps>;
18
41
  axisIds: string[];
19
42
  };
@@ -7,14 +7,14 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.computeValue = computeValue;
8
8
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
9
  var _d3Scale = require("d3-scale");
10
- var _constants = require("../../constants");
11
10
  var _axis = require("../../models/axis");
12
11
  var _colorScale = require("../../internals/colorScale");
13
12
  var _useTicks = require("../../hooks/useTicks");
14
13
  var _getScale = require("../../internals/getScale");
15
14
  var _getAxisExtremum = require("./getAxisExtremum");
16
- const getRange = (drawingArea, axisName, isReverse) => {
17
- const range = axisName === 'x' ? [drawingArea.left, drawingArea.left + drawingArea.width] : [drawingArea.top + drawingArea.height, drawingArea.top];
15
+ var _normalizeAxis = require("./normalizeAxis");
16
+ const getRange = (drawingArea, axisDirection, isReverse) => {
17
+ const range = axisDirection === 'x' ? [drawingArea.left, drawingArea.left + drawingArea.width] : [drawingArea.top + drawingArea.height, drawingArea.top];
18
18
  return isReverse ? range.reverse() : range;
19
19
  };
20
20
  const zoomedScaleRange = (scaleRange, zoomRange) => {
@@ -36,26 +36,30 @@ function createDateFormatter(axis, range) {
36
36
  }
37
37
  const DEFAULT_CATEGORY_GAP_RATIO = 0.2;
38
38
  const DEFAULT_BAR_GAP_RATIO = 0.1;
39
- function computeValue(drawingArea, formattedSeries, inAxis, extremumGetters, axisName, zoomRange = [0, 100]) {
40
- const DEFAULT_AXIS_KEY = axisName === 'x' ? _constants.DEFAULT_X_AXIS_KEY : _constants.DEFAULT_Y_AXIS_KEY;
41
- const allAxis = [...(inAxis?.map((axis, index) => (0, _extends2.default)({
42
- id: `defaultized-${axisName}-axis-${index}`
43
- }, axis)) ?? []), ...(inAxis === undefined || inAxis.findIndex(({
44
- id
45
- }) => id === DEFAULT_AXIS_KEY) === -1 ? [{
46
- id: DEFAULT_AXIS_KEY,
47
- scaleType: 'linear'
48
- }] : [])];
39
+ function computeValue({
40
+ drawingArea,
41
+ formattedSeries,
42
+ axis: inAxis,
43
+ extremumGetters,
44
+ dataset,
45
+ axisDirection,
46
+ zoomData
47
+ }) {
48
+ const allAxis = (0, _normalizeAxis.normalizeAxis)(inAxis, dataset, axisDirection);
49
49
  const completeAxis = {};
50
50
  allAxis.forEach((axis, axisIndex) => {
51
51
  const isDefaultAxis = axisIndex === 0;
52
52
  const [minData, maxData] = (0, _getAxisExtremum.getAxisExtremum)(axis, extremumGetters, isDefaultAxis, formattedSeries);
53
- const range = getRange(drawingArea, axisName, axis.reverse);
53
+ const zoom = zoomData?.find(({
54
+ axisId
55
+ }) => axisId === axis.id);
56
+ const zoomRange = zoom ? [zoom.start, zoom.end] : [0, 100];
57
+ const range = getRange(drawingArea, axisDirection, axis.reverse);
54
58
  if ((0, _axis.isBandScaleConfig)(axis)) {
55
59
  const categoryGapRatio = axis.categoryGapRatio ?? DEFAULT_CATEGORY_GAP_RATIO;
56
60
  const barGapRatio = axis.barGapRatio ?? DEFAULT_BAR_GAP_RATIO;
57
61
  // Reverse range because ordinal scales are presented from top to bottom on y-axis
58
- const scaleRange = axisName === 'x' ? range : [range[1], range[0]];
62
+ const scaleRange = axisDirection === 'x' ? range : [range[1], range[0]];
59
63
  const zoomedRange = zoomedScaleRange(scaleRange, zoomRange);
60
64
  completeAxis[axis.id] = (0, _extends2.default)({
61
65
  categoryGapRatio,
@@ -73,7 +77,7 @@ function computeValue(drawingArea, formattedSeries, inAxis, extremumGetters, axi
73
77
  }
74
78
  }
75
79
  if ((0, _axis.isPointScaleConfig)(axis)) {
76
- const scaleRange = axisName === 'x' ? range : [...range].reverse();
80
+ const scaleRange = axisDirection === 'x' ? range : [...range].reverse();
77
81
  const zoomedRange = zoomedScaleRange(scaleRange, zoomRange);
78
82
  completeAxis[axis.id] = (0, _extends2.default)({}, axis, {
79
83
  scale: (0, _d3Scale.scalePoint)(axis.data, zoomedRange),
@@ -0,0 +1,36 @@
1
+ import { MakeOptional } from '../../models/helpers';
2
+ import { AxisConfig, ScaleName } from '../../models';
3
+ import { ChartsAxisProps } from '../../models/axis';
4
+ export declare const defaultizeAxis: (inAxis: MakeOptional<AxisConfig<ScaleName, any, ChartsAxisProps>, "id">[] | undefined, axisName: "x" | "y") => {
5
+ reverse?: boolean;
6
+ fill?: string;
7
+ stroke?: string;
8
+ data?: any[] | undefined;
9
+ label?: string;
10
+ max?: number | Date;
11
+ min?: number | Date;
12
+ classes?: Partial<import("../..").ChartsAxisClasses>;
13
+ slots?: Partial<import("../../models/axis").ChartsAxisSlots>;
14
+ slotProps?: Partial<import("../../models/axis").ChartsAxisSlotProps>;
15
+ dataKey?: string;
16
+ valueFormatter?: ((value: any, context: import("../../models/axis").AxisValueFormatterContext) => string) | undefined;
17
+ colorMap?: import("../../models/colorMapping").ContinuousColorConfig<number | Date> | import("../../models/colorMapping").PiecewiseColorConfig<number | Date> | import("../../models/colorMapping").OrdinalColorConfig<string | number | Date> | undefined;
18
+ tickMaxStep?: number;
19
+ tickMinStep?: number;
20
+ tickNumber?: number;
21
+ tickPlacement?: "start" | "end" | "middle" | "extremities";
22
+ tickLabelPlacement?: "middle" | "tick";
23
+ scaleType?: "linear" | "time" | "log" | "band" | "point" | "pow" | "sqrt" | "utc" | undefined;
24
+ axisId?: import("../../models/axis").AxisId;
25
+ disableLine?: boolean;
26
+ disableTicks?: boolean;
27
+ tickFontSize?: number;
28
+ tickLabelStyle?: import("../..").ChartsTextProps["style"];
29
+ labelStyle?: import("../..").ChartsTextProps["style"];
30
+ tickLabelInterval?: "auto" | ((value: any, index: number) => boolean);
31
+ labelFontSize?: number;
32
+ tickSize?: number;
33
+ tickInterval?: "auto" | ((value: any, index: number) => boolean) | any[];
34
+ hideTooltip?: boolean;
35
+ id: import("../../models/axis").AxisId;
36
+ }[];
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.defaultizeAxis = void 0;
8
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
+ var _constants = require("../../constants");
10
+ const defaultizeAxis = (inAxis, axisName) => {
11
+ const DEFAULT_AXIS_KEY = axisName === 'x' ? _constants.DEFAULT_X_AXIS_KEY : _constants.DEFAULT_Y_AXIS_KEY;
12
+ return [...(inAxis?.map((axis, index) => (0, _extends2.default)({
13
+ id: `defaultized-${axisName}-axis-${index}`
14
+ }, axis)) ?? []), ...(inAxis === undefined || inAxis.findIndex(({
15
+ id
16
+ }) => id === DEFAULT_AXIS_KEY) === -1 ? [{
17
+ id: DEFAULT_AXIS_KEY,
18
+ scaleType: 'linear'
19
+ }] : [])];
20
+ };
21
+ exports.defaultizeAxis = defaultizeAxis;
@@ -4,6 +4,5 @@ export * from './CartesianContext';
4
4
  export * from './useCartesianContext';
5
5
  declare const cartesianProviderUtils: {
6
6
  computeValue: typeof computeValue;
7
- normalizeAxis: <T extends import("../../internals").ChartsAxisProps, R extends import("../../internals").MakeOptional<import("../..").AxisConfig<import("../..").ScaleName, any, T>, "id">>(axis: R[] | undefined, dataset: import("../../internals").DatasetType | undefined, axisName: "x" | "y") => R[] | undefined;
8
7
  };
9
8
  export { cartesianProviderUtils };
@@ -8,7 +8,6 @@ var _exportNames = {
8
8
  };
9
9
  exports.cartesianProviderUtils = void 0;
10
10
  var _computeValue = require("./computeValue");
11
- var _normalizeAxis = require("./normalizeAxis");
12
11
  var _CartesianProvider = require("./CartesianProvider");
13
12
  Object.keys(_CartesianProvider).forEach(function (key) {
14
13
  if (key === "default" || key === "__esModule") return;
@@ -46,6 +45,5 @@ Object.keys(_useCartesianContext).forEach(function (key) {
46
45
  });
47
46
  });
48
47
  const cartesianProviderUtils = exports.cartesianProviderUtils = {
49
- computeValue: _computeValue.computeValue,
50
- normalizeAxis: _normalizeAxis.normalizeAxis
48
+ computeValue: _computeValue.computeValue
51
49
  };
@@ -2,4 +2,4 @@ import type { AxisConfig, ScaleName } from '../../models';
2
2
  import { ChartsAxisProps } from '../../models/axis';
3
3
  import { MakeOptional } from '../../models/helpers';
4
4
  import { DatasetType } from '../../models/seriesType/config';
5
- export declare const normalizeAxis: <T extends ChartsAxisProps, R extends MakeOptional<AxisConfig<ScaleName, any, T>, "id">>(axis: R[] | undefined, dataset: DatasetType | undefined, axisName: "x" | "y") => R[] | undefined;
5
+ export declare const normalizeAxis: <T extends ChartsAxisProps, R extends MakeOptional<AxisConfig<ScaleName, any, T>, "id">>(axis: R[] | undefined, dataset: DatasetType | undefined, axisName: "x" | "y") => R[];
@@ -18,6 +18,6 @@ const normalizeAxis = (axis, dataset, axisName) => {
18
18
  return (0, _extends2.default)({}, axisConfig, {
19
19
  data: dataset.map(d => d[dataKey])
20
20
  });
21
- });
21
+ }) ?? [];
22
22
  };
23
23
  exports.normalizeAxis = normalizeAxis;
@@ -33,6 +33,17 @@ export type DrawingArea = {
33
33
  * The height of the drawing area.
34
34
  */
35
35
  height: number;
36
+ /**
37
+ * Checks if a point is inside the drawing area.
38
+ * @param {Object} point The point to check.
39
+ * @param {number} point.x The x coordinate of the point.
40
+ * @param {number} point.y The y coordinate of the point.
41
+ * @returns {boolean} `true` if the point is inside the drawing area, `false` otherwise.
42
+ */
43
+ isPointInside: (point: {
44
+ x: number;
45
+ y: number;
46
+ }) => boolean;
36
47
  };
37
48
  export declare const DrawingContext: React.Context<DrawingArea & {
38
49
  /**
@@ -25,7 +25,8 @@ const DrawingContext = exports.DrawingContext = /*#__PURE__*/React.createContext
25
25
  right: 0,
26
26
  height: 300,
27
27
  width: 400,
28
- chartId: ''
28
+ chartId: '',
29
+ isPointInside: () => false
29
30
  });
30
31
  if (process.env.NODE_ENV !== 'production') {
31
32
  DrawingContext.displayName = 'DrawingContext';
@@ -49,9 +50,15 @@ function DrawingProvider(props) {
49
50
  } = props;
50
51
  const drawingArea = (0, _useChartDimensions.default)(width, height, margin);
51
52
  const chartId = (0, _useId.default)();
53
+ const isPointInside = React.useCallback(({
54
+ x,
55
+ y
56
+ }) => x >= drawingArea.left && x <= drawingArea.left + drawingArea.width && y >= drawingArea.top && y <= drawingArea.top + drawingArea.height, [drawingArea]);
52
57
  const value = React.useMemo(() => (0, _extends2.default)({
53
58
  chartId: chartId ?? ''
54
- }, drawingArea), [chartId, drawingArea]);
59
+ }, drawingArea, {
60
+ isPointInside
61
+ }), [chartId, drawingArea, isPointInside]);
55
62
  const refValue = React.useMemo(() => ({
56
63
  isInitialized: true,
57
64
  data: svgRef
@@ -24,11 +24,11 @@ const mergeDeprecatedOptions = options => {
24
24
  highlighted,
25
25
  faded
26
26
  } = _ref,
27
- rest = (0, _objectWithoutPropertiesLoose2.default)(_ref, _excluded);
27
+ other = (0, _objectWithoutPropertiesLoose2.default)(_ref, _excluded);
28
28
  return (0, _extends2.default)({
29
29
  highlight: highlighted,
30
30
  fade: faded
31
- }, rest);
31
+ }, other);
32
32
  };
33
33
  function HighlightedProvider({
34
34
  children,
@@ -43,8 +43,8 @@ const BarChart = /*#__PURE__*/React.forwardRef(function BarChart(props, ref) {
43
43
  ref: ref
44
44
  }, chartContainerProps, {
45
45
  children: [props.onAxisClick && /*#__PURE__*/_jsx(ChartsOnAxisClickHandler, _extends({}, axisClickHandlerProps)), props.grid && /*#__PURE__*/_jsx(ChartsGrid, _extends({}, gridProps)), /*#__PURE__*/_jsxs("g", _extends({}, clipPathGroupProps, {
46
- children: [/*#__PURE__*/_jsx(BarPlot, _extends({}, barPlotProps)), /*#__PURE__*/_jsx(ChartsOverlay, _extends({}, overlayProps))]
47
- })), /*#__PURE__*/_jsx(ChartsAxis, _extends({}, chartsAxisProps)), /*#__PURE__*/_jsx(ChartsLegend, _extends({}, legendProps)), /*#__PURE__*/_jsx(ChartsAxisHighlight, _extends({}, axisHighlightProps)), !props.loading && /*#__PURE__*/_jsx(ChartsTooltip, _extends({}, tooltipProps)), /*#__PURE__*/_jsx(ChartsClipPath, _extends({}, clipPathProps)), children]
46
+ children: [/*#__PURE__*/_jsx(BarPlot, _extends({}, barPlotProps)), /*#__PURE__*/_jsx(ChartsOverlay, _extends({}, overlayProps)), /*#__PURE__*/_jsx(ChartsAxisHighlight, _extends({}, axisHighlightProps))]
47
+ })), /*#__PURE__*/_jsx(ChartsAxis, _extends({}, chartsAxisProps)), /*#__PURE__*/_jsx(ChartsLegend, _extends({}, legendProps)), !props.loading && /*#__PURE__*/_jsx(ChartsTooltip, _extends({}, tooltipProps)), /*#__PURE__*/_jsx(ChartsClipPath, _extends({}, clipPathProps)), children]
48
48
  }));
49
49
  });
50
50
  process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
@@ -52,7 +52,7 @@ const formatter = (params, dataset) => {
52
52
  if (typeof value !== 'number') {
53
53
  if (process.env.NODE_ENV !== 'production' && !warnOnce && value !== null) {
54
54
  warnOnce = true;
55
- console.error([`MUI-X charts: your dataset key "${dataKey}" is used for plotting bars, but contains nonnumerical elements.`, 'Bar plots only support numbers and null values.']);
55
+ console.error([`MUI X charts: your dataset key "${dataKey}" is used for plotting bars, but contains nonnumerical elements.`, 'Bar plots only support numbers and null values.']);
56
56
  }
57
57
  return 0;
58
58
  }