@mui/x-charts 8.0.0-alpha.6 → 8.0.0-alpha.7

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 (251) hide show
  1. package/BarChart/AnimatedBarElement.js +1 -0
  2. package/BarChart/BarChart.js +17 -7
  3. package/BarChart/BarLabel/BarLabel.d.ts +1 -479
  4. package/BarChart/BarLabel/barLabelClasses.d.ts +1 -1
  5. package/BarChart/legend.js +1 -0
  6. package/BarChart/useBarChartProps.d.ts +4 -2
  7. package/BarChart/useBarChartProps.js +16 -3
  8. package/CHANGELOG.md +127 -1
  9. package/ChartsLabel/ChartsLabel.d.ts +2 -3
  10. package/ChartsLabel/ChartsLabel.js +3 -18
  11. package/ChartsLabel/ChartsLabelGradient.d.ts +9 -8
  12. package/ChartsLabel/ChartsLabelGradient.js +21 -18
  13. package/ChartsLabel/ChartsLabelMark.d.ts +2 -3
  14. package/ChartsLabel/ChartsLabelMark.js +5 -2
  15. package/ChartsLabel/index.d.ts +7 -0
  16. package/ChartsLabel/index.js +6 -0
  17. package/ChartsLabel/labelClasses.d.ts +0 -1
  18. package/ChartsLabel/labelGradientClasses.d.ts +5 -4
  19. package/ChartsLabel/labelGradientClasses.js +3 -2
  20. package/ChartsLabel/labelMarkClasses.d.ts +3 -2
  21. package/ChartsLabel/labelMarkClasses.js +3 -2
  22. package/ChartsLabel/package.json +6 -0
  23. package/ChartsLegend/ChartsLegend.d.ts +18 -22
  24. package/ChartsLegend/ChartsLegend.js +100 -109
  25. package/ChartsLegend/ContinuousColorLegend.d.ts +29 -38
  26. package/ChartsLegend/ContinuousColorLegend.js +198 -321
  27. package/ChartsLegend/PiecewiseColorLegend.d.ts +27 -19
  28. package/ChartsLegend/PiecewiseColorLegend.js +201 -111
  29. package/ChartsLegend/chartsLegend.types.d.ts +17 -60
  30. package/ChartsLegend/chartsLegendClasses.d.ts +7 -8
  31. package/ChartsLegend/chartsLegendClasses.js +16 -2
  32. package/ChartsLegend/colorLegend.types.d.ts +13 -0
  33. package/ChartsLegend/colorLegend.types.js +1 -0
  34. package/ChartsLegend/continuousColorLegendClasses.d.ts +26 -0
  35. package/ChartsLegend/continuousColorLegendClasses.js +23 -0
  36. package/ChartsLegend/direction.d.ts +1 -0
  37. package/ChartsLegend/direction.js +1 -0
  38. package/ChartsLegend/index.d.ts +13 -3
  39. package/ChartsLegend/index.js +9 -3
  40. package/ChartsLegend/legend.types.d.ts +10 -54
  41. package/ChartsLegend/legendContext.types.d.ts +55 -0
  42. package/ChartsLegend/legendContext.types.js +1 -0
  43. package/ChartsLegend/onClickContextBuilder.d.ts +2 -0
  44. package/ChartsLegend/onClickContextBuilder.js +7 -0
  45. package/ChartsLegend/piecewiseColorDefaultLabelFormatter.d.ts +2 -0
  46. package/ChartsLegend/piecewiseColorDefaultLabelFormatter.js +9 -0
  47. package/ChartsLegend/piecewiseColorLegend.types.d.ts +26 -0
  48. package/ChartsLegend/piecewiseColorLegend.types.js +1 -0
  49. package/ChartsLegend/piecewiseColorLegendClasses.d.ts +28 -0
  50. package/ChartsLegend/piecewiseColorLegendClasses.js +23 -0
  51. package/ChartsLegend/useAxis.d.ts +1 -1
  52. package/ChartsLegend/useAxis.js +0 -1
  53. package/ChartsReferenceLine/ChartsXReferenceLine.d.ts +1 -1
  54. package/ChartsReferenceLine/ChartsYReferenceLine.d.ts +1 -1
  55. package/ChartsSurface/ChartsSurface.js +0 -1
  56. package/ChartsTooltip/chartsTooltipClasses.d.ts +1 -1
  57. package/LineChart/AnimatedArea.js +1 -0
  58. package/LineChart/AnimatedLine.js +1 -0
  59. package/LineChart/AppearingMask.js +1 -0
  60. package/LineChart/CircleMarkElement.js +1 -0
  61. package/LineChart/LineChart.js +20 -10
  62. package/LineChart/MarkElement.js +3 -1
  63. package/LineChart/legend.js +1 -0
  64. package/LineChart/useLineChartProps.d.ts +4 -2
  65. package/LineChart/useLineChartProps.js +15 -2
  66. package/PieChart/PieArc.js +3 -1
  67. package/PieChart/PieArcLabel.js +13 -9
  68. package/PieChart/PieArcLabelPlot.js +1 -0
  69. package/PieChart/PieArcPlot.js +1 -0
  70. package/PieChart/PieChart.js +42 -41
  71. package/PieChart/legend.js +1 -0
  72. package/ScatterChart/ScatterChart.js +21 -11
  73. package/ScatterChart/legend.js +1 -0
  74. package/ScatterChart/useScatterChartProps.d.ts +4 -2
  75. package/ScatterChart/useScatterChartProps.js +15 -2
  76. package/SparkLineChart/SparkLineChart.js +1 -4
  77. package/constants/index.d.ts +1 -0
  78. package/constants/index.js +2 -1
  79. package/context/CartesianProvider/defaultizeAxis.d.ts +9 -9
  80. package/context/ChartDataProvider/useChartDataProviderProps.d.ts +18 -18
  81. package/context/ChartDataProvider/useDefaultizeAxis.d.ts +9 -9
  82. package/context/ChartProvider/ChartProvider.types.d.ts +1 -1
  83. package/context/InteractionSelectors.d.ts +11 -11
  84. package/context/PluginProvider/SeriesFormatter.types.d.ts +1 -1
  85. package/context/PluginProvider/mergePlugins.d.ts +8 -8
  86. package/context/SizeProvider/Size.types.d.ts +1 -1
  87. package/context/SizeProvider/useChartContainerDimensions.d.ts +1 -1
  88. package/hooks/index.d.ts +1 -0
  89. package/hooks/index.js +2 -1
  90. package/hooks/useLegend.d.ts +13 -0
  91. package/{modern/ChartsLegend/utils.js → hooks/useLegend.js} +20 -1
  92. package/hooks/useSvgRef.d.ts +1 -1
  93. package/index.d.ts +1 -0
  94. package/index.js +2 -1
  95. package/internals/calculateMargins.d.ts +7 -0
  96. package/internals/calculateMargins.js +25 -0
  97. package/internals/components/ChartsAxesGradients/ChartsAxesGradients.d.ts +2 -1
  98. package/internals/components/ChartsAxesGradients/ChartsAxesGradients.js +60 -16
  99. package/internals/components/ChartsAxesGradients/ChartsContinuousGradient.js +6 -6
  100. package/internals/components/ChartsAxesGradients/ChartsContinuousGradientObjectBound.d.ts +13 -0
  101. package/internals/components/ChartsAxesGradients/ChartsContinuousGradientObjectBound.js +61 -0
  102. package/internals/components/ChartsAxesGradients/ChartsPiecewiseGradient.js +3 -0
  103. package/internals/components/ChartsWrapper/ChartsWrapper.d.ts +17 -0
  104. package/internals/components/ChartsWrapper/ChartsWrapper.js +66 -0
  105. package/internals/components/ChartsWrapper/index.d.ts +1 -0
  106. package/internals/components/ChartsWrapper/index.js +1 -0
  107. package/internals/consumeSlots.d.ts +48 -0
  108. package/internals/consumeSlots.js +101 -0
  109. package/internals/consumeThemeProps.d.ts +3 -7
  110. package/internals/consumeThemeProps.js +18 -27
  111. package/internals/defaultizeColor.d.ts +6 -1
  112. package/internals/index.d.ts +1 -0
  113. package/internals/index.js +1 -0
  114. package/internals/plugins/corePlugins/useChartId/useChartId.selectors.d.ts +1 -1
  115. package/internals/plugins/featurePlugins/useChartInteraction/useChartInteraction.selectors.d.ts +11 -11
  116. package/internals/plugins/models/plugin.d.ts +1 -1
  117. package/internals/store/useCharts.d.ts +2 -2
  118. package/internals/store/useCharts.types.d.ts +1 -1
  119. package/models/seriesType/common.d.ts +9 -0
  120. package/models/seriesType/pie.d.ts +9 -0
  121. package/modern/BarChart/AnimatedBarElement.js +1 -0
  122. package/modern/BarChart/BarChart.js +17 -7
  123. package/modern/BarChart/legend.js +1 -0
  124. package/modern/BarChart/useBarChartProps.js +16 -3
  125. package/modern/ChartsLabel/ChartsLabel.js +3 -18
  126. package/modern/ChartsLabel/ChartsLabelGradient.js +21 -18
  127. package/modern/ChartsLabel/ChartsLabelMark.js +5 -2
  128. package/modern/ChartsLabel/index.js +6 -0
  129. package/modern/ChartsLabel/labelGradientClasses.js +3 -2
  130. package/modern/ChartsLabel/labelMarkClasses.js +3 -2
  131. package/modern/ChartsLegend/ChartsLegend.js +100 -109
  132. package/modern/ChartsLegend/ContinuousColorLegend.js +198 -321
  133. package/modern/ChartsLegend/PiecewiseColorLegend.js +201 -111
  134. package/modern/ChartsLegend/chartsLegendClasses.js +16 -2
  135. package/modern/ChartsLegend/colorLegend.types.js +1 -0
  136. package/modern/ChartsLegend/continuousColorLegendClasses.js +23 -0
  137. package/modern/ChartsLegend/direction.js +1 -0
  138. package/modern/ChartsLegend/index.js +9 -3
  139. package/modern/ChartsLegend/legendContext.types.js +1 -0
  140. package/modern/ChartsLegend/onClickContextBuilder.js +7 -0
  141. package/modern/ChartsLegend/piecewiseColorDefaultLabelFormatter.js +9 -0
  142. package/modern/ChartsLegend/piecewiseColorLegend.types.js +1 -0
  143. package/modern/ChartsLegend/piecewiseColorLegendClasses.js +23 -0
  144. package/modern/ChartsLegend/useAxis.js +0 -1
  145. package/modern/ChartsSurface/ChartsSurface.js +0 -1
  146. package/modern/LineChart/AnimatedArea.js +1 -0
  147. package/modern/LineChart/AnimatedLine.js +1 -0
  148. package/modern/LineChart/AppearingMask.js +1 -0
  149. package/modern/LineChart/CircleMarkElement.js +1 -0
  150. package/modern/LineChart/LineChart.js +20 -10
  151. package/modern/LineChart/MarkElement.js +3 -1
  152. package/modern/LineChart/legend.js +1 -0
  153. package/modern/LineChart/useLineChartProps.js +15 -2
  154. package/modern/PieChart/PieArc.js +3 -1
  155. package/modern/PieChart/PieArcLabel.js +13 -9
  156. package/modern/PieChart/PieArcLabelPlot.js +1 -0
  157. package/modern/PieChart/PieArcPlot.js +1 -0
  158. package/modern/PieChart/PieChart.js +42 -41
  159. package/modern/PieChart/legend.js +1 -0
  160. package/modern/ScatterChart/ScatterChart.js +21 -11
  161. package/modern/ScatterChart/legend.js +1 -0
  162. package/modern/ScatterChart/useScatterChartProps.js +15 -2
  163. package/modern/SparkLineChart/SparkLineChart.js +1 -4
  164. package/modern/constants/index.js +2 -1
  165. package/modern/hooks/index.js +2 -1
  166. package/{ChartsLegend/utils.js → modern/hooks/useLegend.js} +20 -1
  167. package/modern/index.js +2 -1
  168. package/modern/internals/calculateMargins.js +25 -0
  169. package/modern/internals/components/ChartsAxesGradients/ChartsAxesGradients.js +60 -16
  170. package/modern/internals/components/ChartsAxesGradients/ChartsContinuousGradient.js +6 -6
  171. package/modern/internals/components/ChartsAxesGradients/ChartsContinuousGradientObjectBound.js +61 -0
  172. package/modern/internals/components/ChartsAxesGradients/ChartsPiecewiseGradient.js +3 -0
  173. package/modern/internals/components/ChartsWrapper/ChartsWrapper.js +66 -0
  174. package/modern/internals/components/ChartsWrapper/index.js +1 -0
  175. package/modern/internals/consumeSlots.js +101 -0
  176. package/modern/internals/consumeThemeProps.js +18 -27
  177. package/modern/internals/index.js +1 -0
  178. package/node/BarChart/AnimatedBarElement.js +1 -0
  179. package/node/BarChart/BarChart.js +17 -7
  180. package/node/BarChart/legend.js +1 -0
  181. package/node/BarChart/useBarChartProps.js +15 -3
  182. package/node/ChartsLabel/ChartsLabel.js +3 -18
  183. package/node/ChartsLabel/ChartsLabelGradient.js +21 -18
  184. package/node/ChartsLabel/ChartsLabelMark.js +5 -2
  185. package/node/ChartsLabel/index.js +26 -0
  186. package/node/ChartsLabel/labelGradientClasses.js +3 -2
  187. package/node/ChartsLabel/labelMarkClasses.js +3 -2
  188. package/node/ChartsLegend/ChartsLegend.js +99 -108
  189. package/node/ChartsLegend/ContinuousColorLegend.js +199 -322
  190. package/node/ChartsLegend/PiecewiseColorLegend.js +201 -111
  191. package/node/ChartsLegend/chartsLegendClasses.js +17 -3
  192. package/node/ChartsLegend/colorLegend.types.js +5 -0
  193. package/node/ChartsLegend/continuousColorLegendClasses.js +31 -0
  194. package/node/ChartsLegend/direction.js +5 -0
  195. package/node/ChartsLegend/index.js +80 -16
  196. package/node/ChartsLegend/legendContext.types.js +5 -0
  197. package/node/ChartsLegend/onClickContextBuilder.js +14 -0
  198. package/node/ChartsLegend/piecewiseColorDefaultLabelFormatter.js +15 -0
  199. package/node/ChartsLegend/piecewiseColorLegend.types.js +5 -0
  200. package/node/ChartsLegend/piecewiseColorLegendClasses.js +31 -0
  201. package/node/ChartsSurface/ChartsSurface.js +0 -1
  202. package/node/LineChart/AnimatedArea.js +1 -0
  203. package/node/LineChart/AnimatedLine.js +1 -0
  204. package/node/LineChart/AppearingMask.js +1 -0
  205. package/node/LineChart/CircleMarkElement.js +1 -0
  206. package/node/LineChart/LineChart.js +20 -10
  207. package/node/LineChart/MarkElement.js +3 -1
  208. package/node/LineChart/legend.js +1 -0
  209. package/node/LineChart/useLineChartProps.js +14 -2
  210. package/node/PieChart/PieArc.js +3 -1
  211. package/node/PieChart/PieArcLabel.js +13 -9
  212. package/node/PieChart/PieArcLabelPlot.js +1 -0
  213. package/node/PieChart/PieArcPlot.js +1 -0
  214. package/node/PieChart/PieChart.js +42 -41
  215. package/node/PieChart/legend.js +1 -0
  216. package/node/ScatterChart/ScatterChart.js +21 -11
  217. package/node/ScatterChart/legend.js +1 -0
  218. package/node/ScatterChart/useScatterChartProps.js +14 -2
  219. package/node/SparkLineChart/SparkLineChart.js +1 -4
  220. package/node/constants/index.js +3 -2
  221. package/node/hooks/index.js +13 -1
  222. package/node/{ChartsLegend/utils.js → hooks/useLegend.js} +19 -1
  223. package/node/index.js +12 -1
  224. package/node/internals/calculateMargins.js +33 -0
  225. package/node/internals/components/ChartsAxesGradients/ChartsAxesGradients.js +61 -16
  226. package/node/internals/components/ChartsAxesGradients/ChartsContinuousGradient.js +6 -6
  227. package/node/internals/components/ChartsAxesGradients/ChartsContinuousGradientObjectBound.js +69 -0
  228. package/node/internals/components/ChartsAxesGradients/ChartsPiecewiseGradient.js +3 -0
  229. package/node/internals/components/ChartsWrapper/ChartsWrapper.js +72 -0
  230. package/node/internals/components/ChartsWrapper/index.js +16 -0
  231. package/node/internals/consumeSlots.js +109 -0
  232. package/node/internals/consumeThemeProps.js +18 -27
  233. package/node/internals/index.js +12 -0
  234. package/package.json +4 -4
  235. package/ChartsLegend/ChartsLegendItem.d.ts +0 -26
  236. package/ChartsLegend/ChartsLegendItem.js +0 -65
  237. package/ChartsLegend/DefaultChartsLegend.d.ts +0 -25
  238. package/ChartsLegend/DefaultChartsLegend.js +0 -112
  239. package/ChartsLegend/LegendPerItem.d.ts +0 -65
  240. package/ChartsLegend/LegendPerItem.js +0 -129
  241. package/ChartsLegend/legendItemsPlacement.d.ts +0 -3
  242. package/ChartsLegend/legendItemsPlacement.js +0 -72
  243. package/ChartsLegend/utils.d.ts +0 -2
  244. package/modern/ChartsLegend/ChartsLegendItem.js +0 -65
  245. package/modern/ChartsLegend/DefaultChartsLegend.js +0 -112
  246. package/modern/ChartsLegend/LegendPerItem.js +0 -129
  247. package/modern/ChartsLegend/legendItemsPlacement.js +0 -72
  248. package/node/ChartsLegend/ChartsLegendItem.js +0 -72
  249. package/node/ChartsLegend/DefaultChartsLegend.js +0 -118
  250. package/node/ChartsLegend/LegendPerItem.js +0 -137
  251. package/node/ChartsLegend/legendItemsPlacement.js +0 -79
