@mui/x-charts 8.8.0 → 8.9.2

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 (164) hide show
  1. package/BarChart/BarChart.d.ts +3 -2
  2. package/BarChart/BarChart.js +95 -2
  3. package/BarChart/BarClipPath.d.ts +17 -12
  4. package/BarChart/BarClipPath.js +70 -57
  5. package/BarChart/BarPlot.js +4 -0
  6. package/BarChart/barClasses.d.ts +1 -1
  7. package/BarChart/seriesConfig/extremums.js +2 -3
  8. package/BarChart/seriesConfig/seriesProcessor.js +5 -3
  9. package/BarChart/useBarChartProps.d.ts +1 -1
  10. package/BarChart/useBarPlotData.js +32 -5
  11. package/CHANGELOG.md +225 -24
  12. package/ChartContainer/ChartContainer.js +141 -0
  13. package/ChartsLabel/ChartsLabelMark.d.ts +2 -1
  14. package/ChartsLabel/index.d.ts +1 -0
  15. package/ChartsLabel/index.js +18 -0
  16. package/ChartsLegend/chartsLegendClasses.d.ts +1 -1
  17. package/ChartsLegend/piecewiseColorLegendClasses.d.ts +1 -1
  18. package/{internals/components/ChartsWrapper → ChartsWrapper}/ChartsWrapper.d.ts +13 -4
  19. package/{internals/components/ChartsWrapper → ChartsWrapper}/ChartsWrapper.js +33 -7
  20. package/LineChart/LineChart.d.ts +3 -2
  21. package/LineChart/LineChart.js +95 -2
  22. package/LineChart/seriesConfig/extremums.js +2 -3
  23. package/LineChart/useLineChartProps.d.ts +1 -1
  24. package/PieChart/PieArcLabelPlot.js +3 -0
  25. package/PieChart/PieArcPlot.js +3 -0
  26. package/PieChart/PieChart.d.ts +3 -2
  27. package/PieChart/PieChart.js +2 -2
  28. package/PieChart/pieClasses.d.ts +1 -1
  29. package/RadarChart/RadarAxisHighlight/RadarAxisHighlight.js +3 -5
  30. package/RadarChart/RadarAxisHighlight/useRadarAxisHighlight.d.ts +2 -13
  31. package/RadarChart/RadarAxisHighlight/useRadarAxisHighlight.js +8 -45
  32. package/RadarChart/RadarChart.d.ts +3 -2
  33. package/RadarChart/RadarChart.js +24 -3
  34. package/RadarChart/RadarDataProvider/RadarDataProvider.d.ts +3 -2
  35. package/RadarChart/RadarMetricLabels/useRadarMetricData.js +4 -2
  36. package/RadarChart/RadarSeriesPlot/RadarSeriesArea.js +19 -3
  37. package/RadarChart/RadarSeriesPlot/RadarSeriesMarks.js +20 -4
  38. package/RadarChart/RadarSeriesPlot/RadarSeriesPlot.js +38 -4
  39. package/RadarChart/RadarSeriesPlot/RadarSeriesPlot.types.d.ts +32 -3
  40. package/RadarChart/RadarSeriesPlot/useRadarRotationIndex.d.ts +8 -0
  41. package/RadarChart/RadarSeriesPlot/useRadarRotationIndex.js +38 -0
  42. package/RadarChart/RadarSeriesPlot/useRadarSeriesData.d.ts +2 -2
  43. package/RadarChart/index.d.ts +1 -1
  44. package/RadarChart/useRadarChartProps.d.ts +4 -1
  45. package/RadarChart/useRadarChartProps.js +15 -3
  46. package/ScatterChart/ScatterChart.d.ts +3 -2
  47. package/ScatterChart/ScatterChart.js +95 -2
  48. package/ScatterChart/seriesConfig/extremums.js +50 -23
  49. package/ScatterChart/useScatterChartProps.d.ts +1 -1
  50. package/SparkLineChart/SparkLineChart.js +93 -0
  51. package/esm/BarChart/BarChart.d.ts +3 -2
  52. package/esm/BarChart/BarChart.js +95 -2
  53. package/esm/BarChart/BarClipPath.d.ts +17 -12
  54. package/esm/BarChart/BarClipPath.js +69 -55
  55. package/esm/BarChart/BarPlot.js +4 -0
  56. package/esm/BarChart/barClasses.d.ts +1 -1
  57. package/esm/BarChart/seriesConfig/extremums.js +2 -3
  58. package/esm/BarChart/seriesConfig/seriesProcessor.js +5 -3
  59. package/esm/BarChart/useBarChartProps.d.ts +1 -1
  60. package/esm/BarChart/useBarPlotData.js +32 -5
  61. package/esm/ChartContainer/ChartContainer.js +141 -0
  62. package/esm/ChartsLabel/ChartsLabelMark.d.ts +2 -1
  63. package/esm/ChartsLabel/index.d.ts +1 -0
  64. package/esm/ChartsLabel/index.js +1 -0
  65. package/esm/ChartsLegend/chartsLegendClasses.d.ts +1 -1
  66. package/esm/ChartsLegend/piecewiseColorLegendClasses.d.ts +1 -1
  67. package/esm/{internals/components/ChartsWrapper → ChartsWrapper}/ChartsWrapper.d.ts +13 -4
  68. package/esm/{internals/components/ChartsWrapper → ChartsWrapper}/ChartsWrapper.js +31 -6
  69. package/esm/LineChart/LineChart.d.ts +3 -2
  70. package/esm/LineChart/LineChart.js +95 -2
  71. package/esm/LineChart/seriesConfig/extremums.js +2 -3
  72. package/esm/LineChart/useLineChartProps.d.ts +1 -1
  73. package/esm/PieChart/PieArcLabelPlot.js +3 -0
  74. package/esm/PieChart/PieArcPlot.js +3 -0
  75. package/esm/PieChart/PieChart.d.ts +3 -2
  76. package/esm/PieChart/PieChart.js +2 -2
  77. package/esm/PieChart/pieClasses.d.ts +1 -1
  78. package/esm/RadarChart/RadarAxisHighlight/RadarAxisHighlight.js +3 -5
  79. package/esm/RadarChart/RadarAxisHighlight/useRadarAxisHighlight.d.ts +2 -13
  80. package/esm/RadarChart/RadarAxisHighlight/useRadarAxisHighlight.js +8 -45
  81. package/esm/RadarChart/RadarChart.d.ts +3 -2
  82. package/esm/RadarChart/RadarChart.js +24 -3
  83. package/esm/RadarChart/RadarDataProvider/RadarDataProvider.d.ts +3 -2
  84. package/esm/RadarChart/RadarMetricLabels/useRadarMetricData.js +4 -2
  85. package/esm/RadarChart/RadarSeriesPlot/RadarSeriesArea.js +19 -3
  86. package/esm/RadarChart/RadarSeriesPlot/RadarSeriesMarks.js +20 -4
  87. package/esm/RadarChart/RadarSeriesPlot/RadarSeriesPlot.js +38 -4
  88. package/esm/RadarChart/RadarSeriesPlot/RadarSeriesPlot.types.d.ts +32 -3
  89. package/esm/RadarChart/RadarSeriesPlot/useRadarRotationIndex.d.ts +8 -0
  90. package/esm/RadarChart/RadarSeriesPlot/useRadarRotationIndex.js +32 -0
  91. package/esm/RadarChart/RadarSeriesPlot/useRadarSeriesData.d.ts +2 -2
  92. package/esm/RadarChart/index.d.ts +1 -1
  93. package/esm/RadarChart/useRadarChartProps.d.ts +4 -1
  94. package/esm/RadarChart/useRadarChartProps.js +15 -3
  95. package/esm/ScatterChart/ScatterChart.d.ts +3 -2
  96. package/esm/ScatterChart/ScatterChart.js +95 -2
  97. package/esm/ScatterChart/seriesConfig/extremums.js +50 -23
  98. package/esm/ScatterChart/useScatterChartProps.d.ts +1 -1
  99. package/esm/SparkLineChart/SparkLineChart.js +93 -0
  100. package/esm/hooks/useTicks.d.ts +6 -1
  101. package/esm/hooks/useTicks.js +94 -58
  102. package/esm/index.d.ts +2 -1
  103. package/esm/index.js +6 -2
  104. package/esm/internals/findMinMax.d.ts +1 -0
  105. package/esm/internals/findMinMax.js +13 -0
  106. package/esm/internals/getScale.js +3 -0
  107. package/esm/internals/index.d.ts +1 -1
  108. package/esm/internals/index.js +1 -1
  109. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/computeAxisValue.js +4 -1
  110. package/esm/internals/plugins/featurePlugins/useChartHighlight/createIsFaded.d.ts +1 -1
  111. package/esm/internals/plugins/featurePlugins/useChartHighlight/createIsFaded.js +19 -11
  112. package/esm/internals/plugins/featurePlugins/useChartHighlight/createIsHighlighted.d.ts +1 -1
  113. package/esm/internals/plugins/featurePlugins/useChartHighlight/createIsHighlighted.js +19 -11
  114. package/esm/internals/plugins/featurePlugins/useChartHighlight/useChartHighlight.selectors.js +10 -4
  115. package/esm/internals/plugins/featurePlugins/useChartInteraction/useChartInteraction.js +4 -4
  116. package/esm/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarAxis.js +44 -1
  117. package/esm/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarAxis.types.d.ts +8 -1
  118. package/esm/internals/plugins/featurePlugins/useChartVoronoi/useChartVoronoi.js +17 -12
  119. package/esm/internals/symlogScale.d.ts +2 -0
  120. package/esm/internals/symlogScale.js +94 -0
  121. package/esm/models/axis.d.ts +47 -5
  122. package/esm/models/axis.js +3 -0
  123. package/esm/models/seriesType/bar.d.ts +11 -1
  124. package/esm/models/seriesType/common.d.ts +9 -3
  125. package/esm/models/seriesType/line.d.ts +3 -1
  126. package/esm/models/seriesType/scatter.d.ts +4 -1
  127. package/esm/tests/web-components.js +49 -0
  128. package/hooks/useTicks.d.ts +6 -1
  129. package/hooks/useTicks.js +95 -58
  130. package/index.d.ts +2 -1
  131. package/index.js +13 -1
  132. package/internals/findMinMax.d.ts +1 -0
  133. package/internals/findMinMax.js +19 -0
  134. package/internals/getScale.js +3 -0
  135. package/internals/index.d.ts +1 -1
  136. package/internals/index.js +12 -12
  137. package/internals/plugins/featurePlugins/useChartCartesianAxis/computeAxisValue.js +3 -0
  138. package/internals/plugins/featurePlugins/useChartHighlight/createIsFaded.d.ts +1 -1
  139. package/internals/plugins/featurePlugins/useChartHighlight/createIsFaded.js +20 -13
  140. package/internals/plugins/featurePlugins/useChartHighlight/createIsHighlighted.d.ts +1 -1
  141. package/internals/plugins/featurePlugins/useChartHighlight/createIsHighlighted.js +20 -13
  142. package/internals/plugins/featurePlugins/useChartHighlight/useChartHighlight.selectors.js +10 -4
  143. package/internals/plugins/featurePlugins/useChartInteraction/useChartInteraction.js +4 -4
  144. package/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarAxis.js +44 -1
  145. package/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarAxis.types.d.ts +8 -1
  146. package/internals/plugins/featurePlugins/useChartVoronoi/useChartVoronoi.js +17 -12
  147. package/internals/symlogScale.d.ts +2 -0
  148. package/internals/symlogScale.js +100 -0
  149. package/models/axis.d.ts +47 -5
  150. package/models/axis.js +4 -0
  151. package/models/seriesType/bar.d.ts +11 -1
  152. package/models/seriesType/common.d.ts +9 -3
  153. package/models/seriesType/line.d.ts +3 -1
  154. package/models/seriesType/scatter.d.ts +4 -1
  155. package/package.json +6 -7
  156. package/tests/web-components.js +55 -0
  157. package/BarChart/getRadius.d.ts +0 -20
  158. package/BarChart/getRadius.js +0 -37
  159. package/esm/BarChart/getRadius.d.ts +0 -20
  160. package/esm/BarChart/getRadius.js +0 -30
  161. /package/{esm/internals/components/ChartsWrapper → ChartsWrapper}/index.d.ts +0 -0
  162. /package/{internals/components/ChartsWrapper → ChartsWrapper}/index.js +0 -0
  163. /package/{internals/components → esm}/ChartsWrapper/index.d.ts +0 -0
  164. /package/esm/{internals/components/ChartsWrapper → ChartsWrapper}/index.js +0 -0
