@mui/x-charts-pro 8.1.0 → 8.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/BarChartPro/BarChartPro.d.ts +7 -1
- package/BarChartPro/BarChartPro.js +62 -5
- package/CHANGELOG.md +233 -7
- package/ChartContainerPro/useChartContainerProProps.d.ts +1 -1
- package/ChartDataProviderPro/ChartDataProviderPro.js +1 -1
- package/ChartDataProviderPro/useChartDataProviderProProps.d.ts +2 -2
- package/ChartZoomSlider/ChartZoomSlider.d.ts +5 -0
- package/ChartZoomSlider/ChartZoomSlider.js +47 -0
- package/ChartZoomSlider/index.d.ts +2 -0
- package/ChartZoomSlider/index.js +27 -0
- package/ChartZoomSlider/internals/ChartAxisZoomSlider.d.ts +23 -0
- package/ChartZoomSlider/internals/ChartAxisZoomSlider.js +348 -0
- package/ChartZoomSlider/internals/ChartAxisZoomSliderHandle.d.ts +12 -0
- package/ChartZoomSlider/internals/ChartAxisZoomSliderHandle.js +92 -0
- package/ChartZoomSlider/internals/chartAxisZoomSliderHandleClasses.d.ts +17 -0
- package/ChartZoomSlider/internals/chartAxisZoomSliderHandleClasses.js +27 -0
- package/ChartsToolbarPro/ChartsToolbarPro.d.ts +2 -0
- package/ChartsToolbarPro/ChartsToolbarPro.js +31 -0
- package/ChartsToolbarPro/index.d.ts +1 -0
- package/ChartsToolbarPro/index.js +16 -0
- package/ChartsToolbarPro/internal/ChartsToolbarZoomInButton.d.ts +13 -0
- package/ChartsToolbarPro/internal/ChartsToolbarZoomInButton.js +36 -0
- package/ChartsToolbarPro/internal/ChartsToolbarZoomOutButton.d.ts +13 -0
- package/ChartsToolbarPro/internal/ChartsToolbarZoomOutButton.js +36 -0
- package/FunnelChart/FunnelChart.js +9 -8
- package/FunnelChart/FunnelPlot.d.ts +5 -0
- package/FunnelChart/FunnelPlot.js +36 -18
- package/FunnelChart/FunnelSection.d.ts +1 -0
- package/FunnelChart/FunnelSection.js +12 -7
- package/FunnelChart/curves/borderRadiusPolygon.d.ts +8 -0
- package/FunnelChart/curves/borderRadiusPolygon.js +42 -0
- package/FunnelChart/curves/bump.d.ts +27 -0
- package/FunnelChart/curves/bump.js +81 -0
- package/FunnelChart/curves/curve.types.d.ts +38 -0
- package/FunnelChart/curves/curve.types.js +5 -0
- package/FunnelChart/curves/getFunnelCurve.d.ts +3 -0
- package/FunnelChart/curves/getFunnelCurve.js +30 -0
- package/FunnelChart/curves/index.d.ts +2 -0
- package/FunnelChart/curves/index.js +27 -0
- package/FunnelChart/curves/linear.d.ts +32 -0
- package/FunnelChart/curves/linear.js +88 -0
- package/FunnelChart/curves/pyramid.d.ts +34 -0
- package/FunnelChart/curves/pyramid.js +127 -0
- package/FunnelChart/curves/step-pyramid.d.ts +31 -0
- package/FunnelChart/curves/step-pyramid.js +107 -0
- package/FunnelChart/curves/step.d.ts +32 -0
- package/FunnelChart/curves/step.js +88 -0
- package/FunnelChart/curves/utils.d.ts +4 -0
- package/FunnelChart/curves/utils.js +29 -0
- package/FunnelChart/funnel.types.d.ts +25 -4
- package/FunnelChart/funnelPlotSlots.types.d.ts +1 -1
- package/FunnelChart/funnelSectionClasses.d.ts +6 -2
- package/FunnelChart/funnelSectionClasses.js +5 -2
- package/FunnelChart/index.d.ts +3 -2
- package/FunnelChart/seriesConfig/getSeriesWithDefaultValues.js +1 -0
- package/FunnelChart/useFunnelChartProps.d.ts +1 -6
- package/FunnelChart/useFunnelChartProps.js +7 -15
- package/Heatmap/Heatmap.d.ts +3 -3
- package/Heatmap/Heatmap.js +3 -21
- package/LineChartPro/LineChartPro.d.ts +7 -1
- package/LineChartPro/LineChartPro.js +62 -5
- package/ScatterChartPro/ScatterChartPro.d.ts +7 -1
- package/ScatterChartPro/ScatterChartPro.js +62 -5
- package/esm/BarChartPro/BarChartPro.d.ts +7 -1
- package/esm/BarChartPro/BarChartPro.js +62 -5
- package/esm/ChartContainerPro/useChartContainerProProps.d.ts +1 -1
- package/esm/ChartDataProviderPro/ChartDataProviderPro.js +1 -1
- package/esm/ChartDataProviderPro/useChartDataProviderProProps.d.ts +2 -2
- package/esm/ChartZoomSlider/ChartZoomSlider.d.ts +5 -0
- package/esm/ChartZoomSlider/ChartZoomSlider.js +41 -0
- package/esm/ChartZoomSlider/index.d.ts +2 -0
- package/esm/ChartZoomSlider/index.js +2 -0
- package/esm/ChartZoomSlider/internals/ChartAxisZoomSlider.d.ts +23 -0
- package/esm/ChartZoomSlider/internals/ChartAxisZoomSlider.js +339 -0
- package/esm/ChartZoomSlider/internals/ChartAxisZoomSliderHandle.d.ts +12 -0
- package/esm/ChartZoomSlider/internals/ChartAxisZoomSliderHandle.js +85 -0
- package/esm/ChartZoomSlider/internals/chartAxisZoomSliderHandleClasses.d.ts +17 -0
- package/esm/ChartZoomSlider/internals/chartAxisZoomSliderHandleClasses.js +17 -0
- package/esm/ChartsToolbarPro/ChartsToolbarPro.d.ts +2 -0
- package/esm/ChartsToolbarPro/ChartsToolbarPro.js +24 -0
- package/esm/ChartsToolbarPro/index.d.ts +1 -0
- package/esm/ChartsToolbarPro/index.js +1 -0
- package/esm/ChartsToolbarPro/internal/ChartsToolbarZoomInButton.d.ts +13 -0
- package/esm/ChartsToolbarPro/internal/ChartsToolbarZoomInButton.js +29 -0
- package/esm/ChartsToolbarPro/internal/ChartsToolbarZoomOutButton.d.ts +13 -0
- package/esm/ChartsToolbarPro/internal/ChartsToolbarZoomOutButton.js +29 -0
- package/esm/FunnelChart/FunnelChart.js +9 -8
- package/esm/FunnelChart/FunnelPlot.d.ts +5 -0
- package/esm/FunnelChart/FunnelPlot.js +37 -19
- package/esm/FunnelChart/FunnelSection.d.ts +1 -0
- package/esm/FunnelChart/FunnelSection.js +12 -7
- package/esm/FunnelChart/curves/borderRadiusPolygon.d.ts +8 -0
- package/esm/FunnelChart/curves/borderRadiusPolygon.js +36 -0
- package/esm/FunnelChart/curves/bump.d.ts +27 -0
- package/esm/FunnelChart/curves/bump.js +74 -0
- package/esm/FunnelChart/curves/curve.types.d.ts +38 -0
- package/esm/FunnelChart/curves/curve.types.js +1 -0
- package/esm/FunnelChart/curves/getFunnelCurve.d.ts +3 -0
- package/esm/FunnelChart/curves/getFunnelCurve.js +23 -0
- package/esm/FunnelChart/curves/index.d.ts +2 -0
- package/esm/FunnelChart/curves/index.js +2 -0
- package/esm/FunnelChart/curves/linear.d.ts +32 -0
- package/esm/FunnelChart/curves/linear.js +82 -0
- package/esm/FunnelChart/curves/pyramid.d.ts +34 -0
- package/esm/FunnelChart/curves/pyramid.js +121 -0
- package/esm/FunnelChart/curves/step-pyramid.d.ts +31 -0
- package/esm/FunnelChart/curves/step-pyramid.js +101 -0
- package/esm/FunnelChart/curves/step.d.ts +32 -0
- package/esm/FunnelChart/curves/step.js +82 -0
- package/esm/FunnelChart/curves/utils.d.ts +4 -0
- package/esm/FunnelChart/curves/utils.js +19 -0
- package/esm/FunnelChart/funnel.types.d.ts +25 -4
- package/esm/FunnelChart/funnelPlotSlots.types.d.ts +1 -1
- package/esm/FunnelChart/funnelSectionClasses.d.ts +6 -2
- package/esm/FunnelChart/funnelSectionClasses.js +5 -2
- package/esm/FunnelChart/index.d.ts +3 -2
- package/esm/FunnelChart/seriesConfig/getSeriesWithDefaultValues.js +1 -0
- package/esm/FunnelChart/useFunnelChartProps.d.ts +1 -6
- package/esm/FunnelChart/useFunnelChartProps.js +7 -15
- package/esm/Heatmap/Heatmap.d.ts +3 -3
- package/esm/Heatmap/Heatmap.js +3 -21
- package/esm/LineChartPro/LineChartPro.d.ts +7 -1
- package/esm/LineChartPro/LineChartPro.js +62 -5
- package/esm/ScatterChartPro/ScatterChartPro.d.ts +7 -1
- package/esm/ScatterChartPro/ScatterChartPro.js +62 -5
- package/esm/index.d.ts +4 -1
- package/esm/index.js +5 -2
- package/esm/internals/material/icons.d.ts +3 -0
- package/esm/internals/material/icons.js +13 -0
- package/esm/internals/material/index.d.ts +4 -0
- package/esm/internals/material/index.js +12 -0
- package/esm/internals/plugins/useChartProExport/common.d.ts +1 -0
- package/esm/internals/plugins/useChartProExport/common.js +8 -0
- package/esm/internals/plugins/useChartProExport/exportImage.d.ts +3 -0
- package/esm/internals/plugins/useChartProExport/exportImage.js +85 -0
- package/esm/internals/plugins/useChartProExport/print.js +6 -50
- package/esm/internals/plugins/useChartProExport/useChartProExport.js +22 -2
- package/esm/internals/plugins/useChartProExport/useChartProExport.types.d.ts +32 -0
- package/esm/internals/plugins/useChartProZoom/calculateZoom.d.ts +23 -0
- package/esm/internals/plugins/useChartProZoom/calculateZoom.js +32 -0
- package/esm/internals/plugins/useChartProZoom/useChartProZoom.d.ts +1 -1
- package/esm/internals/plugins/useChartProZoom/useChartProZoom.js +46 -4
- package/esm/internals/plugins/useChartProZoom/useChartProZoom.selectors.d.ts +84 -32
- package/esm/internals/plugins/useChartProZoom/useChartProZoom.selectors.js +3 -2
- package/esm/internals/plugins/useChartProZoom/useChartProZoom.types.d.ts +17 -2
- package/esm/internals/slots/chartBaseSlotProps.d.ts +10 -0
- package/esm/internals/slots/chartBaseSlotProps.js +1 -0
- package/esm/internals/slots/chartsBaseSlots.d.ts +6 -0
- package/esm/internals/slots/chartsBaseSlots.js +1 -0
- package/esm/internals/slots/chartsIconSlots.d.ts +14 -0
- package/esm/internals/slots/chartsIconSlots.js +1 -0
- package/esm/themeAugmentation/components.d.ts +0 -4
- package/esm/themeAugmentation/components.js +1 -0
- package/esm/themeAugmentation/index.d.ts +3 -3
- package/esm/themeAugmentation/overrides.d.ts +0 -3
- package/esm/themeAugmentation/overrides.js +2 -0
- package/esm/themeAugmentation/props.d.ts +0 -6
- package/esm/themeAugmentation/props.js +2 -0
- package/esm/typeOverloads/modules.d.ts +1 -1
- package/index.d.ts +4 -1
- package/index.js +90 -1
- package/internals/material/icons.d.ts +3 -0
- package/internals/material/icons.js +20 -0
- package/internals/material/index.d.ts +4 -0
- package/internals/material/index.js +19 -0
- package/internals/plugins/useChartProExport/common.d.ts +1 -0
- package/internals/plugins/useChartProExport/common.js +14 -0
- package/internals/plugins/useChartProExport/exportImage.d.ts +3 -0
- package/internals/plugins/useChartProExport/exportImage.js +95 -0
- package/internals/plugins/useChartProExport/print.js +6 -50
- package/internals/plugins/useChartProExport/useChartProExport.js +22 -2
- package/internals/plugins/useChartProExport/useChartProExport.types.d.ts +32 -0
- package/internals/plugins/useChartProZoom/calculateZoom.d.ts +23 -0
- package/internals/plugins/useChartProZoom/calculateZoom.js +39 -0
- package/internals/plugins/useChartProZoom/useChartProZoom.d.ts +1 -1
- package/internals/plugins/useChartProZoom/useChartProZoom.js +45 -3
- package/internals/plugins/useChartProZoom/useChartProZoom.selectors.d.ts +84 -32
- package/internals/plugins/useChartProZoom/useChartProZoom.selectors.js +3 -2
- package/internals/plugins/useChartProZoom/useChartProZoom.types.d.ts +17 -2
- package/internals/slots/chartBaseSlotProps.d.ts +10 -0
- package/internals/slots/chartBaseSlotProps.js +5 -0
- package/internals/slots/chartsBaseSlots.d.ts +6 -0
- package/internals/slots/chartsBaseSlots.js +5 -0
- package/internals/slots/chartsIconSlots.d.ts +14 -0
- package/internals/slots/chartsIconSlots.js +5 -0
- package/package.json +10 -7
- package/themeAugmentation/components.d.ts +0 -4
- package/themeAugmentation/components.js +5 -0
- package/themeAugmentation/index.d.ts +3 -3
- package/themeAugmentation/overrides.d.ts +0 -3
- package/themeAugmentation/overrides.js +5 -0
- package/themeAugmentation/props.d.ts +0 -6
- package/themeAugmentation/props.js +5 -0
- package/typeOverloads/modules.d.ts +1 -1
- package/FunnelChart/funnelStepCurve.d.ts +0 -4
- package/FunnelChart/funnelStepCurve.js +0 -74
- package/esm/FunnelChart/funnelStepCurve.d.ts +0 -4
- package/esm/FunnelChart/funnelStepCurve.js +0 -67
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export type CurveOptions = {
|
|
2
|
+
/**
|
|
3
|
+
* The gap between each segment.
|
|
4
|
+
* @default 0
|
|
5
|
+
*/
|
|
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;
|
|
33
|
+
};
|
|
34
|
+
export type FunnelCurveType = 'linear' | 'step' | 'bump' | 'pyramid' | 'step-pyramid';
|
|
35
|
+
export type Point = {
|
|
36
|
+
x: number;
|
|
37
|
+
y: number;
|
|
38
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Step } from "./step.js";
|
|
2
|
+
import { Linear } from "./linear.js";
|
|
3
|
+
import { Bump } from "./bump.js";
|
|
4
|
+
import { Pyramid } from "./pyramid.js";
|
|
5
|
+
import { StepPyramid } from "./step-pyramid.js";
|
|
6
|
+
const curveConstructor = curve => {
|
|
7
|
+
if (curve === 'step') {
|
|
8
|
+
return Step;
|
|
9
|
+
}
|
|
10
|
+
if (curve === 'bump') {
|
|
11
|
+
return Bump;
|
|
12
|
+
}
|
|
13
|
+
if (curve === 'pyramid') {
|
|
14
|
+
return Pyramid;
|
|
15
|
+
}
|
|
16
|
+
if (curve === 'step-pyramid') {
|
|
17
|
+
return StepPyramid;
|
|
18
|
+
}
|
|
19
|
+
return Linear;
|
|
20
|
+
};
|
|
21
|
+
export const getFunnelCurve = (curve, options) => {
|
|
22
|
+
return context => new (curveConstructor(curve))(context, options);
|
|
23
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { CurveGenerator } from '@mui/x-charts-vendor/d3-shape';
|
|
2
|
+
import { CurveOptions } from "./curve.types.js";
|
|
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.
|
|
7
|
+
*
|
|
8
|
+
* The implementation is based on the d3-shape linear curve generator.
|
|
9
|
+
* https://github.com/d3/d3-shape/blob/a82254af78f08799c71d7ab25df557c4872a3c51/src/curve/linear.js
|
|
10
|
+
*/
|
|
11
|
+
export declare class Linear implements CurveGenerator {
|
|
12
|
+
private context;
|
|
13
|
+
private position;
|
|
14
|
+
private sections;
|
|
15
|
+
private isHorizontal;
|
|
16
|
+
private gap;
|
|
17
|
+
private borderRadius;
|
|
18
|
+
private points;
|
|
19
|
+
constructor(context: CanvasRenderingContext2D, {
|
|
20
|
+
isHorizontal,
|
|
21
|
+
gap,
|
|
22
|
+
position,
|
|
23
|
+
sections,
|
|
24
|
+
borderRadius
|
|
25
|
+
}: CurveOptions);
|
|
26
|
+
areaStart(): void;
|
|
27
|
+
areaEnd(): void;
|
|
28
|
+
lineStart(): void;
|
|
29
|
+
lineEnd(): void;
|
|
30
|
+
protected getBorderRadius(): number | number[];
|
|
31
|
+
point(xIn: number, yIn: number): void;
|
|
32
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/* eslint-disable class-methods-use-this */
|
|
2
|
+
|
|
3
|
+
import { borderRadiusPolygon } from "./borderRadiusPolygon.js";
|
|
4
|
+
import { lerpX, lerpY } from "./utils.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* This is a custom "linear" curve generator.
|
|
8
|
+
* It draws straight lines for the 4 provided points,
|
|
9
|
+
* with the option to add a gap between sections while also properly handling the border radius.
|
|
10
|
+
*
|
|
11
|
+
* The implementation is based on the d3-shape linear curve generator.
|
|
12
|
+
* https://github.com/d3/d3-shape/blob/a82254af78f08799c71d7ab25df557c4872a3c51/src/curve/linear.js
|
|
13
|
+
*/
|
|
14
|
+
export class Linear {
|
|
15
|
+
constructor(context, {
|
|
16
|
+
isHorizontal,
|
|
17
|
+
gap,
|
|
18
|
+
position,
|
|
19
|
+
sections,
|
|
20
|
+
borderRadius
|
|
21
|
+
}) {
|
|
22
|
+
this.context = void 0;
|
|
23
|
+
this.position = 0;
|
|
24
|
+
this.sections = 0;
|
|
25
|
+
this.isHorizontal = false;
|
|
26
|
+
this.gap = 0;
|
|
27
|
+
this.borderRadius = 0;
|
|
28
|
+
this.points = [];
|
|
29
|
+
this.context = context;
|
|
30
|
+
this.isHorizontal = isHorizontal ?? false;
|
|
31
|
+
this.gap = (gap ?? 0) / 2;
|
|
32
|
+
this.position = position ?? 0;
|
|
33
|
+
this.sections = sections ?? 1;
|
|
34
|
+
this.borderRadius = borderRadius ?? 0;
|
|
35
|
+
}
|
|
36
|
+
areaStart() {}
|
|
37
|
+
areaEnd() {}
|
|
38
|
+
lineStart() {}
|
|
39
|
+
lineEnd() {}
|
|
40
|
+
getBorderRadius() {
|
|
41
|
+
if (this.gap > 0) {
|
|
42
|
+
return this.borderRadius;
|
|
43
|
+
}
|
|
44
|
+
if (this.position === 0) {
|
|
45
|
+
return [0, 0, this.borderRadius, this.borderRadius];
|
|
46
|
+
}
|
|
47
|
+
if (this.position === this.sections - 1) {
|
|
48
|
+
return [this.borderRadius, this.borderRadius];
|
|
49
|
+
}
|
|
50
|
+
return 0;
|
|
51
|
+
}
|
|
52
|
+
point(xIn, yIn) {
|
|
53
|
+
this.points.push({
|
|
54
|
+
x: xIn,
|
|
55
|
+
y: yIn
|
|
56
|
+
});
|
|
57
|
+
if (this.points.length < 4) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Add gaps where they are needed.
|
|
62
|
+
this.points = this.points.map((point, index) => {
|
|
63
|
+
const slopeStart = this.points.at(index <= 1 ? 0 : 2);
|
|
64
|
+
const slopeEnd = this.points.at(index <= 1 ? 1 : 3);
|
|
65
|
+
if (this.isHorizontal) {
|
|
66
|
+
const yGetter = lerpY(slopeStart.x - this.gap, slopeStart.y, slopeEnd.x - this.gap, slopeEnd.y);
|
|
67
|
+
const xGap = point.x + (index === 0 || index === 3 ? this.gap : -this.gap);
|
|
68
|
+
return {
|
|
69
|
+
x: xGap,
|
|
70
|
+
y: yGetter(xGap)
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
const xGetter = lerpX(slopeStart.x, slopeStart.y - this.gap, slopeEnd.x, slopeEnd.y - this.gap);
|
|
74
|
+
const yGap = point.y + (index === 0 || index === 3 ? this.gap : -this.gap);
|
|
75
|
+
return {
|
|
76
|
+
x: xGetter(yGap),
|
|
77
|
+
y: yGap
|
|
78
|
+
};
|
|
79
|
+
});
|
|
80
|
+
borderRadiusPolygon(this.context, this.points, this.getBorderRadius());
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/* eslint-disable class-methods-use-this */
|
|
2
|
+
|
|
3
|
+
import { borderRadiusPolygon } from "./borderRadiusPolygon.js";
|
|
4
|
+
import { lerpX, lerpY } from "./utils.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* This is a custom "pyramid" curve generator.
|
|
8
|
+
* It draws straight lines for the 4 provided points. The slopes are calculated
|
|
9
|
+
* based on the min and max values of the x and y axes.
|
|
10
|
+
* with the option to add a gap between sections while also properly handling the border radius.
|
|
11
|
+
*/
|
|
12
|
+
export class Pyramid {
|
|
13
|
+
constructor(context, {
|
|
14
|
+
isHorizontal,
|
|
15
|
+
gap,
|
|
16
|
+
position,
|
|
17
|
+
sections,
|
|
18
|
+
borderRadius,
|
|
19
|
+
min,
|
|
20
|
+
max
|
|
21
|
+
}) {
|
|
22
|
+
this.context = void 0;
|
|
23
|
+
this.position = 0;
|
|
24
|
+
this.sections = 0;
|
|
25
|
+
this.isHorizontal = false;
|
|
26
|
+
this.gap = 0;
|
|
27
|
+
this.borderRadius = 0;
|
|
28
|
+
this.min = {
|
|
29
|
+
x: 0,
|
|
30
|
+
y: 0
|
|
31
|
+
};
|
|
32
|
+
this.max = {
|
|
33
|
+
x: 0,
|
|
34
|
+
y: 0
|
|
35
|
+
};
|
|
36
|
+
this.points = [];
|
|
37
|
+
this.context = context;
|
|
38
|
+
this.isHorizontal = isHorizontal ?? false;
|
|
39
|
+
this.gap = (gap ?? 0) / 2;
|
|
40
|
+
this.position = position ?? 0;
|
|
41
|
+
this.sections = sections ?? 1;
|
|
42
|
+
this.borderRadius = borderRadius ?? 0;
|
|
43
|
+
this.min = min ?? {
|
|
44
|
+
x: 0,
|
|
45
|
+
y: 0
|
|
46
|
+
};
|
|
47
|
+
this.max = max ?? {
|
|
48
|
+
x: 0,
|
|
49
|
+
y: 0
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
areaStart() {}
|
|
53
|
+
areaEnd() {}
|
|
54
|
+
lineStart() {}
|
|
55
|
+
lineEnd() {}
|
|
56
|
+
getBorderRadius() {
|
|
57
|
+
if (this.gap > 0) {
|
|
58
|
+
return this.borderRadius;
|
|
59
|
+
}
|
|
60
|
+
if (this.position === 0) {
|
|
61
|
+
return [0, 0, this.borderRadius, this.borderRadius];
|
|
62
|
+
}
|
|
63
|
+
if (this.position === this.sections - 1 && this.gap <= 0) {
|
|
64
|
+
return [this.borderRadius];
|
|
65
|
+
}
|
|
66
|
+
if (this.position === this.sections - 1) {
|
|
67
|
+
return [this.borderRadius, this.borderRadius];
|
|
68
|
+
}
|
|
69
|
+
return 0;
|
|
70
|
+
}
|
|
71
|
+
point(xIn, yIn) {
|
|
72
|
+
this.points.push({
|
|
73
|
+
x: xIn,
|
|
74
|
+
y: yIn
|
|
75
|
+
});
|
|
76
|
+
if (this.points.length < 4) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Add gaps where they are needed.
|
|
81
|
+
this.points = this.points.map((point, index) => {
|
|
82
|
+
if (this.isHorizontal) {
|
|
83
|
+
const slopeEnd = {
|
|
84
|
+
x: this.max.x,
|
|
85
|
+
y: (this.max.y + this.min.y) / 2
|
|
86
|
+
};
|
|
87
|
+
const slopeStart = index <= 1 ? this.min : {
|
|
88
|
+
x: this.min.x,
|
|
89
|
+
y: this.max.y
|
|
90
|
+
};
|
|
91
|
+
const yGetter = lerpY(slopeStart.x, slopeStart.y, slopeEnd.x, slopeEnd.y);
|
|
92
|
+
const xGap = point.x + (index === 0 || index === 3 ? this.gap : -this.gap);
|
|
93
|
+
return {
|
|
94
|
+
x: xGap,
|
|
95
|
+
y: yGetter(xGap)
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
const slopeEnd = {
|
|
99
|
+
x: (this.max.x + this.min.x) / 2,
|
|
100
|
+
y: this.max.y
|
|
101
|
+
};
|
|
102
|
+
const slopeStart = index <= 1 ? {
|
|
103
|
+
x: this.max.x,
|
|
104
|
+
y: this.min.y
|
|
105
|
+
} : this.min;
|
|
106
|
+
const xGetter = lerpX(slopeStart.x, slopeStart.y, slopeEnd.x, slopeEnd.y);
|
|
107
|
+
const yGap = point.y + (index === 0 || index === 3 ? this.gap : -this.gap);
|
|
108
|
+
return {
|
|
109
|
+
x: xGetter(yGap),
|
|
110
|
+
y: yGap
|
|
111
|
+
};
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
// In the last section, to form a triangle we need 3 points instead of 4
|
|
115
|
+
// Else the algorithm will break.
|
|
116
|
+
if (this.position === this.sections - 1 && this.gap <= 0) {
|
|
117
|
+
this.points = [this.points[0], this.points[1], this.points[3]];
|
|
118
|
+
}
|
|
119
|
+
borderRadiusPolygon(this.context, this.points, this.getBorderRadius());
|
|
120
|
+
}
|
|
121
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { CurveGenerator } from '@mui/x-charts-vendor/d3-shape';
|
|
2
|
+
import { CurveOptions } from "./curve.types.js";
|
|
3
|
+
/**
|
|
4
|
+
* This is a custom "step-pyramid" curve generator.
|
|
5
|
+
* It creates a step pyramid, which is a step-like shape with static lengths.
|
|
6
|
+
* It has the option to add a gap between sections while also properly handling the border radius.
|
|
7
|
+
*/
|
|
8
|
+
export declare class StepPyramid implements CurveGenerator {
|
|
9
|
+
private context;
|
|
10
|
+
private position;
|
|
11
|
+
private isHorizontal;
|
|
12
|
+
private gap;
|
|
13
|
+
private borderRadius;
|
|
14
|
+
private min;
|
|
15
|
+
private max;
|
|
16
|
+
private points;
|
|
17
|
+
constructor(context: CanvasRenderingContext2D, {
|
|
18
|
+
isHorizontal,
|
|
19
|
+
gap,
|
|
20
|
+
position,
|
|
21
|
+
borderRadius,
|
|
22
|
+
min,
|
|
23
|
+
max
|
|
24
|
+
}: CurveOptions);
|
|
25
|
+
areaStart(): void;
|
|
26
|
+
areaEnd(): void;
|
|
27
|
+
lineStart(): void;
|
|
28
|
+
lineEnd(): void;
|
|
29
|
+
protected getBorderRadius(): number | number[];
|
|
30
|
+
point(xIn: number, yIn: number): void;
|
|
31
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/* eslint-disable class-methods-use-this */
|
|
2
|
+
|
|
3
|
+
import { borderRadiusPolygon } from "./borderRadiusPolygon.js";
|
|
4
|
+
import { lerpX, lerpY } from "./utils.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* This is a custom "step-pyramid" curve generator.
|
|
8
|
+
* It creates a step pyramid, which is a step-like shape with static lengths.
|
|
9
|
+
* It has the option to add a gap between sections while also properly handling the border radius.
|
|
10
|
+
*/
|
|
11
|
+
export class StepPyramid {
|
|
12
|
+
constructor(context, {
|
|
13
|
+
isHorizontal,
|
|
14
|
+
gap,
|
|
15
|
+
position,
|
|
16
|
+
borderRadius,
|
|
17
|
+
min,
|
|
18
|
+
max
|
|
19
|
+
}) {
|
|
20
|
+
this.context = void 0;
|
|
21
|
+
this.position = 0;
|
|
22
|
+
this.isHorizontal = false;
|
|
23
|
+
this.gap = 0;
|
|
24
|
+
this.borderRadius = 0;
|
|
25
|
+
this.min = {
|
|
26
|
+
x: 0,
|
|
27
|
+
y: 0
|
|
28
|
+
};
|
|
29
|
+
this.max = {
|
|
30
|
+
x: 0,
|
|
31
|
+
y: 0
|
|
32
|
+
};
|
|
33
|
+
this.points = [];
|
|
34
|
+
this.context = context;
|
|
35
|
+
this.isHorizontal = isHorizontal ?? false;
|
|
36
|
+
this.gap = (gap ?? 0) / 2;
|
|
37
|
+
this.position = position ?? 0;
|
|
38
|
+
this.borderRadius = borderRadius ?? 0;
|
|
39
|
+
this.min = min ?? {
|
|
40
|
+
x: 0,
|
|
41
|
+
y: 0
|
|
42
|
+
};
|
|
43
|
+
this.max = max ?? {
|
|
44
|
+
x: 0,
|
|
45
|
+
y: 0
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
areaStart() {}
|
|
49
|
+
areaEnd() {}
|
|
50
|
+
lineStart() {}
|
|
51
|
+
lineEnd() {}
|
|
52
|
+
getBorderRadius() {
|
|
53
|
+
return this.gap > 0 || this.position === 0 ? this.borderRadius : [this.borderRadius, this.borderRadius];
|
|
54
|
+
}
|
|
55
|
+
point(xIn, yIn) {
|
|
56
|
+
this.points.push({
|
|
57
|
+
x: xIn,
|
|
58
|
+
y: yIn
|
|
59
|
+
});
|
|
60
|
+
if (this.points.length < 4) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Add gaps where they are needed.
|
|
65
|
+
this.points = this.points.map((point, index) => {
|
|
66
|
+
if (this.isHorizontal) {
|
|
67
|
+
const slopeEnd = {
|
|
68
|
+
x: this.max.x,
|
|
69
|
+
y: (this.max.y + this.min.y) / 2
|
|
70
|
+
};
|
|
71
|
+
const slopeStart = index <= 1 ? this.min : {
|
|
72
|
+
x: this.min.x,
|
|
73
|
+
y: this.max.y
|
|
74
|
+
};
|
|
75
|
+
const yGetter = lerpY(slopeStart.x, slopeStart.y, slopeEnd.x, slopeEnd.y);
|
|
76
|
+
const xGap = point.x + (index === 0 || index === 3 ? this.gap : -this.gap);
|
|
77
|
+
const xInitial = index === 0 || index === 1 ? this.points.at(0).x : this.points.at(3).x;
|
|
78
|
+
return {
|
|
79
|
+
x: xGap,
|
|
80
|
+
y: yGetter(xInitial)
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
const slopeEnd = {
|
|
84
|
+
x: (this.max.x + this.min.x) / 2,
|
|
85
|
+
y: this.max.y
|
|
86
|
+
};
|
|
87
|
+
const slopeStart = index <= 1 ? {
|
|
88
|
+
x: this.max.x,
|
|
89
|
+
y: this.min.y
|
|
90
|
+
} : this.min;
|
|
91
|
+
const xGetter = lerpX(slopeStart.x, slopeStart.y, slopeEnd.x, slopeEnd.y);
|
|
92
|
+
const yGap = point.y + (index === 0 || index === 3 ? this.gap : -this.gap);
|
|
93
|
+
const yInitial = index === 0 || index === 1 ? this.points.at(0).y : this.points.at(3).y;
|
|
94
|
+
return {
|
|
95
|
+
x: xGetter(yInitial),
|
|
96
|
+
y: yGap
|
|
97
|
+
};
|
|
98
|
+
});
|
|
99
|
+
borderRadiusPolygon(this.context, this.points, this.getBorderRadius());
|
|
100
|
+
}
|
|
101
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { CurveGenerator } from '@mui/x-charts-vendor/d3-shape';
|
|
2
|
+
import { CurveOptions } from "./curve.types.js";
|
|
3
|
+
/**
|
|
4
|
+
* This is a custom "step" curve generator.
|
|
5
|
+
* It is used to draw "rectangles" from 4 points without having to rework the rendering logic,
|
|
6
|
+
* with the option to add a gap between sections while also properly handling the border radius.
|
|
7
|
+
*
|
|
8
|
+
* It takes the min and max of the x and y coordinates of the points to create a rectangle.
|
|
9
|
+
*
|
|
10
|
+
* The implementation is based on the d3-shape step curve generator.
|
|
11
|
+
* https://github.com/d3/d3-shape/blob/a82254af78f08799c71d7ab25df557c4872a3c51/src/curve/step.js
|
|
12
|
+
*/
|
|
13
|
+
export declare class Step implements CurveGenerator {
|
|
14
|
+
private context;
|
|
15
|
+
private isHorizontal;
|
|
16
|
+
private gap;
|
|
17
|
+
private borderRadius;
|
|
18
|
+
private position;
|
|
19
|
+
private points;
|
|
20
|
+
constructor(context: CanvasRenderingContext2D, {
|
|
21
|
+
isHorizontal,
|
|
22
|
+
gap,
|
|
23
|
+
position,
|
|
24
|
+
borderRadius
|
|
25
|
+
}: CurveOptions);
|
|
26
|
+
areaStart(): void;
|
|
27
|
+
areaEnd(): void;
|
|
28
|
+
lineStart(): void;
|
|
29
|
+
lineEnd(): void;
|
|
30
|
+
protected getBorderRadius(): number | number[];
|
|
31
|
+
point(xIn: number, yIn: number): void;
|
|
32
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/* eslint-disable class-methods-use-this */
|
|
2
|
+
|
|
3
|
+
import { borderRadiusPolygon } from "./borderRadiusPolygon.js";
|
|
4
|
+
import { max, min } from "./utils.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* This is a custom "step" curve generator.
|
|
8
|
+
* It is used to draw "rectangles" from 4 points without having to rework the rendering logic,
|
|
9
|
+
* with the option to add a gap between sections while also properly handling the border radius.
|
|
10
|
+
*
|
|
11
|
+
* It takes the min and max of the x and y coordinates of the points to create a rectangle.
|
|
12
|
+
*
|
|
13
|
+
* The implementation is based on the d3-shape step curve generator.
|
|
14
|
+
* https://github.com/d3/d3-shape/blob/a82254af78f08799c71d7ab25df557c4872a3c51/src/curve/step.js
|
|
15
|
+
*/
|
|
16
|
+
export class Step {
|
|
17
|
+
constructor(context, {
|
|
18
|
+
isHorizontal,
|
|
19
|
+
gap,
|
|
20
|
+
position,
|
|
21
|
+
borderRadius
|
|
22
|
+
}) {
|
|
23
|
+
this.context = void 0;
|
|
24
|
+
this.isHorizontal = false;
|
|
25
|
+
this.gap = 0;
|
|
26
|
+
this.borderRadius = 0;
|
|
27
|
+
this.position = 0;
|
|
28
|
+
this.points = [];
|
|
29
|
+
this.context = context;
|
|
30
|
+
this.isHorizontal = isHorizontal ?? false;
|
|
31
|
+
this.gap = (gap ?? 0) / 2;
|
|
32
|
+
this.position = position ?? 0;
|
|
33
|
+
this.borderRadius = borderRadius ?? 0;
|
|
34
|
+
}
|
|
35
|
+
areaStart() {}
|
|
36
|
+
areaEnd() {}
|
|
37
|
+
lineStart() {}
|
|
38
|
+
lineEnd() {}
|
|
39
|
+
getBorderRadius() {
|
|
40
|
+
return this.gap > 0 || this.position === 0 ? this.borderRadius : [this.borderRadius, this.borderRadius];
|
|
41
|
+
}
|
|
42
|
+
point(xIn, yIn) {
|
|
43
|
+
this.points.push({
|
|
44
|
+
x: xIn,
|
|
45
|
+
y: yIn
|
|
46
|
+
});
|
|
47
|
+
if (this.points.length < 4) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Ensure we have rectangles instead of trapezoids.
|
|
52
|
+
this.points = this.points.map((_, index) => {
|
|
53
|
+
const allX = this.points.map(p => p.x);
|
|
54
|
+
const allY = this.points.map(p => p.y);
|
|
55
|
+
if (this.isHorizontal) {
|
|
56
|
+
return {
|
|
57
|
+
x: index === 1 || index === 2 ? max(allX) : min(allX),
|
|
58
|
+
y: index <= 1 ? max(allY) : min(allY)
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
x: index <= 1 ? min(allX) : max(allX),
|
|
63
|
+
y: index === 1 || index === 2 ? max(allY) : min(allY)
|
|
64
|
+
};
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
// Add gaps where they are needed.
|
|
68
|
+
this.points = this.points.map((point, index) => {
|
|
69
|
+
if (this.isHorizontal) {
|
|
70
|
+
return {
|
|
71
|
+
x: point.x + (index === 0 || index === 3 ? this.gap : -this.gap),
|
|
72
|
+
y: point.y
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
x: point.x,
|
|
77
|
+
y: point.y + (index === 0 || index === 3 ? this.gap : -this.gap)
|
|
78
|
+
};
|
|
79
|
+
});
|
|
80
|
+
borderRadiusPolygon(this.context, this.points, this.getBorderRadius());
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const max: (numbers: number[]) => number;
|
|
2
|
+
export declare const min: (numbers: number[]) => number;
|
|
3
|
+
export declare const lerpX: (x1: number, y1: number, x2: number, y2: number) => (y: number) => number;
|
|
4
|
+
export declare const lerpY: (x1: number, y1: number, x2: number, y2: number) => (x: number) => number;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export const max = numbers => Math.max(...numbers, -Infinity);
|
|
2
|
+
export const min = numbers => Math.min(...numbers, Infinity);
|
|
3
|
+
// From point1 to point2, get the x value from y
|
|
4
|
+
export const lerpX = (x1, y1, x2, y2) => y => {
|
|
5
|
+
if (y1 === y2) {
|
|
6
|
+
return x1;
|
|
7
|
+
}
|
|
8
|
+
const result = (x2 - x1) * (y - y1) / (y2 - y1) + x1;
|
|
9
|
+
return Number.isNaN(result) ? 0 : result;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
// From point1 to point2, get the y value from x
|
|
13
|
+
export const lerpY = (x1, y1, x2, y2) => x => {
|
|
14
|
+
if (x1 === x2) {
|
|
15
|
+
return y1;
|
|
16
|
+
}
|
|
17
|
+
const result = (y2 - y1) * (x - x1) / (x2 - x1) + y1;
|
|
18
|
+
return Number.isNaN(result) ? 0 : result;
|
|
19
|
+
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { ChartsLabelMarkProps } from '@mui/x-charts/ChartsLabel';
|
|
2
2
|
import { CommonSeriesType, CartesianSeriesType, CommonDefaultizedProps, SeriesId } from '@mui/x-charts/internals';
|
|
3
|
-
import {
|
|
3
|
+
import { Position } from '@mui/x-charts/models';
|
|
4
4
|
import { DefaultizedProps, MakeRequired } from '@mui/x-internals/types';
|
|
5
|
+
import { FunnelCurveType } from "./curves/index.js";
|
|
5
6
|
export type FunnelItemId = string | number;
|
|
6
|
-
export type FunnelCurveType = Extract<CurveType, 'linear' | 'step'> | 'bump';
|
|
7
7
|
export type FunnelValueType = {
|
|
8
8
|
/**
|
|
9
9
|
* A unique identifier of the funnel section.
|
|
@@ -43,11 +43,23 @@ export interface FunnelSeriesType extends Omit<CommonSeriesType<FunnelValueType>
|
|
|
43
43
|
*/
|
|
44
44
|
layout?: 'horizontal' | 'vertical';
|
|
45
45
|
/**
|
|
46
|
-
* The type of curve to use for the line.
|
|
47
|
-
*
|
|
46
|
+
* The type of curve to use for the line.
|
|
47
|
+
*
|
|
48
|
+
* - `bump`: A curve that creates a smooth transition between points, with a bump in the middle.
|
|
49
|
+
* - `linear`: A straight line between points.
|
|
50
|
+
* - `step`: A step line that creates a staircase effect.
|
|
51
|
+
* - `pyramid`: A pyramid shape that connects the points.
|
|
52
|
+
* - `step-pyramid`: A step line that creates a staircase effect, with a pyramid shape.
|
|
53
|
+
*
|
|
54
|
+
* Read more about curves at [curve interpolation](https://mui.com/x/react-charts/funnel/#curve-interpolation).
|
|
48
55
|
* @default 'linear'
|
|
49
56
|
*/
|
|
50
57
|
curve?: FunnelCurveType;
|
|
58
|
+
/**
|
|
59
|
+
* The radius, in pixels, of the corners of the funnel sections.
|
|
60
|
+
* @default 8
|
|
61
|
+
*/
|
|
62
|
+
borderRadius?: number;
|
|
51
63
|
/**
|
|
52
64
|
* The label configuration for the funnel plot.
|
|
53
65
|
* Allows to customize the position and margin of the label that is displayed on the funnel sections.
|
|
@@ -56,6 +68,15 @@ export interface FunnelSeriesType extends Omit<CommonSeriesType<FunnelValueType>
|
|
|
56
68
|
* @default { vertical: 'middle', horizontal: 'center' }
|
|
57
69
|
*/
|
|
58
70
|
sectionLabel?: FunnelLabelOptions | ((item: FunnelItem) => FunnelLabelOptions | false) | false;
|
|
71
|
+
/**
|
|
72
|
+
* Defines if the funnel sections are filled or outlined.
|
|
73
|
+
*
|
|
74
|
+
* An `outlined` funnel will have a stroke around the sections and a translucent fill.
|
|
75
|
+
* A `filled` funnel will have a solid fill and no stroke.
|
|
76
|
+
*
|
|
77
|
+
* @default 'filled'
|
|
78
|
+
*/
|
|
79
|
+
variant?: 'filled' | 'outlined';
|
|
59
80
|
}
|
|
60
81
|
/**
|
|
61
82
|
* An object that allows to identify a funnel item.
|