@mui/x-charts-pro 8.5.0 → 8.5.2

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 (144) hide show
  1. package/BarChartPro/BarChartPro.d.ts +3 -2
  2. package/BarChartPro/BarChartPro.js +1 -1
  3. package/CHANGELOG.md +204 -0
  4. package/ChartContainerPro/ChartProApi.d.ts +2 -0
  5. package/ChartDataProviderPro/ChartDataProviderPro.js +1 -1
  6. package/ChartZoomSlider/internals/ChartAxisZoomSliderActiveTrack.d.ts +0 -2
  7. package/ChartZoomSlider/internals/ChartAxisZoomSliderActiveTrack.js +42 -9
  8. package/ChartZoomSlider/internals/ChartAxisZoomSliderTrack.js +0 -22
  9. package/ChartsToolbarPro/ChartsToolbarPro.d.ts +2 -4
  10. package/ChartsToolbarPro/ChartsToolbarPro.js +7 -13
  11. package/ChartsToolbarPro/{ChartsToolbarZoomInButton.d.ts → ChartsToolbarZoomInTrigger.d.ts} +6 -5
  12. package/ChartsToolbarPro/{ChartsToolbarZoomInButton.js → ChartsToolbarZoomInTrigger.js} +7 -6
  13. package/ChartsToolbarPro/{ChartsToolbarZoomOutButton.d.ts → ChartsToolbarZoomOutTrigger.d.ts} +6 -5
  14. package/ChartsToolbarPro/{ChartsToolbarZoomOutButton.js → ChartsToolbarZoomOutTrigger.js} +7 -6
  15. package/ChartsToolbarPro/Toolbar.types.d.ts +15 -0
  16. package/ChartsToolbarPro/Toolbar.types.js +5 -0
  17. package/ChartsToolbarPro/index.d.ts +2 -2
  18. package/ChartsToolbarPro/index.js +8 -8
  19. package/FunnelChart/FunnelChart.js +4 -11
  20. package/FunnelChart/FunnelChart.plugins.d.ts +3 -2
  21. package/FunnelChart/FunnelChart.plugins.js +2 -1
  22. package/FunnelChart/FunnelPlot.d.ts +0 -5
  23. package/FunnelChart/FunnelPlot.js +40 -50
  24. package/FunnelChart/FunnelSection.d.ts +1 -1
  25. package/FunnelChart/FunnelSectionLabel.d.ts +21 -0
  26. package/FunnelChart/FunnelSectionLabel.js +52 -0
  27. package/FunnelChart/categoryAxis.types.d.ts +2 -1
  28. package/FunnelChart/curves/bump.d.ts +9 -5
  29. package/FunnelChart/curves/bump.js +72 -43
  30. package/FunnelChart/curves/curve.types.d.ts +6 -1
  31. package/FunnelChart/curves/getFunnelCurve.js +3 -0
  32. package/FunnelChart/curves/linear.d.ts +10 -2
  33. package/FunnelChart/curves/linear.js +97 -17
  34. package/FunnelChart/curves/pyramid.js +10 -14
  35. package/FunnelChart/curves/step-pyramid.js +4 -6
  36. package/FunnelChart/curves/step.js +1 -15
  37. package/FunnelChart/funnel.types.d.ts +1 -0
  38. package/FunnelChart/funnelAxisPlugin/computeAxisValue.d.ts +25 -0
  39. package/FunnelChart/funnelAxisPlugin/computeAxisValue.js +124 -0
  40. package/FunnelChart/funnelAxisPlugin/useChartFunnelAxis.d.ts +3 -0
  41. package/FunnelChart/funnelAxisPlugin/useChartFunnelAxis.js +173 -0
  42. package/FunnelChart/funnelAxisPlugin/useChartFunnelAxis.types.d.ts +27 -0
  43. package/FunnelChart/funnelAxisPlugin/useChartFunnelAxis.types.js +5 -0
  44. package/FunnelChart/funnelAxisPlugin/useChartFunnelAxisRendering.selectors.d.ts +1482 -0
  45. package/FunnelChart/funnelAxisPlugin/useChartFunnelAxisRendering.selectors.js +27 -0
  46. package/FunnelChart/funnelPlotSlots.types.d.ts +11 -0
  47. package/FunnelChart/funnelSectionClasses.d.ts +2 -0
  48. package/FunnelChart/funnelSectionClasses.js +17 -4
  49. package/FunnelChart/index.d.ts +3 -1
  50. package/FunnelChart/index.js +18 -2
  51. package/FunnelChart/labelUtils.d.ts +3 -2
  52. package/FunnelChart/labelUtils.js +15 -15
  53. package/FunnelChart/positionGetter.d.ts +1 -0
  54. package/FunnelChart/positionGetter.js +5 -0
  55. package/FunnelChart/useFunnelChartProps.js +1 -3
  56. package/Heatmap/Heatmap.d.ts +8 -3
  57. package/Heatmap/Heatmap.js +10 -2
  58. package/Heatmap/HeatmapTooltip/HeatmapTooltipAxesValue.d.ts +1 -1
  59. package/LineChartPro/LineChartPro.d.ts +3 -2
  60. package/LineChartPro/LineChartPro.js +1 -1
  61. package/PieChartPro/PieChartPro.d.ts +22 -0
  62. package/PieChartPro/PieChartPro.js +204 -0
  63. package/PieChartPro/PieChartPro.plugins.d.ts +4 -0
  64. package/PieChartPro/PieChartPro.plugins.js +9 -0
  65. package/PieChartPro/index.d.ts +1 -0
  66. package/PieChartPro/index.js +16 -0
  67. package/RadarChartPro/RadarChartPro.d.ts +17 -2
  68. package/RadarChartPro/RadarChartPro.js +1 -1
  69. package/ScatterChartPro/ScatterChartPro.d.ts +3 -2
  70. package/ScatterChartPro/ScatterChartPro.js +1 -1
  71. package/esm/BarChartPro/BarChartPro.d.ts +3 -2
  72. package/esm/BarChartPro/BarChartPro.js +1 -1
  73. package/esm/ChartContainerPro/ChartProApi.d.ts +2 -0
  74. package/esm/ChartDataProviderPro/ChartDataProviderPro.js +1 -1
  75. package/esm/ChartZoomSlider/internals/ChartAxisZoomSliderActiveTrack.d.ts +0 -2
  76. package/esm/ChartZoomSlider/internals/ChartAxisZoomSliderActiveTrack.js +43 -10
  77. package/esm/ChartZoomSlider/internals/ChartAxisZoomSliderTrack.js +0 -22
  78. package/esm/ChartsToolbarPro/ChartsToolbarPro.d.ts +2 -4
  79. package/esm/ChartsToolbarPro/ChartsToolbarPro.js +8 -14
  80. package/esm/ChartsToolbarPro/{ChartsToolbarZoomInButton.d.ts → ChartsToolbarZoomInTrigger.d.ts} +6 -5
  81. package/esm/ChartsToolbarPro/{ChartsToolbarZoomInButton.js → ChartsToolbarZoomInTrigger.js} +8 -7
  82. package/esm/ChartsToolbarPro/{ChartsToolbarZoomOutButton.d.ts → ChartsToolbarZoomOutTrigger.d.ts} +6 -5
  83. package/esm/ChartsToolbarPro/{ChartsToolbarZoomOutButton.js → ChartsToolbarZoomOutTrigger.js} +8 -7
  84. package/esm/ChartsToolbarPro/Toolbar.types.d.ts +15 -0
  85. package/esm/ChartsToolbarPro/Toolbar.types.js +1 -0
  86. package/esm/ChartsToolbarPro/index.d.ts +2 -2
  87. package/esm/ChartsToolbarPro/index.js +2 -2
  88. package/esm/FunnelChart/FunnelChart.js +4 -11
  89. package/esm/FunnelChart/FunnelChart.plugins.d.ts +3 -2
  90. package/esm/FunnelChart/FunnelChart.plugins.js +3 -2
  91. package/esm/FunnelChart/FunnelPlot.d.ts +0 -5
  92. package/esm/FunnelChart/FunnelPlot.js +41 -51
  93. package/esm/FunnelChart/FunnelSection.d.ts +1 -1
  94. package/esm/FunnelChart/FunnelSectionLabel.d.ts +21 -0
  95. package/esm/FunnelChart/FunnelSectionLabel.js +46 -0
  96. package/esm/FunnelChart/categoryAxis.types.d.ts +2 -1
  97. package/esm/FunnelChart/curves/bump.d.ts +9 -5
  98. package/esm/FunnelChart/curves/bump.js +72 -43
  99. package/esm/FunnelChart/curves/curve.types.d.ts +6 -1
  100. package/esm/FunnelChart/curves/getFunnelCurve.js +3 -0
  101. package/esm/FunnelChart/curves/linear.d.ts +10 -2
  102. package/esm/FunnelChart/curves/linear.js +97 -17
  103. package/esm/FunnelChart/curves/pyramid.js +10 -14
  104. package/esm/FunnelChart/curves/step-pyramid.js +4 -6
  105. package/esm/FunnelChart/curves/step.js +1 -15
  106. package/esm/FunnelChart/funnel.types.d.ts +1 -0
  107. package/esm/FunnelChart/funnelAxisPlugin/computeAxisValue.d.ts +25 -0
  108. package/esm/FunnelChart/funnelAxisPlugin/computeAxisValue.js +114 -0
  109. package/esm/FunnelChart/funnelAxisPlugin/useChartFunnelAxis.d.ts +3 -0
  110. package/esm/FunnelChart/funnelAxisPlugin/useChartFunnelAxis.js +165 -0
  111. package/esm/FunnelChart/funnelAxisPlugin/useChartFunnelAxis.types.d.ts +27 -0
  112. package/esm/FunnelChart/funnelAxisPlugin/useChartFunnelAxis.types.js +1 -0
  113. package/esm/FunnelChart/funnelAxisPlugin/useChartFunnelAxisRendering.selectors.d.ts +1482 -0
  114. package/esm/FunnelChart/funnelAxisPlugin/useChartFunnelAxisRendering.selectors.js +20 -0
  115. package/esm/FunnelChart/funnelPlotSlots.types.d.ts +11 -0
  116. package/esm/FunnelChart/funnelSectionClasses.d.ts +2 -0
  117. package/esm/FunnelChart/funnelSectionClasses.js +15 -3
  118. package/esm/FunnelChart/index.d.ts +3 -1
  119. package/esm/FunnelChart/index.js +3 -1
  120. package/esm/FunnelChart/labelUtils.d.ts +3 -2
  121. package/esm/FunnelChart/labelUtils.js +15 -15
  122. package/esm/FunnelChart/positionGetter.d.ts +1 -0
  123. package/esm/FunnelChart/positionGetter.js +1 -0
  124. package/esm/FunnelChart/useFunnelChartProps.js +1 -3
  125. package/esm/Heatmap/Heatmap.d.ts +8 -3
  126. package/esm/Heatmap/Heatmap.js +10 -2
  127. package/esm/Heatmap/HeatmapTooltip/HeatmapTooltipAxesValue.d.ts +1 -1
  128. package/esm/LineChartPro/LineChartPro.d.ts +3 -2
  129. package/esm/LineChartPro/LineChartPro.js +1 -1
  130. package/esm/PieChartPro/PieChartPro.d.ts +22 -0
  131. package/esm/PieChartPro/PieChartPro.js +197 -0
  132. package/esm/PieChartPro/PieChartPro.plugins.d.ts +4 -0
  133. package/esm/PieChartPro/PieChartPro.plugins.js +3 -0
  134. package/esm/PieChartPro/index.d.ts +1 -0
  135. package/esm/PieChartPro/index.js +1 -0
  136. package/esm/RadarChartPro/RadarChartPro.d.ts +17 -2
  137. package/esm/RadarChartPro/RadarChartPro.js +1 -1
  138. package/esm/ScatterChartPro/ScatterChartPro.d.ts +3 -2
  139. package/esm/ScatterChartPro/ScatterChartPro.js +1 -1
  140. package/esm/index.d.ts +1 -0
  141. package/esm/index.js +2 -1
  142. package/index.d.ts +1 -0
  143. package/index.js +12 -1
  144. package/package.json +7 -7
