@mui/x-charts-pro 8.0.0-alpha.12 → 8.0.0-alpha.14

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 (204) hide show
  1. package/BarChartPro/BarChartPro.d.ts +2 -1
  2. package/BarChartPro/BarChartPro.js +25 -30
  3. package/CHANGELOG.md +430 -0
  4. package/ChartContainerPro/ChartContainerPro.d.ts +1 -1
  5. package/ChartContainerPro/ChartContainerPro.js +1 -1
  6. package/ChartContainerPro/useChartContainerProProps.d.ts +1 -1
  7. package/ChartContainerPro/useChartContainerProProps.js +3 -1
  8. package/ChartDataProviderPro/ChartDataProviderPro.d.ts +1 -1
  9. package/ChartDataProviderPro/ChartDataProviderPro.js +3 -2
  10. package/ChartDataProviderPro/useChartDataProviderProProps.d.ts +1 -1
  11. package/FunnelChart/FunnelChart.d.ts +37 -0
  12. package/FunnelChart/FunnelChart.js +218 -0
  13. package/FunnelChart/FunnelPlot.d.ts +16 -0
  14. package/FunnelChart/FunnelPlot.js +191 -0
  15. package/FunnelChart/FunnelSection.d.ts +15 -0
  16. package/FunnelChart/FunnelSection.js +62 -0
  17. package/FunnelChart/categoryAxis.types.d.ts +24 -0
  18. package/FunnelChart/categoryAxis.types.js +5 -0
  19. package/FunnelChart/funnel.types.d.ts +124 -0
  20. package/FunnelChart/funnel.types.js +5 -0
  21. package/FunnelChart/funnelPlotSlots.types.d.ts +20 -0
  22. package/FunnelChart/funnelPlotSlots.types.js +5 -0
  23. package/FunnelChart/funnelSectionClasses.d.ts +13 -0
  24. package/FunnelChart/funnelSectionClasses.js +28 -0
  25. package/FunnelChart/funnelSlots.types.d.ts +19 -0
  26. package/FunnelChart/funnelSlots.types.js +5 -0
  27. package/FunnelChart/funnelStepCurve.d.ts +4 -0
  28. package/FunnelChart/funnelStepCurve.js +74 -0
  29. package/FunnelChart/index.d.ts +7 -0
  30. package/FunnelChart/index.js +59 -0
  31. package/FunnelChart/labelUtils.d.ts +42 -0
  32. package/FunnelChart/labelUtils.js +174 -0
  33. package/FunnelChart/seriesConfig/extremums.d.ts +3 -0
  34. package/FunnelChart/seriesConfig/extremums.js +50 -0
  35. package/FunnelChart/seriesConfig/getColor.d.ts +3 -0
  36. package/FunnelChart/seriesConfig/getColor.js +10 -0
  37. package/FunnelChart/seriesConfig/getSeriesWithDefaultValues.d.ts +3 -0
  38. package/FunnelChart/seriesConfig/getSeriesWithDefaultValues.js +18 -0
  39. package/FunnelChart/seriesConfig/index.d.ts +2 -0
  40. package/FunnelChart/seriesConfig/index.js +22 -0
  41. package/FunnelChart/seriesConfig/legend.d.ts +3 -0
  42. package/FunnelChart/seriesConfig/legend.js +31 -0
  43. package/FunnelChart/seriesConfig/seriesProcessor.d.ts +3 -0
  44. package/FunnelChart/seriesConfig/seriesProcessor.js +96 -0
  45. package/FunnelChart/seriesConfig/tooltip.d.ts +3 -0
  46. package/FunnelChart/seriesConfig/tooltip.js +36 -0
  47. package/FunnelChart/useFunnelChartProps.d.ts +30 -0
  48. package/FunnelChart/useFunnelChartProps.js +168 -0
  49. package/Heatmap/Heatmap.d.ts +5 -4
  50. package/Heatmap/Heatmap.js +37 -52
  51. package/Heatmap/seriesConfig/getSeriesWithDefaultValues.d.ts +3 -0
  52. package/Heatmap/seriesConfig/getSeriesWithDefaultValues.js +15 -0
  53. package/Heatmap/seriesConfig/index.js +3 -1
  54. package/LineChartPro/LineChartPro.d.ts +2 -1
  55. package/LineChartPro/LineChartPro.js +25 -30
  56. package/ScatterChartPro/ScatterChartPro.js +25 -30
  57. package/esm/BarChartPro/BarChartPro.d.ts +2 -1
  58. package/esm/BarChartPro/BarChartPro.js +25 -30
  59. package/esm/ChartContainerPro/ChartContainerPro.d.ts +1 -1
  60. package/esm/ChartContainerPro/ChartContainerPro.js +1 -1
  61. package/esm/ChartContainerPro/useChartContainerProProps.d.ts +1 -1
  62. package/esm/ChartContainerPro/useChartContainerProProps.js +3 -1
  63. package/esm/ChartDataProviderPro/ChartDataProviderPro.d.ts +1 -1
  64. package/esm/ChartDataProviderPro/ChartDataProviderPro.js +3 -2
  65. package/esm/ChartDataProviderPro/useChartDataProviderProProps.d.ts +1 -1
  66. package/esm/FunnelChart/FunnelChart.d.ts +37 -0
  67. package/esm/FunnelChart/FunnelChart.js +212 -0
  68. package/esm/FunnelChart/FunnelPlot.d.ts +16 -0
  69. package/esm/FunnelChart/FunnelPlot.js +184 -0
  70. package/esm/FunnelChart/FunnelSection.d.ts +15 -0
  71. package/esm/FunnelChart/FunnelSection.js +56 -0
  72. package/esm/FunnelChart/categoryAxis.types.d.ts +24 -0
  73. package/esm/FunnelChart/categoryAxis.types.js +1 -0
  74. package/esm/FunnelChart/funnel.types.d.ts +124 -0
  75. package/esm/FunnelChart/funnel.types.js +1 -0
  76. package/esm/FunnelChart/funnelPlotSlots.types.d.ts +20 -0
  77. package/esm/FunnelChart/funnelPlotSlots.types.js +1 -0
  78. package/esm/FunnelChart/funnelSectionClasses.d.ts +13 -0
  79. package/esm/FunnelChart/funnelSectionClasses.js +20 -0
  80. package/esm/FunnelChart/funnelSlots.types.d.ts +19 -0
  81. package/esm/FunnelChart/funnelSlots.types.js +1 -0
  82. package/esm/FunnelChart/funnelStepCurve.d.ts +4 -0
  83. package/esm/FunnelChart/funnelStepCurve.js +67 -0
  84. package/esm/FunnelChart/index.d.ts +7 -0
  85. package/esm/FunnelChart/index.js +5 -0
  86. package/esm/FunnelChart/labelUtils.d.ts +42 -0
  87. package/esm/FunnelChart/labelUtils.js +166 -0
  88. package/esm/FunnelChart/seriesConfig/extremums.d.ts +3 -0
  89. package/esm/FunnelChart/seriesConfig/extremums.js +42 -0
  90. package/esm/FunnelChart/seriesConfig/getColor.d.ts +3 -0
  91. package/esm/FunnelChart/seriesConfig/getColor.js +4 -0
  92. package/esm/FunnelChart/seriesConfig/getSeriesWithDefaultValues.d.ts +3 -0
  93. package/esm/FunnelChart/seriesConfig/getSeriesWithDefaultValues.js +11 -0
  94. package/esm/FunnelChart/seriesConfig/index.d.ts +2 -0
  95. package/esm/FunnelChart/seriesConfig/index.js +15 -0
  96. package/esm/FunnelChart/seriesConfig/legend.d.ts +3 -0
  97. package/esm/FunnelChart/seriesConfig/legend.js +25 -0
  98. package/esm/FunnelChart/seriesConfig/seriesProcessor.d.ts +3 -0
  99. package/esm/FunnelChart/seriesConfig/seriesProcessor.js +89 -0
  100. package/esm/FunnelChart/seriesConfig/tooltip.d.ts +3 -0
  101. package/esm/FunnelChart/seriesConfig/tooltip.js +29 -0
  102. package/esm/FunnelChart/useFunnelChartProps.d.ts +30 -0
  103. package/esm/FunnelChart/useFunnelChartProps.js +161 -0
  104. package/esm/Heatmap/Heatmap.d.ts +5 -4
  105. package/esm/Heatmap/Heatmap.js +37 -52
  106. package/esm/Heatmap/seriesConfig/getSeriesWithDefaultValues.d.ts +3 -0
  107. package/esm/Heatmap/seriesConfig/getSeriesWithDefaultValues.js +8 -0
  108. package/esm/Heatmap/seriesConfig/index.js +3 -1
  109. package/esm/LineChartPro/LineChartPro.d.ts +2 -1
  110. package/esm/LineChartPro/LineChartPro.js +25 -30
  111. package/esm/ScatterChartPro/ScatterChartPro.js +25 -30
  112. package/esm/hooks/useFunnelSeries.d.ts +33 -0
  113. package/esm/hooks/useFunnelSeries.js +42 -0
  114. package/esm/index.d.ts +3 -1
  115. package/esm/index.js +4 -2
  116. package/esm/internals/plugins/allPlugins.d.ts +3 -3
  117. package/esm/internals/plugins/allPlugins.js +2 -2
  118. package/esm/internals/plugins/useChartProZoom/useChartProZoom.js +63 -12
  119. package/esm/internals/plugins/useChartProZoom/useChartProZoom.selectors.d.ts +26 -24
  120. package/esm/internals/plugins/useChartProZoom/useChartProZoom.types.d.ts +12 -3
  121. package/esm/internals/utils/releaseInfo.js +1 -1
  122. package/esm/models/seriesType/heatmap.d.ts +2 -2
  123. package/esm/typeOverloads/modules.d.ts +13 -2
  124. package/hooks/useFunnelSeries.d.ts +33 -0
  125. package/hooks/useFunnelSeries.js +48 -0
  126. package/index.d.ts +3 -1
  127. package/index.js +23 -1
  128. package/internals/plugins/allPlugins.d.ts +3 -3
  129. package/internals/plugins/allPlugins.js +1 -1
  130. package/internals/plugins/useChartProZoom/useChartProZoom.js +63 -12
  131. package/internals/plugins/useChartProZoom/useChartProZoom.selectors.d.ts +26 -24
  132. package/internals/plugins/useChartProZoom/useChartProZoom.types.d.ts +12 -3
  133. package/internals/utils/releaseInfo.js +1 -1
  134. package/models/seriesType/heatmap.d.ts +2 -2
  135. package/modern/BarChartPro/BarChartPro.d.ts +2 -1
  136. package/modern/BarChartPro/BarChartPro.js +25 -30
  137. package/modern/ChartContainerPro/ChartContainerPro.d.ts +1 -1
  138. package/modern/ChartContainerPro/ChartContainerPro.js +1 -1
  139. package/modern/ChartContainerPro/useChartContainerProProps.d.ts +1 -1
  140. package/modern/ChartContainerPro/useChartContainerProProps.js +3 -1
  141. package/modern/ChartDataProviderPro/ChartDataProviderPro.d.ts +1 -1
  142. package/modern/ChartDataProviderPro/ChartDataProviderPro.js +3 -2
  143. package/modern/ChartDataProviderPro/useChartDataProviderProProps.d.ts +1 -1
  144. package/modern/FunnelChart/FunnelChart.d.ts +37 -0
  145. package/modern/FunnelChart/FunnelChart.js +212 -0
  146. package/modern/FunnelChart/FunnelPlot.d.ts +16 -0
  147. package/modern/FunnelChart/FunnelPlot.js +184 -0
  148. package/modern/FunnelChart/FunnelSection.d.ts +15 -0
  149. package/modern/FunnelChart/FunnelSection.js +56 -0
  150. package/modern/FunnelChart/categoryAxis.types.d.ts +24 -0
  151. package/modern/FunnelChart/categoryAxis.types.js +1 -0
  152. package/modern/FunnelChart/funnel.types.d.ts +124 -0
  153. package/modern/FunnelChart/funnel.types.js +1 -0
  154. package/modern/FunnelChart/funnelPlotSlots.types.d.ts +20 -0
  155. package/modern/FunnelChart/funnelPlotSlots.types.js +1 -0
  156. package/modern/FunnelChart/funnelSectionClasses.d.ts +13 -0
  157. package/modern/FunnelChart/funnelSectionClasses.js +20 -0
  158. package/modern/FunnelChart/funnelSlots.types.d.ts +19 -0
  159. package/modern/FunnelChart/funnelSlots.types.js +1 -0
  160. package/modern/FunnelChart/funnelStepCurve.d.ts +4 -0
  161. package/modern/FunnelChart/funnelStepCurve.js +67 -0
  162. package/modern/FunnelChart/index.d.ts +7 -0
  163. package/modern/FunnelChart/index.js +5 -0
  164. package/modern/FunnelChart/labelUtils.d.ts +42 -0
  165. package/modern/FunnelChart/labelUtils.js +166 -0
  166. package/modern/FunnelChart/seriesConfig/extremums.d.ts +3 -0
  167. package/modern/FunnelChart/seriesConfig/extremums.js +42 -0
  168. package/modern/FunnelChart/seriesConfig/getColor.d.ts +3 -0
  169. package/modern/FunnelChart/seriesConfig/getColor.js +4 -0
  170. package/modern/FunnelChart/seriesConfig/getSeriesWithDefaultValues.d.ts +3 -0
  171. package/modern/FunnelChart/seriesConfig/getSeriesWithDefaultValues.js +11 -0
  172. package/modern/FunnelChart/seriesConfig/index.d.ts +2 -0
  173. package/modern/FunnelChart/seriesConfig/index.js +15 -0
  174. package/modern/FunnelChart/seriesConfig/legend.d.ts +3 -0
  175. package/modern/FunnelChart/seriesConfig/legend.js +25 -0
  176. package/modern/FunnelChart/seriesConfig/seriesProcessor.d.ts +3 -0
  177. package/modern/FunnelChart/seriesConfig/seriesProcessor.js +89 -0
  178. package/modern/FunnelChart/seriesConfig/tooltip.d.ts +3 -0
  179. package/modern/FunnelChart/seriesConfig/tooltip.js +29 -0
  180. package/modern/FunnelChart/useFunnelChartProps.d.ts +30 -0
  181. package/modern/FunnelChart/useFunnelChartProps.js +161 -0
  182. package/modern/Heatmap/Heatmap.d.ts +5 -4
  183. package/modern/Heatmap/Heatmap.js +37 -52
  184. package/modern/Heatmap/seriesConfig/getSeriesWithDefaultValues.d.ts +3 -0
  185. package/modern/Heatmap/seriesConfig/getSeriesWithDefaultValues.js +8 -0
  186. package/modern/Heatmap/seriesConfig/index.js +3 -1
  187. package/modern/LineChartPro/LineChartPro.d.ts +2 -1
  188. package/modern/LineChartPro/LineChartPro.js +25 -30
  189. package/modern/ScatterChartPro/ScatterChartPro.js +25 -30
  190. package/modern/hooks/useFunnelSeries.d.ts +33 -0
  191. package/modern/hooks/useFunnelSeries.js +42 -0
  192. package/modern/index.d.ts +3 -1
  193. package/modern/index.js +4 -2
  194. package/modern/internals/plugins/allPlugins.d.ts +3 -3
  195. package/modern/internals/plugins/allPlugins.js +2 -2
  196. package/modern/internals/plugins/useChartProZoom/useChartProZoom.js +63 -12
  197. package/modern/internals/plugins/useChartProZoom/useChartProZoom.selectors.d.ts +26 -24
  198. package/modern/internals/plugins/useChartProZoom/useChartProZoom.types.d.ts +12 -3
  199. package/modern/internals/utils/releaseInfo.js +1 -1
  200. package/modern/models/seriesType/heatmap.d.ts +2 -2
  201. package/modern/typeOverloads/modules.d.ts +13 -2
  202. package/package.json +5 -5
  203. package/tsconfig.build.tsbuildinfo +1 -1
  204. package/typeOverloads/modules.d.ts +13 -2
