@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
@@ -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
 
@@ -11,7 +11,7 @@ export declare function useSeries(): FormattedSeries;
11
11
  * The returned object contains:
12
12
  * - series: a mapping from ids to series attributes.
13
13
  * - seriesOrder: the array of series ids.
14
- * @returns { series: Record<SeriesId, DefaultizedPieSeriesType>; seriesOrder: SeriesId[]; } | undefined pieSeries
14
+ * @returns {{ series: Record<SeriesId, DefaultizedPieSeriesType>; seriesOrder: SeriesId[]; } | undefined} pieSeries
15
15
  */
16
16
  export declare function usePieSeries(): FormattedSeries['pie'];
17
17
  /**
@@ -19,7 +19,7 @@ export declare function usePieSeries(): FormattedSeries['pie'];
19
19
  * The returned object contains:
20
20
  * - series: a mapping from ids to series attributes.
21
21
  * - seriesOrder: the array of series ids.
22
- * @returns { series: Record<SeriesId, DefaultizedLineSeriesType>; seriesOrder: SeriesId[]; } | undefined lineSeries
22
+ * @returns {{ series: Record<SeriesId, DefaultizedLineSeriesType>; seriesOrder: SeriesId[]; } | undefined} lineSeries
23
23
  */
24
24
  export declare function useLineSeries(): FormattedSeries['line'];
25
25
  /**
@@ -27,7 +27,7 @@ export declare function useLineSeries(): FormattedSeries['line'];
27
27
  * The returned object contains:
28
28
  * - series: a mapping from ids to series attributes.
29
29
  * - seriesOrder: the array of series ids.
30
- * @returns { series: Record<SeriesId, DefaultizedBarSeriesType>; seriesOrder: SeriesId[]; } | undefined barSeries
30
+ * @returns {{ series: Record<SeriesId, DefaultizedBarSeriesType>; seriesOrder: SeriesId[]; } | undefined} barSeries
31
31
  */
32
32
  export declare function useBarSeries(): FormattedSeries['bar'];
33
33
  /**
@@ -35,6 +35,6 @@ export declare function useBarSeries(): FormattedSeries['bar'];
35
35
  * The returned object contains:
36
36
  * - series: a mapping from ids to series attributes.
37
37
  * - seriesOrder: the array of series ids.
38
- * @returns { series: Record<SeriesId, DefaultizedScatterSeriesType>; seriesOrder: SeriesId[]; } | undefined scatterSeries
38
+ * @returns {{ series: Record<SeriesId, DefaultizedScatterSeriesType>; seriesOrder: SeriesId[]; } | undefined} scatterSeries
39
39
  */
40
40
  export declare function useScatterSeries(): FormattedSeries['scatter'];
