@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
@@ -14,25 +14,25 @@ Object.keys(_ChartsToolbarPro).forEach(function (key) {
14
14
  }
15
15
  });
16
16
  });
17
- var _ChartsToolbarZoomInButton = require("./ChartsToolbarZoomInButton");
18
- Object.keys(_ChartsToolbarZoomInButton).forEach(function (key) {
17
+ var _ChartsToolbarZoomInTrigger = require("./ChartsToolbarZoomInTrigger");
18
+ Object.keys(_ChartsToolbarZoomInTrigger).forEach(function (key) {
19
19
  if (key === "default" || key === "__esModule") return;
20
- if (key in exports && exports[key] === _ChartsToolbarZoomInButton[key]) return;
20
+ if (key in exports && exports[key] === _ChartsToolbarZoomInTrigger[key]) return;
21
21
  Object.defineProperty(exports, key, {
22
22
  enumerable: true,
23
23
  get: function () {
24
- return _ChartsToolbarZoomInButton[key];
24
+ return _ChartsToolbarZoomInTrigger[key];
25
25
  }
26
26
  });
27
27
  });
28
- var _ChartsToolbarZoomOutButton = require("./ChartsToolbarZoomOutButton");
29
- Object.keys(_ChartsToolbarZoomOutButton).forEach(function (key) {
28
+ var _ChartsToolbarZoomOutTrigger = require("./ChartsToolbarZoomOutTrigger");
29
+ Object.keys(_ChartsToolbarZoomOutTrigger).forEach(function (key) {
30
30
  if (key === "default" || key === "__esModule") return;
31
- if (key in exports && exports[key] === _ChartsToolbarZoomOutButton[key]) return;
31
+ if (key in exports && exports[key] === _ChartsToolbarZoomOutTrigger[key]) return;
32
32
  Object.defineProperty(exports, key, {
33
33
  enumerable: true,
34
34
  get: function () {
35
- return _ChartsToolbarZoomOutButton[key];
35
+ return _ChartsToolbarZoomOutTrigger[key];
36
36
  }
37
37
  });
38
38
  });
@@ -23,6 +23,7 @@ var _useFunnelChartProps = require("./useFunnelChartProps");
23
23
  var _seriesConfig = require("./seriesConfig");
24
24
  var _useChartContainerProProps = require("../ChartContainerPro/useChartContainerProProps");
25
25
  var _ChartDataProviderPro = require("../ChartDataProviderPro");
26
+ var _FunnelChart2 = require("./FunnelChart.plugins");
26
27
  var _jsxRuntime = require("react/jsx-runtime");
27
28
  const seriesConfig = {
28
29
  funnel: _seriesConfig.seriesConfig
@@ -48,7 +49,9 @@ const FunnelChart = exports.FunnelChart = /*#__PURE__*/React.forwardRef(function
48
49
  } = (0, _useChartContainerProProps.useChartContainerProProps)(chartContainerProps, ref);
49
50
  const Tooltip = themedProps.slots?.tooltip ?? _ChartsTooltip.ChartsTooltip;
50
51
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartDataProviderPro.ChartDataProviderPro, (0, _extends2.default)({}, chartDataProviderProProps, {
52
+ gap: themedProps.gap,
51
53
  seriesConfig: seriesConfig,
54
+ plugins: _FunnelChart2.FUNNEL_CHART_PLUGINS,
52
55
  children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_internals.ChartsWrapper, (0, _extends2.default)({}, chartsWrapperProps, {
53
56
  children: [!themedProps.hideLegend && /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsLegend.ChartsLegend, (0, _extends2.default)({}, legendProps)), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_ChartsSurface.ChartsSurface, (0, _extends2.default)({}, chartsSurfaceProps, {
54
57
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_FunnelPlot.FunnelPlot, (0, _extends2.default)({}, funnelPlotProps)), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsOverlay.ChartsOverlay, (0, _extends2.default)({}, overlayProps)), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsAxisHighlight.ChartsAxisHighlight, (0, _extends2.default)({}, axisHighlightProps)), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsAxis.ChartsAxis, (0, _extends2.default)({}, chartsAxisProps)), children]
@@ -95,16 +98,6 @@ process.env.NODE_ENV !== "production" ? FunnelChart.propTypes = {
95
98
  size: _propTypes.default.number,
96
99
  tickLabelStyle: _propTypes.default.object,
97
100
  tickSize: _propTypes.default.number
98
- }), _propTypes.default.shape({
99
- categories: _propTypes.default.arrayOf(_propTypes.default.string),
100
- disableLine: _propTypes.default.bool,
101
- disableTicks: _propTypes.default.bool,
102
- id: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]),
103
- position: _propTypes.default.oneOf(['bottom', 'left', 'none', 'right', 'top']),
104
- scaleType: _propTypes.default.oneOf(['point']),
105
- size: _propTypes.default.number,
106
- tickLabelStyle: _propTypes.default.object,
107
- tickSize: _propTypes.default.number
108
101
  }), _propTypes.default.shape({
109
102
  categories: _propTypes.default.arrayOf(_propTypes.default.string),
110
103
  disableLine: _propTypes.default.bool,
@@ -229,7 +222,7 @@ process.env.NODE_ENV !== "production" ? FunnelChart.propTypes = {
229
222
  })]),
230
223
  /**
231
224
  * The function called for onClick events.
232
- * The second argument contains information about all line/bar elements at the current mouse position.
225
+ * The second argument contains information about all funnel elements at the current position.
233
226
  * @param {MouseEvent} event The mouse event recorded on the `<svg/>` element.
234
227
  * @param {null | ChartsAxisData} data The data about the clicked axis and items associated with it.
235
228
  */
@@ -1,4 +1,5 @@
1
- import { ConvertSignaturesIntoPlugins, UseChartCartesianAxisSignature, UseChartHighlightSignature, UseChartInteractionSignature } from '@mui/x-charts/internals';
1
+ import { ConvertSignaturesIntoPlugins, UseChartHighlightSignature, UseChartInteractionSignature } from '@mui/x-charts/internals';
2
2
  import { UseChartProExportSignature } from "../internals/plugins/useChartProExport/index.js";
3
- export type FunnelChartPluginsSignatures = [UseChartCartesianAxisSignature, UseChartInteractionSignature, UseChartHighlightSignature, UseChartProExportSignature];
3
+ import { UseChartFunnelAxisSignature } from "./funnelAxisPlugin/useChartFunnelAxis.types.js";
4
+ export type FunnelChartPluginsSignatures = [UseChartFunnelAxisSignature, UseChartInteractionSignature, UseChartHighlightSignature, UseChartProExportSignature];
4
5
  export declare const FUNNEL_CHART_PLUGINS: ConvertSignaturesIntoPlugins<FunnelChartPluginsSignatures>;
@@ -6,4 +6,5 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.FUNNEL_CHART_PLUGINS = void 0;
7
7
  var _internals = require("@mui/x-charts/internals");
8
8
  var _useChartProExport = require("../internals/plugins/useChartProExport");
9
- const FUNNEL_CHART_PLUGINS = exports.FUNNEL_CHART_PLUGINS = [_internals.useChartCartesianAxis, _internals.useChartInteraction, _internals.useChartHighlight, _useChartProExport.useChartProExport];
9
+ var _useChartFunnelAxis = require("./funnelAxisPlugin/useChartFunnelAxis");
10
+ const FUNNEL_CHART_PLUGINS = exports.FUNNEL_CHART_PLUGINS = [_useChartFunnelAxis.useChartFunnelAxis, _internals.useChartInteraction, _internals.useChartHighlight, _useChartProExport.useChartProExport];
@@ -2,11 +2,6 @@ import * as React from 'react';
2
2
  import { FunnelItemIdentifier } from "./funnel.types.js";
3
3
  import { FunnelPlotSlotExtension } from "./funnelPlotSlots.types.js";
4
4
  export interface FunnelPlotProps extends FunnelPlotSlotExtension {
5
- /**
6
- * The gap, in pixels, between funnel sections.
7
- * @default 0
8
- */
9
- gap?: number;
10
5
  /**
11
6
  * Callback fired when a funnel item is clicked.
12
7
  * @param {React.MouseEvent<SVGElement, MouseEvent>} event The event source of the callback.
@@ -13,25 +13,27 @@ var React = _react;
13
13
  var _propTypes = _interopRequireDefault(require("prop-types"));
14
14
  var _d3Shape = require("@mui/x-charts-vendor/d3-shape");
15
15
  var _internals = require("@mui/x-charts/internals");
16
- var _hooks = require("@mui/x-charts/hooks");
17
- var _styles = require("@mui/material/styles");
18
16
  var _FunnelSection = require("./FunnelSection");
19
17
  var _labelUtils = require("./labelUtils");
20
18
  var _useFunnelSeries = require("../hooks/useFunnelSeries");
21
19
  var _curves = require("./curves");
20
+ var _FunnelSectionLabel = require("./FunnelSectionLabel");
21
+ var _useChartFunnelAxisRendering = require("./funnelAxisPlugin/useChartFunnelAxisRendering.selectors");
22
22
  var _jsxRuntime = require("react/jsx-runtime");
23
- const _excluded = ["onItemClick", "gap"];
23
+ const _excluded = ["onItemClick"];
24
24
  _internals.cartesianSeriesTypes.addType('funnel');
25
- const useAggregatedData = gap => {
25
+ const useAggregatedData = () => {
26
26
  const seriesData = (0, _useFunnelSeries.useFunnelSeriesContext)();
27
+ const store = (0, _internals.useStore)();
27
28
  const {
28
- xAxis,
29
- xAxisIds
30
- } = (0, _hooks.useXAxes)();
29
+ axis: xAxis,
30
+ axisIds: xAxisIds
31
+ } = (0, _internals.useSelector)(store, _useChartFunnelAxisRendering.selectorChartXAxis);
31
32
  const {
32
- yAxis,
33
- yAxisIds
34
- } = (0, _hooks.useYAxes)();
33
+ axis: yAxis,
34
+ axisIds: yAxisIds
35
+ } = (0, _internals.useSelector)(store, _useChartFunnelAxisRendering.selectorChartYAxis);
36
+ const gap = (0, _internals.useSelector)(store, _useChartFunnelAxisRendering.selectorFunnelGap);
35
37
  const allData = React.useMemo(() => {
36
38
  if (seriesData === undefined) {
37
39
  return [];
@@ -54,22 +56,28 @@ const useAggregatedData = gap => {
54
56
  const bandWidth = (isXAxisBand || isYAxisBand) && baseScaleConfig.scale?.bandwidth() || 0;
55
57
  const xScale = xAxis[xAxisId].scale;
56
58
  const yScale = yAxis[yAxisId].scale;
57
- const xPosition = (value, bandIndex, stackOffset, useBand) => {
58
- if (isXAxisBand) {
59
- const position = xScale(bandIndex);
59
+ const xPosition = (value, bandIndex, bandIdentifier, stackOffset, useBand) => {
60
+ if ((0, _internals.isBandScale)(xScale)) {
61
+ const position = xScale(bandIdentifier);
60
62
  return useBand ? position + bandWidth : position;
61
63
  }
62
- return xScale(isHorizontal ? value + (stackOffset || 0) : value);
64
+ if (isHorizontal) {
65
+ return xScale(value + (stackOffset || 0)) + bandIndex * gap;
66
+ }
67
+ return xScale(value);
63
68
  };
64
- const yPosition = (value, bandIndex, stackOffset, useBand) => {
65
- if (isYAxisBand) {
66
- const position = yScale(bandIndex);
69
+ const yPosition = (value, bandIndex, bandIdentifier, stackOffset, useBand) => {
70
+ if ((0, _internals.isBandScale)(yScale)) {
71
+ const position = yScale(bandIdentifier);
67
72
  return useBand ? position + bandWidth : position;
68
73
  }
69
- return yScale(isHorizontal ? value : value + (stackOffset || 0));
74
+ if (isHorizontal) {
75
+ return yScale(value);
76
+ }
77
+ return yScale(value + (stackOffset || 0)) + bandIndex * gap;
70
78
  };
71
- const allY = currentSeries.dataPoints.flatMap((d, dataIndex) => d.flatMap(v => yPosition(v.y, baseScaleConfig.data?.[dataIndex], v.stackOffset, v.useBandWidth)));
72
- const allX = currentSeries.dataPoints.flatMap((d, dataIndex) => d.flatMap(v => xPosition(v.x, baseScaleConfig.data?.[dataIndex], v.stackOffset, v.useBandWidth)));
79
+ const allY = currentSeries.dataPoints.flatMap((d, dataIndex) => d.flatMap(v => yPosition(v.y, dataIndex, baseScaleConfig.data?.[dataIndex], v.stackOffset, v.useBandWidth)));
80
+ const allX = currentSeries.dataPoints.flatMap((d, dataIndex) => d.flatMap(v => xPosition(v.x, dataIndex, baseScaleConfig.data?.[dataIndex], v.stackOffset, v.useBandWidth)));
73
81
  const minPoint = {
74
82
  x: Math.min(...allX),
75
83
  y: Math.min(...allY)
@@ -97,7 +105,7 @@ const useAggregatedData = gap => {
97
105
  min: minPoint,
98
106
  max: maxPoint
99
107
  });
100
- const line = (0, _d3Shape.line)().x(d => xPosition(d.x, baseScaleConfig.data?.[dataIndex], d.stackOffset, d.useBandWidth)).y(d => yPosition(d.y, baseScaleConfig.data?.[dataIndex], d.stackOffset, d.useBandWidth)).curve(curve);
108
+ const line = (0, _d3Shape.line)().x(d => xPosition(d.x, dataIndex, baseScaleConfig.data?.[dataIndex], d.stackOffset, d.useBandWidth)).y(d => yPosition(d.y, dataIndex, baseScaleConfig.data?.[dataIndex], d.stackOffset, d.useBandWidth)).curve(curve);
101
109
  return {
102
110
  d: line(values),
103
111
  color,
@@ -126,12 +134,10 @@ const useAggregatedData = gap => {
126
134
  };
127
135
  function FunnelPlot(props) {
128
136
  const {
129
- onItemClick,
130
- gap
137
+ onItemClick
131
138
  } = props,
132
139
  other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
133
- const theme = (0, _styles.useTheme)();
134
- const data = useAggregatedData(gap);
140
+ const data = useAggregatedData();
135
141
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(React.Fragment, {
136
142
  children: [data.map(({
137
143
  d,
@@ -156,29 +162,18 @@ function FunnelPlot(props) {
156
162
  })
157
163
  }))), data.map(({
158
164
  id,
159
- label
165
+ label,
166
+ seriesId,
167
+ dataIndex
160
168
  }) => {
161
- if (!label) {
169
+ if (!label || !label.value) {
162
170
  return null;
163
171
  }
164
- return /*#__PURE__*/(0, _jsxRuntime.jsx)("text", {
165
- x: label.x,
166
- y: label.y,
167
- textAnchor: label.textAnchor,
168
- dominantBaseline: label.dominantBaseline,
169
- stroke: "none",
170
- pointerEvents: "none",
171
- fontFamily: theme.typography.body2.fontFamily,
172
- fontSize: theme.typography.body2.fontSize,
173
- fontSizeAdjust: theme.typography.body2.fontSizeAdjust,
174
- fontWeight: theme.typography.body2.fontWeight,
175
- letterSpacing: theme.typography.body2.letterSpacing,
176
- fontStretch: theme.typography.body2.fontStretch,
177
- fontStyle: theme.typography.body2.fontStyle,
178
- fontVariant: theme.typography.body2.fontVariant,
179
- fill: (theme.vars || theme)?.palette?.text?.primary,
180
- children: label.value
181
- }, id);
172
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_FunnelSectionLabel.FunnelSectionLabel, (0, _extends2.default)({
173
+ label: label,
174
+ dataIndex: dataIndex,
175
+ seriesId: seriesId
176
+ }, other), id);
182
177
  })]
