@mui/x-charts 8.5.3 → 8.7.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 (228) hide show
  1. package/BarChart/AnimatedBarElement.js +3 -1
  2. package/BarChart/BarLabel/BarLabelPlot.d.ts +2 -2
  3. package/BarChart/BarLabel/BarLabelPlot.js +33 -25
  4. package/BarChart/BarPlot.js +59 -183
  5. package/BarChart/barClasses.d.ts +12 -0
  6. package/BarChart/barClasses.js +25 -0
  7. package/BarChart/index.d.ts +3 -1
  8. package/BarChart/index.js +23 -1
  9. package/BarChart/types.d.ts +5 -1
  10. package/BarChart/useBarPlotData.d.ts +8 -0
  11. package/BarChart/useBarPlotData.js +146 -0
  12. package/CHANGELOG.md +210 -0
  13. package/ChartContainer/ChartContainer.d.ts +1 -21
  14. package/ChartContainer/ChartContainer.js +0 -8
  15. package/ChartContainer/index.d.ts +8 -1
  16. package/ChartsLegend/ChartsLegend.js +1 -0
  17. package/ChartsReferenceLine/ChartsReferenceLine.d.ts +1 -1
  18. package/ChartsReferenceLine/ChartsXReferenceLine.d.ts +3 -0
  19. package/ChartsReferenceLine/ChartsXReferenceLine.js +48 -1
  20. package/ChartsReferenceLine/ChartsYReferenceLine.d.ts +3 -0
  21. package/ChartsReferenceLine/ChartsYReferenceLine.js +48 -1
  22. package/ChartsReferenceLine/index.d.ts +3 -1
  23. package/ChartsSurface/ChartsSurface.js +2 -1
  24. package/ChartsTooltip/ChartsTooltipContainer.js +6 -3
  25. package/ChartsTooltip/ChartsTooltipTable.d.ts +1 -1
  26. package/ChartsTooltip/utils.js +18 -29
  27. package/ChartsXAxis/ChartsXAxis.js +4 -108
  28. package/ChartsXAxis/getVisibleLabels.d.ts +14 -0
  29. package/ChartsXAxis/getVisibleLabels.js +71 -0
  30. package/ChartsXAxis/shortenLabels.d.ts +4 -0
  31. package/ChartsXAxis/shortenLabels.js +48 -0
  32. package/ChartsYAxis/ChartsYAxis.js +2 -39
  33. package/ChartsYAxis/shortenLabels.d.ts +4 -0
  34. package/ChartsYAxis/shortenLabels.js +46 -0
  35. package/LineChart/AnimatedArea.js +4 -1
  36. package/LineChart/AnimatedLine.js +4 -1
  37. package/LineChart/AreaPlot.js +5 -115
  38. package/LineChart/CircleMarkElement.js +4 -1
  39. package/LineChart/LinePlot.js +5 -99
  40. package/LineChart/MarkElement.js +4 -1
  41. package/LineChart/MarkPlot.js +1 -0
  42. package/LineChart/useAreaPlotData.d.ts +12 -0
  43. package/LineChart/useAreaPlotData.js +125 -0
  44. package/LineChart/useLinePlotData.d.ts +11 -0
  45. package/LineChart/useLinePlotData.js +108 -0
  46. package/PieChart/PieArc.js +3 -1
  47. package/PieChart/PiePlot.js +6 -0
  48. package/PieChart/index.d.ts +3 -1
  49. package/PieChart/index.js +18 -1
  50. package/PieChart/pieClasses.d.ts +12 -0
  51. package/PieChart/pieClasses.js +24 -0
  52. package/ScatterChart/Scatter.js +22 -48
  53. package/ScatterChart/useScatterPlotData.d.ts +8 -0
  54. package/ScatterChart/useScatterPlotData.js +33 -0
  55. package/Toolbar/ToolbarButton.js +2 -0
  56. package/context/ChartApi.d.ts +22 -0
  57. package/context/ChartApi.js +5 -0
  58. package/context/ChartProvider/ChartContext.js +1 -0
  59. package/context/index.d.ts +2 -1
  60. package/context/useChartApiContext.d.ts +1 -1
  61. package/esm/BarChart/AnimatedBarElement.js +3 -1
  62. package/esm/BarChart/BarLabel/BarLabelPlot.d.ts +2 -2
  63. package/esm/BarChart/BarLabel/BarLabelPlot.js +33 -25
  64. package/esm/BarChart/BarPlot.js +60 -185
  65. package/esm/BarChart/barClasses.d.ts +12 -0
  66. package/esm/BarChart/barClasses.js +15 -0
  67. package/esm/BarChart/index.d.ts +3 -1
  68. package/esm/BarChart/index.js +2 -1
  69. package/esm/BarChart/types.d.ts +5 -1
  70. package/esm/BarChart/useBarPlotData.d.ts +8 -0
  71. package/esm/BarChart/useBarPlotData.js +139 -0
  72. package/esm/ChartContainer/ChartContainer.d.ts +1 -21
  73. package/esm/ChartContainer/ChartContainer.js +0 -8
  74. package/esm/ChartContainer/index.d.ts +8 -1
  75. package/esm/ChartContainer/index.js +6 -1
  76. package/esm/ChartsLegend/ChartsLegend.js +1 -0
  77. package/esm/ChartsReferenceLine/ChartsReferenceLine.d.ts +1 -1
  78. package/esm/ChartsReferenceLine/ChartsXReferenceLine.d.ts +3 -0
  79. package/esm/ChartsReferenceLine/ChartsXReferenceLine.js +47 -0
  80. package/esm/ChartsReferenceLine/ChartsYReferenceLine.d.ts +3 -0
  81. package/esm/ChartsReferenceLine/ChartsYReferenceLine.js +47 -0
  82. package/esm/ChartsReferenceLine/index.d.ts +3 -1
  83. package/esm/ChartsReferenceLine/index.js +2 -1
  84. package/esm/ChartsSurface/ChartsSurface.js +2 -1
  85. package/esm/ChartsTooltip/ChartsTooltipContainer.js +6 -3
  86. package/esm/ChartsTooltip/ChartsTooltipTable.d.ts +1 -1
  87. package/esm/ChartsTooltip/utils.js +18 -29
  88. package/esm/ChartsXAxis/ChartsXAxis.js +2 -106
  89. package/esm/ChartsXAxis/getVisibleLabels.d.ts +14 -0
  90. package/esm/ChartsXAxis/getVisibleLabels.js +67 -0
  91. package/esm/ChartsXAxis/shortenLabels.d.ts +4 -0
  92. package/esm/ChartsXAxis/shortenLabels.js +42 -0
  93. package/esm/ChartsYAxis/ChartsYAxis.js +1 -38
  94. package/esm/ChartsYAxis/shortenLabels.d.ts +4 -0
  95. package/esm/ChartsYAxis/shortenLabels.js +41 -0
  96. package/esm/LineChart/AnimatedArea.js +4 -1
  97. package/esm/LineChart/AnimatedLine.js +4 -1
  98. package/esm/LineChart/AreaPlot.js +5 -115
  99. package/esm/LineChart/CircleMarkElement.js +4 -1
  100. package/esm/LineChart/LinePlot.js +5 -99
  101. package/esm/LineChart/MarkElement.js +4 -1
  102. package/esm/LineChart/MarkPlot.js +1 -0
  103. package/esm/LineChart/useAreaPlotData.d.ts +12 -0
  104. package/esm/LineChart/useAreaPlotData.js +118 -0
  105. package/esm/LineChart/useLinePlotData.d.ts +11 -0
  106. package/esm/LineChart/useLinePlotData.js +101 -0
  107. package/esm/PieChart/PieArc.js +3 -1
  108. package/esm/PieChart/PiePlot.js +6 -0
  109. package/esm/PieChart/index.d.ts +3 -1
  110. package/esm/PieChart/index.js +2 -1
  111. package/esm/PieChart/pieClasses.d.ts +12 -0
  112. package/esm/PieChart/pieClasses.js +15 -0
  113. package/esm/ScatterChart/Scatter.js +23 -49
  114. package/esm/ScatterChart/useScatterPlotData.d.ts +8 -0
  115. package/esm/ScatterChart/useScatterPlotData.js +26 -0
  116. package/esm/Toolbar/ToolbarButton.js +2 -0
  117. package/esm/context/ChartApi.d.ts +22 -0
  118. package/esm/context/ChartApi.js +1 -0
  119. package/esm/context/ChartProvider/ChartContext.js +2 -0
  120. package/esm/context/index.d.ts +2 -1
  121. package/esm/context/useChartApiContext.d.ts +1 -1
  122. package/esm/hooks/useInteractionItemProps.d.ts +14 -9
  123. package/esm/hooks/useInteractionItemProps.js +28 -28
  124. package/esm/index.d.ts +2 -1
  125. package/esm/index.js +2 -2
  126. package/esm/internals/components/NotRendered.d.ts +9 -0
  127. package/esm/internals/components/NotRendered.js +10 -0
  128. package/esm/internals/index.d.ts +6 -0
  129. package/esm/internals/index.js +6 -0
  130. package/esm/internals/plugins/corePlugins/corePlugins.d.ts +3 -2
  131. package/esm/internals/plugins/corePlugins/corePlugins.js +2 -1
  132. package/esm/internals/plugins/corePlugins/useChartAnimation/useChartAnimation.selectors.d.ts +1 -1
  133. package/esm/internals/plugins/corePlugins/useChartDimensions/useChartDimensions.js +1 -1
  134. package/esm/internals/plugins/corePlugins/useChartDimensions/useChartDimensions.selectors.d.ts +3 -3
  135. package/esm/internals/plugins/corePlugins/useChartDimensions/useChartDimensions.types.d.ts +2 -2
  136. package/esm/internals/plugins/corePlugins/useChartId/useChartId.js +2 -0
  137. package/esm/internals/plugins/corePlugins/useChartId/useChartId.selectors.d.ts +1 -1
  138. package/esm/internals/plugins/corePlugins/useChartInteractionListener/index.d.ts +2 -0
  139. package/esm/internals/plugins/corePlugins/useChartInteractionListener/index.js +1 -0
  140. package/esm/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.d.ts +3 -0
  141. package/esm/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.js +77 -0
  142. package/esm/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.types.d.ts +31 -0
  143. package/esm/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.types.js +1 -0
  144. package/esm/internals/plugins/corePlugins/useChartSeries/useChartSeries.selectors.d.ts +2 -2
  145. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartAxisSize.selectors.d.ts +4 -4
  146. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.js +44 -33
  147. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.d.ts +5 -5
  148. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianInteraction.selectors.d.ts +7 -7
  149. package/esm/internals/plugins/featurePlugins/useChartHighlight/useChartHighlight.selectors.d.ts +5 -5
  150. package/esm/internals/plugins/featurePlugins/useChartInteraction/useChartInteraction.selectors.d.ts +6 -6
  151. package/esm/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarAxis.js +52 -36
  152. package/esm/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarAxis.selectors.d.ts +5 -5
  153. package/esm/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarInteraction.selectors.d.ts +6 -6
  154. package/esm/internals/plugins/featurePlugins/useChartVoronoi/useChartVoronoi.js +47 -30
  155. package/esm/internals/plugins/featurePlugins/useChartVoronoi/useChartVoronoi.selectors.d.ts +1 -1
  156. package/esm/internals/plugins/featurePlugins/useChartZAxis/useChartZAxis.selectors.d.ts +1 -1
  157. package/esm/internals/store/useCharts.d.ts +1 -1
  158. package/esm/locales/elGR.d.ts +19 -0
  159. package/esm/locales/elGR.js +15 -0
  160. package/esm/locales/enUS.d.ts +3 -0
  161. package/esm/locales/enUS.js +8 -2
  162. package/esm/locales/frFR.d.ts +3 -0
  163. package/esm/locales/frFR.js +7 -0
  164. package/esm/locales/index.d.ts +1 -0
  165. package/esm/locales/index.js +1 -0
  166. package/esm/locales/ptBR.d.ts +3 -0
  167. package/esm/locales/ptBR.js +7 -1
  168. package/esm/locales/ptPT.d.ts +3 -0
  169. package/esm/locales/ptPT.js +7 -1
  170. package/esm/locales/utils/chartsLocaleTextApi.d.ts +17 -0
  171. package/esm/locales/utils/getChartsLocalization.d.ts +3 -0
  172. package/esm/locales/utils/imageMimeTypes.d.ts +2 -0
  173. package/esm/locales/utils/imageMimeTypes.js +5 -0
  174. package/esm/models/slots/chartsBaseSlotProps.d.ts +4 -0
  175. package/hooks/useInteractionItemProps.d.ts +14 -9
  176. package/hooks/useInteractionItemProps.js +29 -28
  177. package/index.d.ts +2 -1
  178. package/index.js +37 -11
  179. package/internals/components/NotRendered.d.ts +9 -0
  180. package/internals/components/NotRendered.js +16 -0
  181. package/internals/index.d.ts +6 -0
  182. package/internals/index.js +56 -0
  183. package/internals/plugins/corePlugins/corePlugins.d.ts +3 -2
  184. package/internals/plugins/corePlugins/corePlugins.js +2 -1
  185. package/internals/plugins/corePlugins/useChartAnimation/useChartAnimation.selectors.d.ts +1 -1
  186. package/internals/plugins/corePlugins/useChartDimensions/useChartDimensions.js +1 -1
  187. package/internals/plugins/corePlugins/useChartDimensions/useChartDimensions.selectors.d.ts +3 -3
  188. package/internals/plugins/corePlugins/useChartDimensions/useChartDimensions.types.d.ts +2 -2
  189. package/internals/plugins/corePlugins/useChartId/useChartId.js +1 -0
  190. package/internals/plugins/corePlugins/useChartId/useChartId.selectors.d.ts +1 -1
  191. package/internals/plugins/corePlugins/useChartInteractionListener/index.d.ts +2 -0
  192. package/internals/plugins/corePlugins/useChartInteractionListener/index.js +12 -0
  193. package/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.d.ts +3 -0
  194. package/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.js +84 -0
  195. package/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.types.d.ts +31 -0
  196. package/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.types.js +5 -0
  197. package/internals/plugins/corePlugins/useChartSeries/useChartSeries.selectors.d.ts +2 -2
  198. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartAxisSize.selectors.d.ts +4 -4
  199. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.js +44 -33
  200. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.d.ts +5 -5
  201. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianInteraction.selectors.d.ts +7 -7
  202. package/internals/plugins/featurePlugins/useChartHighlight/useChartHighlight.selectors.d.ts +5 -5
  203. package/internals/plugins/featurePlugins/useChartInteraction/useChartInteraction.selectors.d.ts +6 -6
  204. package/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarAxis.js +52 -36
  205. package/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarAxis.selectors.d.ts +5 -5
  206. package/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarInteraction.selectors.d.ts +6 -6
  207. package/internals/plugins/featurePlugins/useChartVoronoi/useChartVoronoi.js +46 -30
  208. package/internals/plugins/featurePlugins/useChartVoronoi/useChartVoronoi.selectors.d.ts +1 -1
  209. package/internals/plugins/featurePlugins/useChartZAxis/useChartZAxis.selectors.d.ts +1 -1
  210. package/internals/store/useCharts.d.ts +1 -1
  211. package/locales/elGR.d.ts +19 -0
  212. package/locales/elGR.js +21 -0
  213. package/locales/enUS.d.ts +3 -0
  214. package/locales/enUS.js +8 -2
  215. package/locales/frFR.d.ts +3 -0
  216. package/locales/frFR.js +7 -0
  217. package/locales/index.d.ts +1 -0
  218. package/locales/index.js +11 -0
  219. package/locales/ptBR.d.ts +3 -0
  220. package/locales/ptBR.js +7 -1
  221. package/locales/ptPT.d.ts +3 -0
  222. package/locales/ptPT.js +7 -1
  223. package/locales/utils/chartsLocaleTextApi.d.ts +17 -0
  224. package/locales/utils/getChartsLocalization.d.ts +3 -0
  225. package/locales/utils/imageMimeTypes.d.ts +2 -0
  226. package/locales/utils/imageMimeTypes.js +11 -0
  227. package/models/slots/chartsBaseSlotProps.d.ts +4 -0
  228. package/package.json +3 -2