@@ -11,7 +11,7 @@ var _utils = require("./utils");
11
11
  /**
12
12
  * This is a custom "linear" curve generator.
13
13
  * It draws straight lines for the 4 provided points,
14
- * with the option to add a gap between sections while also properly handling the border radius.
14
+ * with the option to properly handling the border radius.
15
15
  *
16
16
  * The implementation is based on the d3-shape linear curve generator.
17
17
  * https://github.com/d3/d3-shape/blob/a82254af78f08799c71d7ab25df557c4872a3c51/src/curve/linear.js
@@ -22,21 +22,51 @@ class Linear {
22
22
  gap,
23
23
  position,
24
24
  sections,
25
- borderRadius
25
+ borderRadius,
26
+ min,
27
+ max,
28
+ isIncreasing,
29
+ pointShape
26
30
  }) {
27
31
  this.context = void 0;
28
32
  this.position = 0;
29
33
  this.sections = 0;
30
34
  this.isHorizontal = false;
35
+ this.isIncreasing = false;
31
36
  this.gap = 0;
32
37
  this.borderRadius = 0;
38
+ this.min = {
39
+ x: 0,
40
+ y: 0
41
+ };
42
+ this.max = {
43
+ x: 0,
44
+ y: 0
45
+ };
33
46
  this.points = [];
47
+ this.pointShape = 'square';
34
48
  this.context = context;
35
49
  this.isHorizontal = isHorizontal ?? false;
36
- this.gap = (gap ?? 0) / 2;
50
+ this.gap = gap ?? 0;
37
51
  this.position = position ?? 0;
38
52
  this.sections = sections ?? 1;
39
53
  this.borderRadius = borderRadius ?? 0;
54
+ this.isIncreasing = isIncreasing ?? false;
55
+ this.min = min ?? {
56
+ x: 0,
57
+ y: 0
58
+ };
59
+ this.max = max ?? {
60
+ x: 0,
61
+ y: 0
62
+ };
63
+ this.pointShape = pointShape ?? 'square';
64
+ if (isIncreasing) {
65
+ const currentMin = this.min;
66
+ const currentMax = this.max;
67
+ this.min = currentMax;
68
+ this.max = currentMin;
69
+ }
40
70
  }
41
71
  areaStart() {}
42
72
  areaEnd() {}
@@ -46,11 +76,34 @@ class Linear {
46
76
  if (this.gap > 0) {
47
77
  return this.borderRadius;
48
78
  }
49
- if (this.position === 0) {
50
- return [0, 0, this.borderRadius, this.borderRadius];
79
+ if (this.isIncreasing) {
80
+ // Is largest section
81
+ if (this.position === this.sections - 1) {
82
+ return [this.borderRadius, this.borderRadius];
83
+ }
84
+ // Is smallest section and shaped like a triangle
85
+ if (this.position === 0 && this.pointShape === 'sharp') {
86
+ return [0, 0, this.borderRadius];
87
+ }
88
+ // Is smallest section
89
+ if (this.position === 0) {
90
+ return [0, 0, this.borderRadius, this.borderRadius];
91
+ }
51
92
  }
52
- if (this.position === this.sections - 1) {
53
- return [this.borderRadius, this.borderRadius];
93
+ if (!this.isIncreasing) {
94
+ // Is largest section
95
+ if (this.position === 0) {
96
+ return [0, 0, this.borderRadius, this.borderRadius];
97
+ }
98
+ // Is smallest section and shaped like a triangle
99
+ if (this.position === this.sections - 1 && this.pointShape === 'sharp') {
100
+ return [this.borderRadius];
101
+ }
102
+
103
+ // Is smallest section
104
+ if (this.position === this.sections - 1) {
105
+ return [this.borderRadius, this.borderRadius];
106
+ }
54
107
  }
55
108
  return 0;
56
109
  }
@@ -65,23 +118,50 @@ class Linear {
65
118
 
66
119
  // Add gaps where they are needed.
67
120
  this.points = this.points.map((point, index) => {
68
- const slopeStart = this.points.at(index <= 1 ? 0 : 2);
69
- const slopeEnd = this.points.at(index <= 1 ? 1 : 3);
121
+ const slopeStart = this.points.at(index <= 1 ? 0 : 3);
122
+ const slopeEnd = this.points.at(index <= 1 ? 1 : 2);
70
123
  if (this.isHorizontal) {
71
- const yGetter = (0, _utils.lerpY)(slopeStart.x - this.gap, slopeStart.y, slopeEnd.x - this.gap, slopeEnd.y);
72
- const xGap = point.x + (index === 0 || index === 3 ? this.gap : -this.gap);
124
+ const yGetter = (0, _utils.lerpY)(slopeStart.x - this.gap, slopeStart.y, slopeEnd.x, slopeEnd.y);
73
125
  return {
74
- x: xGap,
75
- y: yGetter(xGap)
126
+ x: point.x,
127
+ y: yGetter(point.x)
76
128
  };
77
129
  }
78
- const xGetter = (0, _utils.lerpX)(slopeStart.x, slopeStart.y - this.gap, slopeEnd.x, slopeEnd.y - this.gap);
79
- const yGap = point.y + (index === 0 || index === 3 ? this.gap : -this.gap);
130
+ const xGetter = (0, _utils.lerpX)(slopeStart.x, slopeStart.y - this.gap, slopeEnd.x, slopeEnd.y);
80
131
  return {
81
- x: xGetter(yGap),
82
- y: yGap
132
+ x: xGetter(point.y),
133
+ y: point.y
83
134
  };
84
135
  });
136
+ if (this.pointShape === 'sharp') {
137
+ // In the last section, to form a triangle we need 3 points instead of 4
138
+ // Else the algorithm will break.
139
+ const isLastSection = this.position === this.sections - 1;
140
+ const isFirstSection = this.position === 0;
141
+ let firstPoint = null;
142
+ let secondPoint = null;
143
+ if (isFirstSection && this.isIncreasing) {
144
+ firstPoint = this.points[1];
145
+ secondPoint = this.points[2];
146
+ }
147
+ if (isLastSection && !this.isIncreasing) {
148
+ firstPoint = this.points[3];
149
+ secondPoint = this.points[0];
150
+ }
151
+ if (firstPoint && secondPoint) {
152
+ this.points = [
153
+ // Sharp point at the start
154
+ this.isHorizontal ? {
155
+ x: this.max.x,
156
+ y: (this.max.y + this.min.y) / 2
157
+ } : {
158
+ x: (this.max.x + this.min.x) / 2,
159
+ y: this.max.y
160
+ },
161
+ // Then other points
162
+ firstPoint, secondPoint];
163
+ }
164
+ }
85
165
  (0, _borderRadiusPolygon.borderRadiusPolygon)(this.context, this.points, this.getBorderRadius());
86
166
  }
87
167
  }
@@ -102,7 +102,7 @@ class Pyramid {
102
102
  return;
103
103
  }
104
104
 
105
- // Add gaps where they are needed.
105
+ // Replace funnel points by pyramids ones.
106
106
  this.points = this.points.map((point, index) => {
107
107
  if (this.isHorizontal) {
108
108
  const slopeEnd = {
@@ -114,10 +114,9 @@ class Pyramid {
114
114
  y: this.max.y
115
115
  };
116
116
  const yGetter = (0, _utils.lerpY)(slopeStart.x, slopeStart.y, slopeEnd.x, slopeEnd.y);
117
- const xGap = point.x + (index === 0 || index === 3 ? this.gap : -this.gap);
118
117
  return {
119
- x: xGap,
120
- y: yGetter(xGap)
118
+ x: point.x,
119
+ y: yGetter(point.x)
121
120
  };
122
121
  }
123
122
  const slopeEnd = {
@@ -129,10 +128,9 @@ class Pyramid {
129
128
  y: this.min.y
130
129
  } : this.min;
131
130
  const xGetter = (0, _utils.lerpX)(slopeStart.x, slopeStart.y, slopeEnd.x, slopeEnd.y);
132
- const yGap = point.y + (index === 0 || index === 3 ? this.gap : -this.gap);
133
131
  return {
134
- x: xGetter(yGap),
135
- y: yGap
132
+ x: xGetter(point.y),
133
+ y: point.y
136
134
  };
137
135
  });
138
136
 
@@ -140,13 +138,11 @@ class Pyramid {
140
138
  // Else the algorithm will break.
141
139
  const isLastSection = this.position === this.sections - 1;
142
140
  const isFirstSection = this.position === 0;
143
- if (this.gap <= 0) {
144
- if (isFirstSection && this.isIncreasing) {
145
- this.points = [this.points[0], this.points[1], this.points[2]];
146
- }
147
- if (isLastSection && !this.isIncreasing) {
148
- this.points = [this.points[0], this.points[1], this.points[3]];
149
- }
141
+ if (isFirstSection && this.isIncreasing) {
142
+ this.points = [this.points[0], this.points[1], this.points[2]];
143
+ }
144
+ if (isLastSection && !this.isIncreasing) {
145
+ this.points = [this.points[0], this.points[1], this.points[3]];
150
146
  }
151
147
  (0, _borderRadiusPolygon.borderRadiusPolygon)(this.context, this.points, this.getBorderRadius());
152
148
  }
@@ -42,7 +42,7 @@ class StepPyramid {
42
42
  this.points = [];
43
43
  this.context = context;
44
44
  this.isHorizontal = isHorizontal ?? false;
45
- this.gap = (gap ?? 0) / 2;
45
+ this.gap = gap ?? 0;
46
46
  this.position = position ?? 0;
47
47
  this.sections = sections ?? 1;
48
48
  this.borderRadius = borderRadius ?? 0;
@@ -156,25 +156,23 @@ class StepPyramid {
156
156
  return;
157
157
  }
158
158
 
159
- // Add gaps where they are needed.
159
+ // Replace funnel points by pyramids ones.
160
160
  this.points = this.points.map((point, index) => {
161
161
  const slopeStart = this.slopeStart(index);
162
162
  const slopeEnd = this.slopeEnd(index);
163
163
  if (this.isHorizontal) {
164
164
  const yGetter = (0, _utils.lerpY)(slopeStart.x, slopeStart.y, slopeEnd.x, slopeEnd.y);
165
- const xGap = point.x + (index === 0 || index === 3 ? this.gap : -this.gap);
166
165
  const xInitial = this.initialX(index);
167
166
  return {
168
- x: xGap,
167
+ x: point.x,
169
168
  y: yGetter(xInitial)
170
169
  };
171
170
  }
172
171
  const xGetter = (0, _utils.lerpX)(slopeStart.x, slopeStart.y, slopeEnd.x, slopeEnd.y);
173
- const yGap = point.y + (index === 0 || index === 3 ? this.gap : -this.gap);
174
172
  const yInitial = this.initialY(index);
175
173
  return {
176
174
  x: xGetter(yInitial),
177
- y: yGap
175
+ y: point.y
178
176
  };
179
177
  });
180
178
  (0, _borderRadiusPolygon.borderRadiusPolygon)(this.context, this.points, this.getBorderRadius());
@@ -37,7 +37,7 @@ class Step {
37
37
  this.points = [];
38
38
  this.context = context;
39
39
  this.isHorizontal = isHorizontal ?? false;
40
- this.gap = (gap ?? 0) / 2;
40
+ this.gap = gap ?? 0;
41
41
  this.position = position ?? 0;
42
42
  this.sections = sections ?? 1;
43
43
  this.borderRadius = borderRadius ?? 0;
@@ -86,20 +86,6 @@ class Step {
86
86
  y: index === 1 || index === 2 ? (0, _utils.max)(allY) : (0, _utils.min)(allY)
87
87
  };
88
88
  });
89
-
90
- // Add gaps where they are needed.
91
- this.points = this.points.map((point, index) => {
92
- if (this.isHorizontal) {
93
- return {
94
- x: point.x + (index === 0 || index === 3 ? this.gap : -this.gap),
95
- y: point.y
96
- };
97
- }
98
- return {
99
- x: point.x,
100
- y: point.y + (index === 0 || index === 3 ? this.gap : -this.gap)
101
- };
102
- });
103
89
  (0, _borderRadiusPolygon.borderRadiusPolygon)(this.context, this.points, this.getBorderRadius());
104
90
  }
105
91
  }
@@ -47,6 +47,7 @@ export interface FunnelSeriesType extends Omit<CommonSeriesType<FunnelValueType>
47
47
  *
48
48
  * - `bump`: A curve that creates a smooth transition between points, with a bump in the middle.
49
49
  * - `linear`: A straight line between points.
50
+ * - `linear-sharp`: A straight line between points, the smaller end of the funnel is a triangle.
50
51
  * - `step`: A step line that creates a staircase effect.
51
52
  * - `pyramid`: A pyramid shape that connects the points.
52
53
  * - `step-pyramid`: A step line that creates a staircase effect, with a pyramid shape.
@@ -0,0 +1,25 @@
1
+ import { ChartsAxisProps } from '@mui/x-charts/ChartsAxis';
2
+ import { ChartDrawingArea } from '@mui/x-charts/hooks';
3
+ import { ComputedAxisConfig, ChartSeriesType, ProcessedSeries, ChartSeriesConfig, DefaultedYAxis, DefaultedXAxis } from '@mui/x-charts/internals';
4
+ import { ChartsXAxisProps, ChartsYAxisProps } from '@mui/x-charts/models';
5
+ export declare const xRangeGetter: (drawingArea: ChartDrawingArea, reverse?: boolean, removedSpace?: number) => [number, number];
6
+ export declare const yRangeGetter: (drawingArea: ChartDrawingArea, reverse?: boolean, removedSpace?: number) => [number, number];
7
+ export type ComputeResult<T extends ChartsAxisProps> = {
8
+ axis: ComputedAxisConfig<T>;
9
+ axisIds: string[];
10
+ };
11
+ type ComputeCommonParams<T extends ChartSeriesType = 'funnel'> = {
12
+ drawingArea: ChartDrawingArea;
13
+ formattedSeries: ProcessedSeries<T>;
14
+ seriesConfig: ChartSeriesConfig<T>;
15
+ gap: number;
16
+ };
17
+ export declare function computeAxisValue(options: ComputeCommonParams<'funnel'> & {
18
+ axis?: DefaultedYAxis[];
19
+ axisDirection: 'y';
20
+ }): ComputeResult<ChartsYAxisProps>;
21
+ export declare function computeAxisValue(options: ComputeCommonParams<'funnel'> & {
22
+ axis?: DefaultedXAxis[];
23
+ axisDirection: 'x';
24
+ }): ComputeResult<ChartsXAxisProps>;
25
+ export {};
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.computeAxisValue = computeAxisValue;
8
+ exports.yRangeGetter = exports.xRangeGetter = void 0;
9
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
10
+ var _d3Scale = require("@mui/x-charts-vendor/d3-scale");
11
+ var _internals = require("@mui/x-charts/internals");
12
+ const xRangeGetter = (drawingArea, reverse, removedSpace = 0) => {
13
+ const range = [drawingArea.left, drawingArea.left + drawingArea.width - removedSpace];
14
+ return reverse ? [range[1], range[0]] : [range[0], range[1]];
15
+ };
16
+ exports.xRangeGetter = xRangeGetter;
17
+ const yRangeGetter = (drawingArea, reverse, removedSpace = 0) => {
18
+ const range = [drawingArea.top + drawingArea.height - removedSpace, drawingArea.top];
19
+ return reverse ? [range[1], range[0]] : [range[0], range[1]];
20
+ };
21
+ exports.yRangeGetter = yRangeGetter;
22
+ function getRange(drawingArea, axisDirection, axis, removedSpace = 0) {
23
+ return axisDirection === 'x' ? xRangeGetter(drawingArea, axis.reverse, removedSpace) : yRangeGetter(drawingArea, axis.reverse, removedSpace);
24
+ }
25
+ function computeAxisValue({
26
+ drawingArea,
27
+ formattedSeries,
28
+ axis: allAxis,
29
+ seriesConfig,
30
+ axisDirection,
31
+ gap
32
+ }) {
33
+ if (allAxis === undefined) {
34
+ return {
35
+ axis: {},
36
+ axisIds: []
37
+ };
38
+ }
39
+ const axisIdsTriggeringTooltip = (0, _internals.getCartesianAxisTriggerTooltip)(axisDirection, seriesConfig, formattedSeries, allAxis[0].id);
40
+ const completeAxis = {};
41
+ allAxis.forEach((eachAxis, axisIndex) => {
42
+ const axis = eachAxis;
43
+ let range = getRange(drawingArea, axisDirection, axis);
44
+ const [minData, maxData] = (0, _internals.getAxisExtremum)(axis, axisDirection, seriesConfig, axisIndex, formattedSeries);
45
+ const triggerTooltip = !axis.ignoreTooltip && axisIdsTriggeringTooltip.has(axis.id);
46
+ const data = axis.data ?? [];
47
+ if ((0, _internals.isBandScaleConfig)(axis)) {
48
+ // Reverse range because ordinal scales are presented from top to bottom on y-axis
49
+ const scaleRange = axisDirection === 'y' ? [range[1], range[0]] : range;
50
+ const rangeSpace = Math.abs(range[1] - range[0]);
51
+ const N = axis.data.length;
52
+ const bandWidth = (rangeSpace - gap * (N - 1)) / N;
53
+ const step = bandWidth + gap;
54
+ completeAxis[axis.id] = (0, _extends2.default)({
55
+ offset: 0,
56
+ height: 0,
57
+ categoryGapRatio: 0,
58
+ barGapRatio: 0,
59
+ triggerTooltip
60
+ }, axis, {
61
+ data,
62
+ scale: (0, _d3Scale.scaleBand)(axis.data, scaleRange).paddingInner(gap / step).paddingOuter(0),
63
+ tickNumber: axis.data.length,
64
+ colorScale: axis.colorMap && (axis.colorMap.type === 'ordinal' ? (0, _internals.getOrdinalColorScale)((0, _extends2.default)({
65
+ values: axis.data
66
+ }, axis.colorMap)) : (0, _internals.getColorScale)(axis.colorMap))
67
+ });
68
+ if ((0, _internals.isDateData)(axis.data)) {
69
+ const dateFormatter = (0, _internals.createDateFormatter)(axis, scaleRange);
70
+ completeAxis[axis.id].valueFormatter = axis.valueFormatter ?? dateFormatter;
71
+ }
72
+ }
73
+ if (axis.scaleType === 'band') {
74
+ return;
75
+ }
76
+ if (axis.scaleType === 'point') {
77
+ throw new Error('Point scale is not supported in FunnelChart. Please use band scale instead.');
78
+ }
79
+ const isHorizontal = Object.values(formattedSeries.funnel?.series ?? {}).some(s => s.layout === 'horizontal');
80
+ if (isHorizontal ? axisDirection === 'x' : axisDirection === 'y') {
81
+ // For linear scale replacing the band scale, we remove the space needed for gap from the scale range.
82
+ const itemNumber = formattedSeries.funnel?.series[formattedSeries.funnel.seriesOrder[0]].data.length ?? 0;
83
+ const spaceToRemove = gap * (itemNumber - 1);
84
+ range = getRange(drawingArea, axisDirection, axis, spaceToRemove);
85
+ }
86
+ const scaleType = axis.scaleType ?? 'linear';
87
+ const domainLimit = axis.domainLimit ?? 'nice';
88
+ const axisExtremums = [axis.min ?? minData, axis.max ?? maxData];
89
+ if (typeof domainLimit === 'function') {
90
+ const {
91
+ min,
92
+ max
93
+ } = domainLimit(minData, maxData);
94
+ axisExtremums[0] = min;
95
+ axisExtremums[1] = max;
96
+ }
97
+ const rawTickNumber = (0, _internals.getTickNumber)((0, _extends2.default)({}, axis, {
98
+ range,
99
+ domain: axisExtremums
100
+ }));
101
+ const tickNumber = (0, _internals.scaleTickNumberByRange)(rawTickNumber, range);
102
+ const scale = (0, _internals.getScale)(scaleType, axisExtremums, range);
103
+ const finalScale = domainLimit === 'nice' ? scale.nice(rawTickNumber) : scale;
104
+ const [minDomain, maxDomain] = finalScale.domain();
105
+ const domain = [axis.min ?? minDomain, axis.max ?? maxDomain];
106
+ completeAxis[axis.id] = (0, _extends2.default)({
107
+ offset: 0,
108
+ height: 0,
109
+ triggerTooltip
110
+ }, axis, {
111
+ data,
112
+ scaleType: scaleType,
113
+ scale: finalScale.domain(domain),
114
+ tickNumber,
115
+ colorScale: axis.colorMap && (0, _internals.getColorScale)(axis.colorMap)
116
+ });
117
+ });
118
+ return {
119
+ axis: completeAxis,
120
+ axisIds: allAxis.map(({
121
+ id
122
+ }) => id)
123
+ };
124
+ }
@@ -0,0 +1,3 @@
1
+ import { ChartPlugin } from '@mui/x-charts/internals';
2
+ import { UseChartFunnelAxisSignature } from "./useChartFunnelAxis.types.js";
3
+ export declare const useChartFunnelAxis: ChartPlugin<UseChartFunnelAxisSignature>;
@@ -0,0 +1,173 @@
1
+ "use strict";
2
+ 'use client';
3
+
4
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
5
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
6
+ Object.defineProperty(exports, "__esModule", {
7
+ value: true
8
+ });
9
+ exports.useChartFunnelAxis = void 0;
10
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
11
+ var React = _interopRequireWildcard(require("react"));
12
+ var _warning = require("@mui/x-internals/warning");
13
+ var _internals = require("@mui/x-charts/internals");
14
+ var _useChartFunnelAxisRendering = require("./useChartFunnelAxisRendering.selectors");
15
+ const useChartFunnelAxis = ({
16
+ params,
17
+ store,
18
+ seriesConfig,
19
+ svgRef,
20
+ instance
21
+ }) => {
22
+ const {
23
+ xAxis,
24
+ yAxis,
25
+ dataset,
26
+ gap
27
+ } = params;
28
+ if (process.env.NODE_ENV !== 'production') {
29
+ const ids = [...(xAxis ?? []), ...(yAxis ?? [])].filter(axis => axis.id).map(axis => axis.id);
30
+ const duplicates = new Set(ids.filter((id, index) => ids.indexOf(id) !== index));
31
+ if (duplicates.size > 0) {
32
+ (0, _warning.warnOnce)([`MUI X Charts: The following axis ids are duplicated: ${Array.from(duplicates).join(', ')}.`, `Please make sure that each axis has a unique id.`].join('\n'), 'error');
33
+ }
34
+ }
35
+ const drawingArea = (0, _internals.useSelector)(store, _internals.selectorChartDrawingArea);
36
+ const isInteractionEnabled = (0, _internals.useSelector)(store, _internals.selectorChartsInteractionIsInitialized);
37
+ const isFirstRender = React.useRef(true);
38
+ React.useEffect(() => {
39
+ if (isFirstRender.current) {
40
+ isFirstRender.current = false;
41
+ return;
42
+ }
43
+ store.update(prev => (0, _extends2.default)({}, prev, {
44
+ funnel: {
45
+ gap: gap ?? 0
46
+ },
47
+ cartesianAxis: (0, _extends2.default)({}, prev.cartesianAxis, {
48
+ x: (0, _internals.defaultizeXAxis)(xAxis, dataset),
49
+ y: (0, _internals.defaultizeYAxis)(yAxis, dataset)
50
+ })
51
+ }));
52
+ }, [seriesConfig, drawingArea, xAxis, yAxis, dataset, store, gap]);
53
+ React.useEffect(() => {
54
+ const element = svgRef.current;
55
+ if (!isInteractionEnabled || element === null || params.disableAxisListener) {
56
+ return () => {};
57
+ }
58
+ const handleOut = () => {
59
+ instance.cleanInteraction?.();
60
+ };
61
+ const handleMove = event => {
62
+ const target = 'targetTouches' in event ? event.targetTouches[0] : event;
63
+ const svgPoint = (0, _internals.getSVGPoint)(element, target);
64
+ if (!instance.isPointInside(svgPoint.x, svgPoint.y, event.target)) {
65
+ instance.cleanInteraction?.();
66
+ return;
67
+ }
68
+ instance.setPointerCoordinate?.(svgPoint);
69
+ };
70
+ const handleDown = event => {
71
+ const target = event.currentTarget;
72
+ if (!target) {
73
+ return;
74
+ }
75
+ if ('hasPointerCapture' in target && target.hasPointerCapture(event.pointerId)) {
76
+ target.releasePointerCapture(event.pointerId);
77
+ }
78
+ };
79
+ element.addEventListener('pointerdown', handleDown);
80
+ element.addEventListener('pointermove', handleMove);
81
+ element.addEventListener('pointercancel', handleOut);
82
+ element.addEventListener('pointerleave', handleOut);
83
+ return () => {
84
+ element.removeEventListener('pointerdown', handleDown);
85
+ element.removeEventListener('pointermove', handleMove);
86
+ element.removeEventListener('pointercancel', handleOut);
87
+ element.removeEventListener('pointerleave', handleOut);
88
+ };
89
+ }, [svgRef, instance, params.disableAxisListener, isInteractionEnabled]);
90
+ React.useEffect(() => {
91
+ const element = svgRef.current;
92
+ const onAxisClick = params.onAxisClick;
93
+ if (element === null || !onAxisClick) {
94
+ return () => {};
95
+ }
96
+ const handleMouseClick = event => {
97
+ event.preventDefault();
98
+ const {
99
+ axis: xAxisWithScale,
100
+ axisIds: xAxisIds
101
+ } = (0, _useChartFunnelAxisRendering.selectorChartXAxis)(store.value);
102
+ const {
103
+ axis: yAxisWithScale,
104
+ axisIds: yAxisIds
105
+ } = (0, _useChartFunnelAxisRendering.selectorChartYAxis)(store.value);
106
+ const processedSeries = (0, _internals.selectorChartSeriesProcessed)(store.value);
107
+ const usedXAxis = xAxisIds[0];
108
+ const usedYAxis = yAxisIds[0];
109
+ let dataIndex = null;
110
+ let isXAxis = false;
111
+ const svgPoint = (0, _internals.getSVGPoint)(element, event);
112
+ const xIndex = (0, _internals.getCartesianAxisIndex)(xAxisWithScale[usedXAxis], svgPoint.x);
113
+ isXAxis = xIndex !== -1;
114
+ dataIndex = isXAxis ? xIndex : (0, _internals.getCartesianAxisIndex)(yAxisWithScale[usedYAxis], svgPoint.y);
115
+ const USED_AXIS_ID = isXAxis ? xAxisIds[0] : yAxisIds[0];
116
+ if (dataIndex == null || dataIndex === -1) {
117
+ return;
118
+ }
119
+
120
+ // The .data exist because otherwise the dataIndex would be null or -1.
121
+ const axisValue = (isXAxis ? xAxisWithScale : yAxisWithScale)[USED_AXIS_ID].data[dataIndex];
122
+ const seriesValues = {};
123
+ processedSeries.funnel?.seriesOrder.forEach(seriesId => {
124
+ const seriesItem = processedSeries.funnel.series[seriesId];
125
+ const providedXAxisId = seriesItem.xAxisId;
126
+ const providedYAxisId = seriesItem.yAxisId;
127
+ const axisKey = isXAxis ? providedXAxisId : providedYAxisId;
128
+ if (axisKey === undefined || axisKey === USED_AXIS_ID) {
129
+ seriesValues[seriesId] = seriesItem.data[dataIndex].value;
130
+ }
131
+ });
132
+ onAxisClick(event, {
133
+ dataIndex,
134
+ axisValue,
135
+ seriesValues
136
+ });
137
+ };
138
+ element.addEventListener('click', handleMouseClick);
139
+ return () => {
140
+ element.removeEventListener('click', handleMouseClick);
141
+ };
142
+ }, [params.onAxisClick, svgRef, store]);
143
+ return {};
144
+ };
145
+ exports.useChartFunnelAxis = useChartFunnelAxis;
146
+ useChartFunnelAxis.params = {
147
+ xAxis: true,
148
+ yAxis: true,
149
+ gap: true,
150
+ dataset: true,
151
+ onAxisClick: true,
152
+ disableAxisListener: true
153
+ };
154
+ useChartFunnelAxis.getDefaultizedParams = ({
155
+ params
156
+ }) => {
157
+ return (0, _extends2.default)({}, params, {
158
+ gap: params.gap ?? 0,
159
+ defaultizedXAxis: (0, _internals.defaultizeXAxis)(params.xAxis, params.dataset),
160
+ defaultizedYAxis: (0, _internals.defaultizeYAxis)(params.yAxis, params.dataset)
161
+ });
162
+ };
163
+ useChartFunnelAxis.getInitialState = params => {
164
+ return {
165
+ funnel: {
166
+ gap: params.gap ?? 0
167
+ },
168
+ cartesianAxis: {
169
+ x: params.defaultizedXAxis,
170
+ y: params.defaultizedYAxis
171
+ }
172
+ };
173
+ };
@@ -0,0 +1,27 @@
1
+ import { ChartPluginSignature, UseChartCartesianAxisDefaultizedParameters, UseChartCartesianAxisParameters, UseChartCartesianAxisState, UseChartInteractionSignature, UseChartSeriesSignature, ChartsAxisData } from '@mui/x-charts/internals';
2
+ export type UseChartFunnelAxisSignature = ChartPluginSignature<{
3
+ params: Omit<UseChartCartesianAxisParameters, 'onAxisClick'> & {
4
+ /**
5
+ * The gap, in pixels, between funnel sections.
6
+ * @default 0
7
+ */
8
+ gap?: number;
9
+ /**
10
+ * The function called for onClick events.
11
+ * The second argument contains information about all funnel elements at the current position.
12
+ * @param {MouseEvent} event The mouse event recorded on the `<svg/>` element.
13
+ * @param {null | ChartsAxisData} data The data about the clicked axis and items associated with it.
14
+ */
15
+ onAxisClick?: (event: MouseEvent, data: null | ChartsAxisData) => void;
16
+ };
17
+ defaultizedParams: UseChartCartesianAxisDefaultizedParameters & {
18
+ gap: number;
19
+ };
20
+ state: Pick<UseChartCartesianAxisState, 'cartesianAxis'> & {
21
+ funnel: {
22
+ gap: number;
23
+ };
24
+ };
25
+ dependencies: [UseChartSeriesSignature<'funnel'>];
26
+ optionalDependencies: [UseChartInteractionSignature];
27
+ }>;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });