@mui/x-charts 7.5.0 → 7.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (245) hide show
  1. package/BarChart/BarChart.js +30 -3
  2. package/BarChart/BarElement.d.ts +0 -3
  3. package/BarChart/BarElement.js +8 -19
  4. package/BarChart/BarLabel/BarLabel.d.ts +1342 -0
  5. package/BarChart/BarLabel/BarLabel.js +60 -0
  6. package/BarChart/BarLabel/BarLabel.types.d.ts +39 -0
  7. package/BarChart/BarLabel/BarLabel.types.js +5 -0
  8. package/BarChart/BarLabel/BarLabelItem.d.ts +53 -0
  9. package/BarChart/BarLabel/BarLabelItem.js +127 -0
  10. package/BarChart/BarLabel/BarLabelPlot.d.ts +16 -0
  11. package/BarChart/BarLabel/BarLabelPlot.js +106 -0
  12. package/BarChart/BarLabel/barLabelClasses.d.ts +13 -0
  13. package/BarChart/BarLabel/barLabelClasses.js +29 -0
  14. package/BarChart/BarLabel/getBarLabel.d.ts +10 -0
  15. package/BarChart/BarLabel/getBarLabel.js +31 -0
  16. package/BarChart/BarLabel/index.d.ts +6 -0
  17. package/BarChart/BarLabel/index.js +25 -0
  18. package/BarChart/BarPlot.d.ts +15 -4
  19. package/BarChart/BarPlot.js +22 -34
  20. package/BarChart/checkScaleErrors.d.ts +11 -0
  21. package/BarChart/checkScaleErrors.js +33 -0
  22. package/BarChart/index.d.ts +1 -0
  23. package/BarChart/index.js +11 -0
  24. package/BarChart/types.d.ts +0 -2
  25. package/CHANGELOG.md +148 -5418
  26. package/ChartContainer/ChartContainer.d.ts +3 -2
  27. package/ChartContainer/ChartContainer.js +20 -3
  28. package/ChartsAxis/ChartsAxis.js +1 -1
  29. package/ChartsAxisHighlight/ChartsAxisHighlight.js +1 -1
  30. package/ChartsClipPath/ChartsClipPath.js +1 -1
  31. package/ChartsGrid/ChartsGrid.js +1 -1
  32. package/ChartsLegend/ChartsLegend.js +1 -1
  33. package/ChartsLegend/DefaultChartsLegend.js +1 -1
  34. package/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +1 -1
  35. package/ChartsReferenceLine/ChartsReferenceLine.js +1 -1
  36. package/ChartsSurface.js +1 -1
  37. package/ChartsText/ChartsText.js +1 -1
  38. package/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
  39. package/ChartsTooltip/ChartsItemTooltipContent.js +1 -1
  40. package/ChartsTooltip/ChartsTooltip.js +1 -1
  41. package/ChartsTooltip/DefaultChartsAxisTooltipContent.js +1 -1
  42. package/ChartsTooltip/DefaultChartsItemTooltipContent.js +1 -1
  43. package/ChartsVoronoiHandler/ChartsVoronoiHandler.js +14 -2
  44. package/ChartsXAxis/ChartsXAxis.js +1 -1
  45. package/ChartsYAxis/ChartsYAxis.js +1 -1
  46. package/Gauge/Gauge.js +1 -1
  47. package/Gauge/GaugeContainer.js +1 -1
  48. package/Gauge/GaugeValueText.js +1 -1
  49. package/LineChart/AnimatedArea.js +1 -1
  50. package/LineChart/AnimatedLine.js +1 -1
  51. package/LineChart/AreaElement.d.ts +0 -2
  52. package/LineChart/AreaElement.js +8 -18
  53. package/LineChart/AreaPlot.js +1 -3
  54. package/LineChart/LineChart.js +19 -2
  55. package/LineChart/LineElement.d.ts +0 -2
  56. package/LineChart/LineElement.js +8 -18
  57. package/LineChart/LineHighlightElement.js +1 -1
  58. package/LineChart/LineHighlightPlot.js +1 -1
  59. package/LineChart/LinePlot.js +1 -3
  60. package/LineChart/MarkElement.d.ts +0 -2
  61. package/LineChart/MarkElement.js +11 -33
  62. package/LineChart/MarkPlot.js +1 -2
  63. package/PieChart/PieArc.d.ts +4 -1
  64. package/PieChart/PieArc.js +8 -4
  65. package/PieChart/PieArcLabel.js +1 -1
  66. package/PieChart/PieArcLabelPlot.d.ts +1 -1
  67. package/PieChart/PieArcLabelPlot.js +2 -8
  68. package/PieChart/PieArcPlot.d.ts +1 -1
  69. package/PieChart/PieArcPlot.js +6 -8
  70. package/PieChart/PieChart.js +19 -2
  71. package/PieChart/PiePlot.js +3 -7
  72. package/PieChart/dataTransform/useTransformData.d.ts +1 -1
  73. package/PieChart/dataTransform/useTransformData.js +10 -25
  74. package/ResponsiveChartContainer/ResponsiveChartContainer.js +14 -1
  75. package/ScatterChart/Scatter.js +15 -11
  76. package/ScatterChart/ScatterChart.js +19 -2
  77. package/ScatterChart/ScatterPlot.js +1 -1
  78. package/SparkLineChart/SparkLineChart.d.ts +1 -1
  79. package/SparkLineChart/SparkLineChart.js +14 -1
  80. package/context/HighlightedProvider/HighlightedContext.d.ts +65 -0
  81. package/context/HighlightedProvider/HighlightedContext.js +36 -0
  82. package/context/HighlightedProvider/HighlightedProvider.d.ts +20 -0
  83. package/context/HighlightedProvider/HighlightedProvider.js +97 -0
  84. package/context/HighlightedProvider/createIsFaded.d.ts +2 -0
  85. package/context/HighlightedProvider/createIsFaded.js +19 -0
  86. package/context/HighlightedProvider/createIsHighlighted.d.ts +2 -0
  87. package/context/HighlightedProvider/createIsHighlighted.js +19 -0
  88. package/context/HighlightedProvider/index.d.ts +4 -0
  89. package/context/HighlightedProvider/index.js +49 -0
  90. package/context/HighlightedProvider/useHighlighted.d.ts +9 -0
  91. package/context/HighlightedProvider/useHighlighted.js +24 -0
  92. package/context/HighlightedProvider/useItemHighlighted.d.ts +21 -0
  93. package/context/HighlightedProvider/useItemHighlighted.js +37 -0
  94. package/context/ZAxisContextProvider.js +1 -1
  95. package/context/index.d.ts +1 -1
  96. package/context/index.js +15 -0
  97. package/esm/BarChart/BarChart.js +30 -3
  98. package/esm/BarChart/BarElement.js +9 -20
  99. package/esm/BarChart/BarLabel/BarLabel.js +51 -0
  100. package/esm/BarChart/BarLabel/BarLabel.types.js +1 -0
  101. package/esm/BarChart/BarLabel/BarLabelItem.js +119 -0
  102. package/esm/BarChart/BarLabel/BarLabelPlot.js +98 -0
  103. package/esm/BarChart/BarLabel/barLabelClasses.js +19 -0
  104. package/esm/BarChart/BarLabel/getBarLabel.js +24 -0
  105. package/esm/BarChart/BarLabel/index.js +2 -0
  106. package/esm/BarChart/BarPlot.js +22 -34
  107. package/esm/BarChart/checkScaleErrors.js +27 -0
  108. package/esm/BarChart/index.js +2 -1
  109. package/esm/ChartContainer/ChartContainer.js +20 -3
  110. package/esm/ChartsAxis/ChartsAxis.js +1 -1
  111. package/esm/ChartsAxisHighlight/ChartsAxisHighlight.js +1 -1
  112. package/esm/ChartsClipPath/ChartsClipPath.js +1 -1
  113. package/esm/ChartsGrid/ChartsGrid.js +1 -1
  114. package/esm/ChartsLegend/ChartsLegend.js +1 -1
  115. package/esm/ChartsLegend/DefaultChartsLegend.js +1 -1
  116. package/esm/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +1 -1
  117. package/esm/ChartsReferenceLine/ChartsReferenceLine.js +1 -1
  118. package/esm/ChartsSurface.js +1 -1
  119. package/esm/ChartsText/ChartsText.js +1 -1
  120. package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
  121. package/esm/ChartsTooltip/ChartsItemTooltipContent.js +1 -1
  122. package/esm/ChartsTooltip/ChartsTooltip.js +1 -1
  123. package/esm/ChartsTooltip/DefaultChartsAxisTooltipContent.js +1 -1
  124. package/esm/ChartsTooltip/DefaultChartsItemTooltipContent.js +1 -1
  125. package/esm/ChartsVoronoiHandler/ChartsVoronoiHandler.js +14 -2
  126. package/esm/ChartsXAxis/ChartsXAxis.js +1 -1
  127. package/esm/ChartsYAxis/ChartsYAxis.js +1 -1
  128. package/esm/Gauge/Gauge.js +1 -1
  129. package/esm/Gauge/GaugeContainer.js +1 -1
  130. package/esm/Gauge/GaugeValueText.js +1 -1
  131. package/esm/LineChart/AnimatedArea.js +1 -1
  132. package/esm/LineChart/AnimatedLine.js +1 -1
  133. package/esm/LineChart/AreaElement.js +9 -19
  134. package/esm/LineChart/AreaPlot.js +1 -3
  135. package/esm/LineChart/LineChart.js +19 -2
  136. package/esm/LineChart/LineElement.js +9 -19
  137. package/esm/LineChart/LineHighlightElement.js +1 -1
  138. package/esm/LineChart/LineHighlightPlot.js +1 -1
  139. package/esm/LineChart/LinePlot.js +1 -3
  140. package/esm/LineChart/MarkElement.js +12 -34
  141. package/esm/LineChart/MarkPlot.js +1 -2
  142. package/esm/PieChart/PieArc.js +8 -4
  143. package/esm/PieChart/PieArcLabel.js +1 -1
  144. package/esm/PieChart/PieArcLabelPlot.js +2 -8
  145. package/esm/PieChart/PieArcPlot.js +6 -8
  146. package/esm/PieChart/PieChart.js +19 -2
  147. package/esm/PieChart/PiePlot.js +3 -7
  148. package/esm/PieChart/dataTransform/useTransformData.js +10 -25
  149. package/esm/ResponsiveChartContainer/ResponsiveChartContainer.js +14 -1
  150. package/esm/ScatterChart/Scatter.js +16 -12
  151. package/esm/ScatterChart/ScatterChart.js +19 -2
  152. package/esm/ScatterChart/ScatterPlot.js +1 -1
  153. package/esm/SparkLineChart/SparkLineChart.js +14 -1
  154. package/esm/context/HighlightedProvider/HighlightedContext.js +29 -0
  155. package/esm/context/HighlightedProvider/HighlightedProvider.js +89 -0
  156. package/esm/context/HighlightedProvider/createIsFaded.js +12 -0
  157. package/esm/context/HighlightedProvider/createIsHighlighted.js +12 -0
  158. package/esm/context/HighlightedProvider/index.js +4 -0
  159. package/esm/context/HighlightedProvider/useHighlighted.js +17 -0
  160. package/esm/context/HighlightedProvider/useItemHighlighted.js +29 -0
  161. package/esm/context/ZAxisContextProvider.js +1 -1
  162. package/esm/context/index.js +1 -0
  163. package/esm/hooks/useInteractionItemProps.js +9 -41
  164. package/hooks/useInteractionItemProps.d.ts +1 -4
  165. package/hooks/useInteractionItemProps.js +11 -45
  166. package/index.js +1 -1
  167. package/internals/colorScale.d.ts +1 -1
  168. package/internals/defaultizeColor.d.ts +13 -13
  169. package/models/seriesType/common.d.ts +4 -1
  170. package/modern/BarChart/BarChart.js +30 -3
  171. package/modern/BarChart/BarElement.js +9 -20
  172. package/modern/BarChart/BarLabel/BarLabel.js +51 -0
  173. package/modern/BarChart/BarLabel/BarLabel.types.js +1 -0
  174. package/modern/BarChart/BarLabel/BarLabelItem.js +119 -0
  175. package/modern/BarChart/BarLabel/BarLabelPlot.js +98 -0
  176. package/modern/BarChart/BarLabel/barLabelClasses.js +19 -0
  177. package/modern/BarChart/BarLabel/getBarLabel.js +24 -0
  178. package/modern/BarChart/BarLabel/index.js +2 -0
  179. package/modern/BarChart/BarPlot.js +22 -34
  180. package/modern/BarChart/checkScaleErrors.js +27 -0
  181. package/modern/BarChart/index.js +2 -1
  182. package/modern/ChartContainer/ChartContainer.js +20 -3
  183. package/modern/ChartsAxis/ChartsAxis.js +1 -1
  184. package/modern/ChartsAxisHighlight/ChartsAxisHighlight.js +1 -1
  185. package/modern/ChartsClipPath/ChartsClipPath.js +1 -1
  186. package/modern/ChartsGrid/ChartsGrid.js +1 -1
  187. package/modern/ChartsLegend/ChartsLegend.js +1 -1
  188. package/modern/ChartsLegend/DefaultChartsLegend.js +1 -1
  189. package/modern/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +1 -1
  190. package/modern/ChartsReferenceLine/ChartsReferenceLine.js +1 -1
  191. package/modern/ChartsSurface.js +1 -1
  192. package/modern/ChartsText/ChartsText.js +1 -1
  193. package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
  194. package/modern/ChartsTooltip/ChartsItemTooltipContent.js +1 -1
  195. package/modern/ChartsTooltip/ChartsTooltip.js +1 -1
  196. package/modern/ChartsTooltip/DefaultChartsAxisTooltipContent.js +1 -1
  197. package/modern/ChartsTooltip/DefaultChartsItemTooltipContent.js +1 -1
  198. package/modern/ChartsVoronoiHandler/ChartsVoronoiHandler.js +14 -2
  199. package/modern/ChartsXAxis/ChartsXAxis.js +1 -1
  200. package/modern/ChartsYAxis/ChartsYAxis.js +1 -1
  201. package/modern/Gauge/Gauge.js +1 -1
  202. package/modern/Gauge/GaugeContainer.js +1 -1
  203. package/modern/Gauge/GaugeValueText.js +1 -1
  204. package/modern/LineChart/AnimatedArea.js +1 -1
  205. package/modern/LineChart/AnimatedLine.js +1 -1
  206. package/modern/LineChart/AreaElement.js +9 -19
  207. package/modern/LineChart/AreaPlot.js +1 -3
  208. package/modern/LineChart/LineChart.js +19 -2
  209. package/modern/LineChart/LineElement.js +9 -19
  210. package/modern/LineChart/LineHighlightElement.js +1 -1
  211. package/modern/LineChart/LineHighlightPlot.js +1 -1
  212. package/modern/LineChart/LinePlot.js +1 -3
  213. package/modern/LineChart/MarkElement.js +12 -34
  214. package/modern/LineChart/MarkPlot.js +1 -2
  215. package/modern/PieChart/PieArc.js +8 -4
  216. package/modern/PieChart/PieArcLabel.js +1 -1
  217. package/modern/PieChart/PieArcLabelPlot.js +2 -8
  218. package/modern/PieChart/PieArcPlot.js +6 -8
  219. package/modern/PieChart/PieChart.js +19 -2
  220. package/modern/PieChart/PiePlot.js +3 -7
  221. package/modern/PieChart/dataTransform/useTransformData.js +10 -25
  222. package/modern/ResponsiveChartContainer/ResponsiveChartContainer.js +14 -1
  223. package/modern/ScatterChart/Scatter.js +16 -12
  224. package/modern/ScatterChart/ScatterChart.js +19 -2
  225. package/modern/ScatterChart/ScatterPlot.js +1 -1
  226. package/modern/SparkLineChart/SparkLineChart.js +14 -1
  227. package/modern/context/HighlightedProvider/HighlightedContext.js +29 -0
  228. package/modern/context/HighlightedProvider/HighlightedProvider.js +89 -0
  229. package/modern/context/HighlightedProvider/createIsFaded.js +12 -0
  230. package/modern/context/HighlightedProvider/createIsHighlighted.js +12 -0
  231. package/modern/context/HighlightedProvider/index.js +4 -0
  232. package/modern/context/HighlightedProvider/useHighlighted.js +17 -0
  233. package/modern/context/HighlightedProvider/useItemHighlighted.js +29 -0
  234. package/modern/context/ZAxisContextProvider.js +1 -1
  235. package/modern/context/index.js +1 -0
  236. package/modern/hooks/useInteractionItemProps.js +9 -41
  237. package/modern/index.js +1 -1
  238. package/package.json +3 -3
  239. package/themeAugmentation/components.d.ts +4 -0
  240. package/themeAugmentation/overrides.d.ts +3 -0
  241. package/themeAugmentation/props.d.ts +2 -0
  242. package/context/HighlightProvider.d.ts +0 -45
  243. package/context/HighlightProvider.js +0 -60
  244. package/esm/context/HighlightProvider.js +0 -51
  245. package/modern/context/HighlightProvider.js +0 -51