@@ -15,24 +15,22 @@ var _useSlotProps = _interopRequireDefault(require("@mui/utils/useSlotProps"));
15
15
  var _composeClasses = _interopRequireDefault(require("@mui/utils/composeClasses"));
16
16
  var _styles = require("@mui/material/styles");
17
17
  var _RtlProvider = require("@mui/system/RtlProvider");
18
- var _clampAngle = require("../internals/clampAngle");
19
18
  var _useIsHydrated = require("../hooks/useIsHydrated");
20
- var _ellipsize = require("../internals/ellipsize");
21
19
  var _domUtils = require("../internals/domUtils");
22
20
  var _useTicks = require("../hooks/useTicks");
23
21
  var _axisClasses = require("../ChartsAxis/axisClasses");
24
22
  var _AxisSharedComponents = require("../internals/components/AxisSharedComponents");
25
23
  var _ChartsText = require("../ChartsText");
26
- var _geometry = require("../internals/geometry");
27
24
  var _useMounted = require("../hooks/useMounted");
28
25
  var _useDrawingArea = require("../hooks/useDrawingArea");
29
- var _getWordsByLines = require("../internals/getWordsByLines");
30
26
  var _isInfinity = require("../internals/isInfinity");
31
27
  var _isBandScale = require("../internals/isBandScale");