@@ -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/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 +1 @@
1
- export declare const AxisRoot: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, Pick<import("react").SVGProps<SVGGElement>, keyof import("react").SVGProps<SVGGElement>>, {}>;
1
+ export declare const AxisRoot: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material").Theme>, Pick<import("react").SVGProps<SVGGElement>, keyof import("react").SVGProps<SVGGElement>>, {}>;
@@ -0,0 +1,38 @@
1
+ import { AxisConfig, ScaleName } from '../models';
2
+ import { ChartsXAxisProps, ChartsAxisProps, ChartsYAxisProps, ChartsRadiusAxisProps, ChartsRotationAxisProps } from '../models/axis';
3
+ import { CartesianChartSeriesType } from '../models/seriesType/config';
4
+ import { DrawingArea } from '../context/DrawingProvider';
5
+ import { FormattedSeries } from '../context/SeriesProvider';
6
+ import { ExtremumGetter } from '../context/PluginProvider';
7
+ import { DefaultizedAxisConfig, ZoomData, ZoomOptions, GetZoomAxisFilters } from '../context/CartesianProvider/Cartesian.types';
8
+ type ComputeResult<T extends ChartsAxisProps> = {
9
+ axis: DefaultizedAxisConfig<T>;
10
+ axisIds: string[];
11
+ };
12
+ type ComputeCommonParams = {
13
+ drawingArea: DrawingArea;
14
+ formattedSeries: FormattedSeries;
15
+ extremumGetters: {
16
+ [K in CartesianChartSeriesType]?: ExtremumGetter<K>;
17
+ };
18
+ zoomData?: ZoomData[];
19
+ zoomOptions?: ZoomOptions;
20
+ getFilters?: GetZoomAxisFilters;
21
+ };
22
+ export declare function computeAxisValue(options: ComputeCommonParams & {
23
+ axis: AxisConfig<ScaleName, any, ChartsYAxisProps>[];
24
+ axisDirection: 'y';
25
+ }): ComputeResult<ChartsYAxisProps>;
26
+ export declare function computeAxisValue(options: ComputeCommonParams & {
27
+ axis: AxisConfig<ScaleName, any, ChartsXAxisProps>[];
28
+ axisDirection: 'x';
29
+ }): ComputeResult<ChartsAxisProps>;
30
+ export declare function computeAxisValue(options: ComputeCommonParams & {
31
+ axis: AxisConfig<ScaleName, any, ChartsRadiusAxisProps>[];
32
+ axisDirection: 'radius';
33
+ }): ComputeResult<ChartsRadiusAxisProps>;
34
+ export declare function computeAxisValue(options: ComputeCommonParams & {
35
+ axis: AxisConfig<ScaleName, any, ChartsRotationAxisProps>[];
36
+ axisDirection: 'rotation';
37
+ }): ComputeResult<ChartsRotationAxisProps>;
38
+ export {};
@@ -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,
@@ -3,7 +3,7 @@ declare class CartesianSeriesTypes {
3
3
  types: Set<ChartSeriesType>;
4
4
  constructor();
5
5
  addType(value: ChartSeriesType): void;
6
- getTypes(): Set<keyof import("../models/seriesType/config").ChartsSeriesConfig>;
6
+ getTypes(): Set<keyof import(".").ChartsSeriesConfig>;
7
7
  }
8
8
  export declare const cartesianSeriesTypes: CartesianSeriesTypes;
9
9
  export {};
@@ -4,7 +4,7 @@ export declare function defaultizeColor(series: AllSeriesType, seriesIndex: numb
4
4
  color: string;
5
5
  label?: (string | ((location: "tooltip" | "legend" | "arc") => string)) | undefined;
6
6
  value: number;
7
- id?: import("../models/seriesType").PieItemId | undefined;
7
+ id?: import("..").PieItemId | undefined;
8
8
  }[];
9
9
  type: "pie";
10
10
  innerRadius?: number | string;