@@ -0,0 +1,166 @@
1
+ /**
2
+ * It tries to keep the label inside the bounds of the section based on the position.
3
+ *
4
+ * @returns The text anchor and dominant baseline of the label.
5
+ */
6
+ export const alignLabel = ({
7
+ position,
8
+ textAnchor,
9
+ dominantBaseline
10
+ }) => {
11
+ const vertical = position?.vertical ?? 'middle';
12
+ const horizontal = position?.horizontal ?? 'center';
13
+ let anchor = 'middle';
14
+ let baseline = 'central';
15
+ if (vertical === 'top') {
16
+ baseline = 'hanging';
17
+ } else if (vertical === 'bottom') {
18
+ baseline = 'baseline';
19
+ }
20
+ if (horizontal === 'start') {
21
+ anchor = 'start';
22
+ } else if (horizontal === 'end') {
23
+ anchor = 'end';
24
+ }
25
+ return {
26
+ textAnchor: textAnchor ?? anchor,
27
+ dominantBaseline: dominantBaseline ?? baseline
28
+ };
29
+ };
30
+
31
+ /**
32
+ * This function calculates the position of the label based on the position and margin.
33
+ *
34
+ * It is quite complex, because it needs to calculate the position based on the position of the points of a rectangle.
35
+ * And we are manually calculating each possible position of the label.
36
+ *
37
+ * @returns The x and y position of the label.
38
+ */
39
+ export const positionLabel = ({
40
+ position,
41
+ offset,
42
+ xPosition,
43
+ yPosition,
44
+ isHorizontal,
45
+ values,
46
+ dataIndex,
47
+ baseScaleData
48
+ }) => {
49
+ const vertical = position?.vertical ?? 'middle';
50
+ const horizontal = position?.horizontal ?? 'center';
51
+ let x = 0;
52
+ let y = 0;
53
+ let minTop = 0;
54
+ let maxTop = 0;
55
+ let minBottom = 0;
56
+ let maxBottom = 0;
57
+ let minLeft = 0;
58
+ let maxLeft = 0;
59
+ let minRight = 0;
60
+ let maxRight = 0;
61
+ let center = 0;
62
+ let leftCenter = 0;
63
+ let rightCenter = 0;
64
+ let middle = 0;
65
+ let topMiddle = 0;
66
+ let bottomMiddle = 0;
67
+ const mv = typeof offset === 'number' ? offset : offset?.y ?? 0;
68
+ const mh = typeof offset === 'number' ? offset : offset?.x ?? 0;
69
+ const stackOffset = values[0].stackOffset;
70
+ if (isHorizontal) {
71
+ maxTop = yPosition(values[0].y, baseScaleData[dataIndex], stackOffset) - mv;
72
+ minTop = yPosition(values[1].y, baseScaleData[dataIndex], stackOffset) - mv;
73
+ minBottom = yPosition(values[2].y, baseScaleData[dataIndex], stackOffset) + mv;
74
+ maxBottom = yPosition(values[3].y, baseScaleData[dataIndex], stackOffset) + mv;
75
+ minRight = 0;
76
+ maxRight = xPosition(Math.min(...values.map(v => v.x)), baseScaleData[dataIndex], stackOffset, true) + mh;
77
+ minLeft = 0;
78
+ maxLeft = xPosition(Math.max(...values.map(v => v.x)), baseScaleData[dataIndex], stackOffset) + mh;
79
+ center = maxRight - (maxRight - maxLeft) / 2;
80
+ leftCenter = 0;
81
+ rightCenter = 0;
82
+ middle = yPosition(0, baseScaleData[dataIndex], stackOffset) - mv;
83
+ topMiddle = yPosition(values[0].y - (values[0].y - values[1].y) / 2, baseScaleData[dataIndex], stackOffset) - mv;
84
+ bottomMiddle = yPosition(values[3].y - (values[3].y - values[2].y) / 2, baseScaleData[dataIndex], stackOffset) + mv;
85
+ } else {
86
+ minTop = 0;
87
+ maxTop = yPosition(Math.max(...values.map(v => v.y)), baseScaleData[dataIndex], stackOffset) - mv;
88
+ minBottom = 0;
89
+ maxBottom = yPosition(Math.min(...values.map(v => v.y)), baseScaleData[dataIndex], stackOffset, true) - mv;
90
+ maxRight = xPosition(values[0].x, baseScaleData[dataIndex], stackOffset) + mh;
91
+ minRight = xPosition(values[1].x, baseScaleData[dataIndex], stackOffset) + mh;
92
+ minLeft = xPosition(values[2].x, baseScaleData[dataIndex], stackOffset) - mh;
93
+ maxLeft = xPosition(values[3].x, baseScaleData[dataIndex], stackOffset) - mh;
94
+ center = xPosition(0, baseScaleData[dataIndex], stackOffset) - mh;
95
+ rightCenter = xPosition(values[0].x - (values[0].x - values[1].x) / 2, baseScaleData[dataIndex], stackOffset) + mh;
96
+ leftCenter = xPosition(values[3].x - (values[3].x - values[2].x) / 2, baseScaleData[dataIndex], stackOffset) - mh;
97
+ middle = yPosition(values[0].y - (values[0].y - values[1].y) / 2, baseScaleData[dataIndex], stackOffset);
98
+ middle = maxTop - (maxTop - maxBottom) / 2;
99
+ topMiddle = 0;
100
+ bottomMiddle = 0;
101
+ }
102
+ if (isHorizontal) {
103
+ if (horizontal === 'center') {
104
+ x = center;
105
+ if (vertical === 'top') {
106
+ y = topMiddle;
107
+ } else if (vertical === 'middle') {
108
+ y = middle;
109
+ } else if (vertical === 'bottom') {
110
+ y = bottomMiddle;
111
+ }
112
+ } else if (horizontal === 'start') {
113
+ x = maxLeft;
114
+ if (vertical === 'top') {
115
+ y = maxTop;
116
+ } else if (vertical === 'middle') {
117
+ y = middle;
118
+ } else if (vertical === 'bottom') {
119
+ y = maxBottom;
120
+ }
121
+ } else if (horizontal === 'end') {
122
+ x = maxRight;
123
+ if (vertical === 'top') {
124
+ y = minTop;
125
+ } else if (vertical === 'middle') {
126
+ y = middle;
127
+ } else if (vertical === 'bottom') {
128
+ y = minBottom;
129
+ }
130
+ }
131
+ }
132
+ if (!isHorizontal) {
133
+ if (vertical === 'middle') {
134
+ y = middle;
135
+ if (horizontal === 'start') {
136
+ x = leftCenter;
137
+ } else if (horizontal === 'center') {
138
+ x = center;
139
+ } else if (horizontal === 'end') {
140
+ x = rightCenter;
141
+ }
142
+ } else if (vertical === 'top') {
143
+ y = maxTop;
144
+ if (horizontal === 'start') {
145
+ x = maxLeft;
146
+ } else if (horizontal === 'center') {
147
+ x = center;
148
+ } else if (horizontal === 'end') {
149
+ x = maxRight;
150
+ }
151
+ } else if (vertical === 'bottom') {
152
+ y = maxBottom;
153
+ if (horizontal === 'start') {
154
+ x = minLeft;
155
+ } else if (horizontal === 'center') {
156
+ x = center;
157
+ } else if (horizontal === 'end') {
158
+ x = minRight;
159
+ }
160
+ }
161
+ }
162
+ return {
163
+ x,
164
+ y
165
+ };
166
+ };
@@ -0,0 +1,3 @@
1
+ import { CartesianExtremumGetter } from '@mui/x-charts/internals';
2
+ export declare const getExtremumX: CartesianExtremumGetter<'funnel'>;
3
+ export declare const getExtremumY: CartesianExtremumGetter<'funnel'>;
@@ -0,0 +1,42 @@
1
+ const getValueExtremum = (direction, isHorizontal, params) => {
2
+ const {
3
+ series,
4
+ axis,
5
+ isDefaultAxis
6
+ } = params;
7
+ return Object.keys(series)
8
+ // Keep only series that are associated with the current axis
9
+ .reduce((acc, seriesId) => {
10
+ const yAxisId = series[seriesId].yAxisId;
11
+ const xAxisId = series[seriesId].xAxisId;
12
+ const {
13
+ dataPoints
14
+ } = series[seriesId];
15
+ if (
16
+ // We skip except if the axis id is not defined for the direction and we are on the default one.
17
+ !(isDefaultAxis && yAxisId === undefined && direction === 'y') && !(isDefaultAxis && xAxisId === undefined && direction === 'x')) {
18
+ return acc;
19
+ }
20
+ if (axis.scaleType === 'band' || !isHorizontal && direction === 'x' || isHorizontal && direction === 'y') {
21
+ const [seriesMin, seriesMax] = dataPoints.map(v => v.map(t => t[direction]))?.reduce((seriesAcc, values) => {
22
+ return [Math.min(...values, seriesAcc[0]), Math.max(...values, seriesAcc[1])];
23
+ }, [Infinity, -Infinity]) ?? [Infinity, -Infinity];
24
+ return [Math.min(seriesMin, acc[0]), Math.max(seriesMax, acc[1])];
25
+ }
26
+ const seriesMin = dataPoints.flatMap(v => v.map(t => t[direction]).reduce((min, value) => Math.min(value, min), Infinity)).reduce((sumAcc, value) => sumAcc + value, 0);
27
+ const seriesMax = dataPoints.flatMap(v => v.map(t => t[direction]).reduce((max, value) => Math.max(value, max), -Infinity)).reduce((sumAcc, value) => sumAcc + value, 0);
28
+ return [Math.min(seriesMin, acc[0]), Math.max(seriesMax, acc[1])];
29
+ }, [Infinity, -Infinity]);
30
+ };
31
+ export const getExtremumX = params => {
32
+ const isHorizontal = Object.keys(params.series).some(seriesId => params.series[seriesId].layout === 'horizontal');
33
+ if (isHorizontal) {
34
+ const [min, max] = getValueExtremum('x', isHorizontal, params);
35
+ return [max, min];
36
+ }
37
+ return getValueExtremum('x', isHorizontal, params);
38
+ };
39
+ export const getExtremumY = params => {
40
+ const isHorizontal = Object.keys(params.series).some(seriesId => params.series[seriesId].layout === 'horizontal');
41
+ return getValueExtremum('y', isHorizontal, params);
42
+ };
@@ -0,0 +1,3 @@
1
+ import { ColorProcessor } from '@mui/x-charts/internals';
2
+ declare const getColor: ColorProcessor<'funnel'>;
3
+ export default getColor;
@@ -0,0 +1,4 @@
1
+ const getColor = series => {
2
+ return dataIndex => series.data[dataIndex].color;
3
+ };
4
+ export default getColor;
@@ -0,0 +1,3 @@
1
+ import { GetSeriesWithDefaultValues } from '@mui/x-charts/internals';
2
+ declare const getSeriesWithDefaultValues: GetSeriesWithDefaultValues<'funnel'>;
3
+ export default getSeriesWithDefaultValues;
@@ -0,0 +1,11 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ const getSeriesWithDefaultValues = (seriesData, seriesIndex, colors) => {
3
+ return _extends({
4
+ id: seriesData.id ?? `auto-generated-id-${seriesIndex}`
5
+ }, seriesData, {
6
+ data: seriesData.data.map((d, index) => _extends({
7
+ color: colors[index % colors.length]
8
+ }, d))
9
+ });
10
+ };
11
+ export default getSeriesWithDefaultValues;
@@ -0,0 +1,2 @@
1
+ import type { ChartSeriesTypeConfig } from '@mui/x-charts/internals';
2
+ export declare const seriesConfig: ChartSeriesTypeConfig<'funnel'>;
@@ -0,0 +1,15 @@
1
+ import { getExtremumX, getExtremumY } from "./extremums.js";
2
+ import seriesProcessor from "./seriesProcessor.js";
3
+ import getColor from "./getColor.js";
4
+ import legendGetter from "./legend.js";
5
+ import tooltipGetter from "./tooltip.js";
6
+ import getSeriesWithDefaultValues from "./getSeriesWithDefaultValues.js";
7
+ export const seriesConfig = {
8
+ seriesProcessor,
9
+ colorProcessor: getColor,
10
+ legendGetter,
11
+ tooltipGetter,
12
+ xExtremumGetter: getExtremumX,
13
+ yExtremumGetter: getExtremumY,
14
+ getSeriesWithDefaultValues
15
+ };
@@ -0,0 +1,3 @@
1
+ import { LegendGetter } from '@mui/x-charts/internals';
2
+ declare const legendGetter: LegendGetter<'funnel'>;
3
+ export default legendGetter;
@@ -0,0 +1,25 @@
1
+ import { getLabel } from '@mui/x-charts/internals';
2
+ const legendGetter = params => {
3
+ const {
4
+ seriesOrder,
5
+ series
6
+ } = params;
7
+ return seriesOrder.reduce((acc, seriesId) => {
8
+ series[seriesId].data.forEach(item => {
9
+ const formattedLabel = getLabel(item.label, 'legend');
10
+ if (formattedLabel === undefined) {
11
+ return;
12
+ }
13
+ acc.push({
14
+ markType: item.labelMarkType ?? series[seriesId].labelMarkType,
15
+ seriesId,
16
+ id: item.id,
17
+ itemId: item.id,
18
+ color: item.color,
19
+ label: formattedLabel
20
+ });
21
+ });
22
+ return acc;
23
+ }, []);
24
+ };
25
+ export default legendGetter;
@@ -0,0 +1,3 @@
1
+ import { SeriesProcessor } from '@mui/x-charts/internals';
2
+ declare const seriesProcessor: SeriesProcessor<'funnel'>;
3
+ export default seriesProcessor;
@@ -0,0 +1,89 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ const createPoint = ({
3
+ main,
4
+ other,
5
+ inverse,
6
+ useBandWidth,
7
+ stackOffset
8
+ }) => inverse ? {
9
+ x: other,
10
+ y: main,
11
+ useBandWidth,
12
+ stackOffset
13
+ } : {
14
+ x: main,
15
+ y: other,
16
+ useBandWidth,
17
+ stackOffset
18
+ };
19
+ const seriesProcessor = params => {
20
+ const {
21
+ seriesOrder,
22
+ series
23
+ } = params;
24
+ const completedSeries = {};
25
+ const isHorizontal = seriesOrder.some(seriesId => series[seriesId].layout === 'horizontal');
26
+ seriesOrder.forEach(seriesId => {
27
+ const currentSeries = series[seriesId];
28
+ completedSeries[seriesId] = _extends({
29
+ labelMarkType: 'square',
30
+ layout: isHorizontal ? 'horizontal' : 'vertical',
31
+ valueFormatter: item => item == null ? '' : item.value.toLocaleString()
32
+ }, currentSeries, {
33
+ data: currentSeries.data.map((v, i) => _extends({
34
+ id: `${seriesId}-funnel-item-${v.id ?? i}`
35
+ }, v)),
36
+ dataPoints: []
37
+ });
38
+ const stackOffsets = completedSeries[seriesId].data.toReversed().map((_, i, array) => array.slice(0, i).reduce((acc, item) => acc + item.value, 0)).toReversed();
39
+ completedSeries[seriesId].dataPoints = completedSeries[seriesId].data.map((item, dataIndex, array) => {
40
+ // Main = main axis, Other = other axis
41
+ // For horizontal layout, main is y, other is x
42
+ // For vertical layout, main is x, other is y
43
+ const currentMaxMain = item.value;
44
+ const nextDataIndex = dataIndex === array.length - 1 ? dataIndex : dataIndex + 1;
45
+ const nextMaxMain = array[nextDataIndex].value ?? 0;
46
+ const nextMaxOther = 0;
47
+ const currentMaxOther = completedSeries[seriesId].data[dataIndex].value;
48
+ const stackOffset = stackOffsets[dataIndex];
49
+ return [
50
+ // Top right (vertical) or Top left (horizontal)
51
+ createPoint({
52
+ main: currentMaxMain,
53
+ other: currentMaxOther,
54
+ inverse: isHorizontal,
55
+ useBandWidth: false,
56
+ stackOffset
57
+ }),
58
+ // Bottom right (vertical) or Top right (horizontal)
59
+ createPoint({
60
+ main: nextMaxMain,
61
+ other: nextMaxOther,
62
+ inverse: isHorizontal,
63
+ useBandWidth: true,
64
+ stackOffset
65
+ }),
66
+ // Bottom left (vertical) or Bottom right (horizontal)
67
+ createPoint({
68
+ main: -nextMaxMain,
69
+ other: nextMaxOther,
70
+ inverse: isHorizontal,
71
+ useBandWidth: true,
72
+ stackOffset
73
+ }),
74
+ // Top left (vertical) or Bottom left (horizontal)
75
+ createPoint({
76
+ main: -currentMaxMain,
77
+ other: currentMaxOther,
78
+ inverse: isHorizontal,
79
+ useBandWidth: false,
80
+ stackOffset
81
+ })];
82
+ });
83
+ });
84
+ return {
85
+ seriesOrder,
86
+ series: completedSeries
87
+ };
88
+ };
89
+ export default seriesProcessor;
@@ -0,0 +1,3 @@
1
+ import { TooltipGetter } from '@mui/x-charts/internals';
2
+ declare const tooltipGetter: TooltipGetter<'funnel'>;
3
+ export default tooltipGetter;
@@ -0,0 +1,29 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import { getLabel } from '@mui/x-charts/internals';
3
+ const tooltipGetter = params => {
4
+ const {
5
+ series,
6
+ getColor,
7
+ identifier
8
+ } = params;
9
+ if (!identifier || identifier.dataIndex === undefined) {
10
+ return null;
11
+ }
12
+ const point = series.data[identifier.dataIndex];
13
+ const label = getLabel(point.label, 'tooltip');
14
+ const value = _extends({}, point, {
15
+ label
16
+ });
17
+ const formattedValue = series.valueFormatter(value, {
18
+ dataIndex: identifier.dataIndex
19
+ });
20
+ return {
21
+ identifier,
22
+ color: getColor(identifier.dataIndex),
23
+ label,
24
+ value,
25
+ formattedValue,
26
+ markType: point.labelMarkType ?? series.labelMarkType
27
+ };
28
+ };
29
+ export default tooltipGetter;
@@ -0,0 +1,30 @@
1
+ import { ChartsOverlayProps } from '@mui/x-charts/ChartsOverlay';
2
+ import { ChartsAxisProps } from '@mui/x-charts/ChartsAxis';
3
+ import { ChartsLegendSlotExtension } from '@mui/x-charts/ChartsLegend';
4
+ import { ChartsClipPathProps } from '@mui/x-charts/ChartsClipPath';
5
+ import { ChartsWrapperProps } from '@mui/x-charts/internals';
6
+ import { ChartsAxisHighlightProps } from '@mui/x-charts/ChartsAxisHighlight';
7
+ import { FunnelPlotProps } from "./FunnelPlot.js";
8
+ import type { FunnelChartProps } from './FunnelChart';
9
+ import { ChartContainerProProps } from "../ChartContainerPro/index.js";
10
+ /**
11
+ * A helper function that extracts FunnelChartProps from the input props
12
+ * and returns an object with props for the children components of FunnelChart.
13
+ *
14
+ * @param props The input props for FunnelChart
15
+ * @returns An object with props for the children components of FunnelChart
16
+ */
17
+ export declare const useFunnelChartProps: (props: FunnelChartProps) => {
18
+ chartContainerProps: ChartContainerProProps<"funnel">;
19
+ funnelPlotProps: FunnelPlotProps;
20
+ overlayProps: ChartsOverlayProps;
21
+ chartsAxisProps: ChartsAxisProps;
22
+ legendProps: ChartsLegendSlotExtension;
23
+ clipPathGroupProps: {
24
+ clipPath: string;
25
+ };
26
+ clipPathProps: ChartsClipPathProps;
27
+ chartsWrapperProps: Omit<ChartsWrapperProps, "children">;
28
+ axisHighlightProps: ChartsAxisHighlightProps;
29
+ children: import("react").ReactNode;
30
+ };
@@ -0,0 +1,161 @@
1
+ 'use client';
2
+
3
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
4
+ import _extends from "@babel/runtime/helpers/esm/extends";
5
+ const _excluded = ["categoryAxis", "series", "width", "height", "margin", "colors", "sx", "children", "slots", "slotProps", "skipAnimation", "loading", "onItemClick", "highlightedItem", "onHighlightChange", "className", "hideLegend", "axisHighlight", "apiRef"];
6
+ import { DEFAULT_MARGINS, DEFAULT_X_AXIS_KEY, DEFAULT_Y_AXIS_KEY } from '@mui/x-charts/constants';
7
+ import useId from '@mui/utils/useId';
8
+ import { defaultizeMargin } from '@mui/x-charts/internals';
9
+ import { warnOnce } from '@mui/x-internals/warning';
10
+ function getCategoryAxisConfig(categoryAxis, series, isHorizontal, direction) {
11
+ const maxSeriesLength = Math.max(...series.map(s => (s.data ?? []).length), 0);
12
+ const maxSeriesValue = Array.from({
13
+ length: maxSeriesLength
14
+ }, (_, index) => series.reduce((a, s) => a + (s.data?.[index]?.value ?? 0), 0));
15
+ if (process.env.NODE_ENV !== 'production') {
16
+ if ((categoryAxis?.position === 'left' || categoryAxis?.position === 'right') && isHorizontal || (categoryAxis?.position === 'top' || categoryAxis?.position === 'bottom') && !isHorizontal) {
17
+ warnOnce([`MUI X: the categoryAxis position is set to '${categoryAxis.position}' but the series layout is ${isHorizontal ? 'horizontal' : 'vertical'}.`, `Ensure that the categoryAxis position is set to '${isHorizontal ? 'top' : 'left'}' or '${isHorizontal ? 'bottom' : 'right'}' for ${isHorizontal ? 'horizontal' : 'vertical'} layout.\n`], 'warning');
18
+ }
19
+ }
20
+ const side = isHorizontal ? 'bottom' : 'left';
21
+ const categoryValues = _extends({
22
+ id: direction === 'x' ? DEFAULT_X_AXIS_KEY : DEFAULT_Y_AXIS_KEY
23
+ }, categoryAxis, categoryAxis?.size ? {
24
+ [isHorizontal ? 'height' : 'width']: categoryAxis.size
25
+ } : {}, {
26
+ position: categoryAxis?.position ?? (categoryAxis?.categories ? side : 'none')
27
+ });
28
+
29
+ // If the scaleType is not defined or is 'band', our job is simple.
30
+ if (!categoryAxis?.scaleType || categoryAxis.scaleType === 'band') {
31
+ return _extends({
32
+ scaleType: 'band',
33
+ categoryGapRatio: 0,
34
+ // Use the categories as the domain if they are defined.
35
+ data: categoryAxis?.categories ? categoryAxis.categories :
36
+ // Otherwise we just need random data to create the band scale.
37
+ Array.from({
38
+ length: maxSeriesLength
39
+ }, (_, index) => index),
40
+ tickLabelPlacement: 'middle'
41
+ }, categoryValues);
42
+ }
43
+
44
+ // If the scaleType is other than 'band', we have to do some magic.
45
+ // First we need to calculate the tick values additively and in reverse order.
46
+ const tickValues = [...maxSeriesValue.toReversed().map((_, i, arr) => arr.slice(0, i).reduce((a, value) => a + value, 0)),
47
+ // We add the total value of the series as the last tick value
48
+ maxSeriesValue.reduce((a, value) => a + value, 0)];
49
+ return _extends({
50
+ scaleType: categoryAxis.scaleType,
51
+ domainLimit: 'strict',
52
+ tickLabelPlacement: 'middle',
53
+ tickInterval: tickValues,
54
+ // No need to show the first tick label
55
+ tickLabelInterval: (_, i) => i !== 0,
56
+ // We trick the valueFormatter to show the category values.
57
+ // By using the index of the tickValues array we can get the category value.
58
+ valueFormatter: value => `${categoryAxis.categories?.toReversed()[tickValues.findIndex(v => v === value) - 1]}`
59
+ }, categoryValues);
60
+ }
61
+
62
+ /**
63
+ * A helper function that extracts FunnelChartProps from the input props
64
+ * and returns an object with props for the children components of FunnelChart.
65
+ *
66
+ * @param props The input props for FunnelChart
67
+ * @returns An object with props for the children components of FunnelChart
68
+ */
69
+ export const useFunnelChartProps = props => {
70
+ const {
71
+ categoryAxis,
72
+ series,
73
+ width,
74
+ height,
75
+ margin: marginProps,
76
+ colors,
77
+ sx,
78
+ children,
79
+ slots,
80
+ slotProps,
81
+ loading,
82
+ onItemClick,
83
+ highlightedItem,
84
+ onHighlightChange,
85
+ className,
86
+ axisHighlight,
87
+ apiRef
88
+ } = props,
89
+ rest = _objectWithoutPropertiesLoose(props, _excluded);
90
+ const margin = defaultizeMargin(marginProps, DEFAULT_MARGINS);
91
+ const id = useId();
92
+ const clipPathId = `${id}-clip-path`;
93
+ const isHorizontal = series.some(s => s.layout === 'horizontal');
94
+ const valueAxisConfig = {
95
+ id: isHorizontal ? DEFAULT_Y_AXIS_KEY : DEFAULT_X_AXIS_KEY,
96
+ scaleType: 'linear',
97
+ domainLimit: 'strict',
98
+ position: 'none'
99
+ };
100
+ const xAxis = isHorizontal ? getCategoryAxisConfig(categoryAxis, series, isHorizontal, 'x') : valueAxisConfig;
101
+ const yAxis = isHorizontal ? valueAxisConfig : getCategoryAxisConfig(categoryAxis, series, isHorizontal, 'y');
102
+ const chartContainerProps = _extends({}, rest, {
103
+ series: series.map(s => _extends({
104
+ type: 'funnel',
105
+ layout: isHorizontal ? 'horizontal' : 'vertical'
106
+ }, s)),
107
+ width,
108
+ height,
109
+ margin,
110
+ colors,
111
+ xAxis: [xAxis],
112
+ yAxis: [yAxis],
113
+ sx,
114
+ highlightedItem,
115
+ onHighlightChange,
116
+ className,
117
+ apiRef
118
+ });
119
+ const funnelPlotProps = {
120
+ onItemClick,
121
+ slots,
122
+ slotProps
123
+ };
124
+ const overlayProps = {
125
+ slots,
126
+ slotProps,
127
+ loading
128
+ };
129
+ const chartsAxisProps = {
130
+ slots,
131
+ slotProps
132
+ };
133
+ const legendProps = {
134
+ slots,
135
+ slotProps
136
+ };
137
+ const clipPathGroupProps = {
138
+ clipPath: `url(#${clipPathId})`
139
+ };
140
+ const clipPathProps = {
141
+ id: clipPathId
142
+ };
143
+ const chartsWrapperProps = {
144
+ sx,
145
+ legendPosition: props.slotProps?.legend?.position,
146
+ legendDirection: props.slotProps?.legend?.direction
147
+ };
148
+ const axisHighlightProps = _extends({}, axisHighlight);
149
+ return {
150
+ chartContainerProps,
151
+ funnelPlotProps,
152
+ overlayProps,
153
+ chartsAxisProps,
154
+ legendProps,
155
+ clipPathGroupProps,
156
+ clipPathProps,
157
+ chartsWrapperProps,
158
+ axisHighlightProps,
159
+ children
160
+ };
161
+ };
@@ -8,6 +8,7 @@ import { ChartContainerProProps } from "../ChartContainerPro/index.js";
8
8
  import { HeatmapSeriesType } from "../models/seriesType/heatmap.js";