@@ -1,6 +1,3 @@
1
- const mergeMinMax = (acc, val) => {
2
- return [val[0] === null ? acc[0] : Math.min(acc[0], val[0]), val[1] === null ? acc[1] : Math.max(acc[1], val[1])];
3
- };
4
1
  export const getExtremumX = params => {
5
2
  const {
6
3
  series,
@@ -8,24 +5,39 @@ export const getExtremumX = params => {
8
5
  isDefaultAxis,
9
6
  getFilters
10
7
  } = params;
11
- return Object.keys(series).filter(seriesId => {
8
+ let min = Infinity;
9
+ let max = -Infinity;
10
+ for (const seriesId in series) {
11
+ if (!Object.hasOwn(series, seriesId)) {
12
+ continue;
13
+ }
12
14
  const axisId = series[seriesId].xAxisId;
13
- return axisId === axis.id || axisId === undefined && isDefaultAxis;
14
- }).reduce((acc, seriesId) => {
15
+ if (!(axisId === axis.id || axisId === undefined && isDefaultAxis)) {
16
+ continue;
17
+ }
15
18
  const filter = getFilters?.({
16
19
  currentAxisId: axis.id,
17
20
  isDefaultAxis,
18
21
  seriesXAxisId: series[seriesId].xAxisId,
19
22
  seriesYAxisId: series[seriesId].yAxisId
20
23
  });
21
- const seriesMinMax = series[seriesId].data?.reduce((accSeries, d, dataIndex) => {
22
- if (filter && !filter(d, dataIndex)) {
23
- return accSeries;
24
+ const seriesData = series[seriesId].data ?? [];
25
+ for (let i = 0; i < seriesData.length; i += 1) {
26
+ const d = seriesData[i];
27
+ if (filter && !filter(d, i)) {
28
+ continue;
29
+ }
30
+ if (d.x !== null) {
31
+ if (d.x < min) {
32
+ min = d.x;
33
+ }
34
+ if (d.x > max) {
35
+ max = d.x;
36
+ }
24
37
  }
25
- return mergeMinMax(accSeries, [d.x, d.x]);
26
- }, [Infinity, -Infinity]);
27
- return mergeMinMax(acc, seriesMinMax ?? [Infinity, -Infinity]);
28
- }, [Infinity, -Infinity]);
38
+ }
39
+ }
40
+ return [min, max];
29
41
  };
30
42
  export const getExtremumY = params => {
31
43
  const {
@@ -34,22 +46,37 @@ export const getExtremumY = params => {
34
46
  isDefaultAxis,
35
47
  getFilters
36
48
  } = params;
37
- return Object.keys(series).filter(seriesId => {
49
+ let min = Infinity;
50
+ let max = -Infinity;
51
+ for (const seriesId in series) {
52
+ if (!Object.hasOwn(series, seriesId)) {
53
+ continue;
54
+ }
38
55
  const axisId = series[seriesId].yAxisId;
39
- return axisId === axis.id || axisId === undefined && isDefaultAxis;
40
- }).reduce((acc, seriesId) => {
56
+ if (!(axisId === axis.id || axisId === undefined && isDefaultAxis)) {
57
+ continue;
58
+ }
41
59
  const filter = getFilters?.({
42
60
  currentAxisId: axis.id,
43
61
  isDefaultAxis,
44
62
  seriesXAxisId: series[seriesId].xAxisId,
45
63
  seriesYAxisId: series[seriesId].yAxisId
46
64
  });
47
- const seriesMinMax = series[seriesId].data?.reduce((accSeries, d, dataIndex) => {
48
- if (filter && !filter(d, dataIndex)) {
49
- return accSeries;
65
+ const seriesData = series[seriesId].data ?? [];
66
+ for (let i = 0; i < seriesData.length; i += 1) {
67
+ const d = seriesData[i];
68
+ if (filter && !filter(d, i)) {
69
+ continue;
70
+ }
71
+ if (d.y !== null) {
72
+ if (d.y < min) {
73
+ min = d.y;
74
+ }
75
+ if (d.y > max) {
76
+ max = d.y;
77
+ }
50
78
  }
51
- return mergeMinMax(accSeries, [d.y, d.y]);
52
- }, [Infinity, -Infinity]);
53
- return mergeMinMax(acc, seriesMinMax ?? [Infinity, -Infinity]);
54
- }, [Infinity, -Infinity]);
79
+ }
80
+ }
81
+ return [min, max];
55
82
  };
@@ -7,7 +7,7 @@ import { ChartsOverlayProps } from "../ChartsOverlay/index.js";
7
7
  import { ChartContainerProps } from "../ChartContainer/index.js";
8
8
  import type { ScatterChartProps } from "./ScatterChart.js";
9
9
  import type { ScatterPlotProps } from "./ScatterPlot.js";
10
- import type { ChartsWrapperProps } from "../internals/components/ChartsWrapper/index.js";
10
+ import type { ChartsWrapperProps } from "../ChartsWrapper/index.js";
11
11
  import { ScatterChartPluginsSignatures } from "./ScatterChart.plugins.js";
12
12
  /**
13
13
  * A helper function that extracts ScatterChartProps from the input props
@@ -477,6 +477,53 @@ process.env.NODE_ENV !== "production" ? SparkLineChart.propTypes = {
477
477
  tickPlacement: PropTypes.oneOf(['end', 'extremities', 'middle', 'start']),
478
478
  tickSize: PropTypes.number,
479
479
  valueFormatter: PropTypes.func
480
+ }), PropTypes.shape({
481
+ axis: PropTypes.oneOf(['x']),
482
+ classes: PropTypes.object,
483
+ colorMap: PropTypes.oneOfType([PropTypes.shape({
484
+ color: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string.isRequired), PropTypes.func]).isRequired,
485
+ max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
486
+ min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
487
+ type: PropTypes.oneOf(['continuous']).isRequired
488
+ }), PropTypes.shape({
489
+ colors: PropTypes.arrayOf(PropTypes.string).isRequired,
490
+ thresholds: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired).isRequired,
491
+ type: PropTypes.oneOf(['piecewise']).isRequired
492
+ })]),
493
+ constant: PropTypes.number,
494
+ data: PropTypes.array,
495
+ dataKey: PropTypes.string,
496
+ disableLine: PropTypes.bool,
497
+ disableTicks: PropTypes.bool,
498
+ domainLimit: PropTypes.oneOfType([PropTypes.oneOf(['nice', 'strict']), PropTypes.func]),
499
+ fill: PropTypes.string,
500
+ height: PropTypes.number,
501
+ hideTooltip: PropTypes.bool,
502
+ id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
503
+ ignoreTooltip: PropTypes.bool,
504
+ label: PropTypes.string,
505
+ labelStyle: PropTypes.object,
506
+ max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
507
+ min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
508
+ offset: PropTypes.number,
509
+ position: PropTypes.oneOf(['bottom', 'none', 'top']),
510
+ reverse: PropTypes.bool,
511
+ scaleType: PropTypes.oneOf(['symlog']),
512
+ slotProps: PropTypes.object,
513
+ slots: PropTypes.object,
514
+ stroke: PropTypes.string,
515
+ sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
516
+ tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
517
+ tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
518
+ tickLabelMinGap: PropTypes.number,
519
+ tickLabelPlacement: PropTypes.oneOf(['middle', 'tick']),
520
+ tickLabelStyle: PropTypes.object,
521
+ tickMaxStep: PropTypes.number,
522
+ tickMinStep: PropTypes.number,
523
+ tickNumber: PropTypes.number,
524
+ tickPlacement: PropTypes.oneOf(['end', 'extremities', 'middle', 'start']),
525
+ tickSize: PropTypes.number,
526
+ valueFormatter: PropTypes.func
480
527
  }), PropTypes.shape({
481
528
  axis: PropTypes.oneOf(['x']),
482
529
  classes: PropTypes.object,
@@ -859,6 +906,52 @@ process.env.NODE_ENV !== "production" ? SparkLineChart.propTypes = {
859
906
  tickSize: PropTypes.number,
860
907
  valueFormatter: PropTypes.func,
861
908
  width: PropTypes.number
909
+ }), PropTypes.shape({
910
+ axis: PropTypes.oneOf(['y']),
911
+ classes: PropTypes.object,
912
+ colorMap: PropTypes.oneOfType([PropTypes.shape({
913
+ color: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string.isRequired), PropTypes.func]).isRequired,
914
+ max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
915
+ min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
916
+ type: PropTypes.oneOf(['continuous']).isRequired
917
+ }), PropTypes.shape({
918
+ colors: PropTypes.arrayOf(PropTypes.string).isRequired,
919
+ thresholds: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired).isRequired,
920
+ type: PropTypes.oneOf(['piecewise']).isRequired
921
+ })]),
922
+ constant: PropTypes.number,
923
+ data: PropTypes.array,
924
+ dataKey: PropTypes.string,
925
+ disableLine: PropTypes.bool,
926
+ disableTicks: PropTypes.bool,
927
+ domainLimit: PropTypes.oneOfType([PropTypes.oneOf(['nice', 'strict']), PropTypes.func]),
928
+ fill: PropTypes.string,
929
+ hideTooltip: PropTypes.bool,
930
+ id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
931
+ ignoreTooltip: PropTypes.bool,
932
+ label: PropTypes.string,
933
+ labelStyle: PropTypes.object,
934
+ max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
935
+ min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
936
+ offset: PropTypes.number,
937
+ position: PropTypes.oneOf(['left', 'none', 'right']),
938
+ reverse: PropTypes.bool,
939
+ scaleType: PropTypes.oneOf(['symlog']),
940
+ slotProps: PropTypes.object,
941
+ slots: PropTypes.object,
942
+ stroke: PropTypes.string,
943
+ sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
944
+ tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
945
+ tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
946
+ tickLabelPlacement: PropTypes.oneOf(['middle', 'tick']),
947
+ tickLabelStyle: PropTypes.object,
948
+ tickMaxStep: PropTypes.number,
949
+ tickMinStep: PropTypes.number,
950
+ tickNumber: PropTypes.number,
951
+ tickPlacement: PropTypes.oneOf(['end', 'extremities', 'middle', 'start']),
952
+ tickSize: PropTypes.number,
953
+ valueFormatter: PropTypes.func,
954
+ width: PropTypes.number
862
955
  }), PropTypes.shape({
863
956
  axis: PropTypes.oneOf(['y']),
864
957
  classes: PropTypes.object,
@@ -49,8 +49,13 @@ export type TickItemType = {
49
49
  offset: number;
50
50
  labelOffset: number;
51
51
  };
52
+ export declare function getTicks(options: {
53
+ scale: D3Scale;
54
+ valueFormatter?: AxisConfig['valueFormatter'];
55
+ isInside: (offset: number) => boolean;
56
+ } & Pick<TickParams, 'tickInterval' | 'tickPlacement' | 'tickLabelPlacement'> & Required<Pick<TickParams, 'tickNumber'>>): TickItemType[];
52
57
  export declare function useTicks(options: {
53
58
  scale: D3Scale;
54
59
  valueFormatter?: AxisConfig['valueFormatter'];
55
60
  direction: 'x' | 'y';
56
- } & Pick<TickParams, 'tickNumber' | 'tickInterval' | 'tickPlacement' | 'tickLabelPlacement'>): TickItemType[];
61
+ } & Pick<TickParams, 'tickInterval' | 'tickPlacement' | 'tickLabelPlacement'> & Required<Pick<TickParams, 'tickNumber'>>): TickItemType[];
@@ -10,7 +10,7 @@ const offsetRatio = {
10
10
  end: 1,
11
11
  middle: 0.5
12
12
  };
13
- export function useTicks(options) {
13
+ export function getTicks(options) {
14
14
  const {
15
15
  scale,
16
16
  tickNumber,
@@ -18,75 +18,111 @@ export function useTicks(options) {
18
18
  tickInterval,
19
19
  tickPlacement = 'extremities',
20
20
  tickLabelPlacement: tickLabelPlacementProp,
21
- direction
21
+ isInside
22
22
  } = options;
23
- const {
24
- instance
25
- } = useChartContext();
26
- return React.useMemo(() => {
27
- // band scale
28
- if (isBandScale(scale)) {
29
- const domain = scale.domain();
30
- const tickLabelPlacement = tickLabelPlacementProp ?? 'middle';
31
- if (scale.bandwidth() > 0) {
32
- // scale type = 'band'
33
- const filteredDomain = typeof tickInterval === 'function' && domain.filter(tickInterval) || typeof tickInterval === 'object' && tickInterval || domain;
34
- return [...filteredDomain.map(value => ({
23
+
24
+ // band scale
25
+ if (isBandScale(scale)) {
26
+ const domain = scale.domain();
27
+ const tickLabelPlacement = tickLabelPlacementProp ?? 'middle';
28
+ if (scale.bandwidth() > 0) {
29
+ // scale type = 'band'
30
+ const filteredDomain = typeof tickInterval === 'function' && domain.filter(tickInterval) || typeof tickInterval === 'object' && tickInterval || domain;
31
+ return [...filteredDomain.map(value => {
32
+ const defaultTickLabel = `${value}`;
33
+ return {
35
34
  value,
36
35
  formattedValue: valueFormatter?.(value, {
37
36
  location: 'tick',
38
- scale
39
- }) ?? `${value}`,
37
+ scale,
38
+ tickNumber,
39
+ defaultTickLabel
40
+ }) ?? defaultTickLabel,
40
41
  offset: scale(value) - (scale.step() - scale.bandwidth()) / 2 + offsetRatio[tickPlacement] * scale.step(),
41
42
  labelOffset: tickLabelPlacement === 'tick' ? 0 : scale.step() * (offsetRatio[tickLabelPlacement] - offsetRatio[tickPlacement])
42
- })), ...(tickPlacement === 'extremities' ? [{
43
- formattedValue: undefined,
44
- offset: scale.range()[1],
45
- labelOffset: 0
46
- }] : [])];
47
- }
43
+ };
44
+ }), ...(tickPlacement === 'extremities' ? [{
45
+ formattedValue: undefined,
46
+ offset: scale.range()[1],
47
+ labelOffset: 0
48
+ }] : [])];
49
+ }
48
50
 
49
- // scale type = 'point'
50
- const filteredDomain = typeof tickInterval === 'function' && domain.filter(tickInterval) || typeof tickInterval === 'object' && tickInterval || domain;
51
- return filteredDomain.map(value => ({
51
+ // scale type = 'point'
52
+ const filteredDomain = typeof tickInterval === 'function' && domain.filter(tickInterval) || typeof tickInterval === 'object' && tickInterval || domain;
53
+ return filteredDomain.map(value => {
54
+ const defaultTickLabel = `${value}`;
55
+ return {
52
56
  value,
53
57
  formattedValue: valueFormatter?.(value, {
54
58
  location: 'tick',
55
- scale
56
- }) ?? `${value}`,
59
+ scale,
60
+ tickNumber,
61
+ defaultTickLabel
62
+ }) ?? defaultTickLabel,
57
63
  offset: scale(value),
58
64
  labelOffset: 0
59
- }));
60
- }
61
- const domain = scale.domain();
62
- // Skip axis rendering if no data is available
63
- // - The domains contains Infinity for continuous scales.
64
- if (domain.some(isInfinity)) {
65
- return [];
66
- }
67
- const tickLabelPlacement = tickLabelPlacementProp;
68
- const ticks = typeof tickInterval === 'object' ? tickInterval : scale.ticks(tickNumber);
65
+ };
66
+ });
67
+ }
68
+ const domain = scale.domain();
69
+ // Skip axis rendering if no data is available
70
+ // - The domains contains Infinity for continuous scales.
71
+ if (domain.some(isInfinity)) {
72
+ return [];
73
+ }
74
+ const tickLabelPlacement = tickLabelPlacementProp;
75
+ const ticks = typeof tickInterval === 'object' ? tickInterval : scale.ticks(tickNumber);
69
76
 
70
- // Ticks inside the drawing area
71
- const visibleTicks = [];
72
- for (let i = 0; i < ticks.length; i += 1) {
73
- const value = ticks[i];
74
- const offset = scale(value);
75
- const isInside = direction === 'x' ? instance.isXInside(offset) : instance.isYInside(offset);
76
- if (isInside) {
77
- visibleTicks.push({
78
- value,
79
- formattedValue: valueFormatter?.(value, {
80
- location: 'tick',
81
- scale
82
- }) ?? scale.tickFormat(tickNumber)(value),
83
- offset,
84
- // Allowing the label to be placed in the middle of a continuous scale is weird.
85
- // But it is useful in some cases, like funnel categories with a linear scale.
86
- labelOffset: tickLabelPlacement === 'middle' ? scale(ticks[i - 1] ?? 0) - (offset + scale(ticks[i - 1] ?? 0)) / 2 : 0
87
- });
88
- }
77
+ // Ticks inside the drawing area
78
+ const visibleTicks = [];
79
+ for (let i = 0; i < ticks.length; i += 1) {
80
+ const value = ticks[i];
81
+ const offset = scale(value);
82
+ if (isInside(offset)) {
83
+ /* If d3 returns an empty string, it means that a tick should be shown, but its label shouldn't.
84
+ * This is especially useful in a log scale where we want to show ticks to demonstrate it's a log
85
+ * scale, but don't want to show labels because they would overlap.
86
+ * https://github.com/mui/mui-x/issues/18239 */
87
+ const defaultTickLabel = scale.tickFormat(tickNumber)(value);
88
+ visibleTicks.push({
89
+ value,
90
+ formattedValue: valueFormatter?.(value, {
91
+ location: 'tick',
92
+ scale,
93
+ tickNumber,
94
+ defaultTickLabel
95
+ }) ?? defaultTickLabel,
96
+ offset,
97
+ // Allowing the label to be placed in the middle of a continuous scale is weird.
98
+ // But it is useful in some cases, like funnel categories with a linear scale.
99
+ labelOffset: tickLabelPlacement === 'middle' ? scale(ticks[i - 1] ?? 0) - (offset + scale(ticks[i - 1] ?? 0)) / 2 : 0
100
+ });
89
101
  }
90
- return visibleTicks;
91
- }, [scale, tickLabelPlacementProp, tickInterval, tickNumber, tickPlacement, valueFormatter, direction, instance]);
102
+ }
103
+ return visibleTicks;
104
+ }
105
+ export function useTicks(options) {
106
+ const {
107
+ scale,
108
+ tickNumber,
109
+ valueFormatter,
110
+ tickInterval,
111
+ tickPlacement = 'extremities',
112
+ tickLabelPlacement,
113
+ direction
114
+ } = options;
115
+ const {
116
+ instance
117
+ } = useChartContext();
118
+ const isInside = direction === 'x' ? instance.isXInside : instance.isYInside;
119
+ return React.useMemo(() => getTicks({
120
+ scale,
121
+ tickNumber,
122
+ tickPlacement,
123
+ tickInterval,
124
+ tickLabelPlacement,
125
+ valueFormatter,
126
+ isInside
127
+ }), [scale, tickNumber, tickPlacement, tickInterval, tickLabelPlacement, valueFormatter, isInside]);
92
128
  }