@@ -1,334 +1,217 @@
1
1
  "use strict";
2
2
  'use client';
3
3
 
4
- var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
5
4
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
6
6
  Object.defineProperty(exports, "__esModule", {
7
7
  value: true
8
8
  });
9
- exports.ContinuousColorLegend = ContinuousColorLegend;
9
+ exports.ContinuousColorLegend = void 0;
10
+ var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
10
11
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
11
12
  var React = _interopRequireWildcard(require("react"));
12
13
  var _propTypes = _interopRequireDefault(require("prop-types"));
13
14
  var _styles = require("@mui/material/styles");
14
- var _RtlProvider = require("@mui/system/RtlProvider");
15
- var _ChartsContinuousGradient = _interopRequireDefault(require("../internals/components/ChartsAxesGradients/ChartsContinuousGradient"));
16
- var _hooks = require("../hooks");
17
- var _getScale = require("../internals/getScale");
18
- var _getPercentageValue = require("../internals/getPercentageValue");
19
- var _ChartsText = require("../ChartsText");
20
- var _domUtils = require("../internals/domUtils");
15
+ var _clsx = _interopRequireDefault(require("clsx"));
21
16
  var _useAxis = require("./useAxis");
17
+ var _ChartsLabel = require("../ChartsLabel/ChartsLabel");
18
+ var _ChartsLabelGradient = require("../ChartsLabel/ChartsLabelGradient");
19
+ var _consumeThemeProps = require("../internals/consumeThemeProps");
20
+ var _continuousColorLegendClasses = require("./continuousColorLegendClasses");
21
+ var _ChartsAxesGradients = require("../internals/components/ChartsAxesGradients");
22
22
  var _jsxRuntime = require("react/jsx-runtime");
