@mui/x-charts-pro 8.2.0 → 8.3.1

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 (154) hide show
  1. package/BarChartPro/BarChartPro.d.ts +7 -1
  2. package/BarChartPro/BarChartPro.js +60 -4
  3. package/CHANGELOG.md +199 -6
  4. package/ChartDataProviderPro/ChartDataProviderPro.js +1 -1
  5. package/ChartZoomSlider/ChartZoomSlider.d.ts +5 -0
  6. package/ChartZoomSlider/ChartZoomSlider.js +47 -0
  7. package/ChartZoomSlider/index.d.ts +2 -0
  8. package/ChartZoomSlider/index.js +27 -0
  9. package/ChartZoomSlider/internals/ChartAxisZoomSlider.d.ts +23 -0
  10. package/ChartZoomSlider/internals/ChartAxisZoomSlider.js +348 -0
  11. package/ChartZoomSlider/internals/ChartAxisZoomSliderHandle.d.ts +12 -0
  12. package/ChartZoomSlider/internals/ChartAxisZoomSliderHandle.js +92 -0
  13. package/ChartZoomSlider/internals/chartAxisZoomSliderHandleClasses.d.ts +17 -0
  14. package/ChartZoomSlider/internals/chartAxisZoomSliderHandleClasses.js +27 -0
  15. package/ChartsToolbarPro/ChartsToolbarPro.d.ts +2 -0
  16. package/ChartsToolbarPro/ChartsToolbarPro.js +31 -0
  17. package/ChartsToolbarPro/index.d.ts +1 -0
  18. package/ChartsToolbarPro/index.js +16 -0
  19. package/ChartsToolbarPro/internal/ChartsToolbarZoomInButton.d.ts +13 -0
  20. package/ChartsToolbarPro/internal/ChartsToolbarZoomInButton.js +36 -0
  21. package/ChartsToolbarPro/internal/ChartsToolbarZoomOutButton.d.ts +13 -0
  22. package/ChartsToolbarPro/internal/ChartsToolbarZoomOutButton.js +36 -0
  23. package/FunnelChart/FunnelChart.js +2 -7
  24. package/FunnelChart/FunnelPlot.js +24 -3
  25. package/FunnelChart/FunnelSection.d.ts +1 -0
  26. package/FunnelChart/FunnelSection.js +12 -7
  27. package/FunnelChart/curves/borderRadiusPolygon.d.ts +8 -0
  28. package/FunnelChart/curves/borderRadiusPolygon.js +42 -0
  29. package/FunnelChart/curves/bump.d.ts +8 -5
  30. package/FunnelChart/curves/bump.js +21 -22
  31. package/FunnelChart/curves/curve.types.d.ts +33 -3
  32. package/FunnelChart/curves/getFunnelCurve.d.ts +2 -2
  33. package/FunnelChart/curves/getFunnelCurve.js +12 -4
  34. package/FunnelChart/curves/linear.d.ts +17 -9
  35. package/FunnelChart/curves/linear.js +62 -87
  36. package/FunnelChart/curves/pyramid.d.ts +34 -0
  37. package/FunnelChart/curves/pyramid.js +127 -0
  38. package/FunnelChart/curves/step-pyramid.d.ts +31 -0
  39. package/FunnelChart/curves/step-pyramid.js +107 -0
  40. package/FunnelChart/curves/step.d.ts +32 -0
  41. package/FunnelChart/curves/step.js +88 -0
  42. package/FunnelChart/curves/utils.d.ts +4 -0
  43. package/FunnelChart/curves/utils.js +29 -0
  44. package/FunnelChart/funnel.types.d.ts +23 -2
  45. package/FunnelChart/funnelSectionClasses.d.ts +5 -1
  46. package/FunnelChart/funnelSectionClasses.js +5 -2
  47. package/FunnelChart/seriesConfig/getSeriesWithDefaultValues.js +1 -0
  48. package/FunnelChart/useFunnelChartProps.d.ts +0 -5
  49. package/FunnelChart/useFunnelChartProps.js +0 -11
  50. package/Heatmap/Heatmap.d.ts +3 -3
  51. package/Heatmap/Heatmap.js +2 -20
  52. package/LineChartPro/LineChartPro.d.ts +7 -1
  53. package/LineChartPro/LineChartPro.js +60 -4
  54. package/ScatterChartPro/ScatterChartPro.d.ts +7 -1
  55. package/ScatterChartPro/ScatterChartPro.js +60 -4
  56. package/esm/BarChartPro/BarChartPro.d.ts +7 -1
  57. package/esm/BarChartPro/BarChartPro.js +60 -4
  58. package/esm/ChartDataProviderPro/ChartDataProviderPro.js +1 -1
  59. package/esm/ChartZoomSlider/ChartZoomSlider.d.ts +5 -0
  60. package/esm/ChartZoomSlider/ChartZoomSlider.js +41 -0
  61. package/esm/ChartZoomSlider/index.d.ts +2 -0
  62. package/esm/ChartZoomSlider/index.js +2 -0
  63. package/esm/ChartZoomSlider/internals/ChartAxisZoomSlider.d.ts +23 -0
  64. package/esm/ChartZoomSlider/internals/ChartAxisZoomSlider.js +339 -0
  65. package/esm/ChartZoomSlider/internals/ChartAxisZoomSliderHandle.d.ts +12 -0
  66. package/esm/ChartZoomSlider/internals/ChartAxisZoomSliderHandle.js +85 -0
  67. package/esm/ChartZoomSlider/internals/chartAxisZoomSliderHandleClasses.d.ts +17 -0
  68. package/esm/ChartZoomSlider/internals/chartAxisZoomSliderHandleClasses.js +17 -0
  69. package/esm/ChartsToolbarPro/ChartsToolbarPro.d.ts +2 -0
  70. package/esm/ChartsToolbarPro/ChartsToolbarPro.js +24 -0
  71. package/esm/ChartsToolbarPro/index.d.ts +1 -0
  72. package/esm/ChartsToolbarPro/index.js +1 -0
  73. package/esm/ChartsToolbarPro/internal/ChartsToolbarZoomInButton.d.ts +13 -0
  74. package/esm/ChartsToolbarPro/internal/ChartsToolbarZoomInButton.js +29 -0
  75. package/esm/ChartsToolbarPro/internal/ChartsToolbarZoomOutButton.d.ts +13 -0
  76. package/esm/ChartsToolbarPro/internal/ChartsToolbarZoomOutButton.js +29 -0
  77. package/esm/FunnelChart/FunnelChart.js +2 -7
  78. package/esm/FunnelChart/FunnelPlot.js +24 -3
  79. package/esm/FunnelChart/FunnelSection.d.ts +1 -0
  80. package/esm/FunnelChart/FunnelSection.js +12 -7
  81. package/esm/FunnelChart/curves/borderRadiusPolygon.d.ts +8 -0
  82. package/esm/FunnelChart/curves/borderRadiusPolygon.js +36 -0
  83. package/esm/FunnelChart/curves/bump.d.ts +8 -5
  84. package/esm/FunnelChart/curves/bump.js +21 -22
  85. package/esm/FunnelChart/curves/curve.types.d.ts +33 -3
  86. package/esm/FunnelChart/curves/getFunnelCurve.d.ts +2 -2
  87. package/esm/FunnelChart/curves/getFunnelCurve.js +12 -4
  88. package/esm/FunnelChart/curves/linear.d.ts +17 -9
  89. package/esm/FunnelChart/curves/linear.js +62 -86
  90. package/esm/FunnelChart/curves/pyramid.d.ts +34 -0
  91. package/esm/FunnelChart/curves/pyramid.js +121 -0
  92. package/esm/FunnelChart/curves/step-pyramid.d.ts +31 -0
  93. package/esm/FunnelChart/curves/step-pyramid.js +101 -0
  94. package/esm/FunnelChart/curves/step.d.ts +32 -0
  95. package/esm/FunnelChart/curves/step.js +82 -0
  96. package/esm/FunnelChart/curves/utils.d.ts +4 -0
  97. package/esm/FunnelChart/curves/utils.js +19 -0
  98. package/esm/FunnelChart/funnel.types.d.ts +23 -2
  99. package/esm/FunnelChart/funnelSectionClasses.d.ts +5 -1
  100. package/esm/FunnelChart/funnelSectionClasses.js +5 -2
  101. package/esm/FunnelChart/seriesConfig/getSeriesWithDefaultValues.js +1 -0
  102. package/esm/FunnelChart/useFunnelChartProps.d.ts +0 -5
  103. package/esm/FunnelChart/useFunnelChartProps.js +0 -11
  104. package/esm/Heatmap/Heatmap.d.ts +3 -3
  105. package/esm/Heatmap/Heatmap.js +2 -20
  106. package/esm/LineChartPro/LineChartPro.d.ts +7 -1
  107. package/esm/LineChartPro/LineChartPro.js +60 -4
  108. package/esm/ScatterChartPro/ScatterChartPro.d.ts +7 -1
  109. package/esm/ScatterChartPro/ScatterChartPro.js +60 -4
  110. package/esm/index.d.ts +4 -1
  111. package/esm/index.js +4 -3
  112. package/esm/internals/material/icons.d.ts +3 -0
  113. package/esm/internals/material/icons.js +13 -0
  114. package/esm/internals/material/index.d.ts +4 -0
  115. package/esm/internals/material/index.js +12 -0
  116. package/esm/internals/plugins/useChartProZoom/calculateZoom.d.ts +23 -0
  117. package/esm/internals/plugins/useChartProZoom/calculateZoom.js +32 -0
  118. package/esm/internals/plugins/useChartProZoom/useChartProZoom.d.ts +1 -1
  119. package/esm/internals/plugins/useChartProZoom/useChartProZoom.js +45 -3
  120. package/esm/internals/plugins/useChartProZoom/useChartProZoom.selectors.d.ts +63 -11
  121. package/esm/internals/plugins/useChartProZoom/useChartProZoom.selectors.js +3 -2
  122. package/esm/internals/plugins/useChartProZoom/useChartProZoom.types.d.ts +17 -2
  123. package/esm/internals/slots/chartBaseSlotProps.d.ts +10 -0
  124. package/esm/internals/slots/chartBaseSlotProps.js +1 -0
  125. package/esm/internals/slots/chartsBaseSlots.d.ts +6 -0
  126. package/esm/internals/slots/chartsBaseSlots.js +1 -0
  127. package/esm/internals/slots/chartsIconSlots.d.ts +14 -0
  128. package/esm/internals/slots/chartsIconSlots.js +1 -0
  129. package/esm/typeOverloads/modules.d.ts +1 -1
  130. package/index.d.ts +4 -1
  131. package/index.js +23 -1
  132. package/internals/material/icons.d.ts +3 -0
  133. package/internals/material/icons.js +20 -0
  134. package/internals/material/index.d.ts +4 -0
  135. package/internals/material/index.js +19 -0
  136. package/internals/plugins/useChartProZoom/calculateZoom.d.ts +23 -0
  137. package/internals/plugins/useChartProZoom/calculateZoom.js +39 -0
  138. package/internals/plugins/useChartProZoom/useChartProZoom.d.ts +1 -1
  139. package/internals/plugins/useChartProZoom/useChartProZoom.js +44 -2
  140. package/internals/plugins/useChartProZoom/useChartProZoom.selectors.d.ts +63 -11
  141. package/internals/plugins/useChartProZoom/useChartProZoom.selectors.js +3 -2
  142. package/internals/plugins/useChartProZoom/useChartProZoom.types.d.ts +17 -2
  143. package/internals/slots/chartBaseSlotProps.d.ts +10 -0
  144. package/internals/slots/chartBaseSlotProps.js +5 -0
  145. package/internals/slots/chartsBaseSlots.d.ts +6 -0
  146. package/internals/slots/chartsBaseSlots.js +5 -0
  147. package/internals/slots/chartsIconSlots.d.ts +14 -0
  148. package/internals/slots/chartsIconSlots.js +5 -0
  149. package/package.json +7 -7
  150. package/typeOverloads/modules.d.ts +1 -1
  151. package/FunnelChart/curves/funnelStep.d.ts +0 -25
  152. package/FunnelChart/curves/funnelStep.js +0 -87
  153. package/esm/FunnelChart/curves/funnelStep.d.ts +0 -25
  154. package/esm/FunnelChart/curves/funnelStep.js +0 -80