package/esm/index.d.ts CHANGED
@@ -26,4 +26,5 @@ export * from "./ChartsSurface/index.js";
26
26
  export { ChartContainer } from "./ChartContainer/index.js";
27
27
  export type { ChartContainerProps } from "./ChartContainer/index.js";
28
28
  export * from "./ChartDataProvider/index.js";
29
- export * from "./Toolbar/index.js";
29
+ export * from "./Toolbar/index.js";
30
+ export * from "./ChartsWrapper/index.js";
package/esm/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-charts v8.8.0
2
+ * @mui/x-charts v8.9.2
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -32,4 +32,8 @@ export * from "./RadarChart/index.js";
32
32
  export * from "./ChartsSurface/index.js";
33
33
  export { ChartContainer } from "./ChartContainer/index.js";
34
34
  export * from "./ChartDataProvider/index.js";
35
- export * from "./Toolbar/index.js";
35
+ export * from "./Toolbar/index.js";
36
+ export * from "./ChartsWrapper/index.js";
37
+
38
+ // Locales should be imported from `@mui/x-charts/locales`
39
+ // export * from './locales';
@@ -0,0 +1 @@
1
+ export declare function findMinMax(data: readonly number[]): [number, number];
@@ -0,0 +1,13 @@
1
+ export function findMinMax(data) {
2
+ let min = Infinity;
3
+ let max = -Infinity;
4
+ for (const value of data ?? []) {
5
+ if (value < min) {
6
+ min = value;
7
+ }
8
+ if (value > max) {
9
+ max = value;
10
+ }
11
+ }
12
+ return [min, max];
13
+ }
@@ -1,4 +1,5 @@
1
1
  import { scaleLog, scalePow, scaleSqrt, scaleTime, scaleUtc, scaleLinear } from '@mui/x-charts-vendor/d3-scale';