@@ -14,8 +14,8 @@ export declare function defaultizeColor(series: AllSeriesType, seriesIndex: numb
14
14
  startAngle?: number;
15
15
  endAngle?: number;
16
16
  paddingAngle?: number;
17
- sortingValues?: import("../models/seriesType").ChartsPieSorting;
18
- arcLabel?: "formattedValue" | "label" | "value" | ((item: Omit<import("../models/seriesType").DefaultizedPieValueType, "label"> & {
17
+ sortingValues?: import("..").ChartsPieSorting;
18
+ arcLabel?: "formattedValue" | "label" | "value" | ((item: Omit<import("..").DefaultizedPieValueType, "label"> & {
19
19
  label?: string;
20
20
  }) => string);
21
21
  arcLabelMinAngle?: number;
@@ -41,7 +41,7 @@ export declare function defaultizeColor(series: AllSeriesType, seriesIndex: numb
41
41
  };
42
42
  id?: import(".").SeriesId;
43
43
  color?: string;
44
- valueFormatter?: import(".").SeriesValueFormatter<import(".").MakeOptional<import("../models/seriesType").PieValueType, "id">> | undefined;
44
+ valueFormatter?: import(".").SeriesValueFormatter<import(".").MakeOptional<import("..").PieValueType, "id">> | undefined;
45
45
  highlightScope?: Partial<import("..").HighlightScope>;
46
46
  } | {
47
47
  type: "bar";
@@ -62,7 +62,7 @@ export declare function defaultizeColor(series: AllSeriesType, seriesIndex: numb
62
62
  stackOrder?: import("..").StackOrderType;
63
63
  } | {
64
64
  type: "scatter";
65
- data: import("../models/seriesType").ScatterValueType[];
65
+ data: import("..").ScatterValueType[];
66
66
  markerSize?: number;
67
67
  label?: string | ((location: "tooltip" | "legend") => string);
68
68
  disableHover?: boolean;
@@ -70,7 +70,7 @@ export declare function defaultizeColor(series: AllSeriesType, seriesIndex: numb
70
70
  zAxisId?: string;
71
71
  id?: import(".").SeriesId;
72
72
  color: string;
73
- valueFormatter?: import(".").SeriesValueFormatter<import("../models/seriesType").ScatterValueType> | undefined;
73
+ valueFormatter?: import(".").SeriesValueFormatter<import("..").ScatterValueType> | undefined;
74
74
  highlightScope?: Partial<import("..").HighlightScope>;
75
75
  xAxisKey?: string;
76
76
  yAxisKey?: string;
@@ -83,8 +83,8 @@ export declare function defaultizeColor(series: AllSeriesType, seriesIndex: numb
83
83
  stack?: string;
84
84
  area?: boolean;
85
85
  label?: string | ((location: "tooltip" | "legend") => string);
86
- curve?: import("../models/seriesType").CurveType;
87
- showMark?: boolean | ((params: import("../models/seriesType").ShowMarkParams) => boolean);
86
+ curve?: import("..").CurveType;
87
+ showMark?: boolean | ((params: import("..").ShowMarkParams) => boolean);
88
88
  disableHighlight?: boolean;
89
89
  connectNulls?: boolean;
90
90
  stackOffset?: import("..").StackOffsetType;
@@ -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
  }
@@ -17,6 +17,7 @@ export * from './getSVGPoint';
17
17
  export * from './isDefined';
18
18
  export { unstable_cleanupDOM } from './domUtils';
19
19
  export * from './getScale';
20
+ export * from './computeAxisValue';
20
21
  export * from '../context/CartesianProvider';
21
22
  export * from '../context/DrawingProvider';
22
23
  export * from '../context/InteractionProvider';
@@ -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
 
package/models/axis.d.ts CHANGED
@@ -127,6 +127,26 @@ export interface ChartsXAxisProps extends ChartsAxisProps {
127
127
  */
128
128
  position?: 'top' | 'bottom';
129
129
  }
130
+ export interface ChartsRotationAxisProps extends ChartsAxisProps {
131
+ /**
132
+ * The start angle (in deg).
133
+ */
134
+ startAngle?: number;
135
+ /**
136
+ * The end angle (in deg).
137
+ */
138
+ endAngle?: number;
139
+ }
140
+ export interface ChartsRadiusAxisProps extends ChartsAxisProps {
141
+ /**
142
+ * The minimal radius.
143
+ */
144
+ minRadius?: number;
145
+ /**
146
+ * The maximal radius.
147
+ */
148
+ maxRadius?: number;
149
+ }
130
150
  export type ScaleName = keyof AxisScaleConfig;
131
151
  export type ContinuousScaleName = 'linear' | 'log' | 'pow' | 'sqrt' | 'time' | 'utc';
132
152
  export interface AxisScaleConfig {
@@ -1,7 +1,7 @@
1
- import { ScatterSeriesType, DefaultizedScatterSeriesType, ScatterItemIdentifier } from './scatter';
1
+ import { ScatterSeriesType, DefaultizedScatterSeriesType, ScatterItemIdentifier, ScatterValueType } from './scatter';
2
2
  import { LineSeriesType, DefaultizedLineSeriesType, LineItemIdentifier } from './line';
3
3
  import { BarItemIdentifier, BarSeriesType, DefaultizedBarSeriesType } from './bar';
4
- import { PieSeriesType, DefaultizedPieSeriesType, PieItemIdentifier, PieValueType } from './pie';
4
+ import { PieSeriesType, DefaultizedPieSeriesType, PieItemIdentifier, PieValueType, DefaultizedPieValueType } from './pie';
5
5
  import { DefaultizedProps, MakeOptional } from '../helpers';
6
6
  export interface ChartsSeriesConfig {
7
7
  bar: {
@@ -20,6 +20,7 @@ export interface ChartsSeriesConfig {
20
20
  */
21
21
  seriesProp: BarSeriesType;
22
22
  itemIdentifier: BarItemIdentifier;
23
+ valueType: number | null;
23
24
  canBeStacked: true;
24
25
  cartesian: true;
25
26
  };
@@ -30,6 +31,7 @@ export interface ChartsSeriesConfig {
30
31
  series: DefaultizedLineSeriesType;
31
32
  seriesProp: LineSeriesType;
32
33
  itemIdentifier: LineItemIdentifier;
34
+ valueType: number | null;
33
35
  canBeStacked: true;
34
36
  cartesian: true;
35
37
  };
@@ -39,6 +41,7 @@ export interface ChartsSeriesConfig {
39
41
  };
40
42
  series: DefaultizedScatterSeriesType;
41
43
  seriesProp: ScatterSeriesType;
44
+ valueType: ScatterValueType;
42
45
  itemIdentifier: ScatterItemIdentifier;
43
46
  cartesian: true;
44
47
  };
@@ -51,6 +54,7 @@ export interface ChartsSeriesConfig {
51
54
  series: DefaultizedPieSeriesType;
52
55
  seriesProp: PieSeriesType<MakeOptional<PieValueType, 'id'>>;
53
56
  itemIdentifier: PieItemIdentifier;
57
+ valueType: DefaultizedPieValueType;
54
58
  };
55
59
  }
56
60
  export type ChartSeriesType = keyof ChartsSeriesConfig;
@@ -40,6 +40,11 @@ export interface LineSeriesType extends CommonSeriesType<number | null>, Cartesi
40
40
  * The label to display on the tooltip or the legend. It can be a string or a function.
41
41
  */
42
42
  label?: string | ((location: 'tooltip' | 'legend') => string);
43
+ /**
44
+ * The type of curve to use for the line.
45
+ * Read more about curves at [line interpolation](https://mui.com/x/react-charts/lines/#interpolation).
46
+ * @default 'monotoneX'
47
+ */
43
48
  curve?: CurveType;
44
49
  /**
45
50
  * Define which items of the series should display a mark.
@@ -196,6 +196,16 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
196
196
  * @param {BarItemIdentifier} barItemIdentifier The bar item identifier.
197
197
  */
198
198
  onItemClick: PropTypes.func,
199
+ /**
200
+ * The chart will try to wait for the parent container to resolve its size
201
+ * before it renders for the first time.
202
+ *
203
+ * This can be useful in some scenarios where the chart appear to grow after
204
+ * the first render, like when used inside a grid.
205
+ *
206
+ * @default false
207
+ */
208
+ resolveSizeBeforeRender: PropTypes.bool,
199
209
  /**
200
210
  * Indicate which axis to display the right of the charts.
201
211
  * Can be a string (the id of the axis) or an object `ChartsYAxisProps`.
@@ -1,8 +1,8 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import { stack as d3Stack } from '@mui/x-charts-vendor/d3-shape';
3
+ import { warnOnce } from '@mui/x-internals/warning';
3
4
  import { getStackingGroups } from "../internals/stackSeries.js";
4
5
  import { defaultizeValueFormatter } from "../internals/defaultizeValueFormatter.js";
5
- let warnOnce = false;
6
6
  const formatter = (params, dataset) => {
7
7
  const {
8
8
  seriesOrder,
@@ -50,9 +50,10 @@ const formatter = (params, dataset) => {
50
50
  data: dataKey ? dataset.map(data => {
51
51
  const value = data[dataKey];
52
52
  if (typeof value !== 'number') {
53
- if (process.env.NODE_ENV !== 'production' && !warnOnce && value !== null) {
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.'].join('\n'));
53
+ if (process.env.NODE_ENV !== 'production') {
54
+ if (value !== null) {
55
+ warnOnce([`MUI X: 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
58
  return 0;
58
59
  }
@@ -18,7 +18,7 @@ const defaultizeAxis = (inAxis, dataset, axisName) => {
18
18
  return axisConfig;
19
19
  }
20
20
  if (dataset === undefined) {
21
- throw Error(`MUI X: ${axisName}-axis uses \`dataKey\` but no \`dataset\` is provided.`);
21
+ throw new Error(`MUI X: ${axisName}-axis uses \`dataKey\` but no \`dataset\` is provided.`);
22
22
  }
23
23
  return _extends({}, axisConfig, {
24
24
  data: dataset.map(d => d[dataKey])
@@ -59,16 +59,16 @@ function ChartsAxis(props) {
59
59
  const topId = getAxisId(topAxis, xAxisIds[0]);
60
60
  const rightId = getAxisId(rightAxis, yAxisIds[0]);
61
61
  if (topId !== null && !xAxis[topId]) {
62
- throw Error([`MUI X: id used for top axis "${topId}" is not defined.`, `Available ids are: ${xAxisIds.join(', ')}.`].join('\n'));
62
+ throw new Error([`MUI X: id used for top axis "${topId}" is not defined.`, `Available ids are: ${xAxisIds.join(', ')}.`].join('\n'));
63
63
  }
64
64
  if (leftId !== null && !yAxis[leftId]) {
65
- throw Error([`MUI X: id used for left axis "${leftId}" is not defined.`, `Available ids are: ${yAxisIds.join(', ')}.`].join('\n'));
65
+ throw new Error([`MUI X: id used for left axis "${leftId}" is not defined.`, `Available ids are: ${yAxisIds.join(', ')}.`].join('\n'));
66
66
  }
67
67
  if (rightId !== null && !yAxis[rightId]) {
68
- throw Error([`MUI X: id used for right axis "${rightId}" is not defined.`, `Available ids are: ${yAxisIds.join(', ')}.`].join('\n'));
68
+ throw new Error([`MUI X: id used for right axis "${rightId}" is not defined.`, `Available ids are: ${yAxisIds.join(', ')}.`].join('\n'));
69
69
  }
70
70
  if (bottomId !== null && !xAxis[bottomId]) {
71
- throw Error([`MUI X: id used for bottom axis "${bottomId}" is not defined.`, `Available ids are: ${xAxisIds.join(', ')}.`].join('\n'));
71
+ throw new Error([`MUI X: id used for bottom axis "${bottomId}" is not defined.`, `Available ids are: ${xAxisIds.join(', ')}.`].join('\n'));
72
72
  }
73
73
  const topAxisProps = mergeProps(topAxis, slots, slotProps);
74
74
  const bottomAxisProps = mergeProps(bottomAxis, slots, slotProps);
@@ -26,7 +26,7 @@ function DefaultChartsLegend(props) {
26
26
  }
27
27
  return /*#__PURE__*/_jsx(LegendPerItem, _extends({}, other, {
28
28
  itemsToDisplay: seriesToDisplay,
29
- onItemClick: onItemClick ? (e, i) => onItemClick(e, seriesContextBuilder(seriesToDisplay[i]), i) : undefined
29
+ onItemClick: onItemClick ? (event, i) => onItemClick(event, seriesContextBuilder(seriesToDisplay[i]), i) : undefined
30
30
  }));
31
31
  }
32
32
  process.env.NODE_ENV !== "production" ? DefaultChartsLegend.propTypes = {
@@ -122,7 +122,7 @@ export function LegendPerItem(props) {
122
122
  markGap: markGap,
123
123
  labelStyle: labelStyle,
124
124
  classes: classes,
125
- onClick: onItemClick ? e => onItemClick(e, i) : undefined
125
+ onClick: onItemClick ? event => onItemClick(event, i) : undefined
126
126
  })))
127
127
  })
128
128
  });