32
28
  var _useChartContext = require("../context/ChartProvider/useChartContext");
33
29
  var _useAxis = require("../hooks/useAxis");
34
30
  var _defaultTextPlacement = require("../ChartsText/defaultTextPlacement");
35
31
  var _invertTextAnchor = require("../internals/invertTextAnchor");
32
+ var _shortenLabels = require("./shortenLabels");
33
+ var _getVisibleLabels = require("./getVisibleLabels");
36
34
  var _jsxRuntime = require("react/jsx-runtime");
37
35
  const _excluded = ["scale", "tickNumber", "reverse"];
38
36
  const useUtilityClasses = ownerState => {
@@ -56,108 +54,6 @@ const useUtilityClasses = ownerState => {
56
54
  const TICK_LABEL_GAP = 3;
57
55
  /* Gap between the axis label and tick labels. */
58
56
  const AXIS_LABEL_TICK_LABEL_GAP = 4;
59
-
60
- /* Returns a set of indices of the tick labels that should be visible. */
61
- function getVisibleLabels(xTicks, {
62
- tickLabelStyle: style,
63
- tickLabelInterval,
64
- tickLabelMinGap,
65
- reverse,
66
- isMounted,
67
- isXInside
68
- }) {
69
- const getTickLabelSize = tick => {
70
- if (!isMounted || tick.formattedValue === undefined) {
71
- return {
72
- width: 0,
73
- height: 0
74
- };
75
- }
76
- const tickSizes = (0, _getWordsByLines.getWordsByLines)({
77
- style,
78
- needsComputation: true,
79
- text: tick.formattedValue
80
- });
81
- return {
82
- width: Math.max(...tickSizes.map(size => size.width)),
83
- height: Math.max(tickSizes.length * tickSizes[0].height)
84
- };
85
- };
86
- if (typeof tickLabelInterval === 'function') {
87
- return new Set(xTicks.filter((item, index) => tickLabelInterval(item.value, index)));
88
- }
89
-
90
- // Filter label to avoid overlap
91
- let previousTextLimit = 0;
92
- const direction = reverse ? -1 : 1;
93
- return new Set(xTicks.filter((item, labelIndex) => {
94
- const {
95
- offset,
96
- labelOffset
97
- } = item;
98
- const textPosition = offset + labelOffset;
99
- if (labelIndex > 0 && direction * textPosition < direction * (previousTextLimit + tickLabelMinGap)) {
100
- return false;
101
- }
102
- if (!isXInside(textPosition)) {
103
- return false;
104
- }
105
-
106
- /* Measuring text width is expensive, so we need to delay it as much as possible to improve performance. */
107
- const {
108
- width,
109
- height
110
- } = getTickLabelSize(item);
111
- const distance = (0, _geometry.getMinXTranslation)(width, height, style?.angle);
112
- const currentTextLimit = textPosition - direction * distance / 2;
113
- if (labelIndex > 0 && direction * currentTextLimit < direction * (previousTextLimit + tickLabelMinGap)) {
114
- // Except for the first label, we skip all label that overlap with the last accepted.
115
- // Notice that the early return prevents `previousTextLimit` from being updated.
116
- return false;
117
- }
118
- previousTextLimit = textPosition + direction * distance / 2;
119
- return true;
120
- }));
121
- }
122
- function shortenLabels(visibleLabels, drawingArea, maxHeight, isRtl, tickLabelStyle) {
123
- const shortenedLabels = new Map();
124
- const angle = (0, _clampAngle.clampAngle)(tickLabelStyle?.angle ?? 0);
125
-
126
- // Multiplying the space available to the left of the text position by leftBoundFactor returns the max width of the text.
127
- // Same for rightBoundFactor
128
- let leftBoundFactor = 1;
129
- let rightBoundFactor = 1;
130
- if (tickLabelStyle?.textAnchor === 'start') {
131
- leftBoundFactor = Infinity;
132
- rightBoundFactor = 1;
133
- } else if (tickLabelStyle?.textAnchor === 'end') {
134
- leftBoundFactor = 1;
135
- rightBoundFactor = Infinity;
136
- } else {
137
- leftBoundFactor = 2;
138
- rightBoundFactor = 2;
139
- }
140
- if (angle > 90 && angle < 270) {
141
- [leftBoundFactor, rightBoundFactor] = [rightBoundFactor, leftBoundFactor];
142
- }
143
- if (isRtl) {
144
- [leftBoundFactor, rightBoundFactor] = [rightBoundFactor, leftBoundFactor];
145
- }
146
- for (const item of visibleLabels) {
147
- if (item.formattedValue) {
148
- // That maximum width of the tick depends on its proximity to the axis bounds.
149
- const width = Math.min((item.offset + item.labelOffset) * leftBoundFactor, (drawingArea.left + drawingArea.width + drawingArea.right - item.offset - item.labelOffset) * rightBoundFactor);
150
- const doesTextFit = text => (0, _ellipsize.doesTextFitInRect)(text, {
151
- width,
152
- height: maxHeight,
153
- angle,
154
- measureText: string => (0, _domUtils.getStringSize)(string, tickLabelStyle)
155
- });
156
- shortenedLabels.set(item, (0, _ellipsize.ellipsize)(item.formattedValue.toString(), doesTextFit));
157
- }
158
- }
159
- return shortenedLabels;
160
- }
161
57
  const XAxisRoot = (0, _styles.styled)(_AxisSharedComponents.AxisRoot, {
162
58
  name: 'MuiChartsXAxis',
163
59
  slot: 'Root'
@@ -261,7 +157,7 @@ function ChartsXAxis(inProps) {
261
157
  tickLabelPlacement,
262
158
  direction: 'x'
263
159
  });
264
- const visibleLabels = getVisibleLabels(xTicks, {
160
+ const visibleLabels = (0, _getVisibleLabels.getVisibleLabels)(xTicks, {
265
161
  tickLabelStyle: axisTickLabelProps.style,
266
162
  tickLabelInterval,
267
163
  tickLabelMinGap,
@@ -299,7 +195,7 @@ function ChartsXAxis(inProps) {
299
195
 
300
196
  /* If there's an axis title, the tick labels have less space to render */
301
197
  const tickLabelsMaxHeight = Math.max(0, axisHeight - (label ? labelHeight + AXIS_LABEL_TICK_LABEL_GAP : 0) - tickSize - TICK_LABEL_GAP);
302
- const tickLabels = isHydrated ? shortenLabels(visibleLabels, drawingArea, tickLabelsMaxHeight, isRtl, axisTickLabelProps.style) : new Map(Array.from(visibleLabels).map(item => [item, item.formattedValue]));
198
+ const tickLabels = isHydrated ? (0, _shortenLabels.shortenLabels)(visibleLabels, drawingArea, tickLabelsMaxHeight, isRtl, axisTickLabelProps.style) : new Map(Array.from(visibleLabels).map(item => [item, item.formattedValue]));
303
199
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(XAxisRoot, {
304
200
  transform: `translate(0, ${position === 'bottom' ? top + height + offset : top - offset})`,
305
201
  className: classes.root,
@@ -0,0 +1,14 @@
1
+ import { TickItemType } from "../hooks/useTicks.js";
2
+ import { ChartsXAxisProps, ComputedXAxis } from "../models/axis.js";
3
+ export declare function getVisibleLabels(xTicks: TickItemType[], {
4
+ tickLabelStyle: style,
5
+ tickLabelInterval,
6
+ tickLabelMinGap,
7
+ reverse,
8
+ isMounted,
9
+ isXInside
10
+ }: Pick<ChartsXAxisProps, 'tickLabelInterval' | 'tickLabelStyle'> & Pick<ComputedXAxis, 'reverse'> & {
11
+ isMounted: boolean;
12
+ tickLabelMinGap: NonNullable<ChartsXAxisProps['tickLabelMinGap']>;
13
+ isXInside: (x: number) => boolean;
14
+ }): Set<TickItemType>;
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ 'use client';
3
+
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.getVisibleLabels = getVisibleLabels;
8
+ var _geometry = require("../internals/geometry");
9
+ var _getWordsByLines = require("../internals/getWordsByLines");
10
+ /* Returns a set of indices of the tick labels that should be visible. */
11
+ function getVisibleLabels(xTicks, {
12
+ tickLabelStyle: style,
13
+ tickLabelInterval,
14
+ tickLabelMinGap,
15
+ reverse,
16
+ isMounted,
17
+ isXInside
18
+ }) {
19
+ const getTickLabelSize = tick => {
20
+ if (!isMounted || tick.formattedValue === undefined) {
21
+ return {
22
+ width: 0,
23
+ height: 0
24
+ };
25
+ }
26
+ const tickSizes = (0, _getWordsByLines.getWordsByLines)({
27
+ style,
28
+ needsComputation: true,
29
+ text: tick.formattedValue
30
+ });
31
+ return {
32
+ width: Math.max(...tickSizes.map(size => size.width)),
33
+ height: Math.max(tickSizes.length * tickSizes[0].height)
34
+ };
35
+ };
36
+ if (typeof tickLabelInterval === 'function') {
37
+ return new Set(xTicks.filter((item, index) => tickLabelInterval(item.value, index)));
38
+ }
39
+
40
+ // Filter label to avoid overlap
41
+ let previousTextLimit = 0;
42
+ const direction = reverse ? -1 : 1;
43
+ return new Set(xTicks.filter((item, labelIndex) => {
44
+ const {
45
+ offset,
46
+ labelOffset
47
+ } = item;
48
+ const textPosition = offset + labelOffset;
49
+ if (labelIndex > 0 && direction * textPosition < direction * (previousTextLimit + tickLabelMinGap)) {
50
+ return false;
51
+ }
52
+ if (!isXInside(textPosition)) {
53
+ return false;
54
+ }
55
+
56
+ /* Measuring text width is expensive, so we need to delay it as much as possible to improve performance. */
57
+ const {
58
+ width,
59
+ height
60
+ } = getTickLabelSize(item);
61
+ const distance = (0, _geometry.getMinXTranslation)(width, height, style?.angle);
62
+ const currentTextLimit = textPosition - direction * distance / 2;
63
+ if (labelIndex > 0 && direction * currentTextLimit < direction * (previousTextLimit + tickLabelMinGap)) {
64
+ // Except for the first label, we skip all label that overlap with the last accepted.
65
+ // Notice that the early return prevents `previousTextLimit` from being updated.
66
+ return false;
67
+ }
68
+ previousTextLimit = textPosition + direction * distance / 2;
69
+ return true;
70
+ }));
71
+ }
@@ -0,0 +1,4 @@
1
+ import { TickItemType } from "../hooks/useTicks.js";
2
+ import { ChartsXAxisProps } from "../models/axis.js";
3
+ import { ChartDrawingArea } from "../hooks/useDrawingArea.js";
4
+ export declare function shortenLabels(visibleLabels: Set<TickItemType>, drawingArea: Pick<ChartDrawingArea, 'left' | 'width' | 'right'>, maxHeight: number, isRtl: boolean, tickLabelStyle: ChartsXAxisProps['tickLabelStyle']): Map<TickItemType, string>;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.shortenLabels = shortenLabels;
7
+ var _clampAngle = require("../internals/clampAngle");
8
+ var _ellipsize = require("../internals/ellipsize");
9
+ var _domUtils = require("../internals/domUtils");
10
+ function shortenLabels(visibleLabels, drawingArea, maxHeight, isRtl, tickLabelStyle) {
11
+ const shortenedLabels = new Map();
12
+ const angle = (0, _clampAngle.clampAngle)(tickLabelStyle?.angle ?? 0);
13
+
14
+ // Multiplying the space available to the left of the text position by leftBoundFactor returns the max width of the text.
15
+ // Same for rightBoundFactor
16
+ let leftBoundFactor = 1;
17
+ let rightBoundFactor = 1;
18
+ if (tickLabelStyle?.textAnchor === 'start') {
19
+ leftBoundFactor = Infinity;
20
+ rightBoundFactor = 1;
21
+ } else if (tickLabelStyle?.textAnchor === 'end') {
22
+ leftBoundFactor = 1;
23
+ rightBoundFactor = Infinity;
24
+ } else {
25
+ leftBoundFactor = 2;
26
+ rightBoundFactor = 2;
27
+ }
28
+ if (angle > 90 && angle < 270) {
29
+ [leftBoundFactor, rightBoundFactor] = [rightBoundFactor, leftBoundFactor];
30
+ }
31
+ if (isRtl) {
32
+ [leftBoundFactor, rightBoundFactor] = [rightBoundFactor, leftBoundFactor];
33
+ }
34
+ for (const item of visibleLabels) {
35
+ if (item.formattedValue) {
36
+ // That maximum width of the tick depends on its proximity to the axis bounds.
37
+ const width = Math.min((item.offset + item.labelOffset) * leftBoundFactor, (drawingArea.left + drawingArea.width + drawingArea.right - item.offset - item.labelOffset) * rightBoundFactor);
38
+ const doesTextFit = text => (0, _ellipsize.doesTextFitInRect)(text, {
39
+ width,
40
+ height: maxHeight,
41
+ angle,
42
+ measureText: string => (0, _domUtils.getStringSize)(string, tickLabelStyle)
43
+ });
44
+ shortenedLabels.set(item, (0, _ellipsize.ellipsize)(item.formattedValue.toString(), doesTextFit));
45
+ }
46
+ }
47
+ return shortenedLabels;
48
+ }
@@ -17,7 +17,6 @@ var _styles = require("@mui/material/styles");
17
17
  var _RtlProvider = require("@mui/system/RtlProvider");
18
18
  var _useIsHydrated = require("../hooks/useIsHydrated");
19
19
  var _defaultTextPlacement = require("../ChartsText/defaultTextPlacement");
20
- var _ellipsize = require("../internals/ellipsize");
21
20
  var _domUtils = require("../internals/domUtils");
22
21
  var _useTicks = require("../hooks/useTicks");
23
22
  var _useDrawingArea = require("../hooks/useDrawingArea");
@@ -28,8 +27,8 @@ var _isInfinity = require("../internals/isInfinity");
28
27
  var _isBandScale = require("../internals/isBandScale");
29
28
  var _ChartProvider = require("../context/ChartProvider");
30
29
  var _hooks = require("../hooks");
31
- var _clampAngle = require("../internals/clampAngle");
32
30
  var _invertTextAnchor = require("../internals/invertTextAnchor");
31
+ var _shortenLabels = require("./shortenLabels");
33
32
  var _jsxRuntime = require("react/jsx-runtime");
34
33
  const _excluded = ["scale", "tickNumber"];
35
34
  const useUtilityClasses = ownerState => {
@@ -53,42 +52,6 @@ const useUtilityClasses = ownerState => {
53
52
  const TICK_LABEL_GAP = 2;
54
53
  /* Gap between the axis label and tick labels. */
55
54
  const AXIS_LABEL_TICK_LABEL_GAP = 2;
56
- function shortenLabels(visibleLabels, drawingArea, maxWidth, isRtl, tickLabelStyle) {
57
- const shortenedLabels = new Map();
58
- const angle = (0, _clampAngle.clampAngle)(tickLabelStyle?.angle ?? 0);
59
- let topBoundFactor = 1;
60
- let bottomBoundFactor = 1;
61
- if (tickLabelStyle?.textAnchor === 'start') {
62
- topBoundFactor = Infinity;
63
- bottomBoundFactor = 1;
64
- } else if (tickLabelStyle?.textAnchor === 'end') {
65
- topBoundFactor = 1;
66
- bottomBoundFactor = Infinity;
67
- } else {
68
- topBoundFactor = 2;
69
- bottomBoundFactor = 2;
70
- }
71
- if (angle > 180) {
72
- [topBoundFactor, bottomBoundFactor] = [bottomBoundFactor, topBoundFactor];
73
- }
74
- if (isRtl) {
75
- [topBoundFactor, bottomBoundFactor] = [bottomBoundFactor, topBoundFactor];
76
- }
77
- for (const item of visibleLabels) {
78
- if (item.formattedValue) {
79
- // That maximum height of the tick depends on its proximity to the axis bounds.
80
- const height = Math.min((item.offset + item.labelOffset) * topBoundFactor, (drawingArea.top + drawingArea.height + drawingArea.bottom - item.offset - item.labelOffset) * bottomBoundFactor);
81
- const doesTextFit = text => (0, _ellipsize.doesTextFitInRect)(text, {
82
- width: maxWidth,
83
- height,
84
- angle,
85
- measureText: string => (0, _domUtils.getStringSize)(string, tickLabelStyle)
86
- });
87
- shortenedLabels.set(item, (0, _ellipsize.ellipsize)(item.formattedValue.toString(), doesTextFit));
88
- }
89
- }
90
- return shortenedLabels;
91
- }
92
55
  const YAxisRoot = (0, _styles.styled)(_AxisSharedComponents.AxisRoot, {
93
56
  name: 'MuiChartsYAxis',
94
57
  slot: 'Root'
@@ -226,7 +189,7 @@ function ChartsYAxis(inProps) {
226
189
  };
227
190
  /* If there's an axis title, the tick labels have less space to render */
228
191
  const tickLabelsMaxWidth = Math.max(0, axisWidth - (label ? (0, _domUtils.getStringSize)(label, axisLabelProps.style).height + AXIS_LABEL_TICK_LABEL_GAP : 0) - tickSize - TICK_LABEL_GAP);
229
- const tickLabels = isHydrated ? shortenLabels(yTicks, drawingArea, tickLabelsMaxWidth, isRtl, axisTickLabelProps.style) : new Map(Array.from(yTicks).map(item => [item, item.formattedValue]));
192
+ const tickLabels = isHydrated ? (0, _shortenLabels.shortenLabels)(yTicks, drawingArea, tickLabelsMaxWidth, isRtl, axisTickLabelProps.style) : new Map(Array.from(yTicks).map(item => [item, item.formattedValue]));
230
193
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(YAxisRoot, {
231
194
  transform: `translate(${position === 'right' ? left + width + offset : left - offset}, 0)`,
232
195
  className: classes.root,
@@ -0,0 +1,4 @@
1
+ import { ChartDrawingArea } from "../hooks/index.js";
2
+ import { TickItemType } from "../hooks/useTicks.js";
3
+ import { ChartsYAxisProps } from "../models/index.js";
4
+ export declare function shortenLabels(visibleLabels: TickItemType[], drawingArea: Pick<ChartDrawingArea, 'top' | 'height' | 'bottom'>, maxWidth: number, isRtl: boolean, tickLabelStyle: ChartsYAxisProps['tickLabelStyle']): Map<TickItemType, string>;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ 'use client';
3
+
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.shortenLabels = shortenLabels;
8
+ var _clampAngle = require("../internals/clampAngle");
9
+ var _ellipsize = require("../internals/ellipsize");
10
+ var _domUtils = require("../internals/domUtils");
11
+ function shortenLabels(visibleLabels, drawingArea, maxWidth, isRtl, tickLabelStyle) {
12
+ const shortenedLabels = new Map();
13
+ const angle = (0, _clampAngle.clampAngle)(tickLabelStyle?.angle ?? 0);
14
+ let topBoundFactor = 1;
15
+ let bottomBoundFactor = 1;
16
+ if (tickLabelStyle?.textAnchor === 'start') {
17
+ topBoundFactor = Infinity;
18
+ bottomBoundFactor = 1;
19
+ } else if (tickLabelStyle?.textAnchor === 'end') {
20
+ topBoundFactor = 1;
21
+ bottomBoundFactor = Infinity;
22
+ } else {
23
+ topBoundFactor = 2;
24
+ bottomBoundFactor = 2;
25
+ }
26
+ if (angle > 180) {
27
+ [topBoundFactor, bottomBoundFactor] = [bottomBoundFactor, topBoundFactor];
28
+ }
29
+ if (isRtl) {
30
+ [topBoundFactor, bottomBoundFactor] = [bottomBoundFactor, topBoundFactor];
31
+ }
32
+ for (const item of visibleLabels) {
33
+ if (item.formattedValue) {
34
+ // That maximum height of the tick depends on its proximity to the axis bounds.
35
+ const height = Math.min((item.offset + item.labelOffset) * topBoundFactor, (drawingArea.top + drawingArea.height + drawingArea.bottom - item.offset - item.labelOffset) * bottomBoundFactor);
36
+ const doesTextFit = text => (0, _ellipsize.doesTextFitInRect)(text, {
37
+ width: maxWidth,
38
+ height,
39
+ angle,
40
+ measureText: string => (0, _domUtils.getStringSize)(string, tickLabelStyle)
41
+ });
42
+ shortenedLabels.set(item, (0, _ellipsize.ellipsize)(item.formattedValue.toString(), doesTextFit));
43
+ }
44
+ }
45
+ return shortenedLabels;
46
+ }
@@ -41,7 +41,10 @@ function AnimatedArea(props) {
41
41
  // eslint-disable-next-line no-nested-ternary
42
42
  ownerState.isHighlighted ? 'brightness(140%)' : ownerState.gradientId ? undefined : 'brightness(120%)',
43
43
  opacity: ownerState.isFaded ? 0.3 : 1,
44
- stroke: "none"
44
+ stroke: "none",
45
+ "data-series": ownerState.id,
46
+ "data-highlighted": ownerState.isHighlighted || undefined,
47
+ "data-faded": ownerState.isFaded || undefined
45
48
  }, other, animatedProps))
46
49
  });
47
50
  }
@@ -43,7 +43,10 @@ const AnimatedLine = exports.AnimatedLine = /*#__PURE__*/React.forwardRef(functi
43
43
  strokeLinejoin: "round",
44
44
  fill: "none",
45
45
  filter: ownerState.isHighlighted ? 'brightness(120%)' : undefined,
46
- opacity: ownerState.isFaded ? 0.3 : 1
46
+ opacity: ownerState.isFaded ? 0.3 : 1,
47
+ "data-series": ownerState.id,
48
+ "data-highlighted": ownerState.isHighlighted || undefined,
49
+ "data-faded": ownerState.isFaded || undefined
47
50
  }, other, animateProps))
48
51
  });
49
52
  });
@@ -7,22 +7,16 @@ Object.defineProperty(exports, "__esModule", {
7
7
  value: true
8
8
  });
9
9
  exports.AreaPlot = AreaPlot;
10
- var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
11
10
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
11
+ var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
12
12
  var React = _interopRequireWildcard(require("react"));
13
13
  var _propTypes = _interopRequireDefault(require("prop-types"));
14
14
  var _styles = require("@mui/material/styles");
15
- var _d3Shape = require("@mui/x-charts-vendor/d3-shape");
16
15
  var _AreaElement = require("./AreaElement");
17
- var _useScale = require("../hooks/useScale");
18
- var _getCurve = require("../internals/getCurve");
19
- var _isBandScale = require("../internals/isBandScale");
20
- var _constants = require("../constants");
21
- var _useLineSeries = require("../hooks/useLineSeries");
22
16
  var _useSkipAnimation = require("../hooks/useSkipAnimation");
23
- var _useChartGradientId = require("../hooks/useChartGradientId");
24
17
  var _useAxis = require("../hooks/useAxis");
25
18
  var _useInternalIsZoomInteracting = require("../internals/plugins/featurePlugins/useChartCartesianAxis/useInternalIsZoomInteracting");
19
+ var _useAreaPlotData = require("./useAreaPlotData");
26
20
  var _jsxRuntime = require("react/jsx-runtime");
27
21
  const _excluded = ["slots", "slotProps", "onItemClick", "skipAnimation"];
28
22
  const AreaPlotRoot = (0, _styles.styled)('g', {
@@ -34,117 +28,13 @@ const AreaPlotRoot = (0, _styles.styled)('g', {
34
28
  }
35
29
  });
36
30
  const useAggregatedData = () => {
37
- const seriesData = (0, _useLineSeries.useLineSeriesContext)();
38
31
  const {
39
- xAxis,
40
- xAxisIds
32
+ xAxis: xAxes
41
33
  } = (0, _useAxis.useXAxes)();
42
34
  const {
43
- yAxis,
44
- yAxisIds
35
+ yAxis: yAxes
45
36
  } = (0, _useAxis.useYAxes)();
46
- const getGradientId = (0, _useChartGradientId.useChartGradientIdBuilder)();
47
-
48
- // This memo prevents odd line chart behavior when hydrating.
49
- const allData = React.useMemo(() => {
50
- if (seriesData === undefined) {
51
- return [];
52
- }
53
- const {
54
- series,
55
- stackingGroups
56
- } = seriesData;
57
- const defaultXAxisId = xAxisIds[0];
58
- const defaultYAxisId = yAxisIds[0];
59
- return stackingGroups.flatMap(({
60
- ids: groupIds
61
- }) => {
62
- return [...groupIds].reverse() // Revert stacked area for a more pleasant animation
63
- .map(seriesId => {
64
- const {
65
- xAxisId = defaultXAxisId,
66
- yAxisId = defaultYAxisId,
67
- stackedData,
68
- data,
69
- connectNulls,
70
- baseline,
71
- curve,
72
- strictStepCurve
73
- } = series[seriesId];
74
- const xScale = xAxis[xAxisId].scale;
75
- const xPosition = (0, _useScale.getValueToPositionMapper)(xScale);
76
- const yScale = yAxis[yAxisId].scale;
77
- const xData = xAxis[xAxisId].data;
78
- const gradientId = yAxis[yAxisId].colorScale && getGradientId(yAxisId) || xAxis[xAxisId].colorScale && getGradientId(xAxisId) || undefined;
79
- if (process.env.NODE_ENV !== 'production') {
80
- if (xData === undefined) {
81
- throw new Error(`MUI X Charts: ${xAxisId === _constants.DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : `The x-axis with id "${xAxisId}"`} should have data property to be able to display a line plot.`);
82
- }
83
- if (xData.length < stackedData.length) {
84
- throw new Error(`MUI X Charts: The data length of the x axis (${xData.length} items) is lower than the length of series (${stackedData.length} items).`);
85
- }
86
- }
87
- const shouldExpand = curve?.includes('step') && !strictStepCurve && (0, _isBandScale.isBandScale)(xScale);
88
- const formattedData = xData?.flatMap((x, index) => {
89
- const nullData = data[index] == null;
90
- if (shouldExpand) {
91
- const rep = [{
92
- x,
93
- y: stackedData[index],
94
- nullData,
95
- isExtension: false
96
- }];
97
- if (!nullData && (index === 0 || data[index - 1] == null)) {
98
- rep.unshift({
99
- x: (xScale(x) ?? 0) - (xScale.step() - xScale.bandwidth()) / 2,
100
- y: stackedData[index],
101
- nullData,
102
- isExtension: true
103
- });
104
- }
105
- if (!nullData && (index === data.length - 1 || data[index + 1] == null)) {
106
- rep.push({
107
- x: (xScale(x) ?? 0) + (xScale.step() + xScale.bandwidth()) / 2,
108
- y: stackedData[index],
109
- nullData,
110
- isExtension: true
111
- });
112
- }
113
- return rep;
114
- }
115
- return {
116
- x,
117
- y: stackedData[index],
118
- nullData
119
- };
120
- }) ?? [];
121
- const d3Data = connectNulls ? formattedData.filter(d => !d.nullData) : formattedData;
122
- const areaPath = (0, _d3Shape.area)().x(d => d.isExtension ? d.x : xPosition(d.x)).defined(d => connectNulls || !d.nullData || !!d.isExtension).y0(d => {
123
- if (typeof baseline === 'number') {
124
- return yScale(baseline);
125
- }
126
- if (baseline === 'max') {
127
- return yScale.range()[1];
128
- }
129
- if (baseline === 'min') {
130
- return yScale.range()[0];
131
- }
132
- const value = d.y && yScale(d.y[0]);
133
- if (Number.isNaN(value)) {
134
- return yScale.range()[0];
135
- }
136
- return value;
137
- }).y1(d => d.y && yScale(d.y[1]));
138
- const d = areaPath.curve((0, _getCurve.getCurveFactory)(curve))(d3Data) || '';
139
- return (0, _extends2.default)({}, series[seriesId], {
140
- gradientId,
141
- d,
142
- seriesId
143
- });
144
- });
145
- });
146
- }, [seriesData, xAxisIds, yAxisIds, xAxis, yAxis, getGradientId]);
147
- return allData;
37
+ return (0, _useAreaPlotData.useAreaPlotData)(xAxes, yAxes);
148
38
  };
149
39
 
150
40
  /**
@@ -76,7 +76,10 @@ function CircleMarkElement(props) {
76
76
  className: classes.root,
77
77
  onClick: onClick,
78
78
  cursor: onClick ? 'pointer' : 'unset'
79
- }, interactionProps));
79
+ }, interactionProps, {
80
+ "data-highlighted": isHighlighted || undefined,
81
+ "data-faded": isFaded || undefined
82
+ }));
80
83
  }
81
84
  process.env.NODE_ENV !== "production" ? CircleMarkElement.propTypes = {
82
85
  // ----------------------------- Warning --------------------------------