@mui/x-charts 7.17.0 → 7.19.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 (180) hide show
  1. package/BarChart/BarChart.js +10 -0
  2. package/BarChart/BarElement.d.ts +1 -1
  3. package/BarChart/BarLabel/BarLabel.d.ts +1 -1
  4. package/BarChart/formatter.js +5 -4
  5. package/CHANGELOG.md +208 -5
  6. package/ChartContainer/useDefaultizeAxis.d.ts +4 -4
  7. package/ChartContainer/useDefaultizeAxis.js +1 -1
  8. package/ChartsAxis/ChartsAxis.js +4 -4
  9. package/ChartsAxisHighlight/ChartsAxisHighlight.d.ts +1 -1
  10. package/ChartsGrid/styledCommonents.d.ts +2 -2
  11. package/ChartsLegend/ChartsLegend.d.ts +2 -2
  12. package/ChartsLegend/DefaultChartsLegend.js +1 -1
  13. package/ChartsLegend/LegendPerItem.d.ts +1 -1
  14. package/ChartsLegend/LegendPerItem.js +1 -1
  15. package/ChartsLegend/PiecewiseColorLegend.js +1 -1
  16. package/ChartsReferenceLine/common.d.ts +1 -1
  17. package/ChartsTooltip/ChartsTooltipTable.d.ts +5 -5
  18. package/ChartsTooltip/index.d.ts +3 -0
  19. package/ChartsTooltip/index.js +4 -1
  20. package/ChartsTooltip/useAxisTooltip.d.ts +18 -0
  21. package/ChartsTooltip/useAxisTooltip.js +84 -0
  22. package/ChartsTooltip/useItemTooltip.d.ts +10 -0
  23. package/ChartsTooltip/useItemTooltip.js +64 -0
  24. package/ChartsTooltip/utils.d.ts +2 -1
  25. package/LineChart/AnimatedArea.d.ts +1 -1
  26. package/LineChart/AnimatedArea.js +9 -45
  27. package/LineChart/AnimatedLine.d.ts +1 -1
  28. package/LineChart/AnimatedLine.js +9 -46
  29. package/LineChart/AppearingMask.d.ts +12 -0
  30. package/LineChart/AppearingMask.js +42 -0
  31. package/LineChart/LineChart.js +10 -0
  32. package/LineChart/formatter.js +5 -5
  33. package/PieChart/PieChart.js +10 -0
  34. package/ResponsiveChartContainer/ResizableContainer.d.ts +1 -1
  35. package/ResponsiveChartContainer/ResponsiveChartContainer.d.ts +10 -0
  36. package/ResponsiveChartContainer/ResponsiveChartContainer.js +10 -0
  37. package/ResponsiveChartContainer/useChartContainerDimensions.d.ts +1 -1
  38. package/ResponsiveChartContainer/useChartContainerDimensions.js +32 -8
  39. package/ResponsiveChartContainer/useResponsiveChartContainerProps.d.ts +1 -1
  40. package/ResponsiveChartContainer/useResponsiveChartContainerProps.js +3 -2
  41. package/ScatterChart/ScatterChart.js +10 -0
  42. package/SparkLineChart/SparkLineChart.d.ts +1 -1
  43. package/SparkLineChart/SparkLineChart.js +10 -0
  44. package/context/CartesianProvider/CartesianProvider.js +3 -3
  45. package/context/CartesianProvider/defaultizeAxis.d.ts +4 -4
  46. package/context/CartesianProvider/getAxisExtremum.d.ts +1 -1
  47. package/context/CartesianProvider/getAxisExtremum.js +5 -4
  48. package/context/CartesianProvider/index.d.ts +0 -5
  49. package/context/CartesianProvider/index.js +1 -6
  50. package/context/PluginProvider/ExtremumGetter.types.d.ts +1 -0
  51. package/context/PluginProvider/Plugin.types.d.ts +4 -0
  52. package/context/PluginProvider/PluginContext.js +3 -1
  53. package/context/PluginProvider/index.d.ts +2 -0
  54. package/context/PluginProvider/index.js +3 -1
  55. package/context/PluginProvider/mergePlugins.d.ts +14 -4
  56. package/context/PluginProvider/mergePlugins.js +11 -1
  57. package/context/PluginProvider/useRadiusExtremumGetter.d.ts +4 -0
  58. package/context/PluginProvider/useRadiusExtremumGetter.js +17 -0
  59. package/context/PluginProvider/useRotationExtremumGetter.d.ts +4 -0
  60. package/context/PluginProvider/useRotationExtremumGetter.js +17 -0
  61. package/context/PolarProvider/Polar.types.d.ts +42 -0
  62. package/context/PolarProvider/Polar.types.js +1 -0
  63. package/context/PolarProvider/PolarContext.d.ts +4 -0
  64. package/context/PolarProvider/PolarContext.js +13 -0
  65. package/context/PolarProvider/PolarProvider.d.ts +4 -0
  66. package/context/PolarProvider/PolarProvider.js +49 -0
  67. package/context/PolarProvider/getAxisExtremum.d.ts +4 -0
  68. package/context/PolarProvider/getAxisExtremum.js +20 -0
  69. package/context/PolarProvider/index.d.ts +0 -0
  70. package/context/PolarProvider/index.js +0 -0
  71. package/context/PolarProvider/usePolarContext.d.ts +2 -0
  72. package/context/PolarProvider/usePolarContext.js +10 -0
  73. package/context/ZAxisContextProvider.js +1 -1
  74. package/hooks/useReducedMotion.js +2 -2
  75. package/hooks/useSeries.d.ts +4 -4
  76. package/hooks/useSeries.js +4 -4
  77. package/index.js +1 -1
  78. package/internals/components/AxisSharedComponents.d.ts +1 -1
  79. package/internals/computeAxisValue.d.ts +38 -0
  80. package/{context/CartesianProvider/computeValue.js → internals/computeAxisValue.js} +28 -15
  81. package/internals/configInit.d.ts +1 -1
  82. package/internals/defaultizeColor.d.ts +8 -8
  83. package/internals/domUtils.js +1 -1
  84. package/internals/geometry.js +3 -5
  85. package/internals/getPercentageValue.js +1 -1
  86. package/internals/index.d.ts +1 -0
  87. package/internals/index.js +1 -0
  88. package/models/axis.d.ts +20 -0
  89. package/models/seriesType/config.d.ts +6 -2
  90. package/models/seriesType/line.d.ts +5 -0
  91. package/modern/BarChart/BarChart.js +10 -0
  92. package/modern/BarChart/formatter.js +5 -4
  93. package/modern/ChartContainer/useDefaultizeAxis.js +1 -1
  94. package/modern/ChartsAxis/ChartsAxis.js +4 -4
  95. package/modern/ChartsLegend/DefaultChartsLegend.js +1 -1
  96. package/modern/ChartsLegend/LegendPerItem.js +1 -1
  97. package/modern/ChartsLegend/PiecewiseColorLegend.js +1 -1
  98. package/modern/ChartsTooltip/index.js +4 -1
  99. package/modern/ChartsTooltip/useAxisTooltip.js +84 -0
  100. package/modern/ChartsTooltip/useItemTooltip.js +64 -0
  101. package/modern/LineChart/AnimatedArea.js +9 -45
  102. package/modern/LineChart/AnimatedLine.js +9 -46
  103. package/modern/LineChart/AppearingMask.js +42 -0
  104. package/modern/LineChart/LineChart.js +10 -0
  105. package/modern/LineChart/formatter.js +5 -5
  106. package/modern/PieChart/PieChart.js +10 -0
  107. package/modern/ResponsiveChartContainer/ResponsiveChartContainer.js +10 -0
  108. package/modern/ResponsiveChartContainer/useChartContainerDimensions.js +32 -8
  109. package/modern/ResponsiveChartContainer/useResponsiveChartContainerProps.js +3 -2
  110. package/modern/ScatterChart/ScatterChart.js +10 -0
  111. package/modern/SparkLineChart/SparkLineChart.js +10 -0
  112. package/modern/context/CartesianProvider/CartesianProvider.js +3 -3
  113. package/modern/context/CartesianProvider/getAxisExtremum.js +5 -4
  114. package/modern/context/CartesianProvider/index.js +1 -6
  115. package/modern/context/PluginProvider/PluginContext.js +3 -1
  116. package/modern/context/PluginProvider/index.js +3 -1
  117. package/modern/context/PluginProvider/mergePlugins.js +11 -1
  118. package/modern/context/PluginProvider/useRadiusExtremumGetter.js +17 -0
  119. package/modern/context/PluginProvider/useRotationExtremumGetter.js +17 -0
  120. package/modern/context/PolarProvider/Polar.types.js +1 -0
  121. package/modern/context/PolarProvider/PolarContext.js +13 -0
  122. package/modern/context/PolarProvider/PolarProvider.js +49 -0
  123. package/modern/context/PolarProvider/getAxisExtremum.js +20 -0
  124. package/modern/context/PolarProvider/index.js +0 -0
  125. package/modern/context/PolarProvider/usePolarContext.js +10 -0
  126. package/modern/context/ZAxisContextProvider.js +1 -1
  127. package/modern/hooks/useReducedMotion.js +2 -2
  128. package/modern/hooks/useSeries.js +4 -4
  129. package/modern/index.js +1 -1
  130. package/modern/{context/CartesianProvider/computeValue.js → internals/computeAxisValue.js} +28 -15
  131. package/modern/internals/domUtils.js +1 -1
  132. package/modern/internals/geometry.js +3 -5
  133. package/modern/internals/getPercentageValue.js +1 -1
  134. package/modern/internals/index.js +1 -0
  135. package/node/BarChart/BarChart.js +10 -0
  136. package/node/BarChart/formatter.js +5 -4
  137. package/node/ChartContainer/useDefaultizeAxis.js +1 -1
  138. package/node/ChartsAxis/ChartsAxis.js +4 -4
  139. package/node/ChartsLegend/DefaultChartsLegend.js +1 -1
  140. package/node/ChartsLegend/LegendPerItem.js +1 -1
  141. package/node/ChartsLegend/PiecewiseColorLegend.js +1 -1
  142. package/node/ChartsTooltip/index.js +42 -1
  143. package/node/ChartsTooltip/useAxisTooltip.js +90 -0
  144. package/node/ChartsTooltip/useItemTooltip.js +71 -0
  145. package/node/LineChart/AnimatedArea.js +8 -44
  146. package/node/LineChart/AnimatedLine.js +8 -45
  147. package/node/LineChart/AppearingMask.js +48 -0
  148. package/node/LineChart/LineChart.js +10 -0
  149. package/node/LineChart/formatter.js +5 -5
  150. package/node/PieChart/PieChart.js +10 -0
  151. package/node/ResponsiveChartContainer/ResponsiveChartContainer.js +10 -0
  152. package/node/ResponsiveChartContainer/useChartContainerDimensions.js +32 -8
  153. package/node/ResponsiveChartContainer/useResponsiveChartContainerProps.js +3 -2
  154. package/node/ScatterChart/ScatterChart.js +10 -0
  155. package/node/SparkLineChart/SparkLineChart.js +10 -0
  156. package/node/context/CartesianProvider/CartesianProvider.js +3 -3
  157. package/node/context/CartesianProvider/getAxisExtremum.js +5 -4
  158. package/node/context/CartesianProvider/index.js +1 -13
  159. package/node/context/PluginProvider/PluginContext.js +3 -1
  160. package/node/context/PluginProvider/index.js +22 -0
  161. package/node/context/PluginProvider/mergePlugins.js +11 -1
  162. package/node/context/PluginProvider/useRadiusExtremumGetter.js +23 -0
  163. package/node/context/PluginProvider/useRotationExtremumGetter.js +23 -0
  164. package/node/context/PolarProvider/Polar.types.js +5 -0
  165. package/node/context/PolarProvider/PolarContext.js +20 -0
  166. package/node/context/PolarProvider/PolarProvider.js +54 -0
  167. package/node/context/PolarProvider/getAxisExtremum.js +27 -0
  168. package/node/context/PolarProvider/index.js +1 -0
  169. package/node/context/PolarProvider/usePolarContext.js +17 -0
  170. package/node/context/ZAxisContextProvider.js +1 -1
  171. package/node/hooks/useReducedMotion.js +2 -2
  172. package/node/hooks/useSeries.js +4 -4
  173. package/node/index.js +1 -1
  174. package/node/{context/CartesianProvider/computeValue.js → internals/computeAxisValue.js} +29 -16
  175. package/node/internals/domUtils.js +1 -1
  176. package/node/internals/geometry.js +3 -5
  177. package/node/internals/getPercentageValue.js +1 -1
  178. package/node/internals/index.js +12 -0
  179. package/package.json +4 -4
  180. package/context/CartesianProvider/computeValue.d.ts +0 -30