23
- function getPositionOffset(position, legendBox, svgBox) {
24
- let offsetX = 0;
25
- let offsetY = 0;
26
- switch (position.horizontal) {
27
- case 'left':
28
- offsetX = 0;
29
- break;
30
- case 'middle':
31
- offsetX = (svgBox.width - legendBox.width) / 2;
32
- break;
33
- case 'right':
34
- default:
35
- offsetX = svgBox.width - legendBox.width;
36
- break;
37
- }
38
- switch (position.vertical) {
39
- case 'top':
40
- offsetY = 0;
41
- break;
42
- case 'middle':
43
- offsetY = (svgBox.height - legendBox.height) / 2;
44
- break;
45
- case 'bottom':
46
- default:
47
- offsetY = svgBox.height - legendBox.height;
48
- break;
49
- }
23
+ const _excluded = ["minLabel", "maxLabel", "direction", "axisDirection", "axisId", "rotateGradient", "reverse", "classes", "className", "gradientId", "labelPosition", "thickness"];
24
+ const templateAreas = reverse => {
25
+ const startLabel = reverse ? 'max-label' : 'min-label';
26
+ const endLabel = reverse ? 'min-label' : 'max-label';
50
27
  return {
51
- offsetX,
52
- offsetY
28
+ row: {
29
+ start: `
30
+ '${startLabel} . ${endLabel}'
31
+ 'gradient gradient gradient'
32
+ `,
33
+ end: `
34
+ 'gradient gradient gradient'
35
+ '${startLabel} . ${endLabel}'
36
+ `,
37
+ extremes: `
38
+ '${startLabel} gradient ${endLabel}'
39
+ `
40
+ },
41
+ column: {
42
+ start: `
43
+ '${endLabel} gradient'
44
+ '. gradient'
45
+ '${startLabel} gradient'
46
+ `,
47
+ end: `
48
+ 'gradient ${endLabel}'
49
+ 'gradient .'
50
+ 'gradient ${startLabel}'
51
+ `,
52
+ extremes: `
53
+ '${endLabel}'
54
+ 'gradient'
55
+ '${startLabel}'
56
+ `
57
+ }
53
58
  };
54
- }
55
-
56
- /**
57
- * Takes placement parameters and element bounding boxes.
58
- * Returns the x, y coordinates of the elements. And the textAnchor, dominantBaseline for texts.
59
- */
60
- function getElementPositions(text1Box, barBox, text2Box, params) {
61
- if (params.direction === 'column') {
62
- const text1 = {
63
- y: text1Box.height,
64
- dominantBaseline: 'auto'
65
- };
66
- const text2 = {
67
- y: text1Box.height + 2 * params.spacing + barBox.height,
68
- dominantBaseline: 'hanging'
69
- };
70
- const bar = {
71
- y: text1Box.height + params.spacing
72
- };
73
- const totalWidth = Math.max(text1Box.width, barBox.width, text2Box.width);
74
- const totalHeight = text1Box.height + barBox.height + text2Box.height + 2 * params.spacing;
75
- const boundingBox = {
76
- width: totalWidth,
77
- height: totalHeight
78
- };
79
- switch (params.align) {
80
- case 'start':
81
- return {
82
- text1: (0, _extends2.default)({}, text1, {
83
- textAnchor: 'start',
84
- x: 0
85
- }),
86
- text2: (0, _extends2.default)({}, text2, {
87
- textAnchor: 'start',
88
- x: 0
89
- }),
90
- bar: (0, _extends2.default)({}, bar, {
91
- x: 0
92
- }),
93
- boundingBox
94
- };
95
- case 'end':
96
- return {
97
- text1: (0, _extends2.default)({}, text1, {
98
- textAnchor: 'end',
99
- x: totalWidth
100
- }),
101
- text2: (0, _extends2.default)({}, text2, {
102
- textAnchor: 'end',
103
- x: totalWidth
104
- }),
105
- bar: (0, _extends2.default)({}, bar, {
106
- x: totalWidth - barBox.width
107
- }),
108
- boundingBox
109
- };
110
- case 'middle':
111
- default:
112
- return {
113
- text1: (0, _extends2.default)({}, text1, {
114
- textAnchor: 'middle',
115
- x: totalWidth / 2
116
- }),
117
- text2: (0, _extends2.default)({}, text2, {
118
- textAnchor: 'middle',
119
- x: totalWidth / 2
120
- }),
121
- bar: (0, _extends2.default)({}, bar, {
122
- x: totalWidth / 2 - barBox.width / 2
123
- }),
124
- boundingBox
125
- };
59
+ };
60
+ const RootElement = (0, _styles.styled)('ul', {
61
+ name: 'MuiContinuousColorLegend',
62
+ slot: 'Root',
63
+ overridesResolver: (props, styles) => styles.root
64
+ })(({
65
+ theme,
66
+ ownerState
67
+ }) => (0, _extends2.default)({}, theme.typography.caption, {
68
+ color: (theme.vars || theme).palette.text.primary,
69
+ lineHeight: '100%',
70
+ display: 'grid',
71
+ flexShrink: 0,
72
+ gap: theme.spacing(0.5),
73
+ listStyleType: 'none',
74
+ paddingInlineStart: 0,
75
+ marginBlock: theme.spacing(1),
76
+ marginInline: theme.spacing(1),
77
+ [`&.${_continuousColorLegendClasses.continuousColorLegendClasses.horizontal}`]: {
78
+ gridTemplateRows: 'min-content min-content',
79
+ gridTemplateColumns: 'min-content auto min-content',
80
+ [`&.${_continuousColorLegendClasses.continuousColorLegendClasses.start}`]: {
81
+ gridTemplateAreas: templateAreas(ownerState.reverse).row.start
82
+ },
83
+ [`&.${_continuousColorLegendClasses.continuousColorLegendClasses.end}`]: {
84
+ gridTemplateAreas: templateAreas(ownerState.reverse).row.end
85
+ },
86
+ [`&.${_continuousColorLegendClasses.continuousColorLegendClasses.extremes}`]: {
87
+ gridTemplateAreas: templateAreas(ownerState.reverse).row.extremes,
88
+ gridTemplateRows: 'min-content',
89
+ alignItems: 'center'
126
90
  }
127
- } else {
128
- const text1 = {
129
- x: text1Box.width,
130
- textAnchor: 'end'
131
- };
132
- const text2 = {
133
- x: text1Box.width + 2 * params.spacing + barBox.width,
134
- textAnchor: 'start'
135
- };
136
- const bar = {
137
- x: text1Box.width + params.spacing
138
- };
139
- const totalHeight = Math.max(text1Box.height, barBox.height, text2Box.height);
140
- const totalWidth = text1Box.width + barBox.width + text2Box.width + 2 * params.spacing;
141
- const boundingBox = {
142
- width: totalWidth,
143
- height: totalHeight
144
- };
145
- switch (params.align) {
146
- case 'start':
147
- return {
148
- text1: (0, _extends2.default)({}, text1, {
149
- dominantBaseline: 'hanging',
150
- y: 0
151
- }),
152
- text2: (0, _extends2.default)({}, text2, {
153
- dominantBaseline: 'hanging',
154
- y: 0
155
- }),
156
- bar: (0, _extends2.default)({}, bar, {
157
- y: 0
158
- }),
159
- boundingBox
160
- };
161
- case 'end':
162
- return {
163
- text1: (0, _extends2.default)({}, text1, {
164
- dominantBaseline: 'auto',
165
- y: totalHeight
166
- }),
167
- text2: (0, _extends2.default)({}, text2, {
168
- dominantBaseline: 'auto',
169
- y: totalHeight
170
- }),
171
- bar: (0, _extends2.default)({}, bar, {
172
- y: totalHeight - barBox.height
173
- }),
174
- boundingBox
175
- };
176
- case 'middle':
177
- default:
178
- return {
179
- text1: (0, _extends2.default)({}, text1, {
180
- dominantBaseline: 'central',
181
- y: totalHeight / 2
182
- }),
183
- text2: (0, _extends2.default)({}, text2, {
184
- dominantBaseline: 'central',
185
- y: totalHeight / 2
186
- }),
187
- bar: (0, _extends2.default)({}, bar, {
188
- y: totalHeight / 2 - barBox.height / 2
189
- }),
190
- boundingBox
191
- };
91
+ },
92
+ [`&.${_continuousColorLegendClasses.continuousColorLegendClasses.vertical}`]: {
93
+ gridTemplateRows: 'min-content auto min-content',
94
+ gridTemplateColumns: 'min-content min-content',
95
+ [`&.${_continuousColorLegendClasses.continuousColorLegendClasses.start}`]: {
96
+ gridTemplateAreas: templateAreas(ownerState.reverse).column.start,
97
+ [`.${_continuousColorLegendClasses.continuousColorLegendClasses.maxLabel}, .${_continuousColorLegendClasses.continuousColorLegendClasses.minLabel}`]: {
98
+ justifySelf: 'end'
99
+ }
100
+ },
101
+ [`&.${_continuousColorLegendClasses.continuousColorLegendClasses.end}`]: {
102
+ gridTemplateAreas: templateAreas(ownerState.reverse).column.end,
103
+ [`.${_continuousColorLegendClasses.continuousColorLegendClasses.maxLabel}, .${_continuousColorLegendClasses.continuousColorLegendClasses.minLabel}`]: {
104
+ justifySelf: 'start'
105
+ }
106
+ },
107
+ [`&.${_continuousColorLegendClasses.continuousColorLegendClasses.extremes}`]: {
108
+ gridTemplateAreas: templateAreas(ownerState.reverse).column.extremes,
109
+ gridTemplateColumns: 'min-content',
110
+ [`.${_continuousColorLegendClasses.continuousColorLegendClasses.maxLabel}, .${_continuousColorLegendClasses.continuousColorLegendClasses.minLabel}`]: {
111
+ justifySelf: 'center'
112
+ }
192
113
  }
114
+ },
115
+ [`.${_continuousColorLegendClasses.continuousColorLegendClasses.gradient}`]: {
116
+ gridArea: 'gradient'
117
+ },
118
+ [`.${_continuousColorLegendClasses.continuousColorLegendClasses.maxLabel}`]: {
119
+ gridArea: 'max-label'
120
+ },
121
+ [`.${_continuousColorLegendClasses.continuousColorLegendClasses.minLabel}`]: {
122
+ gridArea: 'min-label'
123
+ }
124
+ }));
125
+ const getText = (label, value, formattedValue) => {
126
+ if (typeof label === 'string') {
127
+ return label;
193
128
  }
194
- }
195
- const defaultLabelFormatter = ({
196
- formattedValue
197
- }) => formattedValue;
198
- function ContinuousColorLegend(props) {
199
- const theme = (0, _styles.useTheme)();
200
- const isRtl = (0, _RtlProvider.useRtl)();
129
+ return label?.({
130
+ value,
131
+ formattedValue
132
+ }) ?? formattedValue;
133
+ };
134
+ const ContinuousColorLegend = exports.ContinuousColorLegend = (0, _consumeThemeProps.consumeThemeProps)('MuiContinuousColorLegend', {
135
+ defaultProps: {
136
+ direction: 'horizontal',
137
+ labelPosition: 'end',
138
+ axisDirection: 'z'
139
+ },
140
+ classesResolver: _continuousColorLegendClasses.useUtilityClasses
141
+ }, function ContinuousColorLegend(props, ref) {
201
142
  const {
202
- id: idProp,
203
- minLabel = defaultLabelFormatter,
204
- maxLabel = defaultLabelFormatter,
205
- scaleType = 'linear',
206
- direction,
207
- length = '50%',
208
- thickness = 5,
209
- spacing = 4,
210
- align = 'middle',
211
- labelStyle = theme.typography.subtitle1,
212
- position,
213
- axisDirection,
214
- axisId
215
- } = props;
216
- const chartId = (0, _hooks.useChartId)();
217
- const id = idProp ?? `gradient-legend-${chartId}`;
143
+ minLabel,
144
+ maxLabel,
145
+ direction,
146
+ axisDirection,
147
+ axisId,
148
+ rotateGradient,
149
+ reverse,
150
+ classes,
151
+ className,
152
+ gradientId,
153
+ thickness
154
+ } = props,
155
+ other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
156
+ const generateGradientId = (0, _ChartsAxesGradients.useChartGradientObjectBound)();
218
157
  const axisItem = (0, _useAxis.useAxis)({
219
158
  axisDirection,
220
159
  axisId
221
160
  });
222
- const {
223
- width,
224
- height,
225
- left,
226
- right,
227
- top,
228
- bottom
229
- } = (0, _hooks.useDrawingArea)();
230
- const refLength = direction === 'column' ? height + top + bottom : width + left + right;
231
- const size = (0, _getPercentageValue.getPercentageValue)(length, refLength);
232
- const isReversed = direction === 'column';
233
161
  const colorMap = axisItem?.colorMap;
234
162
  if (!colorMap || !colorMap.type || colorMap.type !== 'continuous') {
235
163
  return null;
236
164
  }
237
-
238
- // Define the coordinate to color mapping
239
-
240
- const colorScale = axisItem.colorScale;
241
165
  const minValue = colorMap.min ?? 0;
242
166
  const maxValue = colorMap.max ?? 100;
243
- const scale = (0, _getScale.getScale)(scaleType, [minValue, maxValue], isReversed ? [size, 0] : [0, size]);
244
167
 
245
168
  // Get texts to display
246
169
 
247
- const formattedMin = axisItem.valueFormatter?.(minValue, {
170
+ const valueFormatter = axisItem?.valueFormatter;
171
+ const formattedMin = valueFormatter ? valueFormatter(minValue, {
248
172
  location: 'legend'
249
- }) ?? minValue.toLocaleString();
250
- const formattedMax = axisItem.valueFormatter?.(maxValue, {
173
+ }) : minValue.toLocaleString();
174
+ const formattedMax = valueFormatter ? valueFormatter(maxValue, {
251
175
  location: 'legend'
252
- }) ?? maxValue.toLocaleString();
253
- const minText = typeof minLabel === 'string' ? minLabel : minLabel({
254
- value: minValue ?? 0,
255
- formattedValue: formattedMin
176
+ }) : maxValue.toLocaleString();
177
+ const minText = getText(minLabel, minValue, formattedMin);
178
+ const maxText = getText(maxLabel, maxValue, formattedMax);
179
+ const minComponent = /*#__PURE__*/(0, _jsxRuntime.jsx)("li", {
180
+ className: classes?.minLabel,
181
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsLabel.ChartsLabel, {
182
+ className: classes?.label,
183
+ children: minText
184
+ })
256
185
  });
257
- const maxText = typeof maxLabel === 'string' ? maxLabel : maxLabel({
258
- value: maxValue ?? 0,
259
- formattedValue: formattedMax
186
+ const maxComponent = /*#__PURE__*/(0, _jsxRuntime.jsx)("li", {
187
+ className: classes?.maxLabel,
188
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsLabel.ChartsLabel, {
189
+ className: classes?.label,
190
+ children: maxText
191
+ })
260
192
  });
261
- const text1 = isReversed ? maxText : minText;
262
- const text2 = isReversed ? minText : maxText;
263
- const text1Box = (0, _domUtils.getStringSize)(text1, (0, _extends2.default)({}, labelStyle));
264
- const text2Box = (0, _domUtils.getStringSize)(text2, (0, _extends2.default)({}, labelStyle));
265
-
266
- // Place bar and texts
267
-
268
- const barBox = direction === 'column' || isRtl && direction === 'row' ? {
269
- width: thickness,
270
- height: size
271
- } : {
272
- width: size,
273
- height: thickness
274
- };
275
- const legendPositions = getElementPositions(text1Box, barBox, text2Box, {
276
- spacing,
277
- align,
278
- direction
279
- });
280
- const svgBoundingBox = {
281
- width: width + left + right,
282
- height: height + top + bottom
283
- };
284
- const positionOffset = getPositionOffset((0, _extends2.default)({
285
- horizontal: 'middle',
286
- vertical: 'top'
287
- }, position), legendPositions.boundingBox, svgBoundingBox);
288
- return /*#__PURE__*/(0, _jsxRuntime.jsxs)(React.Fragment, {
289
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsContinuousGradient.default, {
290
- isReversed: isReversed,
291
- gradientId: id,
292
- size: size,
293
- direction: direction === 'row' ? 'x' : 'y',
294
- scale: scale,
295
- colorScale: colorScale,
296
- colorMap: colorMap,
297
- gradientUnits: "objectBoundingBox"
298
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsText.ChartsText, {
299
- text: text1,
300
- x: positionOffset.offsetX + legendPositions.text1.x,
301
- y: positionOffset.offsetY + legendPositions.text1.y,
302
- style: (0, _extends2.default)({
303
- dominantBaseline: legendPositions.text1.dominantBaseline,
304
- textAnchor: legendPositions.text1.textAnchor
305
- }, labelStyle)
306
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)("rect", (0, _extends2.default)({
307
- x: positionOffset.offsetX + legendPositions.bar.x,
308
- y: positionOffset.offsetY + legendPositions.bar.y
309
- }, barBox, {
310
- fill: `url(#${id})`
311
- })), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsText.ChartsText, {
312
- text: text2,
313
- x: positionOffset.offsetX + legendPositions.text2.x,
314
- y: positionOffset.offsetY + legendPositions.text2.y,
315
- style: (0, _extends2.default)({
316
- dominantBaseline: legendPositions.text2.dominantBaseline,
317
- textAnchor: legendPositions.text2.textAnchor
318
- }, labelStyle)
319
- })]
320
- });
321
- }
193
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(RootElement, (0, _extends2.default)({
194
+ className: (0, _clsx.default)(classes?.root, className),
195
+ ref: ref
196
+ }, other, {
197
+ ownerState: props,
198
+ children: [reverse ? maxComponent : minComponent, /*#__PURE__*/(0, _jsxRuntime.jsx)("li", {
199
+ className: classes?.gradient,
200
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsLabelGradient.ChartsLabelGradient, {
201
+ direction: direction,
202
+ rotate: rotateGradient,
203
+ reverse: reverse,
204
+ thickness: thickness,
205
+ gradientId: gradientId ?? generateGradientId(axisItem.id, axisDirection)
206
+ })
207
+ }), reverse ? minComponent : maxComponent]
208
+ }));
209
+ });
322
210
  process.env.NODE_ENV !== "production" ? ContinuousColorLegend.propTypes = {
323
211
  // ----------------------------- Warning --------------------------------
324
212
  // | These PropTypes are generated from the TypeScript type definitions |
325
213
  // | To update them edit the TypeScript types and run "pnpm proptypes" |
326
214
  // ----------------------------------------------------------------------
327
- /**
328
- * The alignment of the texts with the gradient bar.
329
- * @default 'middle'
330
- */
331
- align: _propTypes.default.oneOf(['end', 'middle', 'start']),
332
215
  /**
333
216
  * The axis direction containing the color configuration to represent.
334
217
  * @default 'z'
@@ -340,60 +223,54 @@ process.env.NODE_ENV !== "production" ? ContinuousColorLegend.propTypes = {
340
223
  */
341
224
  axisId: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]),
342
225
  /**
343
- * The direction of the legend layout.
344
- * The default depends on the chart.
226
+ * Override or extend the styles applied to the component.
345
227
  */
346
- direction: _propTypes.default.oneOf(['column', 'row']),
228
+ classes: _propTypes.default.object,
229
+ className: _propTypes.default.string,
347
230
  /**
348
- * A unique identifier for the gradient.
349
- * @default auto-generated id
231
+ * The direction of the legend layout.
232
+ * @default 'horizontal'
350
233
  */
351
- id: _propTypes.default.string,
234
+ direction: _propTypes.default.oneOf(['horizontal', 'vertical']),
352
235
  /**
353
- * The style applied to labels.
354
- * @default theme.typography.subtitle1
236
+ * The id for the gradient to use.
237
+ * If not provided, it will use the generated gradient from the axis configuration.
238
+ * The `gradientId` will be used as `fill="url(#gradientId)"`.
239
+ * @default auto-generated id
355
240
  */
356
- labelStyle: _propTypes.default.object,
241
+ gradientId: _propTypes.default.string,
357
242
  /**
358
- * The length of the gradient bar.
359
- * Can be a number (in px) or a string with a percentage such as '50%'.
360
- * The '100%' is the length of the svg.
361
- * @default '50%'
243
+ * Where to position the labels relative to the gradient.
244
+ * @default 'end'
362
245
  */
363
- length: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]),
246
+ labelPosition: _propTypes.default.oneOf(['start', 'end', 'extremes']),
364
247
  /**
365
248
  * The label to display at the maximum side of the gradient.
366
249
  * Can either be a string, or a function.
367
250
  * If not defined, the formatted maximal value is display.
368
- * @default ({ formattedValue }) => formattedValue
251
+ * @default formattedValue
369
252
  */
