@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,40 +1,130 @@
1
1
  'use client';
2
2
 
3
- import _extends from "@babel/runtime/helpers/esm/extends";
4
3
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
5
- const _excluded = ["axisDirection", "axisId", "hideFirst", "hideLast", "labelFormatter", "onItemClick"];
4
+ import _extends from "@babel/runtime/helpers/esm/extends";
5
+ const _excluded = ["direction", "classes", "className", "markType", "labelPosition", "axisDirection", "axisId", "labelFormatter", "onItemClick"];
6
6
  import * as React from 'react';
7
7
  import PropTypes from 'prop-types';
8
+ import { styled } from '@mui/material/styles';
9
+ import clsx from 'clsx';
10
+ import { ChartsLabel } from "../ChartsLabel/ChartsLabel.js";
11
+ import { ChartsLabelMark } from "../ChartsLabel/ChartsLabelMark.js";
12
+ import { consumeThemeProps } from "../internals/consumeThemeProps.js";
13
+ import { piecewiseColorLegendClasses, useUtilityClasses } from "./piecewiseColorLegendClasses.js";
8
14
  import { useAxis } from "./useAxis.js";
9
- import { LegendPerItem } from "./LegendPerItem.js";
10
- import { notNull } from "../internals/notNull.js";
11
- import { jsx as _jsx } from "react/jsx-runtime";
12
- function defaultLabelFormatter(params) {
13
- if (params.min === null) {
14
- return `<${params.formattedMax}`;
15
- }
16
- if (params.max === null) {
17
- return `>${params.formattedMin}`;
18
- }
19
- return `${params.formattedMin}-${params.formattedMax}`;
20
- }
21
- const piecewiseColorContextBuilder = context => ({
22
- type: 'piecewiseColor',
23
- color: context.color,
24
- label: context.label,
25
- maxValue: context.maxValue,
26
- minValue: context.minValue
15
+ import { piecewiseColorDefaultLabelFormatter } from "./piecewiseColorDefaultLabelFormatter.js";
16
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
17
+ const RootElement = styled('ul', {
18
+ name: 'MuiPiecewiseColorLegend',
19
+ slot: 'Root',
20
+ overridesResolver: (props, styles) => styles.root
21
+ })(({
22
+ theme,
23
+ ownerState
24
+ }) => {
25
+ return _extends({}, theme.typography.caption, {
26
+ color: (theme.vars || theme).palette.text.primary,
27
+ lineHeight: '100%',
28
+ display: 'flex',
29
+ flexDirection: ownerState.direction === 'vertical' ? 'column' : 'row',
30
+ flexShrink: 0,
31
+ gap: theme.spacing(0.5),
32
+ listStyleType: 'none',
33
+ paddingInlineStart: 0,
34
+ marginBlock: theme.spacing(1),
35
+ marginInline: theme.spacing(1),
36
+ width: 'max-content',
37
+ [`button.${piecewiseColorLegendClasses.item}`]: {
38
+ // Reset button styles
39
+ background: 'none',
40
+ border: 'none',
41
+ padding: 0,
42
+ cursor: ownerState.onItemClick ? 'pointer' : 'unset',
43
+ fontFamily: 'inherit',
44
+ fontWeight: 'inherit',
45
+ fontSize: 'inherit',
46
+ letterSpacing: 'inherit',
47
+ color: 'inherit'
48
+ },
49
+ [`.${piecewiseColorLegendClasses.item}`]: {
50
+ display: 'flex',
51
+ gap: theme.spacing(0.5)
52
+ },
53
+ [`li :not(.${piecewiseColorLegendClasses.minLabel}, .${piecewiseColorLegendClasses.maxLabel}) .${piecewiseColorLegendClasses?.mark}`]: {
54
+ alignSelf: 'center'
55
+ },
56
+ [`&.${piecewiseColorLegendClasses.start}`]: {
57
+ alignItems: 'end'
58
+ },
59
+ [`&.${piecewiseColorLegendClasses.end}`]: {
60
+ alignItems: 'start'
61
+ },
62
+ [`&.${piecewiseColorLegendClasses.horizontal}`]: {
63
+ alignItems: 'center',
64
+ [`.${piecewiseColorLegendClasses.item}`]: {
65
+ flexDirection: 'column'
66
+ },
67
+ [`&.${piecewiseColorLegendClasses.start}`]: {
68
+ alignItems: 'end'
69
+ },
70
+ [`&.${piecewiseColorLegendClasses.end}`]: {
71
+ alignItems: 'start'
72
+ },
73
+ [`.${piecewiseColorLegendClasses.minLabel}`]: {
74
+ alignItems: 'end'
75
+ },
76
+ [`&.${piecewiseColorLegendClasses.extremes}`]: {
77
+ [`.${piecewiseColorLegendClasses.minLabel}, .${piecewiseColorLegendClasses.maxLabel}`]: {
78
+ alignItems: 'center',
79
+ display: 'flex',
80
+ flexDirection: 'row'
81
+ }
82
+ }
83
+ },
84
+ [`&.${piecewiseColorLegendClasses.vertical}`]: {
85
+ [`.${piecewiseColorLegendClasses.item}`]: {
86
+ flexDirection: 'row',
87
+ alignItems: 'center'
88
+ },
89
+ [`&.${piecewiseColorLegendClasses.start}`]: {
90
+ alignItems: 'end'
91
+ },
92
+ [`&.${piecewiseColorLegendClasses.end}`]: {
93
+ alignItems: 'start'
94
+ },
95
+ [`&.${piecewiseColorLegendClasses.extremes}`]: {
96
+ alignItems: 'center',
97
+ [`.${piecewiseColorLegendClasses.minLabel}, .${piecewiseColorLegendClasses.maxLabel}`]: {
98
+ alignItems: 'center',
99
+ display: 'flex',
100
+ flexDirection: 'column'
101
+ }
102
+ }
103
+ }
104
+ });
27
105
  });
28
- function PiecewiseColorLegend(props) {
106
+ const PiecewiseColorLegend = consumeThemeProps('MuiPiecewiseColorLegend', {
107
+ defaultProps: {
108
+ direction: 'horizontal',
109
+ labelPosition: 'extremes',
110
+ labelFormatter: piecewiseColorDefaultLabelFormatter
111
+ },
112
+ classesResolver: useUtilityClasses
113
+ }, function PiecewiseColorLegend(props, ref) {
29
114
  const {
115
+ direction,
116
+ classes,
117
+ className,
118
+ markType,
119
+ labelPosition,
30
120
  axisDirection,
31
121
  axisId,
32
- hideFirst,
33
- hideLast,
34
- labelFormatter = defaultLabelFormatter,
122
+ labelFormatter,
35
123
  onItemClick
36
124
  } = props,
37
125
  other = _objectWithoutPropertiesLoose(props, _excluded);
126
+ const isVertical = direction === 'vertical';
127
+ const isReverse = isVertical;
38
128
  const axisItem = useAxis({
39
129
  axisDirection,
40
130
  axisId
@@ -47,42 +137,83 @@ function PiecewiseColorLegend(props) {
47
137
  location: 'legend'
48
138
  }) ?? v.toLocaleString();
49
139
  const formattedLabels = colorMap.thresholds.map(valueFormatter);
50
- const itemsToDisplay = colorMap.colors.map((color, index) => {
51
- const isFirst = index === 0;
52
- const isLast = index === colorMap.colors.length - 1;
53
- if (hideFirst && isFirst || hideLast && isLast) {
54
- return null;
55
- }
56
- const data = _extends({}, isFirst ? {
57
- min: null,
58
- formattedMin: null
59
- } : {
60
- min: colorMap.thresholds[index - 1],
61
- formattedMin: formattedLabels[index - 1]
62
- }, isLast ? {
63
- max: null,
64
- formattedMax: null
65
- } : {
66
- max: colorMap.thresholds[index],
67
- formattedMax: formattedLabels[index]
68
- });
69
- const label = labelFormatter(data);
70
- if (label === null) {
71
- return null;
72
- }
73
- return {
74
- id: label,
140
+ const startClass = isReverse ? classes?.maxLabel : classes?.minLabel;
141
+ const endClass = isReverse ? classes?.minLabel : classes?.maxLabel;
142
+ const colors = colorMap.colors.map((color, colorIndex) => ({
143
+ color,
144
+ colorIndex
145
+ }));
146
+ const orderedColors = isReverse ? colors.reverse() : colors;
147
+ const isStart = labelPosition === 'start';
148
+ const isEnd = labelPosition === 'end';
149
+ const isExtremes = labelPosition === 'extremes';
150
+ return /*#__PURE__*/_jsx(RootElement, _extends({
151
+ className: clsx(classes?.root, className),
152
+ ref: ref
153
+ }, other, {
154
+ ownerState: props,
155
+ children: orderedColors.map(({
75
156
  color,
76
- label,
77
- minValue: data.min,
78
- maxValue: data.max
79
- };
80
- }).filter(notNull);
81
- return /*#__PURE__*/_jsx(LegendPerItem, _extends({}, other, {
82
- itemsToDisplay: itemsToDisplay,
83
- onItemClick: onItemClick ? (event, i) => onItemClick(event, piecewiseColorContextBuilder(itemsToDisplay[i]), i) : undefined
157
+ colorIndex
158
+ }, index) => {
159
+ const isFirst = index === 0;
160
+ const isLast = index === colorMap.colors.length - 1;
161
+ const isFirstColor = colorIndex === 0;
162
+ const isLastColor = colorIndex === colorMap.colors.length - 1;
163
+ const data = _extends({
164
+ index: colorIndex,
165
+ length: formattedLabels.length
166
+ }, isFirstColor ? {
167
+ min: null,
168
+ formattedMin: null
169
+ } : {
170
+ min: colorMap.thresholds[colorIndex - 1],
171
+ formattedMin: formattedLabels[colorIndex - 1]
172
+ }, isLastColor ? {
173
+ max: null,
174
+ formattedMax: null
175
+ } : {
176
+ max: colorMap.thresholds[colorIndex],
177
+ formattedMax: formattedLabels[colorIndex]
178
+ });
179
+ const label = labelFormatter?.(data);
180
+ if (label === null || label === undefined) {
181
+ return null;
182
+ }
183
+ const isTextBefore = isStart || isExtremes && isFirst;
184
+ const isTextAfter = isEnd || isExtremes && isLast;
185
+ const clickObject = {
186
+ type: 'piecewiseColor',
187
+ color,
188
+ label,
189
+ minValue: data.min,
190
+ maxValue: data.max
191
+ };
192
+ const Element = onItemClick ? 'button' : 'div';
193
+ return /*#__PURE__*/_jsx("li", {
194
+ children: /*#__PURE__*/_jsxs(Element, {
195
+ role: onItemClick ? 'button' : undefined,
196
+ type: onItemClick ? 'button' : undefined,
197
+ onClick:
198
+ // @ts-ignore onClick is only attached to a button
199
+ onItemClick ? event => onItemClick(event, clickObject, index) : undefined,
200
+ className: clsx(classes?.item, index === 0 && `${startClass}`, index === orderedColors.length - 1 && `${endClass}`),
201
+ children: [isTextBefore && /*#__PURE__*/_jsx(ChartsLabel, {
202
+ className: classes?.label,
203
+ children: label
204
+ }), /*#__PURE__*/_jsx(ChartsLabelMark, {
205
+ className: classes?.mark,
206
+ type: markType,
207
+ color: color
208
+ }), isTextAfter && /*#__PURE__*/_jsx(ChartsLabel, {
209
+ className: classes?.label,
210
+ children: label
211
+ })]
212
+ })
213
+ }, colorIndex);
214
+ })
84
215
  }));
85
- }
216
+ });
86
217
  process.env.NODE_ENV !== "production" ? PiecewiseColorLegend.propTypes = {
87
218
  // ----------------------------- Warning --------------------------------
88
219
  // | These PropTypes are generated from the TypeScript type definitions |
@@ -102,76 +233,35 @@ process.env.NODE_ENV !== "production" ? PiecewiseColorLegend.propTypes = {
102
233
  * Override or extend the styles applied to the component.
103
234
  */
104
235
  classes: PropTypes.object,
236
+ className: PropTypes.string,
105
237
  /**
106
238
  * The direction of the legend layout.
107
- * The default depends on the chart.
108
- */
109
- direction: PropTypes.oneOf(['column', 'row']).isRequired,
110
- /**
111
- * Hide the first item of the legend, corresponding to the [-infinity, min] piece.
112
- * @default false
239
+ * @default 'horizontal'
113
240
  */
114
- hideFirst: PropTypes.bool,
115
- /**
116
- * Hide the last item of the legend, corresponding to the [max, +infinity] piece.
117
- * @default false
118
- */
119
- hideLast: PropTypes.bool,
120
- /**
121
- * Space between two legend items (in px).
122
- * @default 10
123
- */
124
- itemGap: PropTypes.number,
125
- /**
126
- * Height of the item mark (in px).
127
- * @default 20
128
- */
129
- itemMarkHeight: PropTypes.number,
130
- /**
131
- * Width of the item mark (in px).
132
- * @default 20
133
- */
134
- itemMarkWidth: PropTypes.number,
241
+ direction: PropTypes.oneOf(['horizontal', 'vertical']),
135
242
  /**
136
243
  * Format the legend labels.
137
244
  * @param {PiecewiseLabelFormatterParams} params The bound of the piece to format.
138
- * @returns {string|null} The displayed label, or `null` to skip the item.
245
+ * @returns {string|null} The displayed label, `''` to skip the label but show the color mark, or `null` to skip it entirely.
139
246
  */
140
247
  labelFormatter: PropTypes.func,
141
248
  /**
142
- * Style applied to legend labels.
143
- * @default theme.typography.subtitle1
249
+ * Where to position the labels relative to the gradient.
250
+ * @default 'extremes'
144
251
  */
145
- labelStyle: PropTypes.object,
252
+ labelPosition: PropTypes.oneOf(['start', 'end', 'extremes']),
146
253
  /**
147
- * Space between the mark and the label (in px).
148
- * @default 5
254
+ * The type of the mark.
255
+ * @default 'square'
149
256
  */
150
- markGap: PropTypes.number,
257
+ markType: PropTypes.oneOf(['square', 'circle', 'line']),
151
258
  /**
152
259
  * Callback fired when a legend item is clicked.
153
- * @param {React.MouseEvent<SVGRectElement, MouseEvent>} event The click event.
260
+ * @param {React.MouseEvent<HTMLButtonElement, MouseEvent>} event The click event.
154
261
  * @param {PiecewiseColorLegendItemContext} legendItem The legend item data.
155
262
  * @param {number} index The index of the clicked legend item.
156
263
  */
157
264
  onItemClick: PropTypes.func,
158
- /**
159
- * Legend padding (in px).
160
- * Can either be a single number, or an object with top, left, bottom, right properties.
161
- * @default 10
162
- */
163
- padding: PropTypes.oneOfType([PropTypes.number, PropTypes.shape({
164
- bottom: PropTypes.number,
165
- left: PropTypes.number,
166
- right: PropTypes.number,
167
- top: PropTypes.number
168
- })]),
169
- /**
170
- * The position of the legend.
171
- */
172
- position: PropTypes.shape({
173
- horizontal: PropTypes.oneOf(['left', 'middle', 'right']).isRequired,
174
- vertical: PropTypes.oneOf(['bottom', 'middle', 'top']).isRequired
175
- }).isRequired
265
+ sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
176
266
  } : void 0;
177
267
  export { PiecewiseColorLegend };
@@ -1,69 +1,26 @@
1
- import { ChartsTextStyle } from '../ChartsText';
2
- import { PieItemId } from '../models';
3
- import { SeriesId } from '../models/seriesType/common';
4
- interface LegendItemContextBase {
1
+ import type { ChartsLegendProps } from './ChartsLegend';
2
+ import { ContinuousColorLegendProps } from './ContinuousColorLegend';
3
+ import { ChartsLegendPosition } from './legend.types';
4
+ import { PiecewiseColorLegendProps } from './PiecewiseColorLegend';
5
+ export interface ChartsLegendSlots {
5
6
  /**
6
- * The color used in the legend
7
+ * Custom rendering of the legend.
8
+ * @default ChartsLegend
7
9
  */
8
- color: string;
9
- /**
10
- * The label displayed in the legend
11
- */
12
- label: string;
10
+ legend?: React.JSXElementConstructor<ChartsLegendProps> | React.JSXElementConstructor<ContinuousColorLegendProps> | React.JSXElementConstructor<PiecewiseColorLegendProps>;
13
11
  }
14
- export interface LegendItemParams extends Partial<Omit<SeriesLegendItemContext, 'type' | keyof LegendItemContextBase>>, Partial<Omit<PiecewiseColorLegendItemContext, 'type' | keyof LegendItemContextBase>>, LegendItemContextBase {
15
- /**
16
- * The identifier of the legend element.
17
- * Used for internal purpose such as `key` props
18
- */
19
- id: number | string;
20
- }
21
- export interface SeriesLegendItemContext extends LegendItemContextBase {
22
- /**
23
- * The type of the legend item
24
- * - `series` is used for series legend item
25
- * - `piecewiseColor` is used for piecewise color legend item
26
- */
27
- type: 'series';
28
- /**
29
- * The identifier of the series
30
- */
31
- seriesId: SeriesId;
32
- /**
33
- * The identifier of the pie item
34
- */
35
- itemId?: PieItemId;
12
+ export interface ChartsLegendSlotProps {
13
+ legend?: Partial<ChartsLegendProps | ContinuousColorLegendProps | PiecewiseColorLegendProps> & ChartsLegendPosition;
36
14
  }
37
- export interface PiecewiseColorLegendItemContext extends LegendItemContextBase {
15
+ export interface ChartsLegendSlotExtension {
38
16
  /**
39
- * The type of the legend item
40
- * - `series` is used for series legend item
41
- * - `piecewiseColor` is used for piecewise color legend item
17
+ * Overridable component slots.
18
+ * @default {}
42
19
  */
43
- type: 'piecewiseColor';
20
+ slots?: ChartsLegendSlots;
44
21
  /**
45
- * The minimum value of the category
22
+ * The props used for each component slot.
23
+ * @default {}
46
24
  */
47
- minValue: number | Date | null;
48
- /**
49
- * The maximum value of the category
50
- */
51
- maxValue: number | Date | null;
52
- }
53
- export type LegendItemContext = SeriesLegendItemContext | PiecewiseColorLegendItemContext;
54
- export interface LegendItemWithPosition extends LegendItemParams {
55
- positionX: number;
56
- positionY: number;
57
- innerHeight: number;
58
- innerWidth: number;
59
- outerHeight: number;
60
- outerWidth: number;
61
- rowIndex: number;
25
+ slotProps?: ChartsLegendSlotProps;
62
26
  }
63
- export type GetItemSpaceType = (label: string, inStyle?: ChartsTextStyle) => {
64
- innerWidth: number;
65
- innerHeight: number;
66
- outerWidth: number;
67
- outerHeight: number;
68
- };
69
- export {};
@@ -1,19 +1,18 @@
1
+ import type { ChartsLegendProps } from './ChartsLegend';
2
+ import type { ChartsLegendSlotExtension } from './chartsLegend.types';
1
3
  export interface ChartsLegendClasses {
2
4
  /** Styles applied to the root element. */
3
5
  root: string;
4
6
  /** Styles applied to a series element. */
5
7
  series: string;
6
- /** Styles applied to the item background. */
7
- itemBackground: string;
8
8
  /** Styles applied to series mark element. */
9
9
  mark: string;
10
10
  /** Styles applied to the series label. */
11
11
  label: string;
12
- /** Styles applied to the legend with column layout. */
13
- column: string;
14
- /** Styles applied to the legend with row layout. */
15
- row: string;
12
+ /** Styles applied to the legend in column layout. */
13
+ vertical: string;
14
+ /** Styles applied to the legend in row layout. */
15
+ horizontal: string;
16
16
  }
17
- export type ChartsLegendClassKey = keyof ChartsLegendClasses;
18
- export declare function getLegendUtilityClass(slot: string): string;
17
+ export declare const useUtilityClasses: (props: ChartsLegendProps & ChartsLegendSlotExtension) => Record<"root" | "label" | "mark" | "series", string>;
19
18
  export declare const legendClasses: ChartsLegendClasses;
@@ -1,6 +1,20 @@
1
1
  import generateUtilityClass from '@mui/utils/generateUtilityClass';
2
2
  import generateUtilityClasses from '@mui/utils/generateUtilityClasses';
3
- export function getLegendUtilityClass(slot) {
3
+ import composeClasses from '@mui/utils/composeClasses';
4
+ function getLegendUtilityClass(slot) {
4
5
  return generateUtilityClass('MuiChartsLegend', slot);
5
6
  }
6
- export const legendClasses = generateUtilityClasses('MuiChartsLegend', ['root', 'series', 'itemBackground', 'mark', 'label', 'column', 'row']);
7
+ export const useUtilityClasses = props => {
8
+ const {
9
+ classes,
10
+ direction
11
+ } = props;
12
+ const slots = {
13
+ root: ['root', direction],
14
+ mark: ['mark'],
15
+ label: ['label'],
16
+ series: ['series']
17
+ };
18
+ return composeClasses(slots, getLegendUtilityClass, classes);
19
+ };
20
+ export const legendClasses = generateUtilityClasses('MuiChartsLegend', ['root', 'series', 'mark', 'label', 'vertical', 'horizontal']);
@@ -0,0 +1,13 @@
1
+ import { AxisId } from '../models/axis';
2
+ export interface ColorLegendSelector {
3
+ /**
4
+ * The axis direction containing the color configuration to represent.
5
+ * @default 'z'
6
+ */
7
+ axisDirection?: 'x' | 'y' | 'z';
8
+ /**
9
+ * The id of the axis item with the color configuration to represent.
10
+ * @default The first axis item.
11
+ */
12
+ axisId?: AxisId;
13
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,26 @@
1
+ import type { ContinuousColorLegendProps } from './ContinuousColorLegend';
2
+ import type { ChartsLegendSlotExtension } from './chartsLegend.types';
3
+ export interface ContinuousColorLegendClasses {
4
+ /** Styles applied to the root element. */
5
+ root: string;
6
+ /** Styles applied to the list item that renders the `minLabel`. */
7
+ minLabel: string;
8
+ /** Styles applied to the list item that renders the `maxLabel`. */
9
+ maxLabel: string;
10
+ /** Styles applied to the list item with the gradient. */
11
+ gradient: string;
12
+ /** Styles applied to the legend in column layout. */
13
+ vertical: string;
14
+ /** Styles applied to the legend in row layout. */
15
+ horizontal: string;
16
+ /** Styles applied to the legend with the labels before the gradient. */
17
+ start: string;
18
+ /** Styles applied to the legend with the labels after the gradient. */
19
+ end: string;
20
+ /** Styles applied to the legend with the labels on the extremes of the gradient. */
21
+ extremes: string;
22
+ /** Styles applied to the series label. */
23
+ label: string;
24
+ }
25
+ export declare const useUtilityClasses: (props: ContinuousColorLegendProps & ChartsLegendSlotExtension) => Record<"root" | "label" | "mark" | "minLabel" | "maxLabel" | "gradient", string>;
26
+ export declare const continuousColorLegendClasses: ContinuousColorLegendClasses;
@@ -0,0 +1,23 @@
1
+ import generateUtilityClass from '@mui/utils/generateUtilityClass';
2
+ import generateUtilityClasses from '@mui/utils/generateUtilityClasses';
3
+ import composeClasses from '@mui/utils/composeClasses';
4
+ function getLegendUtilityClass(slot) {
5
+ return generateUtilityClass('MuiContinuousColorLegend', slot);
6
+ }
7
+ export const useUtilityClasses = props => {
8
+ const {
9
+ classes,
10
+ direction,
11
+ labelPosition
12
+ } = props;
13
+ const slots = {
14
+ root: ['root', direction, labelPosition],
15
+ minLabel: ['minLabel'],
16
+ maxLabel: ['maxLabel'],
17
+ gradient: ['gradient'],
18
+ mark: ['mark'],
19
+ label: ['label']
20
+ };
21
+ return composeClasses(slots, getLegendUtilityClass, classes);
22
+ };
23
+ export const continuousColorLegendClasses = generateUtilityClasses('MuiContinuousColorLegend', ['root', 'minLabel', 'maxLabel', 'gradient', 'vertical', 'horizontal', 'start', 'end', 'extremes', 'label']);
@@ -0,0 +1 @@
1
+ export type Direction = 'vertical' | 'horizontal';
@@ -0,0 +1 @@
1
+ export {};
@@ -1,6 +1,16 @@
1
1
  export * from './ChartsLegend';
2
- export * from './DefaultChartsLegend';
2
+ export * from './chartsLegend.types';
3
+ export * from './direction';
4
+ export * from './legendContext.types';
5
+ export { legendClasses } from './chartsLegendClasses';
6
+ export type { ChartsLegendClasses } from './chartsLegendClasses';
3
7
  export * from './ContinuousColorLegend';
8
+ export * from './colorLegend.types';
9
+ export { continuousColorLegendClasses } from './continuousColorLegendClasses';
10
+ export type { ContinuousColorLegendClasses } from './continuousColorLegendClasses';
4
11
  export * from './PiecewiseColorLegend';
5
- export * from './chartsLegendClasses';
6
- export * from './utils';
12
+ export { piecewiseColorLegendClasses } from './piecewiseColorLegendClasses';
13
+ export type { PiecewiseColorLegendClasses } from './piecewiseColorLegendClasses';
14
+ export { piecewiseColorDefaultLabelFormatter } from './piecewiseColorDefaultLabelFormatter';
15
+ export type { PiecewiseLabelFormatterParams } from './piecewiseColorLegend.types';
16
+ export * from './legend.types';
@@ -1,6 +1,12 @@
1
1
  export * from "./ChartsLegend.js";
2
- export * from "./DefaultChartsLegend.js";
2
+ export * from "./chartsLegend.types.js";
3
+ export * from "./direction.js";
4
+ export * from "./legendContext.types.js";
5
+ export { legendClasses } from "./chartsLegendClasses.js";
3
6
  export * from "./ContinuousColorLegend.js";
7
+ export * from "./colorLegend.types.js";
8
+ export { continuousColorLegendClasses } from "./continuousColorLegendClasses.js";
4
9
  export * from "./PiecewiseColorLegend.js";
5
- export * from "./chartsLegendClasses.js";
6
- export * from "./utils.js";
10
+ export { piecewiseColorLegendClasses } from "./piecewiseColorLegendClasses.js";
11
+ export { piecewiseColorDefaultLabelFormatter } from "./piecewiseColorDefaultLabelFormatter.js";
12
+ export * from "./legend.types.js";