2
+ import { scaleSymlog } from "./symlogScale.js";
2
3
  export function getScale(scaleType, domain, range) {
3
4
  switch (scaleType) {
4
5
  case 'log':
@@ -11,6 +12,8 @@ export function getScale(scaleType, domain, range) {
11
12
  return scaleTime(domain, range);
12
13
  case 'utc':
13
14
  return scaleUtc(domain, range);
15
+ case 'symlog':
16
+ return scaleSymlog(domain, range);
14
17
  default:
15
18
  return scaleLinear(domain, range);
16
19
  }
@@ -1,5 +1,4 @@
1
1
  export * from "./components/ChartsAxesGradients/index.js";
2
- export * from "./components/ChartsWrapper/index.js";
3
2
  export * from "../ChartsLabel/ChartsLabelMark.js";
4
3
  export * from "./components/NotRendered.js";
5
4
  export { useSeries } from "../hooks/useSeries.js";
@@ -54,6 +53,7 @@ export * from "./ticks.js";
54
53
  export * from "./dateHelpers.js";
55
54
  export * from "./invertScale.js";
56
55
  export * from "./isBandScale.js";
56
+ export * from "./findMinMax.js";
57
57
  export { getAxisExtremum } from "./plugins/featurePlugins/useChartCartesianAxis/getAxisExtremum.js";
58
58
  export * from "../context/ChartProvider/index.js";
59
59
  export * from "../context/ChartsSlotsContext.js";
@@ -1,6 +1,5 @@
1
1
  // Components
2
2
  export * from "./components/ChartsAxesGradients/index.js";
3
- export * from "./components/ChartsWrapper/index.js";
4
3
  export * from "../ChartsLabel/ChartsLabelMark.js";
5
4
  export * from "./components/NotRendered.js";
6
5
 
@@ -64,6 +63,7 @@ export * from "./ticks.js";
64
63
  export * from "./dateHelpers.js";
65
64
  export * from "./invertScale.js";
66
65
  export * from "./isBandScale.js";
66
+ export * from "./findMinMax.js";
67
67
 
68
68
  // contexts
69
69
  export { getAxisExtremum } from "./plugins/featurePlugins/useChartCartesianAxis/getAxisExtremum.js";
@@ -1,7 +1,7 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import { scaleBand, scalePoint } from '@mui/x-charts-vendor/d3-scale';
3
3
  import { createScalarFormatter } from "../../../defaultValueFormatters.js";
4
- import { isBandScaleConfig, isPointScaleConfig } from "../../../../models/axis.js";
4
+ import { isBandScaleConfig, isPointScaleConfig, isSymlogScaleConfig } from "../../../../models/axis.js";
5
5
  import { getColorScale, getOrdinalColorScale } from "../../../colorScale.js";
6
6
  import { getTickNumber, scaleTickNumberByRange } from "../../../ticks.js";
7
7
  import { getScale } from "../../../getScale.js";
@@ -114,6 +114,9 @@ export function computeAxisValue({
114
114
  const tickNumber = scaleTickNumberByRange(rawTickNumber, zoomRange);
115
115
  const zoomedRange = zoomScaleRange(range, zoomRange);
116
116
  const scale = getScale(scaleType, axisExtremums, zoomedRange);
117
+ if (isSymlogScaleConfig(axis) && axis.constant != null) {
118
+ scale.constant(axis.constant);
119
+ }
117
120
  const finalScale = domainLimit === 'nice' ? scale.nice(rawTickNumber) : scale;
118
121
  const [minDomain, maxDomain] = finalScale.domain();
119
122
  const domain = [axis.min ?? minDomain, axis.max ?? maxDomain];
@@ -1,3 +1,3 @@
1
1
  import { HighlightScope } from "./highlightConfig.types.js";
2
2
  import { HighlightItemData } from "./useChartHighlight.types.js";
3
- export declare const createIsFaded: (highlightScope: HighlightScope | null | undefined, highlightedItem: HighlightItemData | null) => (item: HighlightItemData | null) => boolean;
3
+ export declare function createIsFaded(highlightScope: HighlightScope | null | undefined, highlightedItem: HighlightItemData | null): (item: HighlightItemData | null) => boolean;
@@ -1,12 +1,20 @@
1
- export const createIsFaded = (highlightScope, highlightedItem) => item => {
2
- if (!highlightScope || !highlightedItem || !item) {
3
- return false;
4
- }
5
- if (highlightScope.fade === 'series') {
6
- return item.seriesId === highlightedItem.seriesId && item.dataIndex !== highlightedItem.dataIndex;
7
- }
8
- if (highlightScope.fade === 'global') {
9
- return item.seriesId !== highlightedItem.seriesId || item.dataIndex !== highlightedItem.dataIndex;
10
- }
1
+ function alwaysFalse() {
11
2
  return false;
12
- };
3
+ }
4
+ export function createIsFaded(highlightScope, highlightedItem) {
5
+ if (!highlightScope || !highlightedItem) {
6
+ return alwaysFalse;
7
+ }
8
+ return function isFaded(item) {
9
+ if (!item) {
10
+ return false;
11
+ }
12
+ if (highlightScope.fade === 'series') {
13
+ return item.seriesId === highlightedItem.seriesId && item.dataIndex !== highlightedItem.dataIndex;
14
+ }
15
+ if (highlightScope.fade === 'global') {
16
+ return item.seriesId !== highlightedItem.seriesId || item.dataIndex !== highlightedItem.dataIndex;
17
+ }
18
+ return false;
19
+ };
20
+ }
@@ -1,3 +1,3 @@
1
1
  import { HighlightScope } from "./highlightConfig.types.js";
2
2
  import { HighlightItemData } from "./useChartHighlight.types.js";
3
- export declare const createIsHighlighted: (highlightScope: HighlightScope | null | undefined, highlightedItem: HighlightItemData | null) => (item: HighlightItemData | null) => boolean;
3
+ export declare function createIsHighlighted(highlightScope: HighlightScope | null | undefined, highlightedItem: HighlightItemData | null): (item: HighlightItemData | null) => boolean;
@@ -1,12 +1,20 @@
1
- export const createIsHighlighted = (highlightScope, highlightedItem) => item => {
2
- if (!highlightScope || !highlightedItem || !item) {
3
- return false;
4
- }
5
- if (highlightScope.highlight === 'series') {
6
- return item.seriesId === highlightedItem.seriesId;
7
- }
8
- if (highlightScope.highlight === 'item') {
9
- return item.dataIndex === highlightedItem.dataIndex && item.seriesId === highlightedItem.seriesId;
10
- }
1
+ function alwaysFalse() {
11
2
  return false;
12
- };
3
+ }
4
+ export function createIsHighlighted(highlightScope, highlightedItem) {
5
+ if (!highlightScope || !highlightedItem) {
6
+ return alwaysFalse;
7
+ }
8
+ return function isHighlighted(item) {
9
+ if (!item) {
10
+ return false;
11
+ }
12
+ if (highlightScope.highlight === 'series') {
13
+ return item.seriesId === highlightedItem.seriesId;
14
+ }
15
+ if (highlightScope.highlight === 'item') {
16
+ return item.dataIndex === highlightedItem.dataIndex && item.seriesId === highlightedItem.seriesId;
17
+ }
18
+ return false;
19
+ };
20
+ }
@@ -14,8 +14,10 @@ export const selectorChartsHighlightScopePerSeriesId = createSelector([selectSer
14
14
  });
15
15
  return map;
16
16
  });
17
- export const selectorChartsHighlightedItem = createSelector([selectHighlight], highlight => highlight.item);
18
- export const selectorChartsHighlightScope = createSelector([selectorChartsHighlightScopePerSeriesId, selectorChartsHighlightedItem], (seriesIdToHighlightScope, highlightedItem) => {
17
+ export const selectorChartsHighlightedItem = createSelector([selectHighlight], function selectorChartsHighlightedItem(highlight) {
18
+ return highlight.item;
19
+ });
20
+ export const selectorChartsHighlightScope = createSelector([selectorChartsHighlightScopePerSeriesId, selectorChartsHighlightedItem], function selectorChartsHighlightScope(seriesIdToHighlightScope, highlightedItem) {
19
21
  if (!highlightedItem) {
20
22
  return null;
21
23
  }
@@ -27,5 +29,9 @@ export const selectorChartsHighlightScope = createSelector([selectorChartsHighli
27
29
  });
28
30
  export const selectorChartsIsHighlightedCallback = createSelector([selectorChartsHighlightScope, selectorChartsHighlightedItem], createIsHighlighted);
29
31
  export const selectorChartsIsFadedCallback = createSelector([selectorChartsHighlightScope, selectorChartsHighlightedItem], createIsFaded);
30
- export const selectorChartsIsHighlighted = createSelector([selectorChartsHighlightScope, selectorChartsHighlightedItem, (_, item) => item], (highlightScope, highlightedItem, item) => createIsHighlighted(highlightScope, highlightedItem)(item));
31
- export const selectorChartsIsFaded = createSelector([selectorChartsHighlightScope, selectorChartsHighlightedItem, (_, item) => item], (highlightScope, highlightedItem, item) => createIsFaded(highlightScope, highlightedItem)(item));
32
+ export const selectorChartsIsHighlighted = createSelector([selectorChartsHighlightScope, selectorChartsHighlightedItem, (_, item) => item], function selectorChartsIsHighlighted(highlightScope, highlightedItem, item) {
33
+ return createIsHighlighted(highlightScope, highlightedItem)(item);
34
+ });
35
+ export const selectorChartsIsFaded = createSelector([selectorChartsHighlightScope, selectorChartsHighlightedItem, (_, item) => item], function selectorChartsIsFaded(highlightScope, highlightedItem, item) {
36
+ return createIsFaded(highlightScope, highlightedItem)(item);
37
+ });