370
253
  maxLabel: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.string]),
371
254
  /**
372
255
  * The label to display at the minimum side of the gradient.
373
256
  * Can either be a string, or a function.
374
- * @default ({ formattedValue }) => formattedValue
257
+ * @default formattedValue
375
258
  */
376
259
  minLabel: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.string]),
377
260
  /**
378
- * The position of the legend.
379
- */
380
- position: _propTypes.default.shape({
381
- horizontal: _propTypes.default.oneOf(['left', 'middle', 'right']).isRequired,
382
- vertical: _propTypes.default.oneOf(['bottom', 'middle', 'top']).isRequired
383
- }),
384
- /**
385
- * The scale used to display gradient colors.
386
- * @default 'linear'
261
+ * If `true`, the gradient and labels will be reversed.
262
+ * @default false
387
263
  */
388
- scaleType: _propTypes.default.oneOf(['linear', 'log', 'pow', 'sqrt', 'time', 'utc']),
264
+ reverse: _propTypes.default.bool,
389
265
  /**
390
- * The space between the gradient bar and the labels.
391
- * @default 4
266
+ * If provided, the gradient will be rotated by 90deg.
267
+ * Useful for linear gradients that are not in the correct orientation.
392
268
  */
393
- spacing: _propTypes.default.number,
269
+ rotateGradient: _propTypes.default.bool,
394
270
  /**
395
- * The thickness of the gradient bar.
396
- * @default 5
271
+ * The thickness of the gradient
272
+ * @default 12
397
273
  */
398
- thickness: _propTypes.default.number
274
+ thickness: _propTypes.default.number,
275
+ sx: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.object, _propTypes.default.bool])), _propTypes.default.func, _propTypes.default.object])
399
276
  } : void 0;