@mui/x-charts 6.0.0-alpha.9 → 6.18.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 (281) hide show
  1. package/BarChart/BarChart.d.ts +19 -5
  2. package/BarChart/BarChart.js +52 -13
  3. package/BarChart/BarElement.d.ts +1319 -4
  4. package/BarChart/BarElement.js +10 -10
  5. package/BarChart/BarPlot.d.ts +17 -1
  6. package/BarChart/BarPlot.js +152 -66
  7. package/BarChart/formatter.js +2 -3
  8. package/BarChart/legend.js +1 -2
  9. package/CHANGELOG.md +735 -55
  10. package/ChartContainer/index.js +7 -5
  11. package/ChartsAxis/ChartsAxis.d.ts +9 -0
  12. package/ChartsAxis/ChartsAxis.js +28 -2
  13. package/ChartsAxis/axisClasses.d.ts +1 -1
  14. package/ChartsAxis/axisClasses.js +1 -2
  15. package/ChartsAxisHighlight/ChartsAxisHighlight.d.ts +21 -0
  16. package/ChartsAxisHighlight/ChartsAxisHighlight.js +61 -22
  17. package/ChartsClipPath/ChartsClipPath.d.ts +5 -0
  18. package/ChartsClipPath/ChartsClipPath.js +7 -2
  19. package/ChartsLegend/ChartsLegend.d.ts +44 -24
  20. package/ChartsLegend/ChartsLegend.js +192 -150
  21. package/ChartsLegend/chartsLegendClasses.js +1 -2
  22. package/ChartsLegend/utils.d.ts +1 -6
  23. package/ChartsSurface.d.ts +1 -1
  24. package/ChartsSurface.js +9 -18
  25. package/ChartsTooltip/ChartsAxisTooltipContent.d.ts +1 -0
  26. package/ChartsTooltip/ChartsAxisTooltipContent.js +46 -32
  27. package/ChartsTooltip/ChartsItemTooltipContent.d.ts +3 -2
  28. package/ChartsTooltip/ChartsItemTooltipContent.js +18 -9
  29. package/ChartsTooltip/ChartsTooltip.d.ts +32 -0
  30. package/ChartsTooltip/ChartsTooltip.js +62 -18
  31. package/ChartsTooltip/ChartsTooltipTable.d.ts +3 -10
  32. package/ChartsTooltip/ChartsTooltipTable.js +22 -20
  33. package/ChartsTooltip/tooltipClasses.js +1 -2
  34. package/ChartsTooltip/utils.js +2 -2
  35. package/ChartsXAxis/ChartsXAxis.d.ts +9 -0
  36. package/ChartsXAxis/ChartsXAxis.js +161 -40
  37. package/ChartsYAxis/ChartsYAxis.d.ts +9 -0
  38. package/ChartsYAxis/ChartsYAxis.js +86 -33
  39. package/LineChart/AreaElement.d.ts +11 -1
  40. package/LineChart/AreaElement.js +14 -6
  41. package/LineChart/AreaPlot.d.ts +11 -0
  42. package/LineChart/AreaPlot.js +27 -8
  43. package/LineChart/LineChart.d.ts +16 -3
  44. package/LineChart/LineChart.js +48 -13
  45. package/LineChart/LineElement.d.ts +11 -1
  46. package/LineChart/LineElement.js +14 -6
  47. package/LineChart/LineHighlightElement.d.ts +10 -0
  48. package/LineChart/LineHighlightElement.js +13 -4
  49. package/LineChart/LineHighlightPlot.d.ts +10 -0
  50. package/LineChart/LineHighlightPlot.js +14 -3
  51. package/LineChart/LinePlot.d.ts +10 -0
  52. package/LineChart/LinePlot.js +25 -12
  53. package/LineChart/MarkElement.d.ts +10 -0
  54. package/LineChart/MarkElement.js +14 -5
  55. package/LineChart/MarkPlot.d.ts +10 -0
  56. package/LineChart/MarkPlot.js +40 -9
  57. package/LineChart/formatter.js +5 -5
  58. package/LineChart/legend.js +1 -2
  59. package/PieChart/PieArc.d.ts +11 -13
  60. package/PieChart/PieArc.js +28 -60
  61. package/PieChart/PieArcLabel.d.ts +8 -9
  62. package/PieChart/PieArcLabel.js +46 -38
  63. package/PieChart/PieArcLabelPlot.d.ts +28 -0
  64. package/PieChart/PieArcLabelPlot.js +99 -0
  65. package/PieChart/PieArcPlot.d.ts +35 -0
  66. package/PieChart/PieArcPlot.js +92 -0
  67. package/PieChart/PieChart.d.ts +19 -5
  68. package/PieChart/PieChart.js +61 -14
  69. package/PieChart/PiePlot.d.ts +15 -9
  70. package/PieChart/PiePlot.js +77 -55
  71. package/PieChart/dataTransform/transition.d.ts +4 -0
  72. package/PieChart/dataTransform/transition.js +136 -0
  73. package/PieChart/dataTransform/useTransformData.d.ts +15 -0
  74. package/PieChart/dataTransform/useTransformData.js +67 -0
  75. package/PieChart/formatter.js +1 -2
  76. package/PieChart/legend.js +1 -2
  77. package/README.md +8 -14
  78. package/ResponsiveChartContainer/index.js +7 -8
  79. package/ScatterChart/Scatter.d.ts +10 -0
  80. package/ScatterChart/Scatter.js +12 -2
  81. package/ScatterChart/ScatterChart.d.ts +16 -3
  82. package/ScatterChart/ScatterChart.js +43 -12
  83. package/ScatterChart/ScatterPlot.d.ts +10 -0
  84. package/ScatterChart/ScatterPlot.js +12 -2
  85. package/ScatterChart/formatter.js +1 -2
  86. package/ScatterChart/legend.js +1 -2
  87. package/SparkLineChart/SparkLineChart.d.ts +12 -3
  88. package/SparkLineChart/SparkLineChart.js +28 -7
  89. package/colorPalettes/colorPalettes.js +6 -12
  90. package/constants.js +5 -8
  91. package/context/CartesianContextProvider.d.ts +5 -0
  92. package/context/CartesianContextProvider.js +31 -16
  93. package/context/DrawingProvider.d.ts +7 -0
  94. package/context/DrawingProvider.js +12 -6
  95. package/context/HighlightProvider.js +3 -4
  96. package/context/InteractionProvider.js +3 -4
  97. package/context/SeriesContextProvider.js +3 -4
  98. package/esm/BarChart/BarChart.js +49 -9
  99. package/esm/BarChart/BarElement.js +7 -4
  100. package/esm/BarChart/BarPlot.js +152 -67
  101. package/esm/BarChart/formatter.js +1 -1
  102. package/esm/ChartContainer/index.js +3 -0
  103. package/esm/ChartsAxis/ChartsAxis.js +26 -0
  104. package/esm/ChartsAxisHighlight/ChartsAxisHighlight.js +57 -20
  105. package/esm/ChartsClipPath/ChartsClipPath.js +5 -0
  106. package/esm/ChartsLegend/ChartsLegend.js +188 -142
  107. package/esm/ChartsSurface.js +4 -12
  108. package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +44 -30
  109. package/esm/ChartsTooltip/ChartsItemTooltipContent.js +15 -7
  110. package/esm/ChartsTooltip/ChartsTooltip.js +59 -14
  111. package/esm/ChartsTooltip/ChartsTooltipTable.js +17 -10
  112. package/esm/ChartsXAxis/ChartsXAxis.js +158 -37
  113. package/esm/ChartsYAxis/ChartsYAxis.js +83 -30
  114. package/esm/LineChart/AreaElement.js +10 -0
  115. package/esm/LineChart/AreaPlot.js +26 -6
  116. package/esm/LineChart/LineChart.js +45 -9
  117. package/esm/LineChart/LineElement.js +10 -0
  118. package/esm/LineChart/LineHighlightElement.js +10 -0
  119. package/esm/LineChart/LineHighlightPlot.js +12 -1
  120. package/esm/LineChart/LinePlot.js +25 -14
  121. package/esm/LineChart/MarkElement.js +11 -1
  122. package/esm/LineChart/MarkPlot.js +38 -7
  123. package/esm/LineChart/formatter.js +7 -3
  124. package/esm/PieChart/PieArc.js +26 -58
  125. package/esm/PieChart/PieArcLabel.js +43 -34
  126. package/esm/PieChart/PieArcLabelPlot.js +92 -0
  127. package/esm/PieChart/PieArcPlot.js +84 -0
  128. package/esm/PieChart/PieChart.js +59 -12
  129. package/esm/PieChart/PiePlot.js +76 -57
  130. package/esm/PieChart/dataTransform/transition.js +130 -0
  131. package/esm/PieChart/dataTransform/useTransformData.js +59 -0
  132. package/esm/ResponsiveChartContainer/index.js +3 -3
  133. package/esm/ScatterChart/Scatter.js +10 -0
  134. package/esm/ScatterChart/ScatterChart.js +40 -8
  135. package/esm/ScatterChart/ScatterPlot.js +10 -0
  136. package/esm/SparkLineChart/SparkLineChart.js +25 -3
  137. package/esm/constants.js +1 -1
  138. package/esm/context/CartesianContextProvider.js +30 -14
  139. package/esm/context/DrawingProvider.js +8 -0
  140. package/esm/hooks/useChartDimensions.js +2 -0
  141. package/esm/hooks/useMounted.js +16 -0
  142. package/esm/hooks/useReducedMotion.js +27 -0
  143. package/esm/hooks/useTicks.js +15 -9
  144. package/esm/internals/components/AxisSharedComponents.js +15 -70
  145. package/esm/internals/components/ChartsText.js +77 -0
  146. package/esm/internals/domUtils.js +113 -0
  147. package/esm/internals/geometry.js +36 -0
  148. package/hooks/useAxisEvents.js +2 -2
  149. package/hooks/useChartDimensions.d.ts +2 -0
  150. package/hooks/useChartDimensions.js +5 -4
  151. package/hooks/useDrawingArea.js +2 -2
  152. package/hooks/useInteractionItemProps.js +2 -2
  153. package/hooks/useMounted.d.ts +1 -0
  154. package/hooks/useMounted.js +25 -0
  155. package/hooks/useReducedMotion.d.ts +8 -0
  156. package/hooks/useReducedMotion.js +33 -0
  157. package/hooks/useScale.d.ts +2 -2
  158. package/hooks/useScale.js +2 -2
  159. package/hooks/useTicks.d.ts +19 -11
  160. package/hooks/useTicks.js +19 -14
  161. package/index.js +1 -1
  162. package/internals/components/AxisSharedComponents.d.ts +0 -4
  163. package/internals/components/AxisSharedComponents.js +18 -78
  164. package/internals/components/ChartsText.d.ts +35 -0
  165. package/internals/components/ChartsText.js +87 -0
  166. package/internals/defaultizeColor.d.ts +7 -2
  167. package/internals/defaultizeValueFormatter.js +1 -2
  168. package/internals/domUtils.d.ts +13 -0
  169. package/internals/domUtils.js +122 -0
  170. package/internals/geometry.d.ts +9 -0
  171. package/internals/geometry.js +42 -0
  172. package/internals/stackSeries.js +2 -4
  173. package/legacy/BarChart/BarChart.js +49 -9
  174. package/legacy/BarChart/BarElement.js +6 -3
  175. package/legacy/BarChart/BarPlot.js +151 -63
  176. package/legacy/BarChart/formatter.js +1 -1
  177. package/legacy/ChartContainer/index.js +3 -0
  178. package/legacy/ChartsAxis/ChartsAxis.js +26 -0
  179. package/legacy/ChartsAxisHighlight/ChartsAxisHighlight.js +60 -20
  180. package/legacy/ChartsClipPath/ChartsClipPath.js +5 -0
  181. package/legacy/ChartsLegend/ChartsLegend.js +203 -140
  182. package/legacy/ChartsSurface.js +3 -12
  183. package/legacy/ChartsTooltip/ChartsAxisTooltipContent.js +22 -10
  184. package/legacy/ChartsTooltip/ChartsItemTooltipContent.js +15 -7
  185. package/legacy/ChartsTooltip/ChartsTooltip.js +62 -14
  186. package/legacy/ChartsTooltip/ChartsTooltipTable.js +34 -26
  187. package/legacy/ChartsXAxis/ChartsXAxis.js +162 -39
  188. package/legacy/ChartsYAxis/ChartsYAxis.js +83 -30
  189. package/legacy/LineChart/AreaElement.js +10 -0
  190. package/legacy/LineChart/AreaPlot.js +31 -7
  191. package/legacy/LineChart/LineChart.js +45 -9
  192. package/legacy/LineChart/LineElement.js +10 -0
  193. package/legacy/LineChart/LineHighlightElement.js +10 -0
  194. package/legacy/LineChart/LineHighlightPlot.js +12 -1
  195. package/legacy/LineChart/LinePlot.js +29 -12
  196. package/legacy/LineChart/MarkElement.js +11 -1
  197. package/legacy/LineChart/MarkPlot.js +37 -7
  198. package/legacy/LineChart/formatter.js +7 -3
  199. package/legacy/PieChart/PieArc.js +30 -62
  200. package/legacy/PieChart/PieArcLabel.js +48 -34
  201. package/legacy/PieChart/PieArcLabelPlot.js +93 -0
  202. package/legacy/PieChart/PieArcPlot.js +84 -0
  203. package/legacy/PieChart/PieChart.js +59 -12
  204. package/legacy/PieChart/PiePlot.js +76 -59
  205. package/legacy/PieChart/dataTransform/transition.js +142 -0
  206. package/legacy/PieChart/dataTransform/useTransformData.js +60 -0
  207. package/legacy/ResponsiveChartContainer/index.js +3 -3
  208. package/legacy/ScatterChart/Scatter.js +10 -0
  209. package/legacy/ScatterChart/ScatterChart.js +40 -8
  210. package/legacy/ScatterChart/ScatterPlot.js +10 -0
  211. package/legacy/SparkLineChart/SparkLineChart.js +25 -3
  212. package/legacy/constants.js +1 -1
  213. package/legacy/context/CartesianContextProvider.js +30 -14
  214. package/legacy/context/DrawingProvider.js +8 -0
  215. package/legacy/hooks/useChartDimensions.js +2 -0
  216. package/legacy/hooks/useMounted.js +21 -0
  217. package/legacy/hooks/useReducedMotion.js +27 -0
  218. package/legacy/hooks/useTicks.js +16 -9
  219. package/legacy/index.js +1 -1
  220. package/legacy/internals/components/AxisSharedComponents.js +11 -65
  221. package/legacy/internals/components/ChartsText.js +79 -0
  222. package/legacy/internals/domUtils.js +121 -0
  223. package/legacy/internals/geometry.js +37 -0
  224. package/models/axis.d.ts +27 -9
  225. package/models/layout.d.ts +7 -6
  226. package/models/seriesType/line.d.ts +8 -3
  227. package/models/seriesType/pie.d.ts +5 -1
  228. package/modern/BarChart/BarChart.js +49 -9
  229. package/modern/BarChart/BarElement.js +7 -4
  230. package/modern/BarChart/BarPlot.js +149 -65
  231. package/modern/BarChart/formatter.js +1 -1
  232. package/modern/ChartContainer/index.js +3 -0
  233. package/modern/ChartsAxis/ChartsAxis.js +26 -0
  234. package/modern/ChartsAxisHighlight/ChartsAxisHighlight.js +57 -20
  235. package/modern/ChartsClipPath/ChartsClipPath.js +5 -0
  236. package/modern/ChartsLegend/ChartsLegend.js +188 -142
  237. package/modern/ChartsSurface.js +4 -12
  238. package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +44 -30
  239. package/modern/ChartsTooltip/ChartsItemTooltipContent.js +15 -7
  240. package/modern/ChartsTooltip/ChartsTooltip.js +58 -14
  241. package/modern/ChartsTooltip/ChartsTooltipTable.js +17 -10
  242. package/modern/ChartsXAxis/ChartsXAxis.js +158 -37
  243. package/modern/ChartsYAxis/ChartsYAxis.js +83 -30
  244. package/modern/LineChart/AreaElement.js +10 -0
  245. package/modern/LineChart/AreaPlot.js +25 -6
  246. package/modern/LineChart/LineChart.js +45 -9
  247. package/modern/LineChart/LineElement.js +10 -0
  248. package/modern/LineChart/LineHighlightElement.js +10 -0
  249. package/modern/LineChart/LineHighlightPlot.js +12 -1
  250. package/modern/LineChart/LinePlot.js +23 -10
  251. package/modern/LineChart/MarkElement.js +11 -1
  252. package/modern/LineChart/MarkPlot.js +38 -7
  253. package/modern/LineChart/formatter.js +4 -3
  254. package/modern/PieChart/PieArc.js +26 -57
  255. package/modern/PieChart/PieArcLabel.js +43 -34
  256. package/modern/PieChart/PieArcLabelPlot.js +90 -0
  257. package/modern/PieChart/PieArcPlot.js +83 -0
  258. package/modern/PieChart/PieChart.js +59 -12
  259. package/modern/PieChart/PiePlot.js +76 -55
  260. package/modern/PieChart/dataTransform/transition.js +130 -0
  261. package/modern/PieChart/dataTransform/useTransformData.js +58 -0
  262. package/modern/ResponsiveChartContainer/index.js +3 -3
  263. package/modern/ScatterChart/Scatter.js +10 -0
  264. package/modern/ScatterChart/ScatterChart.js +40 -8
  265. package/modern/ScatterChart/ScatterPlot.js +10 -0
  266. package/modern/SparkLineChart/SparkLineChart.js +25 -3
  267. package/modern/constants.js +1 -1
  268. package/modern/context/CartesianContextProvider.js +29 -13
  269. package/modern/context/DrawingProvider.js +8 -0
  270. package/modern/hooks/useChartDimensions.js +2 -0
  271. package/modern/hooks/useMounted.js +16 -0
  272. package/modern/hooks/useReducedMotion.js +27 -0
  273. package/modern/hooks/useTicks.js +15 -9
  274. package/modern/index.js +1 -1
  275. package/modern/internals/components/AxisSharedComponents.js +15 -70
  276. package/modern/internals/components/ChartsText.js +77 -0
  277. package/modern/internals/domUtils.js +113 -0
  278. package/modern/internals/geometry.js +36 -0
  279. package/package.json +9 -6
  280. package/themeAugmentation/components.d.ts +1 -0
  281. package/themeAugmentation/overrides.d.ts +2 -0