@@ -15,7 +15,6 @@ var _ChartsOverlay = require("@mui/x-charts/ChartsOverlay");
15
15
  var _ChartsTooltip = require("@mui/x-charts/ChartsTooltip");
16
16
  var _internals = require("@mui/x-charts/internals");
17
17
  var _ChartsLegend = require("@mui/x-charts/ChartsLegend");
18
- var _ChartsClipPath = require("@mui/x-charts/ChartsClipPath");
19
18
  var _ChartsSurface = require("@mui/x-charts/ChartsSurface");
20
19
  var _ChartsAxisHighlight = require("@mui/x-charts/ChartsAxisHighlight");
21
20
  var _ChartsAxis = require("@mui/x-charts/ChartsAxis");
@@ -38,9 +37,7 @@ const FunnelChart = exports.FunnelChart = /*#__PURE__*/React.forwardRef(function
38
37
  funnelPlotProps,
39
38
  overlayProps,
40
39
  legendProps,
41
- clipPathGroupProps,
42
40
  chartsAxisProps,
43
- clipPathProps,
44
41
  chartsWrapperProps,
45
42
  axisHighlightProps,
46
43
  children
@@ -54,11 +51,9 @@ const FunnelChart = exports.FunnelChart = /*#__PURE__*/React.forwardRef(function
54
51
  seriesConfig: seriesConfig,
55
52
  children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_internals.ChartsWrapper, (0, _extends2.default)({}, chartsWrapperProps, {
56
53
  children: [!themedProps.hideLegend && /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsLegend.ChartsLegend, (0, _extends2.default)({}, legendProps)), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_ChartsSurface.ChartsSurface, (0, _extends2.default)({}, chartsSurfaceProps, {
57
- children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("g", (0, _extends2.default)({}, clipPathGroupProps, {
58
- 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))]
59
- })), !themedProps.loading && /*#__PURE__*/(0, _jsxRuntime.jsx)(Tooltip, (0, _extends2.default)({}, themedProps.slotProps?.tooltip, {
54
+ 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)), !themedProps.loading && /*#__PURE__*/(0, _jsxRuntime.jsx)(Tooltip, (0, _extends2.default)({}, themedProps.slotProps?.tooltip, {
60
55
  trigger: "item"
61
- })), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsAxis.ChartsAxis, (0, _extends2.default)({}, chartsAxisProps)), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsClipPath.ChartsClipPath, (0, _extends2.default)({}, clipPathProps)), children]
56
+ })), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsAxis.ChartsAxis, (0, _extends2.default)({}, chartsAxisProps)), children]
62
57
  }))]