@@ -0,0 +1,49 @@
1
+ 'use client';
2
+
3
+ import * as React from 'react';
4
+ import { computeAxisValue } from "../../internals/computeAxisValue.js";
5
+ import { useDrawingArea } from "../../hooks/useDrawingArea.js";
6
+ import { useSeries } from "../../hooks/useSeries.js";
7
+ import { PolarContext } from "./PolarContext.js";
8
+ import { useRadiusExtremumGetter } from "../PluginProvider/useRadiusExtremumGetter.js";
9
+ import { useRotationExtremumGetter } from "../PluginProvider/useRotationExtremumGetter.js";
10
+ import { jsx as _jsx } from "react/jsx-runtime";
11
+ function PolarProvider(props) {
12
+ const {
13
+ rotationAxis,
14
+ radiusAxis,
15
+ children
16
+ } = props;
17
+ const formattedSeries = useSeries();
18
+ const drawingArea = useDrawingArea();
19
+ const rotationExtremumGetters = useRotationExtremumGetter();
20
+ const radiusExtremumGetters = useRadiusExtremumGetter();
21
+ const rotationValues = React.useMemo(() => computeAxisValue({
22
+ drawingArea,
23
+ formattedSeries,
24
+ axis: rotationAxis,
25
+ extremumGetters: rotationExtremumGetters,
26
+ axisDirection: 'rotation'
27
+ }), [drawingArea, formattedSeries, rotationAxis, rotationExtremumGetters]);
28
+ const radiusValues = React.useMemo(() => computeAxisValue({
29
+ drawingArea,
30
+ formattedSeries,
31
+ axis: radiusAxis,
32
+ extremumGetters: radiusExtremumGetters,
33
+ axisDirection: 'radius'
34
+ }), [drawingArea, formattedSeries, radiusAxis, radiusExtremumGetters]);
35
+ const value = React.useMemo(() => ({
36
+ isInitialized: true,
37
+ data: {
38
+ rotationAxis: rotationValues.axis,
39
+ radiusAxis: radiusValues.axis,
40
+ rotationAxisIds: rotationValues.axisIds,
41
+ radiusAxisIds: radiusValues.axisIds
42
+ }
43
+ }), [rotationValues, radiusValues]);
44
+ return /*#__PURE__*/_jsx(PolarContext.Provider, {
45
+ value: value,
46
+ children: children
47
+ });
48
+ }
49
+ export { PolarProvider };
@@ -0,0 +1,20 @@
1
+ const axisExtremumCallback = (acc, chartType, axis, getters, axisIndex, formattedSeries) => {
2
+ const getter = getters[chartType];
3
+ const series = formattedSeries[chartType]?.series ?? {};
4
+ const [minChartTypeData, maxChartTypeData] = getter?.({
5
+ series,
6
+ axis,
7
+ axisIndex,
8
+ isDefaultAxis: axisIndex === 0
9
+ }) ?? [Infinity, -Infinity];
10
+ const [minData, maxData] = acc;
11
+ return [Math.min(minChartTypeData, minData), Math.max(maxChartTypeData, maxData)];
12
+ };
13
+ export const getAxisExtremum = (axis, getters, axisIndex, formattedSeries) => {
14
+ const charTypes = Object.keys(getters);
15
+ const extremums = charTypes.reduce((acc, charType) => axisExtremumCallback(acc, charType, axis, getters, axisIndex, formattedSeries), [Infinity, -Infinity]);
16
+ if (Number.isNaN(extremums[0]) || Number.isNaN(extremums[1])) {
17
+ return [Infinity, -Infinity];
18
+ }
19
+ return extremums;
20
+ };
File without changes
@@ -0,0 +1,10 @@
1
+ 'use client';
2
+
3
+ import * as React from 'react';
4
+ import { PolarContext } from "./PolarContext.js";
5
+ export const usePolarContext = () => {
6
+ const {
7
+ data
8
+ } = React.useContext(PolarContext);
9
+ return data;
10
+ };
@@ -24,7 +24,7 @@ function ZAxisContextProvider(props) {
24
24
  return axisConfig;
25
25
  }