9
9
  import { HeatmapTooltipProps } from "./HeatmapTooltip.js";
10
10
  import { HeatmapItemSlotProps, HeatmapItemSlots } from "./HeatmapItem.js";
11
+ import { HeatmapPluginsSignatures } from "./Heatmap.plugins.js";
11
12
  export interface HeatmapSlots extends ChartsAxisSlots, ChartsOverlaySlots, HeatmapItemSlots {
12
13
  /**
13
14
  * Custom component for the tooltip popper.
@@ -18,24 +19,24 @@ export interface HeatmapSlots extends ChartsAxisSlots, ChartsOverlaySlots, Heatm
18
19
  export interface HeatmapSlotProps extends ChartsAxisSlotProps, ChartsOverlaySlotProps, HeatmapItemSlotProps {
19
20
  tooltip?: Partial<HeatmapTooltipProps>;
20
21
  }
21
- export interface HeatmapProps extends Omit<ChartContainerProProps, 'series' | 'plugins' | 'xAxis' | 'yAxis' | 'zoom' | 'onZoomChange' | 'skipAnimation'>, Omit<ChartsAxisProps, 'slots' | 'slotProps'>, Omit<ChartsOverlayProps, 'slots' | 'slotProps'> {
22
+ export interface HeatmapProps extends Omit<ChartContainerProProps<'heatmap', HeatmapPluginsSignatures>, 'series' | 'plugins' | 'xAxis' | 'yAxis' | 'skipAnimation'>, Omit<ChartsAxisProps, 'slots' | 'slotProps'>, Omit<ChartsOverlayProps, 'slots' | 'slotProps'> {
22
23
  /**
23
24
  * The configuration of the x-axes.
24
25
  * If not provided, a default axis config is used.
25
26
  * An array of [[AxisConfig]] objects.
26
27
  */
27
- xAxis: MakeOptional<AxisConfig<'band', any, ChartsXAxisProps>, 'id' | 'scaleType'>[];
28
+ xAxis: Readonly<MakeOptional<AxisConfig<'band', any, ChartsXAxisProps>, 'id' | 'scaleType'>[]>;
28
29
  /**
29
30
  * The configuration of the y-axes.
30
31
  * If not provided, a default axis config is used.
31
32
  * An array of [[AxisConfig]] objects.
32
33
  */
33
- yAxis: MakeOptional<AxisConfig<'band', any, ChartsYAxisProps>, 'id' | 'scaleType'>[];
34
+ yAxis: Readonly<MakeOptional<AxisConfig<'band', any, ChartsYAxisProps>, 'id' | 'scaleType'>[]>;
34
35
  /**
35
36
  * The series to display in the bar chart.
36
37
  * An array of [[HeatmapSeriesType]] objects.
37
38
  */
38
- series: MakeOptional<HeatmapSeriesType, 'type'>[];
39
+ series: Readonly<MakeOptional<HeatmapSeriesType, 'type'>[]>;
39
40
  /**
40
41
  * The configuration of the tooltip.
41
42
  * @see See {@link https://mui.com/x/react-charts/tooltip/ tooltip docs} for more details.