@@ -80,7 +80,7 @@ function PiecewiseColorLegend(props) {
80
80
  }).filter(notNull);
81
81
  return /*#__PURE__*/_jsx(LegendPerItem, _extends({}, other, {
82
82
  itemsToDisplay: itemsToDisplay,
83
- onItemClick: onItemClick ? (e, i) => onItemClick(e, piecewiseColorContextBuilder(itemsToDisplay[i]), i) : undefined
83
+ onItemClick: onItemClick ? (event, i) => onItemClick(event, piecewiseColorContextBuilder(itemsToDisplay[i]), i) : undefined
84
84
  }));
85
85
  }
86
86
  process.env.NODE_ENV !== "production" ? PiecewiseColorLegend.propTypes = {
@@ -4,4 +4,7 @@ export * from "./ChartsAxisTooltipContent.js";
4
4
  export * from "./ChartsItemTooltipContent.js";
5
5
  export * from "./DefaultChartsAxisTooltipContent.js";
6
6
  export * from "./DefaultChartsItemTooltipContent.js";
7
- export * from "./ChartsTooltipTable.js";
7
+ export * from "./ChartsTooltipTable.js";
8
+ export * from "./useItemTooltip.js";
9
+ export * from "./useAxisTooltip.js";
10
+ export { useMouseTracker } from "./utils.js";
@@ -0,0 +1,84 @@
1
+ 'use client';
2
+
3
+ import * as React from 'react';
4
+ import { InteractionContext } from "../context/InteractionProvider.js";
5
+ import { useSeries } from "../hooks/useSeries.js";
6
+ import { useCartesianContext } from "../context/CartesianProvider/index.js";
7
+ import { ZAxisContext } from "../context/ZAxisContextProvider.js";
8
+ import { useColorProcessor } from "../context/PluginProvider/useColorProcessor.js";
9
+ import { getLabel } from "../internals/getLabel.js";
10
+ import { isCartesianSeriesType } from "../internals/isCartesian.js";
11
+ import { utcFormatter } from "./utils.js";
12
+ export function useAxisTooltip() {
13
+ const {
14
+ axis
15
+ } = React.useContext(InteractionContext);
16
+ const series = useSeries();
17
+ const {
18
+ xAxis,
19
+ yAxis,
20
+ xAxisIds,
21
+ yAxisIds
22
+ } = useCartesianContext();
23
+ const {
24
+ zAxis,
25
+ zAxisIds
26
+ } = React.useContext(ZAxisContext);
27
+ const colorProcessors = useColorProcessor();
28
+
29
+ // By default use the x-axis
30
+ const isXaxis = axis.x !== null && axis.x.index !== -1;
31
+ const axisData = isXaxis ? axis.x && axis.x : axis.y && axis.y;
32
+ if (axisData === null) {
33
+ return null;
34
+ }
35
+ const {
36
+ index: dataIndex,
37
+ value: axisValue
38
+ } = axisData;
39
+ const USED_AXIS_ID = isXaxis ? xAxisIds[0] : yAxisIds[0];
40
+ const usedAxis = isXaxis ? xAxis[USED_AXIS_ID] : yAxis[USED_AXIS_ID];
41
+ const relevantSeries = Object.keys(series).filter(isCartesianSeriesType).flatMap(seriesType => {
42
+ const seriesOfType = series[seriesType];
43
+ if (!seriesOfType) {
44
+ return [];
45
+ }
46
+ return seriesOfType.seriesOrder.map(seriesId => {
47
+ const seriesToAdd = seriesOfType.series[seriesId];
48
+ const providedXAxisId = seriesToAdd.xAxisId ?? seriesToAdd.xAxisKey;
49
+ const providedYAxisId = seriesToAdd.yAxisId ?? seriesToAdd.yAxisKey;
50
+ const axisKey = isXaxis ? providedXAxisId : providedYAxisId;
51
+
52
+ // Test if the series uses the default axis
53
+ if (axisKey === undefined || axisKey === USED_AXIS_ID) {
54
+ const xAxisId = providedXAxisId ?? xAxisIds[0];
55
+ const yAxisId = providedYAxisId ?? yAxisIds[0];
56
+ const zAxisId = seriesToAdd.zAxisId ?? seriesToAdd.zAxisKey ?? zAxisIds[0];
57
+ const color = colorProcessors[seriesType]?.(seriesToAdd, xAxis[xAxisId], yAxis[yAxisId], zAxisId && zAxis[zAxisId])(dataIndex) ?? '';
58
+ const value = seriesToAdd.data[dataIndex] ?? null;
59
+ const formattedValue = seriesToAdd.valueFormatter(value, {
60
+ dataIndex
61
+ });
62
+ const formattedLabel = getLabel(seriesToAdd.label, 'tooltip') ?? null;
63
+ return {
64
+ seriesId,
65
+ color,
66
+ value,
67
+ formattedValue,
68
+ formattedLabel
69
+ };
70
+ }
71
+ return undefined;
72
+ });
73
+ }).filter(item => item != null);
74
+ const axisFormatter = usedAxis.valueFormatter ?? (v => usedAxis.scaleType === 'utc' ? utcFormatter(v) : v.toLocaleString());
75
+ const axisFormattedValue = axisFormatter(axisValue, {
76
+ location: 'tooltip'
77
+ });
78
+ return {
79
+ identifier: axis,
80
+ seriesItems: relevantSeries,
81
+ axisValue,
82
+ axisFormattedValue
83
+ };
84
+ }