26
26
  if (dataset === undefined) {
27
- throw Error('MUI X: z-axis uses `dataKey` but no `dataset` is provided.');
27
+ throw new Error('MUI X: z-axis uses `dataKey` but no `dataset` is provided.');
28
28
  }
29
29
  return _extends({}, axisConfig, {
30
30
  data: dataset.map(d => d[dataKey])
@@ -1,10 +1,10 @@
1
1
  'use client';
2
2
 
3
3
  import { useIsomorphicLayoutEffect, Globals } from '@react-spring/web';
4
- const handleMediaChange = e => {
4
+ const handleMediaChange = event => {
5
5
  Globals.assign({
6
6
  // Modification such the react-spring implementation such that this hook can remove animation but never activate animation.
7
- skipAnimation: e.matches || undefined
7
+ skipAnimation: event.matches || undefined
8
8
  });
9
9
  };
10
10
 
@@ -25,7 +25,7 @@ export function useSeries() {
25
25
  * The returned object contains:
26
26
  * - series: a mapping from ids to series attributes.
27
27
  * - seriesOrder: the array of series ids.
28
- * @returns { series: Record<SeriesId, DefaultizedPieSeriesType>; seriesOrder: SeriesId[]; } | undefined pieSeries
28
+ * @returns {{ series: Record<SeriesId, DefaultizedPieSeriesType>; seriesOrder: SeriesId[]; } | undefined} pieSeries
29
29
  */
30
30
  export function usePieSeries() {
31
31
  const series = useSeries();
@@ -37,7 +37,7 @@ export function usePieSeries() {
37
37
  * The returned object contains:
38
38
  * - series: a mapping from ids to series attributes.
39
39
  * - seriesOrder: the array of series ids.
40
- * @returns { series: Record<SeriesId, DefaultizedLineSeriesType>; seriesOrder: SeriesId[]; } | undefined lineSeries
40
+ * @returns {{ series: Record<SeriesId, DefaultizedLineSeriesType>; seriesOrder: SeriesId[]; } | undefined} lineSeries
41
41
  */
42
42
  export function useLineSeries() {
43
43
  const series = useSeries();
@@ -49,7 +49,7 @@ export function useLineSeries() {
49
49
  * The returned object contains:
50
50
  * - series: a mapping from ids to series attributes.
51
51
  * - seriesOrder: the array of series ids.
52
- * @returns { series: Record<SeriesId, DefaultizedBarSeriesType>; seriesOrder: SeriesId[]; } | undefined barSeries
52
+ * @returns {{ series: Record<SeriesId, DefaultizedBarSeriesType>; seriesOrder: SeriesId[]; } | undefined} barSeries
53
53
  */
54
54
  export function useBarSeries() {
55
55
  const series = useSeries();
@@ -61,7 +61,7 @@ export function useBarSeries() {
61
61
  * The returned object contains:
62
62
  * - series: a mapping from ids to series attributes.
63
63
  * - seriesOrder: the array of series ids.
64
- * @returns { series: Record<SeriesId, DefaultizedScatterSeriesType>; seriesOrder: SeriesId[]; } | undefined scatterSeries
64
+ * @returns {{ series: Record<SeriesId, DefaultizedScatterSeriesType>; seriesOrder: SeriesId[]; } | undefined} scatterSeries
65
65
  */
66
66
  export function useScatterSeries() {
67
67
  const series = useSeries();
package/modern/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-charts v7.17.0
2
+ * @mui/x-charts v7.19.0
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -1,15 +1,29 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import { scaleBand, scalePoint, scaleTime } from '@mui/x-charts-vendor/d3-scale';
3
- import { isBandScaleConfig, isPointScaleConfig } from "../../models/axis.js";
4
- import { getColorScale, getOrdinalColorScale } from "../../internals/colorScale.js";
5
- import { getTickNumber } from "../../hooks/useTicks.js";
6
- import { getScale } from "../../internals/getScale.js";
7
- import { zoomScaleRange } from "./zoom.js";
8
- import { getAxisExtremum } from "./getAxisExtremum.js";
9
- const getRange = (drawingArea, axisDirection, isReverse) => {
3
+ import { isBandScaleConfig, isPointScaleConfig } from "../models/axis.js";
4
+ import { getColorScale, getOrdinalColorScale } from "./colorScale.js";
5
+ import { getTickNumber } from "../hooks/useTicks.js";
6
+ import { getScale } from "./getScale.js";
7
+ import { zoomScaleRange } from "../context/CartesianProvider/zoom.js";
8
+ import { getAxisExtremum } from "../context/CartesianProvider/getAxisExtremum.js";
9
+ function getRange(drawingArea, axisDirection, axis) {
10
+ if (axisDirection === 'rotation') {
11
+ const {
12
+ startAngle = 0,
13
+ endAngle = startAngle + 360
14
+ } = axis;
15
+ return axis.reverse ? [Math.PI * startAngle / 180, Math.PI * endAngle / 180] : [Math.PI * endAngle / 180, Math.PI * startAngle / 180];
16
+ }
17
+ if (axisDirection === 'radius') {
18
+ const {
19
+ minRadius = 0,
20
+ maxRadius = Math.min(drawingArea.width, drawingArea.height) / 2
21
+ } = axis;
22
+ return [minRadius, maxRadius];
23
+ }
10
24
  const range = axisDirection === 'x' ? [drawingArea.left, drawingArea.left + drawingArea.width] : [drawingArea.top + drawingArea.height, drawingArea.top];
11
- return isReverse ? range.reverse() : range;
12
- };
25
+ return axis.reverse ? [range[1], range[0]] : range;
26
+ }
13
27
  const isDateData = data => data?.[0] instanceof Date;
14
28
  function createDateFormatter(axis, range) {
15
29
  const timeScale = scaleTime(axis.data, range);
@@ -19,7 +33,7 @@ function createDateFormatter(axis, range) {
19
33
  }
20
34
  const DEFAULT_CATEGORY_GAP_RATIO = 0.2;
21
35
  const DEFAULT_BAR_GAP_RATIO = 0.1;
22
- export function computeValue({
36
+ export function computeAxisValue({
23
37
  drawingArea,
24
38
  formattedSeries,
25
39
  axis: allAxis,
@@ -32,21 +46,20 @@ export function computeValue({
32
46
  const completeAxis = {};
33
47
  allAxis.forEach((eachAxis, axisIndex) => {
34
48
  const axis = eachAxis;
35
- const isDefaultAxis = axisIndex === 0;
36
49
  const zoomOption = zoomOptions?.[axis.id];
37
50
  const zoom = zoomData?.find(({
38
51
  axisId
39
52
  }) => axisId === axis.id);
40
53
  const zoomRange = zoom ? [zoom.start, zoom.end] : [0, 100];
41
- const range = getRange(drawingArea, axisDirection, axis.reverse);
42
- const [minData, maxData] = getAxisExtremum(axis, extremumGetters, isDefaultAxis, formattedSeries, zoom === undefined && !zoomOption ? getFilters : undefined // Do not apply filtering if zoom is already defined.
54
+ const range = getRange(drawingArea, axisDirection, axis);
55
+ const [minData, maxData] = getAxisExtremum(axis, extremumGetters, axisIndex, formattedSeries, zoom === undefined && !zoomOption ? getFilters : undefined // Do not apply filtering if zoom is already defined.
43
56
  );
44
57
  const data = axis.data ?? [];
45
58
  if (isBandScaleConfig(axis)) {
46
59
  const categoryGapRatio = axis.categoryGapRatio ?? DEFAULT_CATEGORY_GAP_RATIO;
47
60
  const barGapRatio = axis.barGapRatio ?? DEFAULT_BAR_GAP_RATIO;
48
61
  // Reverse range because ordinal scales are presented from top to bottom on y-axis
49
- const scaleRange = axisDirection === 'x' ? range : [range[1], range[0]];
62
+ const scaleRange = axisDirection === 'y' ? [range[1], range[0]] : range;
50
63
  const zoomedRange = zoomScaleRange(scaleRange, zoomRange);
51
64
  completeAxis[axis.id] = _extends({
52
65
  categoryGapRatio,
@@ -65,7 +78,7 @@ export function computeValue({
65
78
  }
66
79
  }
67
80
  if (isPointScaleConfig(axis)) {
68
- const scaleRange = axisDirection === 'x' ? range : [...range].reverse();
81
+ const scaleRange = axisDirection === 'y' ? [...range].reverse() : range;
69
82
  const zoomedRange = zoomScaleRange(scaleRange, zoomRange);
70
83
  completeAxis[axis.id] = _extends({}, axis, {
71
84
  data,
@@ -113,7 +113,7 @@ export const getStringSize = (text, style = {}) => {
113
113
  measurementSpan.textContent = '';
114
114
  }, 0);
115
115
  return result;
116
- } catch (e) {
116
+ } catch {
117
117
  return {
118
118
  width: 0,
119
119
  height: 0
@@ -1,7 +1,6 @@
1
+ import { warnOnce } from '@mui/x-internals/warning';
1
2
  const ANGLE_APPROX = 5; // Angle (in deg) for which we approximate the rectangle as perfectly horizontal/vertical
2
3
 
3
- let warnedOnce = false;
4
-
5
4
  /**
6
5
  * Return the minimal translation along the x-axis to avoid overflow of a rectangle of a given width, height, and rotation.
7
6
  * This assumes that all rectangles have the same height and angle between -90 and 90.
@@ -12,9 +11,8 @@ let warnedOnce = false;
12
11
  */
13
12
  export function getMinXTranslation(width, height, angle = 0) {
14
13
  if (process.env.NODE_ENV !== 'production') {
15
- if (!warnedOnce && angle > 90 && angle < -90) {
16
- warnedOnce = true;
17
- console.warn([`MUI X: It seems you applied an angle larger than 90° or smaller than -90° to an axis text.`, `This could cause some text overlapping.`, `If you encounter a use case where it's needed, please open an issue.`].join('\n'));
14
+ if (angle > 90 && angle < -90) {
15
+ warnOnce([`MUI X: It seems you applied an angle larger than 90° or smaller than -90° to an axis text.`, `This could cause some text overlapping.`, `If you encounter a use case where it's needed, please open an issue.`]);
18
16
  }
19
17
  }
20
18
  const standardAngle = Math.min(Math.abs(angle) % 180, Math.abs(Math.abs(angle) % 180 - 180) % 180); // Map from R to [0, 90]
@@ -24,5 +24,5 @@ export function getPercentageValue(value, refValue) {
24
24
  return val;
25
25
  }
26
26
  }
27
- throw Error(`MUI X: Received an unknown value "${value}". It should be a number, or a string with a percentage value.`);
27
+ throw new Error(`MUI X: Received an unknown value "${value}". It should be a number, or a string with a percentage value.`);
28
28
  }
@@ -22,6 +22,7 @@ export * from "./getSVGPoint.js";
22
22
  export * from "./isDefined.js";
23
23
  export { unstable_cleanupDOM } from "./domUtils.js";
24
24
  export * from "./getScale.js";
25
+ export * from "./computeAxisValue.js";
25
26
 
26
27
  // contexts
27
28
 
@@ -203,6 +203,16 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
203
203
  * @param {BarItemIdentifier} barItemIdentifier The bar item identifier.
204
204
  */
205
205
  onItemClick: _propTypes.default.func,
206
+ /**
207
+ * The chart will try to wait for the parent container to resolve its size
208
+ * before it renders for the first time.
209
+ *
210
+ * This can be useful in some scenarios where the chart appear to grow after
211
+ * the first render, like when used inside a grid.
212
+ *
213
+ * @default false
214
+ */
215
+ resolveSizeBeforeRender: _propTypes.default.bool,
206
216
  /**
207
217
  * Indicate which axis to display the right of the charts.
208
218
  * Can be a string (the id of the axis) or an object `ChartsYAxisProps`.
@@ -7,9 +7,9 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.default = void 0;
8
8
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
9
  var _d3Shape = require("@mui/x-charts-vendor/d3-shape");
10
+ var _warning = require("@mui/x-internals/warning");
10
11
  var _stackSeries = require("../internals/stackSeries");
11
12
  var _defaultizeValueFormatter = require("../internals/defaultizeValueFormatter");
12
- let warnOnce = false;
13
13
  const formatter = (params, dataset) => {
14
14
  const {
15
15
  seriesOrder,
@@ -57,9 +57,10 @@ const formatter = (params, dataset) => {
57
57
  data: dataKey ? dataset.map(data => {
58
58
  const value = data[dataKey];
59
59
  if (typeof value !== 'number') {
60
- if (process.env.NODE_ENV !== 'production' && !warnOnce && value !== null) {
61
- warnOnce = true;
62
- 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.'].join('\n'));
60
+ if (process.env.NODE_ENV !== 'production') {
61
+ if (value !== null) {
62
+ (0, _warning.warnOnce)([`MUI X: your dataset key "${dataKey}" is used for plotting bars, but contains nonnumerical elements.`, 'Bar plots only support numbers and null values.']);
63
+ }
63
64
  }
64
65
  return 0;
65
66
  }
@@ -25,7 +25,7 @@ const defaultizeAxis = (inAxis, dataset, axisName) => {
25
25
  return axisConfig;
26
26
  }
27
27
  if (dataset === undefined) {
28
- throw Error(`MUI X: ${axisName}-axis uses \`dataKey\` but no \`dataset\` is provided.`);
28
+ throw new Error(`MUI X: ${axisName}-axis uses \`dataKey\` but no \`dataset\` is provided.`);
29
29
  }
30
30
  return (0, _extends2.default)({}, axisConfig, {
31
31
  data: dataset.map(d => d[dataKey])
@@ -66,16 +66,16 @@ function ChartsAxis(props) {
66
66
  const topId = getAxisId(topAxis, xAxisIds[0]);
67
67
  const rightId = getAxisId(rightAxis, yAxisIds[0]);
68
68
  if (topId !== null && !xAxis[topId]) {
69
- throw Error([`MUI X: id used for top axis "${topId}" is not defined.`, `Available ids are: ${xAxisIds.join(', ')}.`].join('\n'));
69
+ throw new Error([`MUI X: id used for top axis "${topId}" is not defined.`, `Available ids are: ${xAxisIds.join(', ')}.`].join('\n'));
70
70
  }
71
71
  if (leftId !== null && !yAxis[leftId]) {
72
- throw Error([`MUI X: id used for left axis "${leftId}" is not defined.`, `Available ids are: ${yAxisIds.join(', ')}.`].join('\n'));
72
+ throw new Error([`MUI X: id used for left axis "${leftId}" is not defined.`, `Available ids are: ${yAxisIds.join(', ')}.`].join('\n'));
73
73
  }
74
74
  if (rightId !== null && !yAxis[rightId]) {
75
- throw Error([`MUI X: id used for right axis "${rightId}" is not defined.`, `Available ids are: ${yAxisIds.join(', ')}.`].join('\n'));
75
+ throw new Error([`MUI X: id used for right axis "${rightId}" is not defined.`, `Available ids are: ${yAxisIds.join(', ')}.`].join('\n'));
76
76
  }
77
77
  if (bottomId !== null && !xAxis[bottomId]) {
78
- throw Error([`MUI X: id used for bottom axis "${bottomId}" is not defined.`, `Available ids are: ${xAxisIds.join(', ')}.`].join('\n'));
78
+ throw new Error([`MUI X: id used for bottom axis "${bottomId}" is not defined.`, `Available ids are: ${xAxisIds.join(', ')}.`].join('\n'));
79
79
  }
80
80
  const topAxisProps = mergeProps(topAxis, slots, slotProps);
81
81
  const bottomAxisProps = mergeProps(bottomAxis, slots, slotProps);
@@ -33,7 +33,7 @@ function DefaultChartsLegend(props) {
33
33
  }
34
34
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_LegendPerItem.LegendPerItem, (0, _extends2.default)({}, other, {
35
35
  itemsToDisplay: seriesToDisplay,
36
- onItemClick: onItemClick ? (e, i) => onItemClick(e, seriesContextBuilder(seriesToDisplay[i]), i) : undefined
36
+ onItemClick: onItemClick ? (event, i) => onItemClick(event, seriesContextBuilder(seriesToDisplay[i]), i) : undefined
37
37
  }));
38
38
  }
39
39
  process.env.NODE_ENV !== "production" ? DefaultChartsLegend.propTypes = {
@@ -130,7 +130,7 @@ function LegendPerItem(props) {
130
130
  markGap: markGap,
131
131
  labelStyle: labelStyle,
132
132
  classes: classes,
133
- onClick: onItemClick ? e => onItemClick(e, i) : undefined
133
+ onClick: onItemClick ? event => onItemClick(event, i) : undefined
134
134
  })))
135
135
  })
136
136
  });
@@ -87,7 +87,7 @@ function PiecewiseColorLegend(props) {
87
87
  }).filter(_notNull.notNull);
88
88
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_LegendPerItem.LegendPerItem, (0, _extends2.default)({}, other, {
89
89
  itemsToDisplay: itemsToDisplay,
90
- onItemClick: onItemClick ? (e, i) => onItemClick(e, piecewiseColorContextBuilder(itemsToDisplay[i]), i) : undefined
90
+ onItemClick: onItemClick ? (event, i) => onItemClick(event, piecewiseColorContextBuilder(itemsToDisplay[i]), i) : undefined
91
91
  }));
92
92
  }
93
93
  process.env.NODE_ENV !== "production" ? PiecewiseColorLegend.propTypes = {
@@ -3,9 +3,19 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ var _exportNames = {
7
+ useMouseTracker: true
8
+ };
9
+ Object.defineProperty(exports, "useMouseTracker", {
10
+ enumerable: true,
11
+ get: function () {
12
+ return _utils.useMouseTracker;
13
+ }
14
+ });
6
15
  var _ChartsTooltip = require("./ChartsTooltip");
7
16
  Object.keys(_ChartsTooltip).forEach(function (key) {
8
17
  if (key === "default" || key === "__esModule") return;
18
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
9
19
  if (key in exports && exports[key] === _ChartsTooltip[key]) return;
10
20
  Object.defineProperty(exports, key, {
11
21
  enumerable: true,
@@ -17,6 +27,7 @@ Object.keys(_ChartsTooltip).forEach(function (key) {
17
27
  var _chartsTooltipClasses = require("./chartsTooltipClasses");
18
28
  Object.keys(_chartsTooltipClasses).forEach(function (key) {
19
29
  if (key === "default" || key === "__esModule") return;
30
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
20
31
  if (key in exports && exports[key] === _chartsTooltipClasses[key]) return;
21
32
  Object.defineProperty(exports, key, {
22
33
  enumerable: true,
@@ -28,6 +39,7 @@ Object.keys(_chartsTooltipClasses).forEach(function (key) {
28
39
  var _ChartsAxisTooltipContent = require("./ChartsAxisTooltipContent");
29
40
  Object.keys(_ChartsAxisTooltipContent).forEach(function (key) {
30
41
  if (key === "default" || key === "__esModule") return;
42
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
31
43
  if (key in exports && exports[key] === _ChartsAxisTooltipContent[key]) return;
32
44
  Object.defineProperty(exports, key, {
33
45
  enumerable: true,
@@ -39,6 +51,7 @@ Object.keys(_ChartsAxisTooltipContent).forEach(function (key) {
39
51
  var _ChartsItemTooltipContent = require("./ChartsItemTooltipContent");
40
52
  Object.keys(_ChartsItemTooltipContent).forEach(function (key) {
41
53
  if (key === "default" || key === "__esModule") return;
54
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
42
55
  if (key in exports && exports[key] === _ChartsItemTooltipContent[key]) return;
43
56
  Object.defineProperty(exports, key, {
44
57
  enumerable: true,
@@ -50,6 +63,7 @@ Object.keys(_ChartsItemTooltipContent).forEach(function (key) {
50
63
  var _DefaultChartsAxisTooltipContent = require("./DefaultChartsAxisTooltipContent");
51
64
  Object.keys(_DefaultChartsAxisTooltipContent).forEach(function (key) {
52
65
  if (key === "default" || key === "__esModule") return;
66
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
53
67
  if (key in exports && exports[key] === _DefaultChartsAxisTooltipContent[key]) return;
54
68
  Object.defineProperty(exports, key, {
55
69
  enumerable: true,
@@ -61,6 +75,7 @@ Object.keys(_DefaultChartsAxisTooltipContent).forEach(function (key) {
61
75
  var _DefaultChartsItemTooltipContent = require("./DefaultChartsItemTooltipContent");
62
76
  Object.keys(_DefaultChartsItemTooltipContent).forEach(function (key) {
63
77
  if (key === "default" || key === "__esModule") return;
78
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
64
79
  if (key in exports && exports[key] === _DefaultChartsItemTooltipContent[key]) return;
65
80
  Object.defineProperty(exports, key, {
66
81
  enumerable: true,
@@ -72,6 +87,7 @@ Object.keys(_DefaultChartsItemTooltipContent).forEach(function (key) {
72
87
  var _ChartsTooltipTable = require("./ChartsTooltipTable");
73
88
  Object.keys(_ChartsTooltipTable).forEach(function (key) {
74
89
  if (key === "default" || key === "__esModule") return;
90
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
75
91
  if (key in exports && exports[key] === _ChartsTooltipTable[key]) return;
76
92
  Object.defineProperty(exports, key, {
77
93
  enumerable: true,
@@ -79,4 +95,29 @@ Object.keys(_ChartsTooltipTable).forEach(function (key) {
79
95
  return _ChartsTooltipTable[key];
80
96
  }
81
97
  });
82
- });
98
+ });
99
+ var _useItemTooltip = require("./useItemTooltip");
100
+ Object.keys(_useItemTooltip).forEach(function (key) {
101
+ if (key === "default" || key === "__esModule") return;
102
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
103
+ if (key in exports && exports[key] === _useItemTooltip[key]) return;
104
+ Object.defineProperty(exports, key, {
105
+ enumerable: true,
106
+ get: function () {
107
+ return _useItemTooltip[key];
108
+ }
109
+ });
110
+ });
111
+ var _useAxisTooltip = require("./useAxisTooltip");
112
+ Object.keys(_useAxisTooltip).forEach(function (key) {
113
+ if (key === "default" || key === "__esModule") return;
114
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
115
+ if (key in exports && exports[key] === _useAxisTooltip[key]) return;
116
+ Object.defineProperty(exports, key, {
117
+ enumerable: true,
118
+ get: function () {
119
+ return _useAxisTooltip[key];
120
+ }
121
+ });
122
+ });
123
+ var _utils = require("./utils");
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ 'use client';
3
+
4
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.useAxisTooltip = useAxisTooltip;
9
+ var React = _interopRequireWildcard(require("react"));
10
+ var _InteractionProvider = require("../context/InteractionProvider");
11
+ var _useSeries = require("../hooks/useSeries");
12
+ var _CartesianProvider = require("../context/CartesianProvider");
13
+ var _ZAxisContextProvider = require("../context/ZAxisContextProvider");
14
+ var _useColorProcessor = require("../context/PluginProvider/useColorProcessor");
15
+ var _getLabel = require("../internals/getLabel");
16
+ var _isCartesian = require("../internals/isCartesian");
17
+ var _utils = require("./utils");
18
+ function useAxisTooltip() {
19
+ const {
20
+ axis
21
+ } = React.useContext(_InteractionProvider.InteractionContext);
22
+ const series = (0, _useSeries.useSeries)();
23
+ const {
24
+ xAxis,
25
+ yAxis,
26
+ xAxisIds,
27
+ yAxisIds
28
+ } = (0, _CartesianProvider.useCartesianContext)();
29
+ const {
30
+ zAxis,
31
+ zAxisIds
32
+ } = React.useContext(_ZAxisContextProvider.ZAxisContext);
33
+ const colorProcessors = (0, _useColorProcessor.useColorProcessor)();
34
+
35
+ // By default use the x-axis
36
+ const isXaxis = axis.x !== null && axis.x.index !== -1;
37
+ const axisData = isXaxis ? axis.x && axis.x : axis.y && axis.y;
38
+ if (axisData === null) {
39
+ return null;
40
+ }
41
+ const {
42
+ index: dataIndex,
43
+ value: axisValue
44
+ } = axisData;
45
+ const USED_AXIS_ID = isXaxis ? xAxisIds[0] : yAxisIds[0];
46
+ const usedAxis = isXaxis ? xAxis[USED_AXIS_ID] : yAxis[USED_AXIS_ID];
47
+ const relevantSeries = Object.keys(series).filter(_isCartesian.isCartesianSeriesType).flatMap(seriesType => {
48
+ const seriesOfType = series[seriesType];
49
+ if (!seriesOfType) {
50
+ return [];
51
+ }
52
+ return seriesOfType.seriesOrder.map(seriesId => {
53
+ const seriesToAdd = seriesOfType.series[seriesId];
54
+ const providedXAxisId = seriesToAdd.xAxisId ?? seriesToAdd.xAxisKey;
55
+ const providedYAxisId = seriesToAdd.yAxisId ?? seriesToAdd.yAxisKey;
56
+ const axisKey = isXaxis ? providedXAxisId : providedYAxisId;
57
+
58
+ // Test if the series uses the default axis
59
+ if (axisKey === undefined || axisKey === USED_AXIS_ID) {
60
+ const xAxisId = providedXAxisId ?? xAxisIds[0];
61
+ const yAxisId = providedYAxisId ?? yAxisIds[0];
62
+ const zAxisId = seriesToAdd.zAxisId ?? seriesToAdd.zAxisKey ?? zAxisIds[0];
63
+ const color = colorProcessors[seriesType]?.(seriesToAdd, xAxis[xAxisId], yAxis[yAxisId], zAxisId && zAxis[zAxisId])(dataIndex) ?? '';
64
+ const value = seriesToAdd.data[dataIndex] ?? null;
65
+ const formattedValue = seriesToAdd.valueFormatter(value, {
66
+ dataIndex
67
+ });
68
+ const formattedLabel = (0, _getLabel.getLabel)(seriesToAdd.label, 'tooltip') ?? null;
69
+ return {
70
+ seriesId,
71
+ color,
72
+ value,
73
+ formattedValue,
74
+ formattedLabel
75
+ };
76
+ }
77
+ return undefined;
78
+ });
79
+ }).filter(item => item != null);
80
+ const axisFormatter = usedAxis.valueFormatter ?? (v => usedAxis.scaleType === 'utc' ? (0, _utils.utcFormatter)(v) : v.toLocaleString());
81
+ const axisFormattedValue = axisFormatter(axisValue, {
82
+ location: 'tooltip'
83
+ });
84
+ return {
85
+ identifier: axis,
86
+ seriesItems: relevantSeries,
87
+ axisValue,
88
+ axisFormattedValue
89
+ };
90
+ }
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ 'use client';
3
+
4
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
5
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
6
+ Object.defineProperty(exports, "__esModule", {
7
+ value: true
8
+ });
9
+ exports.useItemTooltip = useItemTooltip;
10
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
11
+ var React = _interopRequireWildcard(require("react"));
12
+ var _InteractionProvider = require("../context/InteractionProvider");
13
+ var _useSeries = require("../hooks/useSeries");
14
+ var _CartesianProvider = require("../context/CartesianProvider");
15
+ var _ZAxisContextProvider = require("../context/ZAxisContextProvider");
16
+ var _useColorProcessor = require("../context/PluginProvider/useColorProcessor");
17
+ var _getLabel = require("../internals/getLabel");
18
+ function useItemTooltip() {
19
+ const {
20
+ item
21
+ } = React.useContext(_InteractionProvider.InteractionContext);
22
+ const series = (0, _useSeries.useSeries)();
23
+ const {
24
+ xAxis,
25
+ yAxis,
26
+ xAxisIds,
27
+ yAxisIds
28
+ } = (0, _CartesianProvider.useCartesianContext)();
29
+ const {
30
+ zAxis,
31
+ zAxisIds
32
+ } = React.useContext(_ZAxisContextProvider.ZAxisContext);
33
+ const colorProcessors = (0, _useColorProcessor.useColorProcessor)();
34
+ const xAxisId = series.xAxisId ?? series.xAxisKey ?? xAxisIds[0];
35
+ const yAxisId = series.yAxisId ?? series.yAxisKey ?? yAxisIds[0];
36
+ const zAxisId = series.zAxisId ?? series.zAxisKey ?? zAxisIds[0];
37
+ if (!item || item.dataIndex === undefined) {
38
+ return null;
39
+ }
40
+ const itemSeries = series[item.type].series[item.seriesId];
41
+ const getColor = colorProcessors[itemSeries.type]?.(itemSeries, xAxisId && xAxis[xAxisId], yAxisId && yAxis[yAxisId], zAxisId && zAxis[zAxisId]) ?? (() => '');
42
+ if (itemSeries.type === 'pie') {
43
+ const point = itemSeries.data[item.dataIndex];
44
+ const label = (0, _getLabel.getLabel)(point.label, 'tooltip');
45
+ const value = (0, _extends2.default)({}, point, {
46
+ label
47
+ });
48
+ const formattedValue = itemSeries.valueFormatter?.(value, {
49
+ dataIndex: item.dataIndex
50
+ });
51
+ return {
52
+ identifier: item,
53
+ color: getColor(item.dataIndex),
54
+ label,
55
+ value,
56
+ formattedValue
57
+ };
58
+ }
59
+ const label = (0, _getLabel.getLabel)(itemSeries.label, 'tooltip');
60
+ const value = itemSeries.data[item.dataIndex];
61
+ const formattedValue = itemSeries.valueFormatter?.(value, {
62
+ dataIndex: item.dataIndex
63
+ });
64
+ return {
65
+ identifier: item,
66
+ color: getColor(item.dataIndex),
67
+ label,
68
+ value,
69
+ formattedValue
70
+ };
71
+ }