183
178
  });
184
179
  }
@@ -187,11 +182,6 @@ process.env.NODE_ENV !== "production" ? FunnelPlot.propTypes = {
187
182
  // | These PropTypes are generated from the TypeScript type definitions |
188
183
  // | To update them edit the TypeScript types and run "pnpm proptypes" |
189
184
  // ----------------------------------------------------------------------
190
- /**
191
- * The gap, in pixels, between funnel sections.
192
- * @default 0
193
- */
194
- gap: _propTypes.default.number,
195
185
  /**
196
186
  * Callback fired when a funnel item is clicked.
197
187
  * @param {React.MouseEvent<SVGElement, MouseEvent>} event The event source of the callback.
@@ -8,7 +8,7 @@ export interface FunnelSectionProps extends Omit<React.SVGProps<SVGPathElement>,
8
8
  classes?: Partial<FunnelSectionClasses>;
9
9
  variant?: 'filled' | 'outlined';
10
10
  }
11
- export declare const FunnelSectionPath: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material").Theme>, React.SVGProps<SVGPathElement>, {}>;
11
+ export declare const FunnelSectionPath: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, React.SVGProps<SVGPathElement>, {}>;
12
12
  /**
13
13
  * @ignore - internal component.
14
14
  */
@@ -0,0 +1,21 @@
1
+ import * as React from 'react';
2
+ import { SeriesId } from '@mui/x-charts/internals';
3
+ import { FunnelSectionClasses } from "./funnelSectionClasses.js";
4
+ export interface FunnelSectionLabelConfig {
5
+ x: number;
6
+ y: number;
7
+ value: string | null;
8
+ textAnchor?: React.SVGProps<SVGTextElement>['textAnchor'];
9
+ dominantBaseline?: React.SVGProps<SVGTextElement>['dominantBaseline'];
10
+ }
11
+ export interface FunnelSectionLabelProps extends Omit<React.SVGProps<SVGTextElement>, 'ref' | 'id'> {
12
+ classes?: Partial<FunnelSectionClasses>;
13
+ label: FunnelSectionLabelConfig;
14
+ seriesId: SeriesId;
15
+ dataIndex: number;
16
+ }
17
+ /**
18
+ * @ignore - internal component.
19
+ */
20
+ declare const FunnelSectionLabel: React.ForwardRefExoticComponent<FunnelSectionLabelProps & React.RefAttributes<{}>>;
21
+ export { FunnelSectionLabel };
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ 'use client';
3
+
4
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
6
+ Object.defineProperty(exports, "__esModule", {
7
+ value: true
8
+ });
9
+ exports.FunnelSectionLabel = void 0;
10
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
11
+ var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
12
+ var React = _interopRequireWildcard(require("react"));
13
+ var _styles = require("@mui/material/styles");
14
+ var _internals = require("@mui/x-charts/internals");
15
+ var _funnelSectionClasses = require("./funnelSectionClasses");
16
+ var _jsxRuntime = require("react/jsx-runtime");
17
+ const _excluded = ["classes", "color", "onClick", "className", "label", "seriesId", "dataIndex"];
18
+ /**
19
+ * @ignore - internal component.
20
+ */
21
+ const FunnelSectionLabel = exports.FunnelSectionLabel = (0, _internals.consumeSlots)('MuiFunnelSectionLabel', 'funnelSectionLabel', {
22
+ classesResolver: _funnelSectionClasses.useLabelUtilityClasses
23
+ }, /*#__PURE__*/React.forwardRef(function FunnelSectionLabel(props, ref) {
24
+ const {
25
+ classes,
26
+ label
27
+ } = props,
28
+ other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
29
+ const theme = (0, _styles.useTheme)();
30
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("text", (0, _extends2.default)({
31
+ stroke: "none",
32
+ pointerEvents: "none",
33
+ fontFamily: theme.typography.body2.fontFamily,
34
+ fontSize: theme.typography.body2.fontSize,
35
+ fontSizeAdjust: theme.typography.body2.fontSizeAdjust,
36
+ fontWeight: theme.typography.body2.fontWeight,
37
+ letterSpacing: theme.typography.body2.letterSpacing,
38
+ fontStretch: theme.typography.body2.fontStretch,
39
+ fontStyle: theme.typography.body2.fontStyle,
40
+ fontVariant: theme.typography.body2.fontVariant,
41
+ fill: (theme.vars || theme)?.palette?.text?.primary,
42
+ className: classes?.label,
43
+ x: label.x,
44
+ y: label.y,
45
+ textAnchor: label.textAnchor ?? 'middle',
46
+ dominantBaseline: label.dominantBaseline ?? 'central'
47
+ }, other, {
48
+ ref: ref,
49
+ children: label.value
50
+ }));
51
+ }));
52
+ if (process.env.NODE_ENV !== "production") FunnelSectionLabel.displayName = "FunnelSectionLabel";
@@ -1,6 +1,7 @@
1
1
  import { AxisConfig, ScaleName } from '@mui/x-charts/models';
2
2
  import { MakeOptional } from '@mui/x-internals/types';
3
- export type CategoryAxis<S extends ScaleName = ScaleName> = S extends ScaleName ? {
3
+ export type FunnelScaleName = Exclude<ScaleName, 'point'>;
4
+ export type CategoryAxis<S extends FunnelScaleName = FunnelScaleName> = S extends FunnelScaleName ? {
4
5
  /**
5
6
  * The categories to be displayed on the axis.
6
7
  * The order of the categories is the order in which they are displayed.
@@ -10,18 +10,22 @@ import { CurveOptions } from "./curve.types.js";
10
10
  */
11
11
  export declare class Bump implements CurveGenerator {
12
12
  private context;
13
- private x;
14
- private y;
15
- private currentPoint;
16
13
  private isHorizontal;
17
- private gap;
14
+ private min;
15
+ private max;
16
+ private points;
18
17
  constructor(context: CanvasRenderingContext2D, {
19
18
  isHorizontal,
20
- gap
19
+ min,
20
+ max,
21
+ isIncreasing
21
22
  }: CurveOptions);
22
23
  areaStart(): void;
23
24
  areaEnd(): void;
24
25
  lineStart(): void;
25
26
  lineEnd(): void;
26
27
  point(x: number, y: number): void;
28
+ private drawPath;
29
+ private drawHorizontalPath;
30
+ private drawVerticalPath;
27
31
  }
@@ -17,65 +17,94 @@ exports.Bump = void 0;
17
17
  class Bump {
18
18
  constructor(context, {
19
19
  isHorizontal,
20
- gap
20
+ min,
21
+ max,
22
+ isIncreasing
21
23
  }) {
22
24
  this.context = void 0;
23
- this.x = NaN;
24
- this.y = NaN;
25
- this.currentPoint = 0;
26
25
  this.isHorizontal = false;
27
- this.gap = 0;
26
+ this.min = {
27
+ x: 0,
28
+ y: 0
29
+ };
30
+ this.max = {
31
+ x: 0,
32
+ y: 0
33
+ };
34
+ this.points = [];
28
35
  this.context = context;
29
36
  this.isHorizontal = isHorizontal ?? false;
30
- this.gap = (gap ?? 0) / 2;
37
+ this.min = min ?? {
38
+ x: 0,
39
+ y: 0
40
+ };
41
+ this.max = max ?? {
42
+ x: 0,
43
+ y: 0
44
+ };
45
+ if (isIncreasing) {
46
+ const currentMin = this.min;
47
+ const currentMax = this.max;
48
+ this.min = currentMax;
49
+ this.max = currentMin;
50
+ }
31
51
  }
32
52
  areaStart() {}
33
53
  areaEnd() {}
34
54
  lineStart() {}
35
55
  lineEnd() {}
36
56
  point(x, y) {
37
- x = +x;
38
- y = +y;
39
-
40
- // 0 is the top-left corner.
41
- if (this.isHorizontal) {
42
- if (this.currentPoint === 0) {
43
- this.context.moveTo(x + this.gap, y);
44
- this.context.lineTo(x + this.gap, y);
45
- } else if (this.currentPoint === 1) {
46
- this.context.bezierCurveTo((this.x + x) / 2, this.y, (this.x + x) / 2, y, x - this.gap, y);
47
- } else if (this.currentPoint === 2) {
48
- this.context.lineTo(x - this.gap, y);
49
- } else {
50
- this.context.bezierCurveTo((this.x + x) / 2, this.y, (this.x + x) / 2, y, x + this.gap, y);
51
- }
52
- if (this.currentPoint === 3) {
53
- this.context.closePath();
54
- }
55
- this.currentPoint += 1;
56
- this.x = x;
57
- this.y = y;
57
+ this.points.push({
58
+ x,
59
+ y
60
+ });
61
+ if (this.points.length < 4) {
58
62
  return;
59
63
  }
60
64
 
61
- // 0 is the top-right corner.
62
- if (this.currentPoint === 0) {
63
- // X from Y
64
- this.context.moveTo(x, y + this.gap);
65
- this.context.lineTo(x, y + this.gap);
66
- } else if (this.currentPoint === 1) {
67
- this.context.bezierCurveTo(this.x, (this.y + y) / 2, x, (this.y + y) / 2, x, y - this.gap);
68
- } else if (this.currentPoint === 2) {
69
- this.context.lineTo(x, y - this.gap);
65
+ // Draw the path using bezier curves
66
+ this.drawPath();
67
+ }
68
+ drawPath() {
69
+ if (this.isHorizontal) {
70
+ this.drawHorizontalPath();
70
71
  } else {
71
- this.context.bezierCurveTo(this.x, (this.y + y) / 2, x, (this.y + y) / 2, x, y + this.gap);
72
- }
73
- if (this.currentPoint === 3) {
74
- this.context.closePath();
72
+ this.drawVerticalPath();
75
73
  }
76
- this.currentPoint += 1;
77
- this.x = x;
78
- this.y = y;
74
+ }
75
+ drawHorizontalPath() {
76
+ const [p0, p1, p2, p3] = this.points;
77
+
78
+ // 0 is the top-left corner
79
+ this.context.moveTo(p0.x, p0.y);
80
+ this.context.lineTo(p0.x, p0.y);
81
+
82
+ // Bezier curve to point 1
83
+ this.context.bezierCurveTo((p0.x + p1.x) / 2, p0.y, (p0.x + p1.x) / 2, p1.y, p1.x, p1.y);
84
+
85
+ // Line to point 2
86
+ this.context.lineTo(p2.x, p2.y);
87
+
88
+ // Bezier curve back to point 3
89
+ this.context.bezierCurveTo((p2.x + p3.x) / 2, p2.y, (p2.x + p3.x) / 2, p3.y, p3.x, p3.y);
90
+ this.context.closePath();
91
+ }
92
+ drawVerticalPath() {
93
+ const [p0, p1, p2, p3] = this.points;
94
+
95
+ // 0 is the top-right corner
96
+ this.context.moveTo(p0.x, p0.y);
97
+ this.context.lineTo(p0.x, p0.y);
98
+
99
+ // Bezier curve to point 1
100
+ this.context.bezierCurveTo(p0.x, (p0.y + p1.y) / 2, p1.x, (p0.y + p1.y) / 2, p1.x, p1.y);
101
+
102
+ // Line to point 2
103
+ this.context.lineTo(p2.x, p2.y);
104
+
105
+ // Bezier curve back to point 3
106
+ this.context.bezierCurveTo(p2.x, (p2.y + p3.y) / 2, p3.x, (p2.y + p3.y) / 2, p3.x, p3.y);
107
+ this.context.closePath();
79
108
  }
80
109
  }
81
110
  exports.Bump = Bump;
@@ -34,8 +34,13 @@ export type CurveOptions = {
34
34
  * The maximum point for all the segments.
35
35
  */
36
36
  max?: Point;
37
+ /**
38
+ * The shape of the point of the funnel for the curves that support it.
39
+ */
40
+ pointShape?: FunnelPointShape;
37
41
  };
38
- export type FunnelCurveType = 'linear' | 'step' | 'bump' | 'pyramid' | 'step-pyramid';
42
+ export type FunnelCurveType = 'linear' | 'linear-sharp' | 'step' | 'bump' | 'pyramid' | 'step-pyramid';
43
+ export type FunnelPointShape = 'square' | 'sharp';
39
44
  export type Point = {
40
45
  x: number;
41
46
  y: number;
@@ -25,6 +25,9 @@ const curveConstructor = curve => {
25
25
  return _linear.Linear;
26
26
  };
27
27
  const getFunnelCurve = (curve, options) => {
28
+ if (curve === 'linear-sharp') {
29
+ options.pointShape = 'sharp';
30
+ }
28
31
  return context => new (curveConstructor(curve))(context, options);
29
32
  };
30
33
  exports.getFunnelCurve = getFunnelCurve;
@@ -3,7 +3,7 @@ import { CurveOptions } from "./curve.types.js";
3
3
  /**
4
4
  * This is a custom "linear" curve generator.
5
5
  * It draws straight lines for the 4 provided points,
6
- * with the option to add a gap between sections while also properly handling the border radius.
6
+ * with the option to properly handling the border radius.
7
7
  *
8
8
  * The implementation is based on the d3-shape linear curve generator.
9
9
  * https://github.com/d3/d3-shape/blob/a82254af78f08799c71d7ab25df557c4872a3c51/src/curve/linear.js
@@ -13,15 +13,23 @@ export declare class Linear implements CurveGenerator {
13
13
  private position;
14
14
  private sections;
15
15
  private isHorizontal;
16
+ private isIncreasing;
16
17
  private gap;
17
18
  private borderRadius;
19
+ private min;
20
+ private max;
18
21
  private points;
22
+ private pointShape;
19
23
  constructor(context: CanvasRenderingContext2D, {
20
24
  isHorizontal,
21
25
  gap,
22
26
  position,
23
27
  sections,
24
- borderRadius
28
+ borderRadius,
29
+ min,
30
+ max,
31
+ isIncreasing,
32
+ pointShape
25
33
  }: CurveOptions);
26
34
  areaStart(): void;
27
35
  areaEnd(): void;