63
58
  }))
64
59
  }));
@@ -54,7 +54,6 @@ const useAggregatedData = gap => {
54
54
  const bandWidth = (isXAxisBand || isYAxisBand) && baseScaleConfig.scale?.bandwidth() || 0;
55
55
  const xScale = xAxis[xAxisId].scale;
56
56
  const yScale = yAxis[yAxisId].scale;
57
- const curve = (0, _curves.getFunnelCurve)(currentSeries.curve, isHorizontal, gap);
58
57
  const xPosition = (value, bandIndex, stackOffset, useBand) => {
59
58
  if (isXAxisBand) {
60
59
  const position = xScale(bandIndex);
@@ -69,7 +68,17 @@ const useAggregatedData = gap => {
69
68
  }
70
69
  return yScale(isHorizontal ? value : value + (stackOffset || 0));
71
70
  };
72
- return currentSeries.dataPoints.map((values, dataIndex) => {
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)));
73
+ const minPoint = {
74
+ x: Math.min(...allX),
75
+ y: Math.min(...allY)
76
+ };
77
+ const maxPoint = {
78
+ x: Math.max(...allX),
79
+ y: Math.max(...allY)
80
+ };
81
+ return currentSeries.dataPoints.flatMap((values, dataIndex) => {
73
82
  const color = currentSeries.data[dataIndex].color;
74
83
  const id = `${seriesId}-${dataIndex}`;
75
84
  const sectionLabel = typeof currentSeries.sectionLabel === 'function' ? currentSeries.sectionLabel({
@@ -77,6 +86,15 @@ const useAggregatedData = gap => {
77
86
  seriesId,
78
87
  value: currentSeries.data[dataIndex].value
79
88
  }) : currentSeries.sectionLabel;
89
+ const curve = (0, _curves.getFunnelCurve)(currentSeries.curve, {
90
+ isHorizontal,
91
+ gap,
92
+ position: dataIndex,
93
+ sections: currentSeries.dataPoints.length,
94
+ borderRadius: currentSeries.borderRadius,
95
+ min: minPoint,
96
+ max: maxPoint
97
+ });
80
98
  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);
81
99
  return {
82
100
  d: line(values),
@@ -84,6 +102,7 @@ const useAggregatedData = gap => {
84
102
  id,
85
103
  seriesId,
86
104
  dataIndex,
105
+ variant: currentSeries.variant,
87
106
  label: sectionLabel !== false && (0, _extends2.default)({}, (0, _labelUtils.positionLabel)((0, _extends2.default)({}, sectionLabel, {
88
107
  xPosition,
89
108
  yPosition,
@@ -117,13 +136,15 @@ function FunnelPlot(props) {
117
136
  color,
118
137
  id,
119
138
  seriesId,
120
- dataIndex
139
+ dataIndex,
140
+ variant
121
141
  }) => /*#__PURE__*/(0, _react.createElement)(_FunnelSection.FunnelSection, (0, _extends2.default)({}, other, {
122
142
  d: d,
123
143
  color: color,
124
144
  key: id,
125
145
  dataIndex: dataIndex,
126
146
  seriesId: seriesId,
147
+ variant: variant,
127
148
  onClick: onItemClick && (event => {
128
149
  onItemClick(event, {
129
150
  type: 'funnel',
@@ -6,6 +6,7 @@ export interface FunnelSectionProps extends Omit<React.SVGProps<SVGPathElement>,
6
6
  dataIndex: number;
7
7
  color: string;
8
8
  classes?: Partial<FunnelSectionClasses>;
9
+ variant?: 'filled' | 'outlined';
9
10
  }
10
11
  export declare const FunnelSectionPath: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material").Theme>, React.SVGProps<SVGPathElement>, {}>;
11
12
  /**
@@ -16,9 +16,9 @@ var _hooks = require("@mui/x-charts/hooks");
16
16
  var _clsx = _interopRequireDefault(require("clsx"));
17
17
  var _funnelSectionClasses = require("./funnelSectionClasses");
18
18
  var _jsxRuntime = require("react/jsx-runtime");
19
- const _excluded = ["seriesId", "dataIndex", "classes", "color", "onClick", "className"];
19
+ const _excluded = ["seriesId", "dataIndex", "classes", "color", "onClick", "className", "variant"];
20
20
  const FunnelSectionPath = exports.FunnelSectionPath = (0, _styles.styled)('path')(() => ({
21
- transition: 'opacity 0.2s ease-in, fill 0.2s ease-in'
21
+ transition: 'opacity 0.2s ease-in, fill 0.2s ease-in, fill-opacity 0.2s ease-in, filter 0.2s ease-in'
22
22
  }));
23
23
 
24
24
  /**
@@ -33,7 +33,8 @@ const FunnelSection = exports.FunnelSection = (0, _internals.consumeSlots)('MuiF
33
33
  classes,
34
34
  color,
35
35
  onClick,
36
- className
36
+ className,
37
+ variant = 'filled'
37
38
  } = props,
38
39
  other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
39
40
  const interactionProps = (0, _internals.useInteractionItemProps)({
@@ -48,14 +49,18 @@ const FunnelSection = exports.FunnelSection = (0, _internals.consumeSlots)('MuiF
48
49
  seriesId,
49
50
  dataIndex
50
51
  });
52
+ const isOutlined = variant === 'outlined';
51
53
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(FunnelSectionPath, (0, _extends2.default)({}, interactionProps, {
52
- filter: isHighlighted ? 'brightness(120%)' : undefined,
53
- opacity: isFaded ? 0.3 : 1,
54
+ filter: isHighlighted && !isOutlined ? 'brightness(120%)' : undefined,
55
+ opacity: isFaded && !isOutlined ? 0.3 : 1,
54
56
  fill: color,
55
- stroke: "none",
57
+ stroke: isOutlined ? color : 'none',
58
+ fillOpacity: isOutlined && !isHighlighted ? 0.4 : 1,
59
+ strokeOpacity: 1,
60
+ strokeWidth: isOutlined ? 1.5 : 0,
56
61
  cursor: onClick ? 'pointer' : 'unset',
57
62
  onClick: onClick,
58
- className: (0, _clsx.default)(classes?.root, className, isHighlighted && classes?.highlighted, isFaded && classes?.faded)
63
+ className: (0, _clsx.default)(classes?.root, className, isOutlined ? classes?.outlined : classes?.filled, isHighlighted && classes?.highlighted, isFaded && classes?.faded)
59
64
  }, other, {
60
65
  ref: ref
61
66
  }));
@@ -0,0 +1,8 @@
1
+ import { Point } from "./curve.types.js";
2
+ /**
3
+ * Draws a polygon with rounded corners
4
+ * @param {CanvasRenderingContext2D} ctx The canvas context
5
+ * @param {Array} points A list of `{x, y}` points
6
+ * @param {number} radius how much to round the corners
7
+ */
8
+ export declare function borderRadiusPolygon(ctx: CanvasRenderingContext2D, points: Point[], radius: number | number[]): void;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.borderRadiusPolygon = borderRadiusPolygon;
7
+ const distance = (p1, p2) => Math.sqrt((p1.x - p2.x) ** 2 + (p1.y - p2.y) ** 2);
8
+ const lerp = (a, b, x) => a + (b - a) * x;
9
+ const lerp2D = (p1, p2, t) => ({
10
+ x: lerp(p1.x, p2.x, t),
11
+ y: lerp(p1.y, p2.y, t)
12
+ });
13
+
14
+ /**
15
+ * Draws a polygon with rounded corners
16
+ * @param {CanvasRenderingContext2D} ctx The canvas context
17
+ * @param {Array} points A list of `{x, y}` points
18
+ * @param {number} radius how much to round the corners
19
+ */
20
+ function borderRadiusPolygon(ctx, points, radius) {
21
+ const numPoints = points.length;
22
+ radius = Array.isArray(radius) ? radius : Array(numPoints).fill(radius);
23
+ const corners = [];
24
+ for (let i = 0; i < numPoints; i += 1) {
25
+ const lastPoint = points[i];
26
+ const thisPoint = points[(i + 1) % numPoints];
27
+ const nextPoint = points[(i + 2) % numPoints];
28
+ const lastEdgeLength = distance(lastPoint, thisPoint);
29
+ const lastOffsetDistance = Math.min(lastEdgeLength / 2, radius[i] ?? 0);
30
+ const start = lerp2D(thisPoint, lastPoint, lastOffsetDistance / lastEdgeLength);
31
+ const nextEdgeLength = distance(nextPoint, thisPoint);
32
+ const nextOffsetDistance = Math.min(nextEdgeLength / 2, radius[i] ?? 0);
33
+ const end = lerp2D(thisPoint, nextPoint, nextOffsetDistance / nextEdgeLength);
34
+ corners.push([start, thisPoint, end]);
35
+ }
36
+ ctx.moveTo(corners[0][0].x, corners[0][0].y);
37
+ for (const [start, ctrl, end] of corners) {
38
+ ctx.lineTo(start.x, start.y);
39
+ ctx.quadraticCurveTo(ctrl.x, ctrl.y, end.x, end.y);
40
+ }
41
+ ctx.closePath();
42
+ }
@@ -1,21 +1,24 @@
1
1
  import { CurveGenerator } from '@mui/x-charts-vendor/d3-shape';
2
+ import { CurveOptions } from "./curve.types.js";
2
3
  /**
3
4
  * This is a custom "bump" curve generator.
5
+ * It draws smooth curves for the 4 provided points,
6
+ * with the option to add a gap between sections while also properly handling the border radius.
4
7
  *
5
- * It takes into account the gap between the points and draws a smooth curve between them.
6
- *
7
- * It is based on the d3-shape bump curve generator.
8
+ * The implementation is based on the d3-shape bump curve generator.
8
9
  * https://github.com/d3/d3-shape/blob/a82254af78f08799c71d7ab25df557c4872a3c51/src/curve/bump.js
9
10
  */
10
11
  export declare class Bump implements CurveGenerator {
11
12
  private context;
12
- private line;
13
13
  private x;
14
14
  private y;
15
15
  private currentPoint;
16
16
  private isHorizontal;
17
17
  private gap;
18
- constructor(context: CanvasRenderingContext2D, isHorizontal: boolean, gap?: number);
18
+ constructor(context: CanvasRenderingContext2D, {
19
+ isHorizontal,
20
+ gap
21
+ }: CurveOptions);
19
22
  areaStart(): void;
20
23
  areaEnd(): void;
21
24
  lineStart(): void;
@@ -4,42 +4,35 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.Bump = void 0;
7
+ /* eslint-disable class-methods-use-this */
8
+
7
9
  /**
8
10
  * This is a custom "bump" curve generator.
11
+ * It draws smooth curves for the 4 provided points,
12
+ * with the option to add a gap between sections while also properly handling the border radius.
9
13
  *
10
- * It takes into account the gap between the points and draws a smooth curve between them.
11
- *
12
- * It is based on the d3-shape bump curve generator.
14
+ * The implementation is based on the d3-shape bump curve generator.
13
15
  * https://github.com/d3/d3-shape/blob/a82254af78f08799c71d7ab25df557c4872a3c51/src/curve/bump.js
14
16
  */
15
17
  class Bump {
16
- constructor(context, isHorizontal, gap = 0) {
18
+ constructor(context, {
19
+ isHorizontal,
20
+ gap
21
+ }) {
17
22
  this.context = void 0;
18
- this.line = NaN;
19
23
  this.x = NaN;
20
24
  this.y = NaN;
21
25
  this.currentPoint = 0;
22
26
  this.isHorizontal = false;
23
27
  this.gap = 0;
24
28
  this.context = context;
25
- this.isHorizontal = isHorizontal;
26
- this.gap = gap / 2;
27
- }
28
- areaStart() {
29
- this.line = 0;
30
- }
31
- areaEnd() {
32
- this.line = NaN;
33
- }
34
- lineStart() {
35
- this.currentPoint = 0;
36
- }
37
- lineEnd() {
38
- if (this.line || this.line !== 0 && this.currentPoint === 1) {
39
- this.context.closePath();
40
- }
41
- this.line = 1 - this.line;
29
+ this.isHorizontal = isHorizontal ?? false;
30
+ this.gap = (gap ?? 0) / 2;
42
31
  }
32
+ areaStart() {}
33
+ areaEnd() {}
34
+ lineStart() {}
35
+ lineEnd() {}
43
36
  point(x, y) {
44
37
  x = +x;
45
38
  y = +y;
@@ -56,6 +49,9 @@ class Bump {
56
49
  } else {
57
50
  this.context.bezierCurveTo((this.x + x) / 2, this.y, (this.x + x) / 2, y, x + this.gap, y);
58
51
  }
52
+ if (this.currentPoint === 3) {
53
+ this.context.closePath();
54
+ }
59
55
  this.currentPoint += 1;
60
56
  this.x = x;
61
57
  this.y = y;
@@ -74,6 +70,9 @@ class Bump {
74
70
  } else {
75
71
  this.context.bezierCurveTo(this.x, (this.y + y) / 2, x, (this.y + y) / 2, x, y + this.gap);
76
72
  }
73
+ if (this.currentPoint === 3) {
74
+ this.context.closePath();
75
+ }
77
76
  this.currentPoint += 1;
78
77
  this.x = x;
79
78
  this.y = y;
@@ -1,8 +1,38 @@
1
- export type FunnelCurveOptions = {
1
+ export type CurveOptions = {
2
2
  /**
3
- * The gap between the funnel segments.
3
+ * The gap between each segment.
4
4
  * @default 0
5
5
  */
6
6
  gap?: number;
7
+ /**
8
+ * Indicates if the main axis of the visualization.
9
+ */
10
+ isHorizontal?: boolean;
11
+ /**
12
+ * The order position of the segment.
13
+ */
14
+ position?: number;
15
+ /**
16
+ * The total number of segments that will be drawn.
17
+ * @default 1
18
+ */
19
+ sections?: number;
20
+ /**
21
+ * The border radius of the segments.
22
+ * @default 0
23
+ */
24
+ borderRadius?: number;
25
+ /**
26
+ * The minimum point for all the segments.
27
+ */
28
+ min?: Point;
29
+ /**
30
+ * The maximum point for all the segments.
31
+ */
32
+ max?: Point;
7
33
  };
8
- export type FunnelCurveType = 'linear' | 'step' | 'bump';
34
+ export type FunnelCurveType = 'linear' | 'step' | 'bump' | 'pyramid' | 'step-pyramid';
35
+ export type Point = {
36
+ x: number;
37
+ y: number;
38
+ };
@@ -1,3 +1,3 @@
1
1
  import { CurveFactory } from '@mui/x-charts-vendor/d3-shape';
2
- import { FunnelCurveType } from "./curve.types.js";
3
- export declare const getFunnelCurve: (curve: FunnelCurveType | undefined, isHorizontal: boolean, gap?: number) => CurveFactory;
2
+ import { CurveOptions, FunnelCurveType } from "./curve.types.js";
3
+ export declare const getFunnelCurve: (curve: FunnelCurveType | undefined, options: CurveOptions) => CurveFactory;
@@ -4,19 +4,27 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.getFunnelCurve = void 0;
7
- var _funnelStep = require("./funnelStep");
7
+ var _step = require("./step");
8
8
  var _linear = require("./linear");
9
9
  var _bump = require("./bump");
10
+ var _pyramid = require("./pyramid");
11
+ var _stepPyramid = require("./step-pyramid");
10
12
  const curveConstructor = curve => {
11
13
  if (curve === 'step') {
12
- return _funnelStep.FunnelStep;
14
+ return _step.Step;
13
15
  }
14
16
  if (curve === 'bump') {
15
17
  return _bump.Bump;
16
18
  }
19
+ if (curve === 'pyramid') {
20
+ return _pyramid.Pyramid;
21
+ }
22
+ if (curve === 'step-pyramid') {
23
+ return _stepPyramid.StepPyramid;
24
+ }
17
25
  return _linear.Linear;
18
26
  };
19
- const getFunnelCurve = (curve, isHorizontal, gap = 0) => {
20
- return context => new (curveConstructor(curve))(context, isHorizontal, gap);
27
+ const getFunnelCurve = (curve, options) => {
28
+ return context => new (curveConstructor(curve))(context, options);
21
29
  };
22
30
  exports.getFunnelCurve = getFunnelCurve;
@@ -1,24 +1,32 @@
1
1
  import { CurveGenerator } from '@mui/x-charts-vendor/d3-shape';
2
+ import { CurveOptions } from "./curve.types.js";
2
3
  /**
3
4
  * This is a custom "linear" curve generator.
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.
4
7
  *
5
- * It takes into account the gap between the points and draws a smooth curve between them.
6
- *
7
- * It is based on the d3-shape linear curve generator.
8
+ * The implementation is based on the d3-shape linear curve generator.
8
9
  * https://github.com/d3/d3-shape/blob/a82254af78f08799c71d7ab25df557c4872a3c51/src/curve/linear.js
9
10
  */
10
11
  export declare class Linear implements CurveGenerator {
11
12
  private context;
12
- private line;
13
- private x;
14
- private y;
15
- private currentPoint;
13
+ private position;
14
+ private sections;
16
15
  private isHorizontal;
17
16
  private gap;
18
- constructor(context: CanvasRenderingContext2D, isHorizontal: boolean, gap?: number);
17
+ private borderRadius;
18
+ private points;
19
+ constructor(context: CanvasRenderingContext2D, {
20
+ isHorizontal,
21
+ gap,
22
+ position,
23
+ sections,
24
+ borderRadius
25
+ }: CurveOptions);
19
26
  areaStart(): void;
20
27
  areaEnd(): void;
21
28
  lineStart(): void;
22
29
  lineEnd(): void;
23
- point(x: number, y: number): void;
30
+ protected getBorderRadius(): number | number[];
31
+ point(xIn: number, yIn: number): void;
24
32
  }
@@ -4,110 +4,85 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.Linear = void 0;
7
- // From point1 to point2, get the x value from y
8
- const xFromY = (x1, y1, x2, y2) => y => {
9
- if (y1 === y2) {
10
- return x1;
11
- }
12
- const result = (x2 - x1) * (y - y1) / (y2 - y1) + x1;
13
- return Number.isNaN(result) ? 0 : result;
14
- };
15
-
16
- // From point1 to point2, get the y value from x
17
- const yFromX = (x1, y1, x2, y2) => x => {
18
- if (x1 === x2) {
19
- return y1;
20
- }
21
- const result = (y2 - y1) * (x - x1) / (x2 - x1) + y1;
22
- return Number.isNaN(result) ? 0 : result;
23
- };
7
+ var _borderRadiusPolygon = require("./borderRadiusPolygon");
8
+ var _utils = require("./utils");
9
+ /* eslint-disable class-methods-use-this */
24
10
 
25
11
  /**
26
12
  * This is a custom "linear" curve generator.
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.
27
15
  *
28
- * It takes into account the gap between the points and draws a smooth curve between them.
29
- *
30
- * It is based on the d3-shape linear curve generator.
16
+ * The implementation is based on the d3-shape linear curve generator.
31
17
  * https://github.com/d3/d3-shape/blob/a82254af78f08799c71d7ab25df557c4872a3c51/src/curve/linear.js
32
18
  */
33
19
  class Linear {
34
- constructor(context, isHorizontal, gap = 0) {
20
+ constructor(context, {
21
+ isHorizontal,
22
+ gap,
23
+ position,
24
+ sections,
25
+ borderRadius
26
+ }) {
35
27
  this.context = void 0;
36
- this.line = NaN;
37
- this.x = NaN;
38
- this.y = NaN;
39
- this.currentPoint = 0;
28
+ this.position = 0;
29
+ this.sections = 0;
40
30
  this.isHorizontal = false;
41
31
  this.gap = 0;
32
+ this.borderRadius = 0;
33
+ this.points = [];
42
34
  this.context = context;
43
- this.isHorizontal = isHorizontal;
44
- this.gap = gap / 2;
35
+ this.isHorizontal = isHorizontal ?? false;
36
+ this.gap = (gap ?? 0) / 2;
37
+ this.position = position ?? 0;
38
+ this.sections = sections ?? 1;
39
+ this.borderRadius = borderRadius ?? 0;
45
40
  }
46
- areaStart() {
47
- this.line = 0;
48
- }
49
- areaEnd() {
50
- this.line = NaN;
51
- }
52
- lineStart() {
53
- this.currentPoint = 0;
54
- }
55
- lineEnd() {
56
- if (this.line || this.line !== 0 && this.currentPoint === 1) {
57
- this.context.closePath();
41
+ areaStart() {}
42
+ areaEnd() {}
43
+ lineStart() {}
44
+ lineEnd() {}
45
+ getBorderRadius() {
46
+ if (this.gap > 0) {
47
+ return this.borderRadius;
48
+ }
49
+ if (this.position === 0) {
50
+ return [0, 0, this.borderRadius, this.borderRadius];
58
51
  }
59
- this.line = 1 - this.line;
52
+ if (this.position === this.sections - 1) {
53
+ return [this.borderRadius, this.borderRadius];
54
+ }
55
+ return 0;
60
56
  }
61
- point(x, y) {
62
- x = +x;
63
- y = +y;
64
-
65
- // We draw the lines only at currentPoint 1 & 3 because we need
66
- // The data of a pair of points to draw the lines.
67
- // Hence currentPoint 1 draws a line from point 0 to point 1 and point 1 to point 2.
68
- // currentPoint 3 draws a line from point 2 to point 3 and point 3 to point 0.
69
-
70
- if (this.isHorizontal) {
71
- const yGetter = yFromX(this.x, this.y, x, y);
72
- let xGap = 0;
73
-
74
- // 0 is the top-left corner.
75
- if (this.currentPoint === 1) {
76
- xGap = this.x + this.gap;
77
- this.context.moveTo(xGap, yGetter(xGap));
78
- this.context.lineTo(xGap, yGetter(xGap));
79
- xGap = x - this.gap;
80
- this.context.lineTo(xGap, yGetter(xGap));
81
- } else if (this.currentPoint === 3) {
82
- xGap = this.x - this.gap;
83
- this.context.lineTo(xGap, yGetter(xGap));
84
- xGap = x + this.gap;
85
- this.context.lineTo(xGap, yGetter(xGap));
86
- }
57
+ point(xIn, yIn) {
58
+ this.points.push({
59
+ x: xIn,
60
+ y: yIn
61
+ });
62
+ if (this.points.length < 4) {
63
+ return;
87
64
  }
88
- if (!this.isHorizontal) {
89
- const xGetter = xFromY(this.x, this.y, x, y);
90
- let yGap = 0;
91
65
 
92
- // 0 is the top-right corner.
93
- if (this.currentPoint === 1) {
94
- yGap = this.y + this.gap;
95
- this.context.moveTo(xGetter(yGap), yGap);
96
- this.context.lineTo(xGetter(yGap), yGap);
97
- yGap = y - this.gap;
98
- this.context.lineTo(xGetter(yGap), yGap);
99
- } else if (this.currentPoint === 3) {
100
- yGap = this.y - this.gap;
101
- this.context.lineTo(xGetter(yGap), yGap);
102
- yGap = y + this.gap;
103
- this.context.lineTo(xGetter(yGap), yGap);
66
+ // Add gaps where they are needed.
67
+ 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);
70
+ 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);
73
+ return {
74
+ x: xGap,
75
+ y: yGetter(xGap)
76
+ };
104
77
  }
105
- }
106
-
107
- // Increment the values
108
- this.currentPoint += 1;
109
- this.x = x;
110
- this.y = y;
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);
80
+ return {
81
+ x: xGetter(yGap),
82
+ y: yGap
83
+ };
84
+ });
85
+ (0, _borderRadiusPolygon.borderRadiusPolygon)(this.context, this.points, this.getBorderRadius());
111
86
  }
112
87
  }
113
88
  exports.Linear = Linear;
@@ -0,0 +1,34 @@
1
+ import { CurveGenerator } from '@mui/x-charts-vendor/d3-shape';
2
+ import { CurveOptions } from "./curve.types.js";
3
+ /**
4
+ * This is a custom "pyramid" curve generator.
5
+ * It draws straight lines for the 4 provided points. The slopes are calculated
6
+ * based on the min and max values of the x and y axes.
7
+ * with the option to add a gap between sections while also properly handling the border radius.
8
+ */
9
+ export declare class Pyramid implements CurveGenerator {
10
+ private context;
11
+ private position;
12
+ private sections;
13
+ private isHorizontal;
14
+ private gap;
15
+ private borderRadius;
16
+ private min;
17
+ private max;
18
+ private points;
19
+ constructor(context: CanvasRenderingContext2D, {
20
+ isHorizontal,
21
+ gap,
22
+ position,
23
+ sections,
24
+ borderRadius,
25
+ min,
26
+ max
27
+ }: CurveOptions);
28
+ areaStart(): void;
29
+ areaEnd(): void;
30
+ lineStart(): void;
31
+ lineEnd(): void;
32
+ protected getBorderRadius(): number | number[];
33
+ point(xIn: number, yIn: number): void;
34
+ }