@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,327 +1,210 @@
1
1
  'use client';
2
2
 
3
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
4
  import _extends from "@babel/runtime/helpers/esm/extends";
5
+ const _excluded = ["minLabel", "maxLabel", "direction", "axisDirection", "axisId", "rotateGradient", "reverse", "classes", "className", "gradientId", "labelPosition", "thickness"];
4
6
  import * as React from 'react';
5
7
  import PropTypes from 'prop-types';
6
- import { useTheme } from '@mui/material/styles';
7
- import { useRtl } from '@mui/system/RtlProvider';
8
- import ChartsContinuousGradient from "../internals/components/ChartsAxesGradients/ChartsContinuousGradient.js";
9
- import { useChartId, useDrawingArea } from "../hooks/index.js";
10
- import { getScale } from "../internals/getScale.js";
11
- import { getPercentageValue } from "../internals/getPercentageValue.js";
12
- import { ChartsText } from "../ChartsText/index.js";
13
- import { getStringSize } from "../internals/domUtils.js";
8
+ import { styled } from '@mui/material/styles';
9
+ import clsx from 'clsx';
14
10
  import { useAxis } from "./useAxis.js";
11
+ import { ChartsLabel } from "../ChartsLabel/ChartsLabel.js";
12
+ import { ChartsLabelGradient } from "../ChartsLabel/ChartsLabelGradient.js";
13
+ import { consumeThemeProps } from "../internals/consumeThemeProps.js";
14
+ import { continuousColorLegendClasses, useUtilityClasses } from "./continuousColorLegendClasses.js";
15
+ import { useChartGradientObjectBound } from "../internals/components/ChartsAxesGradients/index.js";
15
16
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
16
- function getPositionOffset(position, legendBox, svgBox) {
17
- let offsetX = 0;
18
- let offsetY = 0;
19
- switch (position.horizontal) {
20
- case 'left':
21
- offsetX = 0;
22
- break;
23
- case 'middle':
24
- offsetX = (svgBox.width - legendBox.width) / 2;
25
- break;
26
- case 'right':
27
- default:
28
- offsetX = svgBox.width - legendBox.width;
29
- break;
30
- }
31
- switch (position.vertical) {
32
- case 'top':
33
- offsetY = 0;
34
- break;
35
- case 'middle':
36
- offsetY = (svgBox.height - legendBox.height) / 2;
37
- break;
38
- case 'bottom':
39
- default:
40
- offsetY = svgBox.height - legendBox.height;
41
- break;
42
- }
17
+ const templateAreas = reverse => {
18
+ const startLabel = reverse ? 'max-label' : 'min-label';
19
+ const endLabel = reverse ? 'min-label' : 'max-label';
43
20
  return {
44
- offsetX,
45
- offsetY
21
+ row: {
22
+ start: `
23
+ '${startLabel} . ${endLabel}'
24
+ 'gradient gradient gradient'
25
+ `,
26
+ end: `
27
+ 'gradient gradient gradient'
28
+ '${startLabel} . ${endLabel}'
29
+ `,
30
+ extremes: `
31
+ '${startLabel} gradient ${endLabel}'
32
+ `
33
+ },
34
+ column: {
35
+ start: `
36
+ '${endLabel} gradient'
37
+ '. gradient'
38
+ '${startLabel} gradient'
39
+ `,
40
+ end: `
41
+ 'gradient ${endLabel}'
42
+ 'gradient .'
43
+ 'gradient ${startLabel}'
44
+ `,
45
+ extremes: `
46
+ '${endLabel}'
47
+ 'gradient'
48
+ '${startLabel}'
49
+ `
50
+ }
46
51
  };
47
- }
48
-
49
- /**
50
- * Takes placement parameters and element bounding boxes.
51
- * Returns the x, y coordinates of the elements. And the textAnchor, dominantBaseline for texts.
52
- */
53
- function getElementPositions(text1Box, barBox, text2Box, params) {
54
- if (params.direction === 'column') {
55
- const text1 = {
56
- y: text1Box.height,
57
- dominantBaseline: 'auto'
58
- };
59
- const text2 = {
60
- y: text1Box.height + 2 * params.spacing + barBox.height,
61
- dominantBaseline: 'hanging'
62
- };
63
- const bar = {
64
- y: text1Box.height + params.spacing
65
- };
66
- const totalWidth = Math.max(text1Box.width, barBox.width, text2Box.width);
67
- const totalHeight = text1Box.height + barBox.height + text2Box.height + 2 * params.spacing;
68
- const boundingBox = {
69
- width: totalWidth,
70
- height: totalHeight
71
- };
72
- switch (params.align) {
73
- case 'start':
74
- return {
75
- text1: _extends({}, text1, {
76
- textAnchor: 'start',
77
- x: 0
78
- }),
79
- text2: _extends({}, text2, {
80
- textAnchor: 'start',
81
- x: 0
82
- }),
83
- bar: _extends({}, bar, {
84
- x: 0
85
- }),
86
- boundingBox
87
- };
88
- case 'end':
89
- return {
90
- text1: _extends({}, text1, {
91
- textAnchor: 'end',
92
- x: totalWidth
93
- }),
94
- text2: _extends({}, text2, {
95
- textAnchor: 'end',
96
- x: totalWidth
97
- }),
98
- bar: _extends({}, bar, {
99
- x: totalWidth - barBox.width
100
- }),
101
- boundingBox
102
- };
103
- case 'middle':
104
- default:
105
- return {
106
- text1: _extends({}, text1, {
107
- textAnchor: 'middle',
108
- x: totalWidth / 2
109
- }),
110
- text2: _extends({}, text2, {
111
- textAnchor: 'middle',
112
- x: totalWidth / 2
113
- }),
114
- bar: _extends({}, bar, {
115
- x: totalWidth / 2 - barBox.width / 2
116
- }),
117
- boundingBox
118
- };
52
+ };
53
+ const RootElement = styled('ul', {
54
+ name: 'MuiContinuousColorLegend',
55
+ slot: 'Root',
56
+ overridesResolver: (props, styles) => styles.root
57
+ })(({
58
+ theme,
59
+ ownerState
60
+ }) => _extends({}, theme.typography.caption, {
61
+ color: (theme.vars || theme).palette.text.primary,
62
+ lineHeight: '100%',
63
+ display: 'grid',
64
+ flexShrink: 0,
65
+ gap: theme.spacing(0.5),
66
+ listStyleType: 'none',
67
+ paddingInlineStart: 0,
68
+ marginBlock: theme.spacing(1),
69
+ marginInline: theme.spacing(1),
70
+ [`&.${continuousColorLegendClasses.horizontal}`]: {
71
+ gridTemplateRows: 'min-content min-content',
72
+ gridTemplateColumns: 'min-content auto min-content',
73
+ [`&.${continuousColorLegendClasses.start}`]: {
74
+ gridTemplateAreas: templateAreas(ownerState.reverse).row.start
75
+ },
76
+ [`&.${continuousColorLegendClasses.end}`]: {
77
+ gridTemplateAreas: templateAreas(ownerState.reverse).row.end
78
+ },
79
+ [`&.${continuousColorLegendClasses.extremes}`]: {
80
+ gridTemplateAreas: templateAreas(ownerState.reverse).row.extremes,
81
+ gridTemplateRows: 'min-content',
82
+ alignItems: 'center'
119
83
  }
120
- } else {
121
- const text1 = {
122
- x: text1Box.width,
123
- textAnchor: 'end'
124
- };
125
- const text2 = {
126
- x: text1Box.width + 2 * params.spacing + barBox.width,
127
- textAnchor: 'start'
128
- };
129
- const bar = {
130
- x: text1Box.width + params.spacing
131
- };
132
- const totalHeight = Math.max(text1Box.height, barBox.height, text2Box.height);
133
- const totalWidth = text1Box.width + barBox.width + text2Box.width + 2 * params.spacing;
134
- const boundingBox = {
135
- width: totalWidth,
136
- height: totalHeight
137
- };
138
- switch (params.align) {
139
- case 'start':
140
- return {
141
- text1: _extends({}, text1, {
142
- dominantBaseline: 'hanging',
143
- y: 0
144
- }),
145
- text2: _extends({}, text2, {
146
- dominantBaseline: 'hanging',
147
- y: 0
148
- }),
149
- bar: _extends({}, bar, {
150
- y: 0
151
- }),
152
- boundingBox
153
- };
154
- case 'end':
155
- return {
156
- text1: _extends({}, text1, {
157
- dominantBaseline: 'auto',
158
- y: totalHeight
159
- }),
160
- text2: _extends({}, text2, {
161
- dominantBaseline: 'auto',
162
- y: totalHeight
163
- }),
164
- bar: _extends({}, bar, {
165
- y: totalHeight - barBox.height
166
- }),
167
- boundingBox
168
- };
169
- case 'middle':
170
- default:
171
- return {
172
- text1: _extends({}, text1, {
173
- dominantBaseline: 'central',
174
- y: totalHeight / 2
175
- }),
176
- text2: _extends({}, text2, {
177
- dominantBaseline: 'central',
178
- y: totalHeight / 2
179
- }),
180
- bar: _extends({}, bar, {
181
- y: totalHeight / 2 - barBox.height / 2
182
- }),
183
- boundingBox
184
- };
84
+ },
85
+ [`&.${continuousColorLegendClasses.vertical}`]: {
86
+ gridTemplateRows: 'min-content auto min-content',
87
+ gridTemplateColumns: 'min-content min-content',
88
+ [`&.${continuousColorLegendClasses.start}`]: {
89
+ gridTemplateAreas: templateAreas(ownerState.reverse).column.start,
90
+ [`.${continuousColorLegendClasses.maxLabel}, .${continuousColorLegendClasses.minLabel}`]: {
91
+ justifySelf: 'end'
92
+ }
93
+ },
94
+ [`&.${continuousColorLegendClasses.end}`]: {
95
+ gridTemplateAreas: templateAreas(ownerState.reverse).column.end,
96
+ [`.${continuousColorLegendClasses.maxLabel}, .${continuousColorLegendClasses.minLabel}`]: {
97
+ justifySelf: 'start'
98
+ }
99
+ },
100
+ [`&.${continuousColorLegendClasses.extremes}`]: {
101
+ gridTemplateAreas: templateAreas(ownerState.reverse).column.extremes,
102
+ gridTemplateColumns: 'min-content',
103
+ [`.${continuousColorLegendClasses.maxLabel}, .${continuousColorLegendClasses.minLabel}`]: {
104
+ justifySelf: 'center'
105
+ }
185
106
  }
107
+ },
108
+ [`.${continuousColorLegendClasses.gradient}`]: {
109
+ gridArea: 'gradient'
110
+ },
111
+ [`.${continuousColorLegendClasses.maxLabel}`]: {
112
+ gridArea: 'max-label'
113
+ },
114
+ [`.${continuousColorLegendClasses.minLabel}`]: {
115
+ gridArea: 'min-label'
116
+ }
117
+ }));
118
+ const getText = (label, value, formattedValue) => {
119
+ if (typeof label === 'string') {
120
+ return label;
186
121
  }
187
- }
188
- const defaultLabelFormatter = ({
189
- formattedValue
190
- }) => formattedValue;
191
- function ContinuousColorLegend(props) {
192
- const theme = useTheme();
193
- const isRtl = useRtl();
122
+ return label?.({
123
+ value,
124
+ formattedValue
125
+ }) ?? formattedValue;
126
+ };
127
+ const ContinuousColorLegend = consumeThemeProps('MuiContinuousColorLegend', {
128
+ defaultProps: {
129
+ direction: 'horizontal',
130
+ labelPosition: 'end',
131
+ axisDirection: 'z'
132
+ },
133
+ classesResolver: useUtilityClasses
134
+ }, function ContinuousColorLegend(props, ref) {
194
135
  const {
195
- id: idProp,
196
- minLabel = defaultLabelFormatter,
197
- maxLabel = defaultLabelFormatter,
198
- scaleType = 'linear',
199
- direction,
200
- length = '50%',
201
- thickness = 5,
202
- spacing = 4,
203
- align = 'middle',
204
- labelStyle = theme.typography.subtitle1,
205
- position,
206
- axisDirection,
207
- axisId
208
- } = props;
209
- const chartId = useChartId();
210
- const id = idProp ?? `gradient-legend-${chartId}`;
136
+ minLabel,
137
+ maxLabel,
138
+ direction,
139
+ axisDirection,
140
+ axisId,
141
+ rotateGradient,
142
+ reverse,
143
+ classes,
144
+ className,
145
+ gradientId,
146
+ thickness
147
+ } = props,
148
+ other = _objectWithoutPropertiesLoose(props, _excluded);
149
+ const generateGradientId = useChartGradientObjectBound();
211
150
  const axisItem = useAxis({
212
151
  axisDirection,
213
152
  axisId
214
153
  });
215
- const {
216
- width,
217
- height,
218
- left,
219
- right,
220
- top,
221
- bottom
222
- } = useDrawingArea();
223
- const refLength = direction === 'column' ? height + top + bottom : width + left + right;
224
- const size = getPercentageValue(length, refLength);
225
- const isReversed = direction === 'column';
226
154
  const colorMap = axisItem?.colorMap;
227
155
  if (!colorMap || !colorMap.type || colorMap.type !== 'continuous') {
228
156
  return null;
229
157
  }
230
-
231
- // Define the coordinate to color mapping
232
-
233
- const colorScale = axisItem.colorScale;
234
158
  const minValue = colorMap.min ?? 0;
235
159
  const maxValue = colorMap.max ?? 100;
236
- const scale = getScale(scaleType, [minValue, maxValue], isReversed ? [size, 0] : [0, size]);
237
160
 
238
161
  // Get texts to display
239
162
 
240
- const formattedMin = axisItem.valueFormatter?.(minValue, {
163
+ const valueFormatter = axisItem?.valueFormatter;
164
+ const formattedMin = valueFormatter ? valueFormatter(minValue, {
241
165
  location: 'legend'
242
- }) ?? minValue.toLocaleString();
243
- const formattedMax = axisItem.valueFormatter?.(maxValue, {
166
+ }) : minValue.toLocaleString();
167
+ const formattedMax = valueFormatter ? valueFormatter(maxValue, {
244
168
  location: 'legend'
245
- }) ?? maxValue.toLocaleString();
246
- const minText = typeof minLabel === 'string' ? minLabel : minLabel({
247
- value: minValue ?? 0,
248
- formattedValue: formattedMin
249
- });
250
- const maxText = typeof maxLabel === 'string' ? maxLabel : maxLabel({
251
- value: maxValue ?? 0,
252
- formattedValue: formattedMax
253
- });
254
- const text1 = isReversed ? maxText : minText;
255
- const text2 = isReversed ? minText : maxText;
256
- const text1Box = getStringSize(text1, _extends({}, labelStyle));
257
- const text2Box = getStringSize(text2, _extends({}, labelStyle));
258
-
259
- // Place bar and texts
260
-
261
- const barBox = direction === 'column' || isRtl && direction === 'row' ? {
262
- width: thickness,
263
- height: size
264
- } : {
265
- width: size,
266
- height: thickness
267
- };
268
- const legendPositions = getElementPositions(text1Box, barBox, text2Box, {
269
- spacing,
270
- align,
271
- direction
169
+ }) : maxValue.toLocaleString();
170
+ const minText = getText(minLabel, minValue, formattedMin);
171
+ const maxText = getText(maxLabel, maxValue, formattedMax);
172
+ const minComponent = /*#__PURE__*/_jsx("li", {
173
+ className: classes?.minLabel,
174
+ children: /*#__PURE__*/_jsx(ChartsLabel, {
175
+ className: classes?.label,
176
+ children: minText
177
+ })
272
178
  });
273
- const svgBoundingBox = {
274
- width: width + left + right,
275
- height: height + top + bottom
276
- };
277
- const positionOffset = getPositionOffset(_extends({
278
- horizontal: 'middle',
279
- vertical: 'top'
280
- }, position), legendPositions.boundingBox, svgBoundingBox);
281
- return /*#__PURE__*/_jsxs(React.Fragment, {
282
- children: [/*#__PURE__*/_jsx(ChartsContinuousGradient, {
283
- isReversed: isReversed,
284
- gradientId: id,
285
- size: size,
286
- direction: direction === 'row' ? 'x' : 'y',
287
- scale: scale,
288
- colorScale: colorScale,
289
- colorMap: colorMap,
290
- gradientUnits: "objectBoundingBox"
291
- }), /*#__PURE__*/_jsx(ChartsText, {
292
- text: text1,
293
- x: positionOffset.offsetX + legendPositions.text1.x,
294
- y: positionOffset.offsetY + legendPositions.text1.y,
295
- style: _extends({
296
- dominantBaseline: legendPositions.text1.dominantBaseline,
297
- textAnchor: legendPositions.text1.textAnchor
298
- }, labelStyle)
299
- }), /*#__PURE__*/_jsx("rect", _extends({
300
- x: positionOffset.offsetX + legendPositions.bar.x,
301
- y: positionOffset.offsetY + legendPositions.bar.y
302
- }, barBox, {
303
- fill: `url(#${id})`
304
- })), /*#__PURE__*/_jsx(ChartsText, {
305
- text: text2,
306
- x: positionOffset.offsetX + legendPositions.text2.x,
307
- y: positionOffset.offsetY + legendPositions.text2.y,
308
- style: _extends({
309
- dominantBaseline: legendPositions.text2.dominantBaseline,
310
- textAnchor: legendPositions.text2.textAnchor
311
- }, labelStyle)
312
- })]
179
+ const maxComponent = /*#__PURE__*/_jsx("li", {
180
+ className: classes?.maxLabel,
181
+ children: /*#__PURE__*/_jsx(ChartsLabel, {
182
+ className: classes?.label,
183
+ children: maxText
184
+ })
313
185
  });
314
- }
186
+ return /*#__PURE__*/_jsxs(RootElement, _extends({
187
+ className: clsx(classes?.root, className),
188
+ ref: ref
189
+ }, other, {
190
+ ownerState: props,
191
+ children: [reverse ? maxComponent : minComponent, /*#__PURE__*/_jsx("li", {
192
+ className: classes?.gradient,
193
+ children: /*#__PURE__*/_jsx(ChartsLabelGradient, {
194
+ direction: direction,
195
+ rotate: rotateGradient,
196
+ reverse: reverse,
197
+ thickness: thickness,
198
+ gradientId: gradientId ?? generateGradientId(axisItem.id, axisDirection)
199
+ })
200
+ }), reverse ? minComponent : maxComponent]
201
+ }));
202
+ });
315
203
  process.env.NODE_ENV !== "production" ? ContinuousColorLegend.propTypes = {
316
204
  // ----------------------------- Warning --------------------------------
317
205
  // | These PropTypes are generated from the TypeScript type definitions |
318
206
  // | To update them edit the TypeScript types and run "pnpm proptypes" |
319
207
  // ----------------------------------------------------------------------
320
- /**
321
- * The alignment of the texts with the gradient bar.
322
- * @default 'middle'
323
- */
324
- align: PropTypes.oneOf(['end', 'middle', 'start']),
325
208
  /**
326
209
  * The axis direction containing the color configuration to represent.
327
210
  * @default 'z'
@@ -333,61 +216,55 @@ process.env.NODE_ENV !== "production" ? ContinuousColorLegend.propTypes = {
333
216
  */
334
217
  axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
335
218
  /**
336
- * The direction of the legend layout.
337
- * The default depends on the chart.
219
+ * Override or extend the styles applied to the component.
338
220
  */
339
- direction: PropTypes.oneOf(['column', 'row']),
221
+ classes: PropTypes.object,
222
+ className: PropTypes.string,
340
223
  /**
341
- * A unique identifier for the gradient.
342
- * @default auto-generated id
224
+ * The direction of the legend layout.
225
+ * @default 'horizontal'
343
226
  */
344
- id: PropTypes.string,
227
+ direction: PropTypes.oneOf(['horizontal', 'vertical']),
345
228
  /**
346
- * The style applied to labels.
347
- * @default theme.typography.subtitle1
229
+ * The id for the gradient to use.
230
+ * If not provided, it will use the generated gradient from the axis configuration.
231
+ * The `gradientId` will be used as `fill="url(#gradientId)"`.
232
+ * @default auto-generated id
348
233
  */
349
- labelStyle: PropTypes.object,
234
+ gradientId: PropTypes.string,
350
235
  /**
351
- * The length of the gradient bar.
352
- * Can be a number (in px) or a string with a percentage such as '50%'.
353
- * The '100%' is the length of the svg.
354
- * @default '50%'
236
+ * Where to position the labels relative to the gradient.
237
+ * @default 'end'
355
238
  */
356
- length: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
239
+ labelPosition: PropTypes.oneOf(['start', 'end', 'extremes']),
357
240
  /**
358
241
  * The label to display at the maximum side of the gradient.
359
242
  * Can either be a string, or a function.
360
243
  * If not defined, the formatted maximal value is display.
361
- * @default ({ formattedValue }) => formattedValue
244
+ * @default formattedValue
362
245
  */
363
246
  maxLabel: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
364
247
  /**
365
248
  * The label to display at the minimum side of the gradient.
366
249
  * Can either be a string, or a function.
367
- * @default ({ formattedValue }) => formattedValue
250
+ * @default formattedValue
368
251
  */
369
252
  minLabel: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
370
253
  /**
371
- * The position of the legend.
372
- */
373
- position: PropTypes.shape({
374
- horizontal: PropTypes.oneOf(['left', 'middle', 'right']).isRequired,
375
- vertical: PropTypes.oneOf(['bottom', 'middle', 'top']).isRequired
376
- }),
377
- /**
378
- * The scale used to display gradient colors.
379
- * @default 'linear'
254
+ * If `true`, the gradient and labels will be reversed.
255
+ * @default false
380
256
  */
381
- scaleType: PropTypes.oneOf(['linear', 'log', 'pow', 'sqrt', 'time', 'utc']),
257
+ reverse: PropTypes.bool,
382
258
  /**
383
- * The space between the gradient bar and the labels.
384
- * @default 4
259
+ * If provided, the gradient will be rotated by 90deg.
260
+ * Useful for linear gradients that are not in the correct orientation.
385
261
  */
386
- spacing: PropTypes.number,
262
+ rotateGradient: PropTypes.bool,
387
263
  /**
388
- * The thickness of the gradient bar.
389
- * @default 5
264
+ * The thickness of the gradient
265
+ * @default 12
390
266
  */
391
- thickness: PropTypes.number
267
+ thickness: PropTypes.number,
268
+ sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
392
269
  } : void 0;
393
270
  export { ContinuousColorLegend };
@@ -1,34 +1,42 @@
1
1
  import * as React from 'react';
2
- import { ColorLegendSelector, PiecewiseLabelFormatterParams } from './legend.types';
3
- import { LegendPerItemProps } from './LegendPerItem';
4
- import { PiecewiseColorLegendItemContext } from './chartsLegend.types';
5
- export interface PiecewiseColorLegendProps extends ColorLegendSelector, Omit<LegendPerItemProps, 'itemsToDisplay' | 'onItemClick'> {
2
+ import { SxProps, Theme } from '@mui/material/styles';
3
+ import { PrependKeys } from '@mui/x-internals/types';
4
+ import { ChartsLabelMarkProps } from '../ChartsLabel/ChartsLabelMark';
5
+ import { Direction } from './direction';
6
+ import { PiecewiseColorLegendClasses } from './piecewiseColorLegendClasses';
7
+ import { ColorLegendSelector } from './colorLegend.types';
8
+ import { PiecewiseLabelFormatterParams } from './piecewiseColorLegend.types';
9
+ import { PiecewiseColorLegendItemContext } from './legendContext.types';
10
+ export interface PiecewiseColorLegendProps extends ColorLegendSelector, PrependKeys<Pick<ChartsLabelMarkProps, 'type'>, 'mark'> {
6
11
  /**
7
- * Hide the first item of the legend, corresponding to the [-infinity, min] piece.
8
- * @default false
12
+ * The direction of the legend layout.
13
+ * @default 'horizontal'
9
14
  */
10
- hideFirst?: boolean;
11
- /**
12
- * Hide the last item of the legend, corresponding to the [max, +infinity] piece.
13
- * @default false
14
- */
15
- hideLast?: boolean;
15
+ direction?: Direction;
16
16
  /**
17
17
  * Format the legend labels.
18
18
  * @param {PiecewiseLabelFormatterParams} params The bound of the piece to format.
19
- * @returns {string|null} The displayed label, or `null` to skip the item.
19
+ * @returns {string|null} The displayed label, `''` to skip the label but show the color mark, or `null` to skip it entirely.
20
20
  */
21
21
  labelFormatter?: (params: PiecewiseLabelFormatterParams) => string | null;
22
+ /**
23
+ * Where to position the labels relative to the gradient.
24
+ * @default 'extremes'
25
+ */
26
+ labelPosition?: 'start' | 'end' | 'extremes';
22
27
  /**
23
28
  * Callback fired when a legend item is clicked.
24
- * @param {React.MouseEvent<SVGRectElement, MouseEvent>} event The click event.
29
+ * @param {React.MouseEvent<HTMLButtonElement, MouseEvent>} event The click event.
25
30
  * @param {PiecewiseColorLegendItemContext} legendItem The legend item data.
26
31
  * @param {number} index The index of the clicked legend item.
27
32
  */
28
- onItemClick?: (event: React.MouseEvent<SVGRectElement, MouseEvent>, legendItem: PiecewiseColorLegendItemContext, index: number) => void;
29
- }
30
- declare function PiecewiseColorLegend(props: PiecewiseColorLegendProps): React.JSX.Element | null;
31
- declare namespace PiecewiseColorLegend {
32
- var propTypes: any;
33
+ onItemClick?: (event: React.MouseEvent<HTMLButtonElement, MouseEvent>, legendItem: PiecewiseColorLegendItemContext, index: number) => void;
34
+ /**
35
+ * Override or extend the styles applied to the component.
36
+ */
37
+ classes?: Partial<PiecewiseColorLegendClasses>;
38
+ className?: string;
39
+ sx?: SxProps<Theme>;
33
40
  }
41
+ declare const PiecewiseColorLegend: React.ForwardRefExoticComponent<PiecewiseColorLegendProps & import("./chartsLegend.types").ChartsLegendSlotExtension & React.RefAttributes<{}>>;
34
42
  export { PiecewiseColorLegend };