@@ -12,9 +12,10 @@ import { getScale } from '../internals/getScale';
12
12
  import { DrawingContext } from './DrawingProvider';
13
13
  import { SeriesContext } from './SeriesContextProvider';
14
14
  import { DEFAULT_X_AXIS_KEY, DEFAULT_Y_AXIS_KEY } from '../constants';
15
- import { getTicksNumber } from '../hooks/useTicks';
15
+ import { getTickNumber } from '../hooks/useTicks';
16
16
  import { jsx as _jsx } from "react/jsx-runtime";
17
- var DEFAULT_CATEGORY_GAP_RATIO = 0.1;
17
+ var DEFAULT_CATEGORY_GAP_RATIO = 0.2;
18
+ var DEFAULT_BAR_GAP_RATIO = 0.1;
18
19
 
19
20
  // TODO: those might be better placed in a distinct file
20
21
  var xExtremumGetters = {
@@ -33,6 +34,12 @@ export var CartesianContext = /*#__PURE__*/React.createContext({
33
34
  xAxisIds: [],
34
35
  yAxisIds: []
35
36
  });
37
+
38
+ /**
39
+ * API:
40
+ *
41
+ * - [CartesianContextProvider API](https://mui.com/x/api/charts/cartesian-context-provider/)
42
+ */
36
43
  function CartesianContextProvider(_ref) {
37
44
  var inXAxis = _ref.xAxis,
38
45
  inYAxis = _ref.yAxis,
@@ -124,20 +131,21 @@ function CartesianContextProvider(_ref) {
124
131
  maxData = _getAxisExtremum2[1];
125
132
  var range = [drawingArea.left, drawingArea.left + drawingArea.width];
126
133
  if (isBandScaleConfig(axis)) {
127
- var _axis$categoryGapRati;
134
+ var _axis$categoryGapRati, _axis$barGapRatio;
128
135
  var categoryGapRatio = (_axis$categoryGapRati = axis.categoryGapRatio) != null ? _axis$categoryGapRati : DEFAULT_CATEGORY_GAP_RATIO;
136
+ var barGapRatio = (_axis$barGapRatio = axis.barGapRatio) != null ? _axis$barGapRatio : DEFAULT_BAR_GAP_RATIO;
129
137
  completedXAxis[axis.id] = _extends({
130
138
  categoryGapRatio: categoryGapRatio,
131
- barGapRatio: 0
139
+ barGapRatio: barGapRatio
132
140
  }, axis, {
133
141
  scale: scaleBand(axis.data, range).paddingInner(categoryGapRatio).paddingOuter(categoryGapRatio / 2),
134
- ticksNumber: axis.data.length
142
+ tickNumber: axis.data.length
135
143
  });
136
144
  }
137
145
  if (isPointScaleConfig(axis)) {
138
146
  completedXAxis[axis.id] = _extends({}, axis, {
139
147
  scale: scalePoint(axis.data, range),
140
- ticksNumber: axis.data.length
148
+ tickNumber: axis.data.length
141
149
  });
142
150
  }
143
151
  if (axis.scaleType === 'band' || axis.scaleType === 'point') {
@@ -146,17 +154,17 @@ function CartesianContextProvider(_ref) {
146
154
  }
147
155
  var scaleType = (_axis$scaleType = axis.scaleType) != null ? _axis$scaleType : 'linear';
148
156
  var extremums = [(_axis$min = axis.min) != null ? _axis$min : minData, (_axis$max = axis.max) != null ? _axis$max : maxData];
149
- var ticksNumber = getTicksNumber(_extends({}, axis, {
157
+ var tickNumber = getTickNumber(_extends({}, axis, {
150
158
  range: range,
151
159
  domain: extremums
152
160
  }));
153
- var niceScale = getScale(scaleType, extremums, range).nice(ticksNumber);
161
+ var niceScale = getScale(scaleType, extremums, range).nice(tickNumber);
154
162
  var niceDomain = niceScale.domain();
155
163
  var domain = [(_axis$min2 = axis.min) != null ? _axis$min2 : niceDomain[0], (_axis$max2 = axis.max) != null ? _axis$max2 : niceDomain[1]];
156
164
  completedXAxis[axis.id] = _extends({}, axis, {
157
165
  scaleType: scaleType,
158
166
  scale: niceScale.domain(domain),
159
- ticksNumber: ticksNumber
167
+ tickNumber: tickNumber
160
168
  });
161
169
  });
162
170
  var allYAxis = [].concat(_toConsumableArray((_yAxis$map = yAxis == null ? void 0 : yAxis.map(function (axis, index) {
@@ -187,13 +195,13 @@ function CartesianContextProvider(_ref) {
187
195
  barGapRatio: 0
188
196
  }, axis, {
189
197
  scale: scaleBand(axis.data, [range[1], range[0]]).paddingInner(categoryGapRatio).paddingOuter(categoryGapRatio / 2),
190
- ticksNumber: axis.data.length
198
+ tickNumber: axis.data.length
191
199
  });
192
200
  }
193
201
  if (isPointScaleConfig(axis)) {
194
202
  completedYAxis[axis.id] = _extends({}, axis, {
195
203
  scale: scalePoint(axis.data, [range[1], range[0]]),
196
- ticksNumber: axis.data.length
204
+ tickNumber: axis.data.length
197
205
  });
198
206
  }
199
207
  if (axis.scaleType === 'band' || axis.scaleType === 'point') {
@@ -202,17 +210,17 @@ function CartesianContextProvider(_ref) {
202
210
  }
203
211
  var scaleType = (_axis$scaleType2 = axis.scaleType) != null ? _axis$scaleType2 : 'linear';
204
212
  var extremums = [(_axis$min3 = axis.min) != null ? _axis$min3 : minData, (_axis$max3 = axis.max) != null ? _axis$max3 : maxData];
205
- var ticksNumber = getTicksNumber(_extends({}, axis, {
213
+ var tickNumber = getTickNumber(_extends({}, axis, {
206
214
  range: range,
207
215
  domain: extremums
208
216
  }));
209
- var niceScale = getScale(scaleType, extremums, range).nice(ticksNumber);
217
+ var niceScale = getScale(scaleType, extremums, range).nice(tickNumber);
210
218
  var niceDomain = niceScale.domain();
211
219
  var domain = [(_axis$min4 = axis.min) != null ? _axis$min4 : niceDomain[0], (_axis$max4 = axis.max) != null ? _axis$max4 : niceDomain[1]];
212
220
  completedYAxis[axis.id] = _extends({}, axis, {
213
221
  scaleType: scaleType,
214
222
  scale: niceScale.domain(domain),
215
- ticksNumber: ticksNumber
223
+ tickNumber: tickNumber
216
224
  });
217
225
  });
218
226
  return {
@@ -254,6 +262,7 @@ process.env.NODE_ENV !== "production" ? CartesianContextProvider.propTypes = {
254
262
  id: PropTypes.string,
255
263
  label: PropTypes.string,
256
264
  labelFontSize: PropTypes.number,
265
+ labelStyle: PropTypes.object,
257
266
  max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
258
267
  min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
259
268
  position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
@@ -262,6 +271,9 @@ process.env.NODE_ENV !== "production" ? CartesianContextProvider.propTypes = {
262
271
  slots: PropTypes.object,
263
272
  stroke: PropTypes.string,
264
273
  tickFontSize: PropTypes.number,
274
+ tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
275
+ tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
276
+ tickLabelStyle: PropTypes.object,
265
277
  tickMaxStep: PropTypes.number,
266
278
  tickMinStep: PropTypes.number,
267
279
  tickNumber: PropTypes.number,
@@ -280,6 +292,7 @@ process.env.NODE_ENV !== "production" ? CartesianContextProvider.propTypes = {
280
292
  id: PropTypes.string,
281
293
  label: PropTypes.string,
282
294
  labelFontSize: PropTypes.number,
295
+ labelStyle: PropTypes.object,
283
296
  max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
284
297
  min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
285
298
  position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
@@ -288,6 +301,9 @@ process.env.NODE_ENV !== "production" ? CartesianContextProvider.propTypes = {
288
301
  slots: PropTypes.object,
289
302
  stroke: PropTypes.string,
290
303
  tickFontSize: PropTypes.number,
304
+ tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
305
+ tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
306
+ tickLabelStyle: PropTypes.object,
291
307
  tickMaxStep: PropTypes.number,
292
308
  tickMinStep: PropTypes.number,
293
309
  tickNumber: PropTypes.number,
@@ -9,12 +9,20 @@ import { jsx as _jsx } from "react/jsx-runtime";
9
9
  export var DrawingContext = /*#__PURE__*/React.createContext({
10
10
  top: 0,
11
11
  left: 0,
12
+ bottom: 0,
13
+ right: 0,
12
14
  height: 300,
13
15
  width: 400
14
16
  });
15
17
  export var SVGContext = /*#__PURE__*/React.createContext({
16
18
  current: null
17
19
  });
20
+
21
+ /**
22
+ * API:
23
+ *
24
+ * - [DrawingProvider API](https://mui.com/x/api/charts/drawing-provider/)
25
+ */
18
26
  function DrawingProvider(_ref) {
19
27
  var width = _ref.width,
20
28
  height = _ref.height,
@@ -7,6 +7,8 @@ var useChartDimensions = function useChartDimensions(width, height, margin) {
7
7
  return {
8
8
  left: defaultizedMargin.left,
9
9
  top: defaultizedMargin.top,
10
+ right: defaultizedMargin.right,
11
+ bottom: defaultizedMargin.bottom,
10
12
  width: Math.max(0, width - defaultizedMargin.left - defaultizedMargin.right),
11
13
  height: Math.max(0, height - defaultizedMargin.top - defaultizedMargin.bottom)
12
14
  };
@@ -0,0 +1,21 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
+ import * as React from 'react';
3
+ import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
4
+ export function useMounted() {
5
+ var defer = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
6
+ var _React$useState = React.useState(false),
7
+ _React$useState2 = _slicedToArray(_React$useState, 2),
8
+ mountedState = _React$useState2[0],
9
+ setMountedState = _React$useState2[1];
10
+ useEnhancedEffect(function () {
11
+ if (!defer) {
12
+ setMountedState(true);
13
+ }
14
+ }, [defer]);
15
+ React.useEffect(function () {
16
+ if (defer) {
17
+ setMountedState(true);
18
+ }
19
+ }, [defer]);
20
+ return mountedState;
21
+ }
@@ -0,0 +1,27 @@
1
+ import { useIsomorphicLayoutEffect, Globals } from '@react-spring/web';
2
+
3
+ /**
4
+ * Returns `boolean` or `null`, used to automatically
5
+ * set skipAnimations to the value of the user's
6
+ * `prefers-reduced-motion` query.
7
+ *
8
+ * The return value, post-effect, is the value of their prefered setting
9
+ */
10
+ export var useReducedMotion = function useReducedMotion() {
11
+ // Taken from: https://github.com/pmndrs/react-spring/blob/02ec877bbfab0df46da0e4a47d5f68d3e731206a/packages/shared/src/hooks/useReducedMotion.ts#L13
12
+
13
+ useIsomorphicLayoutEffect(function () {
14
+ var mql = window.matchMedia('(prefers-reduced-motion)');
15
+ var handleMediaChange = function handleMediaChange(e) {
16
+ Globals.assign({
17
+ // Modification such the react-spring implementation such that this hook can remove animation but never activate animation.
18
+ skipAnimation: e.matches || undefined
19
+ });
20
+ };
21
+ handleMediaChange(mql);
22
+ mql.addEventListener('change', handleMediaChange);
23
+ return function () {
24
+ mql.removeEventListener('change', handleMediaChange);
25
+ };
26
+ }, []);
27
+ };
@@ -1,7 +1,8 @@
1
+ import _typeof from "@babel/runtime/helpers/esm/typeof";
1
2
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
3
  import * as React from 'react';
3
4
  import { isBandScale } from '../internals/isBandScale';
4
- export function getTicksNumber(params) {
5
+ export function getTickNumber(params) {
5
6
  var tickMaxStep = params.tickMaxStep,
6
7
  tickMinStep = params.tickMinStep,
7
8
  tickNumber = params.tickNumber,
@@ -14,8 +15,9 @@ export function getTicksNumber(params) {
14
15
  }
15
16
  function useTicks(options) {
16
17
  var scale = options.scale,
17
- ticksNumber = options.ticksNumber,
18
- valueFormatter = options.valueFormatter;
18
+ tickNumber = options.tickNumber,
19
+ valueFormatter = options.valueFormatter,
20
+ tickInterval = options.tickInterval;
19
21
  return React.useMemo(function () {
20
22
  // band scale
21
23
  if (isBandScale(scale)) {
@@ -25,7 +27,8 @@ function useTicks(options) {
25
27
  return [].concat(_toConsumableArray(domain.map(function (value) {
26
28
  var _valueFormatter;
27
29
  return {
28
- formattedValue: (_valueFormatter = valueFormatter == null ? void 0 : valueFormatter(value)) != null ? _valueFormatter : value,
30
+ value: value,
31
+ formattedValue: (_valueFormatter = valueFormatter == null ? void 0 : valueFormatter(value)) != null ? _valueFormatter : "".concat(value),
29
32
  offset: scale(value) - (scale.step() - scale.bandwidth()) / 2,
30
33
  labelOffset: scale.step() / 2
31
34
  };
@@ -37,23 +40,27 @@ function useTicks(options) {
37
40
  }
38
41
 
39
42
  // scale type = 'point'
40
- return domain.map(function (value) {
43
+ var filteredDomain = typeof tickInterval === 'function' && domain.filter(tickInterval) || _typeof(tickInterval) === 'object' && tickInterval || domain;
44
+ return filteredDomain.map(function (value) {
41
45
  var _valueFormatter2;
42
46
  return {
43
- formattedValue: (_valueFormatter2 = valueFormatter == null ? void 0 : valueFormatter(value)) != null ? _valueFormatter2 : value,
47
+ value: value,
48
+ formattedValue: (_valueFormatter2 = valueFormatter == null ? void 0 : valueFormatter(value)) != null ? _valueFormatter2 : "".concat(value),
44
49
  offset: scale(value),
45
50
  labelOffset: 0
46
51
  };
47
52
  });
48
53
  }
49
- return scale.ticks(ticksNumber).map(function (value) {
54
+ var ticks = _typeof(tickInterval) === 'object' ? tickInterval : scale.ticks(tickNumber);
55
+ return ticks.map(function (value) {
50
56
  var _valueFormatter3;
51
57
  return {
52
- formattedValue: (_valueFormatter3 = valueFormatter == null ? void 0 : valueFormatter(value)) != null ? _valueFormatter3 : scale.tickFormat(ticksNumber)(value),
58
+ value: value,
59
+ formattedValue: (_valueFormatter3 = valueFormatter == null ? void 0 : valueFormatter(value)) != null ? _valueFormatter3 : scale.tickFormat(tickNumber)(value),
53
60
  offset: scale(value),
54
61
  labelOffset: 0
55
62
  };
56
63
  });
57
- }, [ticksNumber, scale, valueFormatter]);
64
+ }, [tickNumber, scale, valueFormatter, tickInterval]);
58
65
  }
59
66
  export default useTicks;
package/legacy/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-charts v6.0.0-alpha.9
2
+ * @mui/x-charts v6.18.0
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -1,6 +1,5 @@
1
- import _extends from "@babel/runtime/helpers/esm/extends";
2
1
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
3
- var _$concat, _styled;
2
+ import _extends from "@babel/runtime/helpers/esm/extends";
4
3
  import { styled } from '@mui/material/styles';
5
4
  import { axisClasses } from '../../ChartsAxis/axisClasses';
6
5
  export var AxisRoot = styled('g', {
@@ -9,72 +8,19 @@ export var AxisRoot = styled('g', {
9
8
  overridesResolver: function overridesResolver(props, styles) {
10
9
  return styles.root;
11
10
  }
12
- })((_styled = {}, _defineProperty(_styled, "&.".concat(axisClasses.directionY), (_$concat = {}, _defineProperty(_$concat, ".".concat(axisClasses.tickLabel), {
13
- dominantBaseline: 'middle'
14
- }), _defineProperty(_$concat, ".".concat(axisClasses.label), {
15
- dominantBaseline: 'auto',
16
- textAnchor: 'middle'
17
- }), _$concat)), _defineProperty(_styled, "&.".concat(axisClasses.left), _defineProperty({}, ".".concat(axisClasses.tickLabel), {
18
- dominantBaseline: 'central',
19
- textAnchor: 'end'
20
- })), _defineProperty(_styled, "&.".concat(axisClasses.right), _defineProperty({}, ".".concat(axisClasses.tickLabel), {
21
- dominantBaseline: 'central',
22
- textAnchor: 'start'
23
- })), _defineProperty(_styled, "&.".concat(axisClasses.bottom), _defineProperty({}, ".".concat(axisClasses.tickLabel, ", .").concat(axisClasses.label), {
24
- dominantBaseline: 'hanging',
25
- textAnchor: 'middle'
26
- })), _defineProperty(_styled, "&.".concat(axisClasses.top), _defineProperty({}, ".".concat(axisClasses.tickLabel, ", .").concat(axisClasses.label), {
27
- dominantBaseline: 'baseline',
28
- textAnchor: 'middle'
29
- })), _styled));
30
- export var ChartsLine = styled('line', {
31
- name: 'MuiChartsAxis',
32
- slot: 'Line',
33
- overridesResolver: function overridesResolver(props, styles) {
34
- return styles.line;
35
- }
36
11
  })(function (_ref) {
12
+ var _ref2;
37
13
  var theme = _ref.theme;
38
- return {
39
- stroke: theme.palette.text.primary,
14
+ return _ref2 = {}, _defineProperty(_ref2, "& .".concat(axisClasses.tickLabel), _extends({}, theme.typography.caption, {
15
+ fill: (theme.vars || theme).palette.text.primary
16
+ })), _defineProperty(_ref2, "& .".concat(axisClasses.label), _extends({}, theme.typography.body1, {
17
+ fill: (theme.vars || theme).palette.text.primary
18
+ })), _defineProperty(_ref2, "& .".concat(axisClasses.line), {
19
+ stroke: (theme.vars || theme).palette.text.primary,
40
20
  shapeRendering: 'crispEdges',
41
21
  strokeWidth: 1
42
- };
43
- });
44
- export var ChartsTick = styled('line', {
45
- name: 'MuiChartsAxis',
46
- slot: 'Tick',
47
- overridesResolver: function overridesResolver(props, styles) {
48
- return styles.tick;
49
- }
50
- })(function (_ref2) {
51
- var theme = _ref2.theme;
52
- return {
53
- stroke: theme.palette.text.primary,
22
+ }), _defineProperty(_ref2, "& .".concat(axisClasses.tick), {
23
+ stroke: (theme.vars || theme).palette.text.primary,
54
24
  shapeRendering: 'crispEdges'
55
- };
56
- });
57
- export var ChartsTickLabel = styled('text', {
58
- name: 'MuiChartsAxis',
59
- slot: 'TickLabel',
60
- overridesResolver: function overridesResolver(props, styles) {
61
- return styles.tickLabel;
62
- }
63
- })(function (_ref3) {
64
- var theme = _ref3.theme;
65
- return _extends({}, theme.typography.caption, {
66
- fill: theme.palette.text.primary
67
- });
68
- });
69
- export var ChartsLabel = styled('text', {
70
- name: 'MuiChartsAxis',
71
- slot: 'Label',
72
- overridesResolver: function overridesResolver(props, styles) {
73
- return styles.label;
74
- }
75
- })(function (_ref4) {
76
- var theme = _ref4.theme;
77
- return _extends({}, theme.typography.body1, {
78
- fill: theme.palette.text.primary
79
- });
25
+ }), _ref2;
80
26
  });
@@ -0,0 +1,79 @@
1
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
2
+ import _extends from "@babel/runtime/helpers/esm/extends";
3
+ var _excluded = ["x", "y", "style", "text", "ownerState"],
4
+ _excluded2 = ["angle", "textAnchor", "dominantBaseline"];
5
+ import * as React from 'react';
6
+ import { getStringSize } from '../domUtils';
7
+ import { jsx as _jsx } from "react/jsx-runtime";
8
+ export function getWordsByLines(_ref) {
9
+ var style = _ref.style,
10
+ needsComputation = _ref.needsComputation,
11
+ text = _ref.text;
12
+ return text.split('\n').map(function (subText) {
13
+ return _extends({
14
+ text: subText
15
+ }, needsComputation ? getStringSize(subText, style) : {
16
+ width: 0,
17
+ height: 0
18
+ });
19
+ });
20
+ }
21
+ export function ChartsText(props) {
22
+ var x = props.x,
23
+ y = props.y,
24
+ styleProps = props.style,
25
+ text = props.text,
26
+ ownerState = props.ownerState,
27
+ textProps = _objectWithoutProperties(props, _excluded);
28
+ var _ref2 = styleProps != null ? styleProps : {},
29
+ angle = _ref2.angle,
30
+ textAnchor = _ref2.textAnchor,
31
+ dominantBaseline = _ref2.dominantBaseline,
32
+ style = _objectWithoutProperties(_ref2, _excluded2);
33
+ var wordsByLines = React.useMemo(function () {
34
+ return getWordsByLines({
35
+ style: style,
36
+ needsComputation: text.includes('\n'),
37
+ text: text
38
+ });
39
+ }, [style, text]);
40
+ var startDy;
41
+ switch (dominantBaseline) {
42
+ case 'hanging':
43
+ startDy = 0;
44
+ break;
45
+ case 'central':
46
+ startDy = (wordsByLines.length - 1) / 2 * -wordsByLines[0].height;
47
+ break;
48
+ default:
49
+ startDy = (wordsByLines.length - 1) * -wordsByLines[0].height;
50
+ break;
51
+ }
52
+ var transforms = [];
53
+ // if (scaleToFit) {
54
+ // const lineWidth = wordsByLines[0].width;
55
+ // transforms.push(`scale(${(isNumber(width as number) ? (width as number) / lineWidth : 1) / lineWidth})`);
56
+ // }
57
+ if (angle) {
58
+ transforms.push("rotate(".concat(angle, ", ").concat(x, ", ").concat(y, ")"));
59
+ }
60
+ if (transforms.length) {
61
+ textProps.transform = transforms.join(' ');
62
+ }
63
+ return /*#__PURE__*/_jsx("text", _extends({}, textProps, {
64
+ x: x,
65
+ y: y,
66
+ textAnchor: textAnchor,
67
+ dominantBaseline: dominantBaseline,
68
+ style: style,
69
+ children: wordsByLines.map(function (line, index) {
70
+ return /*#__PURE__*/_jsx("tspan", {
71
+ x: x,
72
+ dy: "".concat(index === 0 ? startDy : wordsByLines[0].height, "px"),
73
+ dominantBaseline: dominantBaseline // Propagated to fix Safari issue: https://github.com/mui/mui-x/issues/10808
74
+ ,
75
+ children: line.text
76
+ }, index);
77
+ })
78
+ }));
79
+ }
@@ -0,0 +1,121 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
3
+ // DOM utils taken from
4
+ // https://github.com/recharts/recharts/blob/master/src/util/DOMUtils.ts
5
+
6
+ var isSsr = function isSsr() {
7
+ return !(typeof window !== 'undefined' && window.document && window.setTimeout);
8
+ };
9
+ var stringCache = {
10
+ widthCache: {},
11
+ cacheCount: 0
12
+ };
13
+ var MAX_CACHE_NUM = 2000;
14
+ var SPAN_STYLE = {
15
+ position: 'absolute',
16
+ top: '-20000px',
17
+ left: 0,
18
+ padding: 0,
19
+ margin: 0,
20
+ border: 'none',
21
+ whiteSpace: 'pre'
22
+ };
23
+ var STYLE_LIST = ['minWidth', 'maxWidth', 'width', 'minHeight', 'maxHeight', 'height', 'top', 'left', 'fontSize', 'padding', 'margin', 'paddingLeft', 'paddingRight', 'paddingTop', 'paddingBottom', 'marginLeft', 'marginRight', 'marginTop', 'marginBottom'];
24
+ var MEASUREMENT_SPAN_ID = 'mui_measurement_span';
25
+
26
+ /**
27
+ *
28
+ * @param name CSS property name
29
+ * @param value
30
+ * @returns add 'px' for distance properties
31
+ */
32
+ function autoCompleteStyle(name, value) {
33
+ if (STYLE_LIST.indexOf(name) >= 0 && value === +value) {
34
+ return "".concat(value, "px");
35
+ }
36
+ return value;
37
+ }
38
+
39
+ /**
40
+ *
41
+ * @param text camelcase css property
42
+ * @returns css property
43
+ */
44
+ function camelToMiddleLine(text) {
45
+ var strs = text.split('');
46
+ var formatStrs = strs.reduce(function (result, entry) {
47
+ if (entry === entry.toUpperCase()) {
48
+ return [].concat(_toConsumableArray(result), ['-', entry.toLowerCase()]);
49
+ }
50
+ return [].concat(_toConsumableArray(result), [entry]);
51
+ }, []);
52
+ return formatStrs.join('');
53
+ }
54
+
55
+ /**
56
+ *
57
+ * @param style React style object
58
+ * @returns CSS styling string
59
+ */
60
+ export var getStyleString = function getStyleString(style) {
61
+ return Object.keys(style).sort().reduce(function (result, s) {
62
+ return "".concat(result).concat(camelToMiddleLine(s), ":").concat(autoCompleteStyle(s, style[s]), ";");
63
+ }, '');
64
+ };
65
+
66
+ /**
67
+ *
68
+ * @param text The string to estimate
69
+ * @param style The style applied
70
+ * @returns width and height of the text
71
+ */
72
+ export var getStringSize = function getStringSize(text) {
73
+ var style = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
74
+ if (text === undefined || text === null || isSsr()) {
75
+ return {
76
+ width: 0,
77
+ height: 0
78
+ };
79
+ }
80
+ var str = "".concat(text);
81
+ var styleString = getStyleString(style);
82
+ var cacheKey = "".concat(str, "-").concat(styleString);
83
+ if (stringCache.widthCache[cacheKey]) {
84
+ return stringCache.widthCache[cacheKey];
85
+ }
86
+ try {
87
+ var measurementSpan = document.getElementById(MEASUREMENT_SPAN_ID);
88
+ if (measurementSpan === null) {
89
+ measurementSpan = document.createElement('span');
90
+ measurementSpan.setAttribute('id', MEASUREMENT_SPAN_ID);
91
+ measurementSpan.setAttribute('aria-hidden', 'true');
92
+ document.body.appendChild(measurementSpan);
93
+ }
94
+ // Need to use CSS Object Model (CSSOM) to be able to comply with Content Security Policy (CSP)
95
+ // https://en.wikipedia.org/wiki/Content_Security_Policy
96
+ var measurementSpanStyle = _extends({}, SPAN_STYLE, style);
97
+ Object.keys(measurementSpanStyle).map(function (styleKey) {
98
+ measurementSpan.style[camelToMiddleLine(styleKey)] = autoCompleteStyle(styleKey, measurementSpanStyle[styleKey]);
99
+ return styleKey;
100
+ });
101
+ measurementSpan.textContent = str;
102
+ var rect = measurementSpan.getBoundingClientRect();
103
+ var result = {
104
+ width: rect.width,
105
+ height: rect.height
106
+ };
107
+ stringCache.widthCache[cacheKey] = result;
108
+ if (stringCache.cacheCount + 1 > MAX_CACHE_NUM) {
109
+ stringCache.cacheCount = 0;
110
+ stringCache.widthCache = {};
111
+ } else {
112
+ stringCache.cacheCount += 1;
113
+ }
114
+ return result;
115
+ } catch (e) {
116
+ return {
117
+ width: 0,
118
+ height: 0
119
+ };
120
+ }
121
+ };
@@ -0,0 +1,37 @@
1
+ var ANGLE_APPROX = 5; // Angle (in deg) for which we approximate the rectangle as perfectly horizontal/vertical
2
+
3
+ var warnedOnce = false;
4
+
5
+ /**
6
+ * Return the minimal translation along the x-axis to avoid overflow of a rectangle of a given width, height, and rotation.
7
+ * This assumes that all rectangles have the same height and angle between -90 and 90.
8
+ * Otherwise it would be problematic because you need the height/width of the next rectangle to do the correct computation.
9
+ * @param width the side along the x axis.
10
+ * @param height the side along the y axis.
11
+ * @param angle the rotation in degrees.
12
+ */
13
+ export function getMinXTranslation(width, height) {
14
+ var angle = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
15
+ if (process.env.NODE_ENV !== 'production') {
16
+ if (!warnedOnce && angle > 90 && angle < -90) {
17
+ warnedOnce = true;
18
+ console.warn(["MUI X: It seems you applied an angle larger than 90\xB0 or smaller than -90\xB0 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'));
19
+ }
20
+ }
21
+ var standardAngle = Math.min(Math.abs(angle) % 180, Math.abs(Math.abs(angle) % 180 - 180) % 180); // Map from R to [0, 90]
22
+
23
+ if (standardAngle < ANGLE_APPROX) {
24
+ // It's nearly horizontal
25
+ return width;
26
+ }
27
+ if (standardAngle > 90 - ANGLE_APPROX) {
28
+ // It's nearly vertical
29
+ return height;
30
+ }
31
+ var radAngle = standardAngle * Math.PI / 180;
32
+ var angleSwich = Math.atan2(height, width);
33
+ if (radAngle < angleSwich) {
34
+ return width / Math.cos(radAngle);
35
+ }
36
+ return height / Math.sin(radAngle);
37
+ }