@@ -0,0 +1,12 @@
1
+ export const createIsHighlighted = (highlightScope, highlightedItem) => input => {
2
+ if (!highlightScope) {
3
+ return false;
4
+ }
5
+ if (highlightScope.highlight === 'series') {
6
+ return input.seriesId === highlightedItem?.seriesId;
7
+ }
8
+ if (highlightScope.highlight === 'item') {
9
+ return input.dataIndex === highlightedItem?.dataIndex && input.seriesId === highlightedItem?.seriesId;
10
+ }
11
+ return false;
12
+ };
@@ -0,0 +1,4 @@
1
+ export * from './HighlightedProvider';
2
+ export * from './HighlightedContext';
3
+ export * from './useHighlighted';
4
+ export * from './useItemHighlighted';
@@ -0,0 +1,17 @@
1
+ import * as React from 'react';
2
+ import { HighlightedContext } from './HighlightedContext';
3
+
4
+ /**
5
+ * A hook to get the highlighted state of the chart.
6
+ *
7
+ * Please consider using the `useItemHighlighted` hook if you need to check the state of a specific item.
8
+ *
9
+ * @returns {HighlightedState} the state of the chart
10
+ */
11
+ export function useHighlighted() {
12
+ const highlighted = React.useContext(HighlightedContext);
13
+ if (highlighted === undefined) {
14
+ throw new Error(['MUI X: Could not find the highlighted ref context.', 'It looks like you rendered your component outside of a ChartsContainer parent component.'].join('\n'));
15
+ }
16
+ return highlighted;
17
+ }
@@ -0,0 +1,29 @@
1
+ import * as React from 'react';
2
+ import { HighlightedContext } from './HighlightedContext';
3
+ /**
4
+ * A hook to check the highlighted state of the item.
5
+ * This function already calculates that an item is not faded if it is highlighted.
6
+ *
7
+ * If you need fine control over the state, use the `useHighlighted` hook instead.
8
+ *
9
+ * @param {HighlightItemData} item is the item to check
10
+ * @returns {ItemHighlightedState} the state of the item
11
+ */
12
+ export function useItemHighlighted(item) {
13
+ const highlighted = React.useContext(HighlightedContext);
14
+ if (highlighted === undefined) {
15
+ throw new Error(['MUI X: Could not find the highlighted ref context.', 'It looks like you rendered your component outside of a ChartsContainer parent component.'].join('\n'));
16
+ }
17
+ if (!item) {
18
+ return {
19
+ isHighlighted: false,
20
+ isFaded: false
21
+ };
22
+ }
23
+ const isHighlighted = highlighted.isHighlighted(item);
24
+ const isFaded = !isHighlighted && highlighted.isFaded(item);
25
+ return {
26
+ isHighlighted,
27
+ isFaded
28
+ };
29
+ }
@@ -55,7 +55,7 @@ function ZAxisContextProvider(props) {
55
55
  process.env.NODE_ENV !== "production" ? ZAxisContextProvider.propTypes = {
56
56
  // ----------------------------- Warning --------------------------------
57
57
  // | These PropTypes are generated from the TypeScript type definitions |
58
- // | To update them edit the TypeScript types and run "yarn proptypes" |
58
+ // | To update them edit the TypeScript types and run "pnpm proptypes" |
59
59
  // ----------------------------------------------------------------------
60
60
  children: PropTypes.node,
61
61
  /**
@@ -1 +1,2 @@
1
+ export * from './HighlightedProvider';
1
2
  export { ZAxisContextProvider } from './ZAxisContextProvider';
@@ -1,13 +1,14 @@
1
1
  import * as React from 'react';
2
2
  import { InteractionContext } from '../context/InteractionProvider';
3
- import { HighlighContext } from '../context/HighlightProvider';
4
- export const useInteractionItemProps = (scope, skip) => {
3
+ import { HighlightedContext } from '../context';
4
+ export const useInteractionItemProps = skip => {
5
5
  const {
6
6
  dispatch: dispatchInteraction
7
7
  } = React.useContext(InteractionContext);
8
8
  const {
9
- dispatch: dispatchHighlight
10
- } = React.useContext(HighlighContext);
9
+ setHighlighted,
10
+ clearHighlighted
11
+ } = React.useContext(HighlightedContext);
11
12
  if (skip) {
12
13
  return () => ({});
13
14
  }
@@ -17,10 +18,9 @@ export const useInteractionItemProps = (scope, skip) => {
17
18
  type: 'enterItem',
18
19
  data
19
20
  });
20
- dispatchHighlight({
21
- type: 'enterItem',
22
- item: data,
23
- scope
21
+ setHighlighted({
22
+ seriesId: data.seriesId,
23
+ dataIndex: data.dataIndex
24
24
  });
25
25
  };
26
26
  const onMouseLeave = () => {
@@ -28,10 +28,7 @@ export const useInteractionItemProps = (scope, skip) => {
28
28
  type: 'leaveItem',
29
29
  data
30
30
  });
31
- dispatchHighlight({
32
- type: 'leaveItem',
33
- item: data
34
- });
31
+ clearHighlighted();
35
32
  };
36
33
  return {
37
34
  onMouseEnter,
@@ -39,33 +36,4 @@ export const useInteractionItemProps = (scope, skip) => {
39
36
  };
40
37
  };
41
38
  return getInteractionItemProps;
42
- };
43
- export const getIsHighlighted = (selectedItem, currentItem, highlightScope) => {
44
- if (!highlightScope?.highlighted || highlightScope.highlighted === 'none' || selectedItem === null) {
45
- return false;
46
- }
47
- const isSeriesSelected = selectedItem.type === currentItem.type && selectedItem.seriesId === currentItem.seriesId;
48
- if (!isSeriesSelected) {
49
- return false;
50
- }
51
- if (highlightScope.highlighted === 'series') {
52
- return isSeriesSelected;
53
- }
54
- return selectedItem.dataIndex !== undefined && selectedItem.dataIndex === currentItem.dataIndex;
55
- };
56
- export const getIsFaded = (selectedItem, currentItem, highlightScope) => {
57
- if (!highlightScope?.faded || highlightScope.faded === 'none' || selectedItem === null) {
58
- return false;
59
- }
60
- const isSeriesSelected = selectedItem.type === currentItem.type && selectedItem.seriesId === currentItem.seriesId;
61
- if (highlightScope.faded === 'series') {
62
- return isSeriesSelected && selectedItem.dataIndex !== currentItem.dataIndex;
63
- }
64
- if (highlightScope.faded === 'global') {
65
- if (!isSeriesSelected) {
66
- return true;
67
- }
68
- return selectedItem.dataIndex !== undefined && selectedItem.dataIndex !== currentItem.dataIndex;
69
- }
70
- return false;
71
39
  };
@@ -1,8 +1,5 @@
1
- import { HighlightScope } from '../context/HighlightProvider';
2
1
  import { SeriesItemIdentifier } from '../models';
3
- export declare const useInteractionItemProps: (scope?: Partial<HighlightScope>, skip?: boolean) => (() => {}) | ((data: SeriesItemIdentifier) => {
2
+ export declare const useInteractionItemProps: (skip?: boolean) => (() => {}) | ((data: SeriesItemIdentifier) => {
4
3
  onMouseEnter: () => void;
5
4
  onMouseLeave: () => void;
6
5
  });
7
- export declare const getIsHighlighted: (selectedItem: SeriesItemIdentifier | null, currentItem: SeriesItemIdentifier, highlightScope?: Partial<HighlightScope>) => boolean;
8
- export declare const getIsFaded: (selectedItem: SeriesItemIdentifier | null, currentItem: SeriesItemIdentifier, highlightScope?: Partial<HighlightScope>) => boolean;
@@ -3,19 +3,20 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.useInteractionItemProps = exports.getIsHighlighted = exports.getIsFaded = void 0;
6
+ exports.useInteractionItemProps = void 0;
7
7
  var React = _interopRequireWildcard(require("react"));
8
8
  var _InteractionProvider = require("../context/InteractionProvider");
9
- var _HighlightProvider = require("../context/HighlightProvider");
9
+ var _context = require("../context");
10
10
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
11
11
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
12
- const useInteractionItemProps = (scope, skip) => {
12
+ const useInteractionItemProps = skip => {
13
13
  const {
14
14
  dispatch: dispatchInteraction
15
15
  } = React.useContext(_InteractionProvider.InteractionContext);
16
16
  const {
17
- dispatch: dispatchHighlight
18
- } = React.useContext(_HighlightProvider.HighlighContext);
17
+ setHighlighted,
18
+ clearHighlighted
19
+ } = React.useContext(_context.HighlightedContext);
19
20
  if (skip) {
20
21
  return () => ({});
21
22
  }
@@ -25,10 +26,9 @@ const useInteractionItemProps = (scope, skip) => {
25
26
  type: 'enterItem',
26
27
  data
27
28
  });
28
- dispatchHighlight({
29
- type: 'enterItem',
30
- item: data,
31
- scope
29
+ setHighlighted({
30
+ seriesId: data.seriesId,
31
+ dataIndex: data.dataIndex
32
32
  });
33
33
  };
34
34
  const onMouseLeave = () => {
@@ -36,10 +36,7 @@ const useInteractionItemProps = (scope, skip) => {
36
36
  type: 'leaveItem',
37
37
  data
38
38
  });
39
- dispatchHighlight({
40
- type: 'leaveItem',
41
- item: data
42
- });
39
+ clearHighlighted();
43
40
  };
44
41
  return {
45
42
  onMouseEnter,
@@ -48,35 +45,4 @@ const useInteractionItemProps = (scope, skip) => {
48
45
  };
49
46
  return getInteractionItemProps;
50
47
  };
51
- exports.useInteractionItemProps = useInteractionItemProps;
52
- const getIsHighlighted = (selectedItem, currentItem, highlightScope) => {
53
- if (!highlightScope?.highlighted || highlightScope.highlighted === 'none' || selectedItem === null) {
54
- return false;
55
- }
56
- const isSeriesSelected = selectedItem.type === currentItem.type && selectedItem.seriesId === currentItem.seriesId;
57
- if (!isSeriesSelected) {
58
- return false;
59
- }
60
- if (highlightScope.highlighted === 'series') {
61
- return isSeriesSelected;
62
- }
63
- return selectedItem.dataIndex !== undefined && selectedItem.dataIndex === currentItem.dataIndex;
64
- };
65
- exports.getIsHighlighted = getIsHighlighted;
66
- const getIsFaded = (selectedItem, currentItem, highlightScope) => {
67
- if (!highlightScope?.faded || highlightScope.faded === 'none' || selectedItem === null) {
68
- return false;
69
- }
70
- const isSeriesSelected = selectedItem.type === currentItem.type && selectedItem.seriesId === currentItem.seriesId;
71
- if (highlightScope.faded === 'series') {
72
- return isSeriesSelected && selectedItem.dataIndex !== currentItem.dataIndex;
73
- }
74
- if (highlightScope.faded === 'global') {
75
- if (!isSeriesSelected) {
76
- return true;
77
- }
78
- return selectedItem.dataIndex !== undefined && selectedItem.dataIndex !== currentItem.dataIndex;
79
- }
80
- return false;
81
- };
82
- exports.getIsFaded = getIsFaded;
48
+ exports.useInteractionItemProps = useInteractionItemProps;
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-charts v7.5.0
2
+ * @mui/x-charts v7.6.0
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -2,4 +2,4 @@ import { ScaleOrdinal } from 'd3-scale';
2
2
  import { ContinuousColorConfig, PiecewiseColorConfig, OrdinalColorConfig } from '../models/colorMapping';
3
3
  export declare function getSequentialColorScale<Value extends number | Date>(config: ContinuousColorConfig<Value> | PiecewiseColorConfig<Value>): import("d3-scale").ScaleThreshold<Value, string, never> | import("d3-scale").ScaleSequential<string, never>;
4
4
  export declare function getOrdinalColorScale<Value extends number | Date | string>(config: OrdinalColorConfig<Value>): ScaleOrdinal<Value, string, null | string> | ScaleOrdinal<number, string, null | string>;
5
- export declare function getColorScale(config: ContinuousColorConfig | PiecewiseColorConfig | OrdinalColorConfig): ScaleOrdinal<string | number | Date, string, string | null> | ScaleOrdinal<number, string, string | null> | import("d3-scale").ScaleSequential<string, never> | import("d3-scale").ScaleThreshold<number | Date, string, never>;
5
+ export declare function getColorScale(config: ContinuousColorConfig | PiecewiseColorConfig | OrdinalColorConfig): import("d3-scale").ScaleSequential<string, never> | ScaleOrdinal<number, string, string | null> | ScaleOrdinal<string | number | Date, string, string | null> | import("d3-scale").ScaleThreshold<number | Date, string, never>;
@@ -58,19 +58,6 @@ export declare function defaultizeColor(series: AllSeriesType, seriesIndex: numb
58
58
  yAxisKey?: string | undefined;
59
59
  stack?: string | undefined;
60
60
  stackOrder?: import("..").StackOrderType | undefined;
61
- } | {
62
- type: "scatter";
63
- data: import("../models/seriesType").ScatterValueType[];
64
- markerSize?: number | undefined;
65
- label?: string | ((location: "tooltip" | "legend") => string) | undefined;
66
- disableHover?: boolean | undefined;
67
- zAxisKey?: string | undefined;
68
- id?: import("../models/seriesType/common").SeriesId | undefined;
69
- color: string;
70
- valueFormatter?: import("../models/seriesType/common").SeriesValueFormatter<import("../models/seriesType").ScatterValueType> | undefined;
71
- highlightScope?: Partial<import("..").HighlightScope> | undefined;
72
- xAxisKey?: string | undefined;
73
- yAxisKey?: string | undefined;
74
61
  } | {
75
62
  type: "line";
76
63
  data?: (number | null)[] | undefined;
@@ -90,4 +77,17 @@ export declare function defaultizeColor(series: AllSeriesType, seriesIndex: numb
90
77
  xAxisKey?: string | undefined;
91
78
  yAxisKey?: string | undefined;
92
79
  stackOrder?: import("..").StackOrderType | undefined;
80
+ } | {
81
+ type: "scatter";
82
+ data: import("../models/seriesType").ScatterValueType[];
83
+ markerSize?: number | undefined;
84
+ label?: string | ((location: "tooltip" | "legend") => string) | undefined;
85
+ disableHover?: boolean | undefined;
86
+ zAxisKey?: string | undefined;
87
+ id?: import("../models/seriesType/common").SeriesId | undefined;
88
+ color: string;
89
+ valueFormatter?: import("../models/seriesType/common").SeriesValueFormatter<import("../models/seriesType").ScatterValueType> | undefined;
90
+ highlightScope?: Partial<import("..").HighlightScope> | undefined;
91
+ xAxisKey?: string | undefined;
92
+ yAxisKey?: string | undefined;
93
93
  };
@@ -1,4 +1,4 @@
1
- import type { HighlightScope } from '../../context/HighlightProvider';
1
+ import type { HighlightScope } from '../../context';
2
2
  import type { StackOffsetType, StackOrderType } from '../stacking';
3
3
  export type SeriesId = number | string;
4
4
  export type SeriesValueFormatterContext = {
@@ -18,6 +18,9 @@ export type CommonSeriesType<TValue> = {
18
18
  * @returns {string} The string to display.
19
19
  */
20
20
  valueFormatter?: SeriesValueFormatter<TValue>;
21
+ /**
22
+ * The scope to apply when the series is highlighted.
23
+ */
21
24
  highlightScope?: Partial<HighlightScope>;
22
25
  };
23
26
  export type CommonDefaultizedProps = 'id' | 'valueFormatter' | 'data';
@@ -52,7 +52,10 @@ const BarChart = /*#__PURE__*/React.forwardRef(function BarChart(props, ref) {
52
52
  children,
53
53
  slots,
54
54
  slotProps,
55
- loading
55
+ loading,
56
+ barLabel,
57
+ highlightedItem,
58
+ onHighlightChange
56
59
  } = props;
57
60
  const id = useId();
58
61
  const clipPathId = `${id}-clip-path`;
@@ -88,6 +91,8 @@ const BarChart = /*#__PURE__*/React.forwardRef(function BarChart(props, ref) {
88
91
  dataset: dataset,
89
92
  sx: sx,
90
93
  disableAxisListener: tooltip?.trigger !== 'axis' && axisHighlight?.x === 'none' && axisHighlight?.y === 'none' && !onAxisClick,
94
+ highlightedItem: highlightedItem,
95
+ onHighlightChange: onHighlightChange,
91
96
  children: [onAxisClick && /*#__PURE__*/_jsx(ChartsOnAxisClickHandler, {
92
97
  onAxisClick: onAxisClick
93
98
  }), grid && /*#__PURE__*/_jsx(ChartsGrid, {
@@ -100,7 +105,8 @@ const BarChart = /*#__PURE__*/React.forwardRef(function BarChart(props, ref) {
100
105
  slotProps: slotProps,
101
106
  skipAnimation: skipAnimation,
102
107
  onItemClick: onItemClick,
103
- borderRadius: borderRadius
108
+ borderRadius: borderRadius,
109
+ barLabel: barLabel
104
110
  }), /*#__PURE__*/_jsx(ChartsOverlay, {
105
111
  loading: loading,
106
112
  slots: slots,
@@ -127,7 +133,7 @@ const BarChart = /*#__PURE__*/React.forwardRef(function BarChart(props, ref) {
127
133
  process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
128
134
  // ----------------------------- Warning --------------------------------
129
135
  // | These PropTypes are generated from the TypeScript type definitions |
130
- // | To update them edit the TypeScript types and run "yarn proptypes" |
136
+ // | To update them edit the TypeScript types and run "pnpm proptypes" |
131
137
  // ----------------------------------------------------------------------
132
138
  /**
133
139
  * The configuration of axes highlight.
@@ -139,6 +145,14 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
139
145
  x: PropTypes.oneOf(['band', 'line', 'none']),
140
146
  y: PropTypes.oneOf(['band', 'line', 'none'])
141
147
  }),
148
+ /**
149
+ * If provided, the function will be used to format the label of the bar.
150
+ * It can be set to 'value' to display the current value.
151
+ * @param {BarItem} item The item to format.
152
+ * @param {BarLabelContext} context data about the bar.
153
+ * @returns {string} The formatted label.
154
+ */
155
+ barLabel: PropTypes.oneOfType([PropTypes.oneOf(['value']), PropTypes.func]),
142
156
  /**
143
157
  * Defines the border radius of the bar element.
144
158
  */
@@ -178,6 +192,13 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
178
192
  * The height of the chart in px. If not defined, it takes the height of the parent element.
179
193
  */
180
194
  height: PropTypes.number,
195
+ /**
196
+ * The item currently highlighted. Turns highlighting into a controlled prop.
197
+ */
198
+ highlightedItem: PropTypes.shape({
199
+ dataIndex: PropTypes.number,
200
+ seriesId: PropTypes.oneOfType([PropTypes.number, PropTypes.string])
201
+ }),
181
202
  /**
182
203
  * The direction of the bar elements.
183
204
  * @default 'vertical'
@@ -227,6 +248,12 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
227
248
  * @param {null | AxisData} data The data about the clicked axis and items associated with it.
228
249
  */
229
250
  onAxisClick: PropTypes.func,
251
+ /**
252
+ * The callback fired when the highlighted item changes.
253
+ *
254
+ * @param {HighlightItemData | null} highlightedItem The newly highlighted item.
255
+ */
256
+ onHighlightChange: PropTypes.func,
230
257
  /**
231
258
  * Callback fired when a bar item is clicked.
232
259
  * @param {React.MouseEvent<SVGElement, MouseEvent>} event The event source of the callback.
@@ -1,6 +1,6 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
- const _excluded = ["id", "dataIndex", "classes", "color", "highlightScope", "slots", "slotProps", "style", "onClick"];
3
+ const _excluded = ["id", "dataIndex", "classes", "color", "slots", "slotProps", "style", "onClick"];
4
4
  import * as React from 'react';
5
5
  import PropTypes from 'prop-types';
6
6
  import composeClasses from '@mui/utils/composeClasses';
@@ -10,8 +10,8 @@ import { styled } from '@mui/material/styles';
10
10
  import { color as d3Color } from 'd3-color';
11
11
  import generateUtilityClasses from '@mui/utils/generateUtilityClasses';
12
12
  import { animated } from '@react-spring/web';
13
- import { getIsFaded, getIsHighlighted, useInteractionItemProps } from '../hooks/useInteractionItemProps';
14
- import { InteractionContext } from '../context/InteractionProvider';
13
+ import { useInteractionItemProps } from '../hooks/useInteractionItemProps';
14
+ import { useItemHighlighted } from '../context';
15
15
  import { jsx as _jsx } from "react/jsx-runtime";
16
16
  export function getBarElementUtilityClass(slot) {
17
17
  return generateUtilityClass('MuiBarElement', slot);
@@ -45,27 +45,20 @@ function BarElement(props) {
45
45
  dataIndex,
46
46
  classes: innerClasses,
47
47
  color,
48
- highlightScope,
49
48
  slots,
50
49
  slotProps,
51
50
  style,
52
51
  onClick
53
52
  } = props,
54
53
  other = _objectWithoutPropertiesLoose(props, _excluded);
55
- const getInteractionItemProps = useInteractionItemProps(highlightScope);
54
+ const getInteractionItemProps = useInteractionItemProps();
56
55
  const {
57
- item
58
- } = React.useContext(InteractionContext);
59
- const isHighlighted = getIsHighlighted(item, {
60
- type: 'bar',
61
- seriesId: id,
62
- dataIndex
63
- }, highlightScope);
64
- const isFaded = !isHighlighted && getIsFaded(item, {
65
- type: 'bar',
56
+ isFaded,
57
+ isHighlighted
58
+ } = useItemHighlighted({
66
59
  seriesId: id,
67
60
  dataIndex
68
- }, highlightScope);
61
+ });
69
62
  const ownerState = {
70
63
  id,
71
64
  dataIndex,
@@ -97,14 +90,10 @@ function BarElement(props) {
97
90
  process.env.NODE_ENV !== "production" ? BarElement.propTypes = {
98
91
  // ----------------------------- Warning --------------------------------
99
92
  // | These PropTypes are generated from the TypeScript type definitions |
100
- // | To update them edit the TypeScript types and run "yarn proptypes" |
93
+ // | To update them edit the TypeScript types and run "pnpm proptypes" |
101
94
  // ----------------------------------------------------------------------
102
95
  classes: PropTypes.object,
103
96
  dataIndex: PropTypes.number.isRequired,
104
- highlightScope: PropTypes.shape({
105
- faded: PropTypes.oneOf(['global', 'none', 'series']),
106
- highlighted: PropTypes.oneOf(['item', 'none', 'series'])
107
- }),
108
97
  id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
109
98
  /**
110
99
  * The props used for each component slot.
@@ -0,0 +1,51 @@
1
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
2
+ import _extends from "@babel/runtime/helpers/esm/extends";
3
+ const _excluded = ["seriesId", "dataIndex", "color", "isFaded", "isHighlighted", "classes"];
4
+ import * as React from 'react';
5
+ import { styled, useThemeProps } from '@mui/material/styles';
6
+ import { animated } from '@react-spring/web';
7
+ import PropTypes from 'prop-types';
8
+ import { barLabelClasses } from './barLabelClasses';
9
+ import { jsx as _jsx } from "react/jsx-runtime";
10
+ export const BarLabelComponent = styled(animated.text, {
11
+ name: 'MuiBarLabel',
12
+ slot: 'Root',
13
+ overridesResolver: (_, styles) => [{
14
+ [`&.${barLabelClasses.faded}`]: styles.faded
15
+ }, {
16
+ [`&.${barLabelClasses.highlighted}`]: styles.highlighted
17
+ }, styles.root]
18
+ })(({
19
+ theme
20
+ }) => _extends({}, theme?.typography?.body2, {
21
+ stroke: 'none',
22
+ fill: (theme.vars || theme)?.palette?.text?.primary,
23
+ transition: 'opacity 0.2s ease-in, fill 0.2s ease-in',
24
+ textAnchor: 'middle',
25
+ dominantBaseline: 'central',
26
+ pointerEvents: 'none',
27
+ opacity: 1,
28
+ [`&.${barLabelClasses.faded}`]: {
29
+ opacity: 0.3
30
+ }
31
+ }));
32
+ function BarLabel(props) {
33
+ const themeProps = useThemeProps({
34
+ props,
35
+ name: 'MuiBarLabel'
36
+ });
37
+ const otherProps = _objectWithoutPropertiesLoose(themeProps, _excluded);
38
+ return /*#__PURE__*/_jsx(BarLabelComponent, _extends({}, otherProps));
39
+ }
40
+ process.env.NODE_ENV !== "production" ? BarLabel.propTypes = {
41
+ // ----------------------------- Warning --------------------------------
42
+ // | These PropTypes are generated from the TypeScript type definitions |
43
+ // | To update them edit the TypeScript types and run "pnpm proptypes" |
44
+ // ----------------------------------------------------------------------
45
+ classes: PropTypes.object,
46
+ dataIndex: PropTypes.number.isRequired,
47
+ isFaded: PropTypes.bool.isRequired,
48
+ isHighlighted: PropTypes.bool.isRequired,
49
+ seriesId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired
50
+ } : void 0;
51
+ export { BarLabel };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,119 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
+ const _excluded = ["seriesId", "classes", "color", "style", "dataIndex", "barLabel", "slots", "slotProps", "height", "width", "value"],
4
+ _excluded2 = ["ownerState"];
5
+ import * as React from 'react';
6
+ import { useSlotProps } from '@mui/base/utils';
7
+ import PropTypes from 'prop-types';
8
+ import { useUtilityClasses } from './barLabelClasses';
9
+ import { getBarLabel } from './getBarLabel';
10
+ import { BarLabel } from './BarLabel';
11
+ import { useItemHighlighted } from '../../context';
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ /**
14
+ * @ignore - internal component.
15
+ */
16
+ function BarLabelItem(props) {
17
+ const {
18
+ seriesId,
19
+ classes: innerClasses,
20
+ color,
21
+ style,
22
+ dataIndex,
23
+ barLabel,
24
+ slots,
25
+ slotProps,
26
+ height,
27
+ width,
28
+ value
29
+ } = props,
30
+ other = _objectWithoutPropertiesLoose(props, _excluded);
31
+ const {
32
+ isFaded,
33
+ isHighlighted
34
+ } = useItemHighlighted({
35
+ seriesId,
36
+ dataIndex
37
+ });
38
+ const ownerState = {
39
+ seriesId,
40
+ classes: innerClasses,
41
+ color,
42
+ isFaded,
43
+ isHighlighted,
44
+ dataIndex
45
+ };
46
+ const classes = useUtilityClasses(ownerState);
47
+ const Component = slots?.barLabel ?? BarLabel;
48
+ const _useSlotProps = useSlotProps({
49
+ elementType: Component,
50
+ externalSlotProps: slotProps?.barLabel,
51
+ additionalProps: _extends({}, other, {
52
+ style,
53
+ className: classes.root
54
+ }),
55
+ ownerState
56
+ }),
57
+ {
58
+ ownerState: barLabelOwnerState
59
+ } = _useSlotProps,
60
+ barLabelProps = _objectWithoutPropertiesLoose(_useSlotProps, _excluded2);
61
+ if (!barLabel) {
62
+ return null;
63
+ }
64
+ const formattedLabelText = getBarLabel({
65
+ barLabel,
66
+ value,
67
+ dataIndex,
68
+ seriesId,
69
+ height,
70
+ width
71
+ });
72
+ if (!formattedLabelText) {
73
+ return null;
74
+ }
75
+ return /*#__PURE__*/_jsx(Component, _extends({}, barLabelProps, barLabelOwnerState, {
76
+ children: formattedLabelText
77
+ }));
78
+ }
79
+ process.env.NODE_ENV !== "production" ? BarLabelItem.propTypes = {
80
+ // ----------------------------- Warning --------------------------------
81
+ // | These PropTypes are generated from the TypeScript type definitions |
82
+ // | To update them edit the TypeScript types and run "pnpm proptypes" |
83
+ // ----------------------------------------------------------------------
84
+ /**
85
+ * If provided, the function will be used to format the label of the bar.
86
+ * It can be set to 'value' to display the current value.
87
+ * @param {BarItem} item The item to format.
88
+ * @param {BarLabelContext} context data about the bar.
89
+ * @returns {string} The formatted label.
90
+ */
91
+ barLabel: PropTypes.oneOfType([PropTypes.oneOf(['value']), PropTypes.func]),
92
+ classes: PropTypes.object,
93
+ color: PropTypes.string.isRequired,
94
+ dataIndex: PropTypes.number.isRequired,
95
+ /**
96
+ * The height of the bar.
97
+ */
98
+ height: PropTypes.number.isRequired,
99
+ seriesId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
100
+ /**
101
+ * The props used for each component slot.
102
+ * @default {}
103
+ */
104
+ slotProps: PropTypes.object,
105
+ /**
106
+ * Overridable component slots.
107
+ * @default {}
108
+ */
109
+ slots: PropTypes.object,
110
+ /**
111
+ * The value of the data point.
112
+ */
113
+ value: PropTypes.number,
114
+ /**
115
+ * The width of the bar.
116
+ */
117
+ width: PropTypes.number.isRequired
118
+ } : void 0;
119
+ export { BarLabelItem };