@mui/x-charts-pro 8.0.0 → 8.2.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.js +7 -1
- package/BarChartPro/BarChartPro.plugins.d.ts +2 -1
- package/BarChartPro/BarChartPro.plugins.js +2 -1
- package/CHANGELOG.md +230 -5
- package/ChartContainerPro/ChartContainerPro.d.ts +1 -0
- package/ChartContainerPro/useChartContainerProProps.d.ts +1 -1
- package/ChartDataProviderPro/ChartDataProviderPro.js +11 -2
- package/ChartDataProviderPro/useChartDataProviderProProps.d.ts +3 -2
- package/ChartDataProviderPro/useChartDataProviderProProps.js +2 -0
- package/FunnelChart/FunnelChart.js +12 -1
- package/FunnelChart/FunnelPlot.d.ts +5 -0
- package/FunnelChart/FunnelPlot.js +13 -16
- package/FunnelChart/curves/bump.d.ts +24 -0
- package/FunnelChart/curves/bump.js +82 -0
- package/FunnelChart/curves/curve.types.d.ts +8 -0
- package/FunnelChart/curves/curve.types.js +5 -0
- package/FunnelChart/curves/funnelStep.d.ts +25 -0
- package/FunnelChart/{funnelStepCurve.js → curves/funnelStep.js} +32 -19
- package/FunnelChart/curves/getFunnelCurve.d.ts +3 -0
- package/FunnelChart/curves/getFunnelCurve.js +22 -0
- package/FunnelChart/curves/index.d.ts +2 -0
- package/FunnelChart/curves/index.js +27 -0
- package/FunnelChart/curves/linear.d.ts +24 -0
- package/FunnelChart/curves/linear.js +113 -0
- package/FunnelChart/funnel.types.d.ts +2 -2
- package/FunnelChart/funnelPlotSlots.types.d.ts +1 -1
- package/FunnelChart/funnelSectionClasses.d.ts +1 -1
- package/FunnelChart/index.d.ts +3 -2
- package/FunnelChart/useFunnelChartProps.d.ts +1 -1
- package/FunnelChart/useFunnelChartProps.js +7 -4
- package/Heatmap/Heatmap.js +5 -1
- package/Heatmap/HeatmapItem.js +1 -1
- package/LineChartPro/LineChartPro.js +7 -1
- package/LineChartPro/LineChartPro.plugins.d.ts +2 -1
- package/LineChartPro/LineChartPro.plugins.js +2 -1
- package/ScatterChartPro/ScatterChartPro.js +7 -1
- package/ScatterChartPro/ScatterChartPro.plugins.d.ts +2 -1
- package/ScatterChartPro/ScatterChartPro.plugins.js +2 -1
- package/esm/BarChartPro/BarChartPro.js +7 -1
- package/esm/BarChartPro/BarChartPro.plugins.d.ts +2 -1
- package/esm/BarChartPro/BarChartPro.plugins.js +2 -1
- package/esm/ChartContainerPro/ChartContainerPro.d.ts +1 -0
- package/esm/ChartContainerPro/useChartContainerProProps.d.ts +1 -1
- package/esm/ChartDataProviderPro/ChartDataProviderPro.js +11 -2
- package/esm/ChartDataProviderPro/useChartDataProviderProProps.d.ts +3 -2
- package/esm/ChartDataProviderPro/useChartDataProviderProProps.js +2 -0
- package/esm/FunnelChart/FunnelChart.js +12 -1
- package/esm/FunnelChart/FunnelPlot.d.ts +5 -0
- package/esm/FunnelChart/FunnelPlot.js +14 -17
- package/esm/FunnelChart/curves/bump.d.ts +24 -0
- package/esm/FunnelChart/curves/bump.js +75 -0
- package/esm/FunnelChart/curves/curve.types.d.ts +8 -0
- package/esm/FunnelChart/curves/curve.types.js +1 -0
- package/esm/FunnelChart/curves/funnelStep.d.ts +25 -0
- package/esm/FunnelChart/{funnelStepCurve.js → curves/funnelStep.js} +32 -19
- package/esm/FunnelChart/curves/getFunnelCurve.d.ts +3 -0
- package/esm/FunnelChart/curves/getFunnelCurve.js +15 -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 +24 -0
- package/esm/FunnelChart/curves/linear.js +106 -0
- package/esm/FunnelChart/funnel.types.d.ts +2 -2
- package/esm/FunnelChart/funnelPlotSlots.types.d.ts +1 -1
- package/esm/FunnelChart/funnelSectionClasses.d.ts +1 -1
- package/esm/FunnelChart/index.d.ts +3 -2
- package/esm/FunnelChart/useFunnelChartProps.d.ts +1 -1
- package/esm/FunnelChart/useFunnelChartProps.js +7 -4
- package/esm/Heatmap/Heatmap.js +5 -1
- package/esm/Heatmap/HeatmapItem.js +1 -1
- package/esm/LineChartPro/LineChartPro.js +7 -1
- package/esm/LineChartPro/LineChartPro.plugins.d.ts +2 -1
- package/esm/LineChartPro/LineChartPro.plugins.js +2 -1
- package/esm/ScatterChartPro/ScatterChartPro.js +7 -1
- package/esm/ScatterChartPro/ScatterChartPro.plugins.d.ts +2 -1
- package/esm/ScatterChartPro/ScatterChartPro.plugins.js +2 -1
- package/esm/index.d.ts +1 -0
- package/esm/index.js +2 -1
- package/esm/internals/plugins/allPlugins.d.ts +5 -4
- package/esm/internals/plugins/allPlugins.js +3 -2
- 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/index.d.ts +2 -0
- package/esm/internals/plugins/useChartProExport/index.js +2 -0
- package/esm/internals/plugins/useChartProExport/print.d.ts +4 -0
- package/esm/internals/plugins/useChartProExport/print.js +28 -0
- package/esm/internals/plugins/useChartProExport/useChartProExport.d.ts +3 -0
- package/esm/internals/plugins/useChartProExport/useChartProExport.js +65 -0
- package/esm/internals/plugins/useChartProExport/useChartProExport.types.d.ts +67 -0
- package/esm/internals/plugins/useChartProExport/useChartProExport.types.js +1 -0
- package/esm/internals/plugins/useChartProZoom/useChartProZoom.d.ts +2 -1
- package/esm/internals/plugins/useChartProZoom/useChartProZoom.js +54 -30
- package/esm/internals/plugins/useChartProZoom/useChartProZoom.selectors.d.ts +25 -25
- package/esm/locales/index.d.ts +1 -0
- package/esm/locales/index.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/index.d.ts +1 -0
- package/index.js +12 -1
- package/internals/plugins/allPlugins.d.ts +5 -4
- package/internals/plugins/allPlugins.js +3 -2
- 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/index.d.ts +2 -0
- package/internals/plugins/useChartProExport/index.js +27 -0
- package/internals/plugins/useChartProExport/print.d.ts +4 -0
- package/internals/plugins/useChartProExport/print.js +35 -0
- package/internals/plugins/useChartProExport/useChartProExport.d.ts +3 -0
- package/internals/plugins/useChartProExport/useChartProExport.js +73 -0
- package/internals/plugins/useChartProExport/useChartProExport.types.d.ts +67 -0
- package/internals/plugins/useChartProExport/useChartProExport.types.js +5 -0
- package/internals/plugins/useChartProZoom/useChartProZoom.d.ts +2 -1
- package/internals/plugins/useChartProZoom/useChartProZoom.js +54 -30
- package/internals/plugins/useChartProZoom/useChartProZoom.selectors.d.ts +25 -25
- package/locales/index.d.ts +1 -0
- package/locales/index.js +16 -0
- package/package.json +7 -4
- 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/FunnelChart/funnelStepCurve.d.ts +0 -4
- package/esm/FunnelChart/funnelStepCurve.d.ts +0 -4
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { ChartAnyPluginSignature, ChartSeriesType } from '@mui/x-charts/internals';
|
|
2
|
-
import type { ChartDataProviderProProps } from
|
|
3
|
-
import type { AllPluginSignatures } from
|
|
2
|
+
import type { ChartDataProviderProProps } from "./ChartDataProviderPro.js";
|
|
3
|
+
import type { AllPluginSignatures } from "../internals/plugins/allPlugins.js";
|
|
4
4
|
export declare const useChartDataProviderProProps: <TSeries extends ChartSeriesType = ChartSeriesType, TSignatures extends readonly ChartAnyPluginSignature[] = AllPluginSignatures<TSeries>>(props: ChartDataProviderProProps<TSeries, TSignatures>) => {
|
|
5
5
|
children: import("react").ReactNode;
|
|
6
|
+
localeText: Partial<import("@mui/x-charts/locales").ChartsLocaleText> | undefined;
|
|
6
7
|
chartProviderProps: import("@mui/x-charts/internals").ChartProviderProps<TSeries, TSignatures>;
|
|
7
8
|
};
|
|
@@ -4,10 +4,12 @@ import { useChartDataProviderProps } from '@mui/x-charts/internals';
|
|
|
4
4
|
export const useChartDataProviderProProps = props => {
|
|
5
5
|
const {
|
|
6
6
|
chartProviderProps,
|
|
7
|
+
localeText,
|
|
7
8
|
children
|
|
8
9
|
} = useChartDataProviderProps(props);
|
|
9
10
|
return {
|
|
10
11
|
children,
|
|
12
|
+
localeText,
|
|
11
13
|
chartProviderProps
|
|
12
14
|
};
|
|
13
15
|
};
|
|
@@ -63,6 +63,8 @@ process.env.NODE_ENV !== "production" ? FunnelChart.propTypes = {
|
|
|
63
63
|
// ----------------------------------------------------------------------
|
|
64
64
|
apiRef: PropTypes.shape({
|
|
65
65
|
current: PropTypes.shape({
|
|
66
|
+
exportAsImage: PropTypes.func.isRequired,
|
|
67
|
+
exportAsPrint: PropTypes.func.isRequired,
|
|
66
68
|
setZoomData: PropTypes.func.isRequired
|
|
67
69
|
})
|
|
68
70
|
}),
|
|
@@ -175,6 +177,11 @@ process.env.NODE_ENV !== "production" ? FunnelChart.propTypes = {
|
|
|
175
177
|
* @default false
|
|
176
178
|
*/
|
|
177
179
|
disableAxisListener: PropTypes.bool,
|
|
180
|
+
/**
|
|
181
|
+
* The gap, in pixels, between funnel sections.
|
|
182
|
+
* @default 0
|
|
183
|
+
*/
|
|
184
|
+
gap: PropTypes.number,
|
|
178
185
|
/**
|
|
179
186
|
* The height of the chart in px. If not defined, it takes the height of the parent element.
|
|
180
187
|
*/
|
|
@@ -211,6 +218,10 @@ process.env.NODE_ENV !== "production" ? FunnelChart.propTypes = {
|
|
|
211
218
|
* @default false
|
|
212
219
|
*/
|
|
213
220
|
loading: PropTypes.bool,
|
|
221
|
+
/**
|
|
222
|
+
* Localized text for chart components.
|
|
223
|
+
*/
|
|
224
|
+
localeText: PropTypes.object,
|
|
214
225
|
/**
|
|
215
226
|
* The margin between the SVG and the drawing area.
|
|
216
227
|
* It's used for leaving some space for extra information such as the x- and y-axis or legend.
|
|
@@ -227,7 +238,7 @@ process.env.NODE_ENV !== "production" ? FunnelChart.propTypes = {
|
|
|
227
238
|
* The function called for onClick events.
|
|
228
239
|
* The second argument contains information about all line/bar elements at the current mouse position.
|
|
229
240
|
* @param {MouseEvent} event The mouse event recorded on the `<svg/>` element.
|
|
230
|
-
* @param {null |
|
|
241
|
+
* @param {null | ChartsAxisData} data The data about the clicked axis and items associated with it.
|
|
231
242
|
*/
|
|
232
243
|
onAxisClick: PropTypes.func,
|
|
233
244
|
/**
|
|
@@ -2,6 +2,11 @@ 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;
|
|
5
10
|
/**
|
|
6
11
|
* Callback fired when a funnel item is clicked.
|
|
7
12
|
* @param {React.MouseEvent<SVGElement, MouseEvent>} event The event source of the callback.
|
|
@@ -1,29 +1,20 @@
|
|
|
1
1
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
2
2
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
|
-
const _excluded = ["onItemClick"];
|
|
3
|
+
const _excluded = ["onItemClick", "gap"];
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import PropTypes from 'prop-types';
|
|
6
6
|
import { line as d3Line } from '@mui/x-charts-vendor/d3-shape';
|
|
7
|
-
import {
|
|
7
|
+
import { cartesianSeriesTypes } from '@mui/x-charts/internals';
|
|
8
8
|
import { useXAxes, useYAxes } from '@mui/x-charts/hooks';
|
|
9
9
|
import { useTheme } from '@mui/material/styles';
|
|
10
10
|
import { FunnelSection } from "./FunnelSection.js";
|
|
11
11
|
import { alignLabel, positionLabel } from "./labelUtils.js";
|
|
12
|
-
import { funnelHorizontalStepCurve, funnelVerticalStepCurve } from "./funnelStepCurve.js";
|
|
13
12
|
import { useFunnelSeriesContext } from "../hooks/useFunnelSeries.js";
|
|
13
|
+
import { getFunnelCurve } from "./curves/index.js";
|
|
14
14
|
import { createElement as _createElement } from "react";
|
|
15
15
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
16
16
|
cartesianSeriesTypes.addType('funnel');
|
|
17
|
-
const
|
|
18
|
-
if (curve === 'step') {
|
|
19
|
-
return isHorizontal ? funnelHorizontalStepCurve : funnelVerticalStepCurve;
|
|
20
|
-
}
|
|
21
|
-
if (curve === 'bump') {
|
|
22
|
-
return isHorizontal ? getCurveFactory('bumpX') : getCurveFactory('bumpY');
|
|
23
|
-
}
|
|
24
|
-
return getCurveFactory(curve ?? 'linear');
|
|
25
|
-
};
|
|
26
|
-
const useAggregatedData = () => {
|
|
17
|
+
const useAggregatedData = gap => {
|
|
27
18
|
const seriesData = useFunnelSeriesContext();
|
|
28
19
|
const {
|
|
29
20
|
xAxis,
|
|
@@ -55,7 +46,7 @@ const useAggregatedData = () => {
|
|
|
55
46
|
const bandWidth = (isXAxisBand || isYAxisBand) && baseScaleConfig.scale?.bandwidth() || 0;
|
|
56
47
|
const xScale = xAxis[xAxisId].scale;
|
|
57
48
|
const yScale = yAxis[yAxisId].scale;
|
|
58
|
-
const curve = getFunnelCurve(currentSeries.curve, isHorizontal);
|
|
49
|
+
const curve = getFunnelCurve(currentSeries.curve, isHorizontal, gap);
|
|
59
50
|
const xPosition = (value, bandIndex, stackOffset, useBand) => {
|
|
60
51
|
if (isXAxisBand) {
|
|
61
52
|
const position = xScale(bandIndex);
|
|
@@ -101,16 +92,17 @@ const useAggregatedData = () => {
|
|
|
101
92
|
});
|
|
102
93
|
});
|
|
103
94
|
return result.flat();
|
|
104
|
-
}, [seriesData, xAxis, xAxisIds, yAxis, yAxisIds]);
|
|
95
|
+
}, [seriesData, xAxis, xAxisIds, yAxis, yAxisIds, gap]);
|
|
105
96
|
return allData;
|
|
106
97
|
};
|
|
107
98
|
function FunnelPlot(props) {
|
|
108
99
|
const {
|
|
109
|
-
onItemClick
|
|
100
|
+
onItemClick,
|
|
101
|
+
gap
|
|
110
102
|
} = props,
|
|
111
103
|
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
112
104
|
const theme = useTheme();
|
|
113
|
-
const data = useAggregatedData();
|
|
105
|
+
const data = useAggregatedData(gap);
|
|
114
106
|
return /*#__PURE__*/_jsxs(React.Fragment, {
|
|
115
107
|
children: [data.map(({
|
|
116
108
|
d,
|
|
@@ -164,6 +156,11 @@ process.env.NODE_ENV !== "production" ? FunnelPlot.propTypes = {
|
|
|
164
156
|
// | These PropTypes are generated from the TypeScript type definitions |
|
|
165
157
|
// | To update them edit the TypeScript types and run "pnpm proptypes" |
|
|
166
158
|
// ----------------------------------------------------------------------
|
|
159
|
+
/**
|
|
160
|
+
* The gap, in pixels, between funnel sections.
|
|
161
|
+
* @default 0
|
|
162
|
+
*/
|
|
163
|
+
gap: PropTypes.number,
|
|
167
164
|
/**
|
|
168
165
|
* Callback fired when a funnel item is clicked.
|
|
169
166
|
* @param {React.MouseEvent<SVGElement, MouseEvent>} event The event source of the callback.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { CurveGenerator } from '@mui/x-charts-vendor/d3-shape';
|
|
2
|
+
/**
|
|
3
|
+
* This is a custom "bump" curve generator.
|
|
4
|
+
*
|
|
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
|
+
* https://github.com/d3/d3-shape/blob/a82254af78f08799c71d7ab25df557c4872a3c51/src/curve/bump.js
|
|
9
|
+
*/
|
|
10
|
+
export declare class Bump implements CurveGenerator {
|
|
11
|
+
private context;
|
|
12
|
+
private line;
|
|
13
|
+
private x;
|
|
14
|
+
private y;
|
|
15
|
+
private currentPoint;
|
|
16
|
+
private isHorizontal;
|
|
17
|
+
private gap;
|
|
18
|
+
constructor(context: CanvasRenderingContext2D, isHorizontal: boolean, gap?: number);
|
|
19
|
+
areaStart(): void;
|
|
20
|
+
areaEnd(): void;
|
|
21
|
+
lineStart(): void;
|
|
22
|
+
lineEnd(): void;
|
|
23
|
+
point(x: number, y: number): void;
|
|
24
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This is a custom "bump" curve generator.
|
|
3
|
+
*
|
|
4
|
+
* It takes into account the gap between the points and draws a smooth curve between them.
|
|
5
|
+
*
|
|
6
|
+
* It is based on the d3-shape bump curve generator.
|
|
7
|
+
* https://github.com/d3/d3-shape/blob/a82254af78f08799c71d7ab25df557c4872a3c51/src/curve/bump.js
|
|
8
|
+
*/
|
|
9
|
+
export class Bump {
|
|
10
|
+
constructor(context, isHorizontal, gap = 0) {
|
|
11
|
+
this.context = void 0;
|
|
12
|
+
this.line = NaN;
|
|
13
|
+
this.x = NaN;
|
|
14
|
+
this.y = NaN;
|
|
15
|
+
this.currentPoint = 0;
|
|
16
|
+
this.isHorizontal = false;
|
|
17
|
+
this.gap = 0;
|
|
18
|
+
this.context = context;
|
|
19
|
+
this.isHorizontal = isHorizontal;
|
|
20
|
+
this.gap = gap / 2;
|
|
21
|
+
}
|
|
22
|
+
areaStart() {
|
|
23
|
+
this.line = 0;
|
|
24
|
+
}
|
|
25
|
+
areaEnd() {
|
|
26
|
+
this.line = NaN;
|
|
27
|
+
}
|
|
28
|
+
lineStart() {
|
|
29
|
+
this.currentPoint = 0;
|
|
30
|
+
}
|
|
31
|
+
lineEnd() {
|
|
32
|
+
if (this.line || this.line !== 0 && this.currentPoint === 1) {
|
|
33
|
+
this.context.closePath();
|
|
34
|
+
}
|
|
35
|
+
this.line = 1 - this.line;
|
|
36
|
+
}
|
|
37
|
+
point(x, y) {
|
|
38
|
+
x = +x;
|
|
39
|
+
y = +y;
|
|
40
|
+
|
|
41
|
+
// 0 is the top-left corner.
|
|
42
|
+
if (this.isHorizontal) {
|
|
43
|
+
if (this.currentPoint === 0) {
|
|
44
|
+
this.context.moveTo(x + this.gap, y);
|
|
45
|
+
this.context.lineTo(x + this.gap, y);
|
|
46
|
+
} else if (this.currentPoint === 1) {
|
|
47
|
+
this.context.bezierCurveTo((this.x + x) / 2, this.y, (this.x + x) / 2, y, x - this.gap, y);
|
|
48
|
+
} else if (this.currentPoint === 2) {
|
|
49
|
+
this.context.lineTo(x - this.gap, y);
|
|
50
|
+
} else {
|
|
51
|
+
this.context.bezierCurveTo((this.x + x) / 2, this.y, (this.x + x) / 2, y, x + this.gap, y);
|
|
52
|
+
}
|
|
53
|
+
this.currentPoint += 1;
|
|
54
|
+
this.x = x;
|
|
55
|
+
this.y = y;
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// 0 is the top-right corner.
|
|
60
|
+
if (this.currentPoint === 0) {
|
|
61
|
+
// X from Y
|
|
62
|
+
this.context.moveTo(x, y + this.gap);
|
|
63
|
+
this.context.lineTo(x, y + this.gap);
|
|
64
|
+
} else if (this.currentPoint === 1) {
|
|
65
|
+
this.context.bezierCurveTo(this.x, (this.y + y) / 2, x, (this.y + y) / 2, x, y - this.gap);
|
|
66
|
+
} else if (this.currentPoint === 2) {
|
|
67
|
+
this.context.lineTo(x, y - this.gap);
|
|
68
|
+
} else {
|
|
69
|
+
this.context.bezierCurveTo(this.x, (this.y + y) / 2, x, (this.y + y) / 2, x, y + this.gap);
|
|
70
|
+
}
|
|
71
|
+
this.currentPoint += 1;
|
|
72
|
+
this.x = x;
|
|
73
|
+
this.y = y;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { CurveGenerator } from '@mui/x-charts-vendor/d3-shape';
|
|
2
|
+
/**
|
|
3
|
+
* This is a custom "step" curve generator for the funnel chart.
|
|
4
|
+
* It is used to draw the funnel using "rectangles" without having to rework the rendering logic.
|
|
5
|
+
*
|
|
6
|
+
* It takes into account the gap between the points and draws a smooth curve between them.
|
|
7
|
+
*
|
|
8
|
+
* It is based on the d3-shape step curve generator.
|
|
9
|
+
* https://github.com/d3/d3-shape/blob/a82254af78f08799c71d7ab25df557c4872a3c51/src/curve/step.js
|
|
10
|
+
*/
|
|
11
|
+
export declare class FunnelStep implements CurveGenerator {
|
|
12
|
+
private context;
|
|
13
|
+
private line;
|
|
14
|
+
private x;
|
|
15
|
+
private y;
|
|
16
|
+
private currentPoint;
|
|
17
|
+
private isHorizontal;
|
|
18
|
+
private gap;
|
|
19
|
+
constructor(context: CanvasRenderingContext2D, isHorizontal: boolean, gap?: number);
|
|
20
|
+
areaStart(): void;
|
|
21
|
+
areaEnd(): void;
|
|
22
|
+
lineStart(): void;
|
|
23
|
+
lineEnd(): void;
|
|
24
|
+
point(x: number, y: number): void;
|
|
25
|
+
}
|
|
@@ -2,19 +2,23 @@
|
|
|
2
2
|
* This is a custom "step" curve generator for the funnel chart.
|
|
3
3
|
* It is used to draw the funnel using "rectangles" without having to rework the rendering logic.
|
|
4
4
|
*
|
|
5
|
+
* It takes into account the gap between the points and draws a smooth curve between them.
|
|
6
|
+
*
|
|
5
7
|
* It is based on the d3-shape step curve generator.
|
|
6
8
|
* https://github.com/d3/d3-shape/blob/a82254af78f08799c71d7ab25df557c4872a3c51/src/curve/step.js
|
|
7
9
|
*/
|
|
8
|
-
class FunnelStep {
|
|
9
|
-
constructor(context, isHorizontal) {
|
|
10
|
+
export class FunnelStep {
|
|
11
|
+
constructor(context, isHorizontal, gap = 0) {
|
|
10
12
|
this.context = void 0;
|
|
11
13
|
this.line = NaN;
|
|
12
14
|
this.x = NaN;
|
|
13
15
|
this.y = NaN;
|
|
14
16
|
this.currentPoint = 0;
|
|
15
17
|
this.isHorizontal = false;
|
|
18
|
+
this.gap = 0;
|
|
16
19
|
this.context = context;
|
|
17
20
|
this.isHorizontal = isHorizontal;
|
|
21
|
+
this.gap = gap / 2;
|
|
18
22
|
}
|
|
19
23
|
areaStart() {
|
|
20
24
|
this.line = 0;
|
|
@@ -41,27 +45,36 @@ class FunnelStep {
|
|
|
41
45
|
point(x, y) {
|
|
42
46
|
x = +x;
|
|
43
47
|
y = +y;
|
|
48
|
+
|
|
49
|
+
// 0 is the top-left corner.
|
|
50
|
+
if (this.isHorizontal) {
|
|
51
|
+
if (this.currentPoint === 0) {
|
|
52
|
+
this.context.moveTo(x + this.gap, y);
|
|
53
|
+
} else if (this.currentPoint === 1 || this.currentPoint === 2) {
|
|
54
|
+
this.context.lineTo(x - this.gap, this.y);
|
|
55
|
+
this.context.lineTo(x - this.gap, y);
|
|
56
|
+
} else {
|
|
57
|
+
this.context.lineTo(this.x - this.gap, y);
|
|
58
|
+
this.context.lineTo(x + this.gap, y);
|
|
59
|
+
}
|
|
60
|
+
this.currentPoint += 1;
|
|
61
|
+
this.x = x;
|
|
62
|
+
this.y = y;
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// 0 is the top-right corner.
|
|
44
67
|
if (this.currentPoint === 0) {
|
|
45
|
-
this.context.moveTo(x, y);
|
|
46
|
-
} else if (this.
|
|
47
|
-
this.context.lineTo(x, this.y);
|
|
48
|
-
this.context.lineTo(x, y);
|
|
49
|
-
} else if (this.currentPoint === 3 && !this.isHorizontal) {
|
|
50
|
-
this.context.lineTo(x, this.y);
|
|
51
|
-
this.context.lineTo(x, y);
|
|
68
|
+
this.context.moveTo(x, y + this.gap);
|
|
69
|
+
} else if (this.currentPoint === 3) {
|
|
70
|
+
this.context.lineTo(x, this.y - this.gap);
|
|
71
|
+
this.context.lineTo(x, y + this.gap);
|
|
52
72
|
} else {
|
|
53
|
-
this.context.lineTo(this.x, y);
|
|
54
|
-
this.context.lineTo(x, y);
|
|
73
|
+
this.context.lineTo(this.x, y - this.gap);
|
|
74
|
+
this.context.lineTo(x, y - this.gap);
|
|
55
75
|
}
|
|
56
76
|
this.currentPoint += 1;
|
|
57
77
|
this.x = x;
|
|
58
78
|
this.y = y;
|
|
59
79
|
}
|
|
60
|
-
}
|
|
61
|
-
const funnelHorizontalStepCurve = context => {
|
|
62
|
-
return new FunnelStep(context, true);
|
|
63
|
-
};
|
|
64
|
-
const funnelVerticalStepCurve = context => {
|
|
65
|
-
return new FunnelStep(context, false);
|
|
66
|
-
};
|
|
67
|
-
export { funnelHorizontalStepCurve, funnelVerticalStepCurve };
|
|
80
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { FunnelStep } from "./funnelStep.js";
|
|
2
|
+
import { Linear } from "./linear.js";
|
|
3
|
+
import { Bump } from "./bump.js";
|
|
4
|
+
const curveConstructor = curve => {
|
|
5
|
+
if (curve === 'step') {
|
|
6
|
+
return FunnelStep;
|
|
7
|
+
}
|
|
8
|
+
if (curve === 'bump') {
|
|
9
|
+
return Bump;
|
|
10
|
+
}
|
|
11
|
+
return Linear;
|
|
12
|
+
};
|
|
13
|
+
export const getFunnelCurve = (curve, isHorizontal, gap = 0) => {
|
|
14
|
+
return context => new (curveConstructor(curve))(context, isHorizontal, gap);
|
|
15
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { CurveGenerator } from '@mui/x-charts-vendor/d3-shape';
|
|
2
|
+
/**
|
|
3
|
+
* This is a custom "linear" curve generator.
|
|
4
|
+
*
|
|
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
|
+
* https://github.com/d3/d3-shape/blob/a82254af78f08799c71d7ab25df557c4872a3c51/src/curve/linear.js
|
|
9
|
+
*/
|
|
10
|
+
export declare class Linear implements CurveGenerator {
|
|
11
|
+
private context;
|
|
12
|
+
private line;
|
|
13
|
+
private x;
|
|
14
|
+
private y;
|
|
15
|
+
private currentPoint;
|
|
16
|
+
private isHorizontal;
|
|
17
|
+
private gap;
|
|
18
|
+
constructor(context: CanvasRenderingContext2D, isHorizontal: boolean, gap?: number);
|
|
19
|
+
areaStart(): void;
|
|
20
|
+
areaEnd(): void;
|
|
21
|
+
lineStart(): void;
|
|
22
|
+
lineEnd(): void;
|
|
23
|
+
point(x: number, y: number): void;
|
|
24
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
// From point1 to point2, get the x value from y
|
|
2
|
+
const xFromY = (x1, y1, x2, y2) => y => {
|
|
3
|
+
if (y1 === y2) {
|
|
4
|
+
return x1;
|
|
5
|
+
}
|
|
6
|
+
const result = (x2 - x1) * (y - y1) / (y2 - y1) + x1;
|
|
7
|
+
return Number.isNaN(result) ? 0 : result;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
// From point1 to point2, get the y value from x
|
|
11
|
+
const yFromX = (x1, y1, x2, y2) => x => {
|
|
12
|
+
if (x1 === x2) {
|
|
13
|
+
return y1;
|
|
14
|
+
}
|
|
15
|
+
const result = (y2 - y1) * (x - x1) / (x2 - x1) + y1;
|
|
16
|
+
return Number.isNaN(result) ? 0 : result;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* This is a custom "linear" curve generator.
|
|
21
|
+
*
|
|
22
|
+
* It takes into account the gap between the points and draws a smooth curve between them.
|
|
23
|
+
*
|
|
24
|
+
* It is based on the d3-shape linear curve generator.
|
|
25
|
+
* https://github.com/d3/d3-shape/blob/a82254af78f08799c71d7ab25df557c4872a3c51/src/curve/linear.js
|
|
26
|
+
*/
|
|
27
|
+
export class Linear {
|
|
28
|
+
constructor(context, isHorizontal, gap = 0) {
|
|
29
|
+
this.context = void 0;
|
|
30
|
+
this.line = NaN;
|
|
31
|
+
this.x = NaN;
|
|
32
|
+
this.y = NaN;
|
|
33
|
+
this.currentPoint = 0;
|
|
34
|
+
this.isHorizontal = false;
|
|
35
|
+
this.gap = 0;
|
|
36
|
+
this.context = context;
|
|
37
|
+
this.isHorizontal = isHorizontal;
|
|
38
|
+
this.gap = gap / 2;
|
|
39
|
+
}
|
|
40
|
+
areaStart() {
|
|
41
|
+
this.line = 0;
|
|
42
|
+
}
|
|
43
|
+
areaEnd() {
|
|
44
|
+
this.line = NaN;
|
|
45
|
+
}
|
|
46
|
+
lineStart() {
|
|
47
|
+
this.currentPoint = 0;
|
|
48
|
+
}
|
|
49
|
+
lineEnd() {
|
|
50
|
+
if (this.line || this.line !== 0 && this.currentPoint === 1) {
|
|
51
|
+
this.context.closePath();
|
|
52
|
+
}
|
|
53
|
+
this.line = 1 - this.line;
|
|
54
|
+
}
|
|
55
|
+
point(x, y) {
|
|
56
|
+
x = +x;
|
|
57
|
+
y = +y;
|
|
58
|
+
|
|
59
|
+
// We draw the lines only at currentPoint 1 & 3 because we need
|
|
60
|
+
// The data of a pair of points to draw the lines.
|
|
61
|
+
// Hence currentPoint 1 draws a line from point 0 to point 1 and point 1 to point 2.
|
|
62
|
+
// currentPoint 3 draws a line from point 2 to point 3 and point 3 to point 0.
|
|
63
|
+
|
|
64
|
+
if (this.isHorizontal) {
|
|
65
|
+
const yGetter = yFromX(this.x, this.y, x, y);
|
|
66
|
+
let xGap = 0;
|
|
67
|
+
|
|
68
|
+
// 0 is the top-left corner.
|
|
69
|
+
if (this.currentPoint === 1) {
|
|
70
|
+
xGap = this.x + this.gap;
|
|
71
|
+
this.context.moveTo(xGap, yGetter(xGap));
|
|
72
|
+
this.context.lineTo(xGap, yGetter(xGap));
|
|
73
|
+
xGap = x - this.gap;
|
|
74
|
+
this.context.lineTo(xGap, yGetter(xGap));
|
|
75
|
+
} else if (this.currentPoint === 3) {
|
|
76
|
+
xGap = this.x - this.gap;
|
|
77
|
+
this.context.lineTo(xGap, yGetter(xGap));
|
|
78
|
+
xGap = x + this.gap;
|
|
79
|
+
this.context.lineTo(xGap, yGetter(xGap));
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (!this.isHorizontal) {
|
|
83
|
+
const xGetter = xFromY(this.x, this.y, x, y);
|
|
84
|
+
let yGap = 0;
|
|
85
|
+
|
|
86
|
+
// 0 is the top-right corner.
|
|
87
|
+
if (this.currentPoint === 1) {
|
|
88
|
+
yGap = this.y + this.gap;
|
|
89
|
+
this.context.moveTo(xGetter(yGap), yGap);
|
|
90
|
+
this.context.lineTo(xGetter(yGap), yGap);
|
|
91
|
+
yGap = y - this.gap;
|
|
92
|
+
this.context.lineTo(xGetter(yGap), yGap);
|
|
93
|
+
} else if (this.currentPoint === 3) {
|
|
94
|
+
yGap = this.y - this.gap;
|
|
95
|
+
this.context.lineTo(xGetter(yGap), yGap);
|
|
96
|
+
yGap = y + this.gap;
|
|
97
|
+
this.context.lineTo(xGetter(yGap), yGap);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Increment the values
|
|
102
|
+
this.currentPoint += 1;
|
|
103
|
+
this.x = x;
|
|
104
|
+
this.y = y;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
@@ -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.
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
export { FunnelChart as Unstable_FunnelChart } from "./FunnelChart.js";
|
|
2
|
-
export type { FunnelChartProps } from
|
|
2
|
+
export type { FunnelChartProps } from "./FunnelChart.js";
|
|
3
3
|
export * from "./FunnelPlot.js";
|
|
4
4
|
export * from "./funnel.types.js";
|
|
5
5
|
export * from "./categoryAxis.types.js";
|
|
6
6
|
export * from "./funnelSlots.types.js";
|
|
7
|
+
export type { FunnelCurveType } from "./curves/index.js";
|
|
7
8
|
export { funnelSectionClasses } from "./funnelSectionClasses.js";
|
|
8
|
-
export type { FunnelSectionClasses } from
|
|
9
|
+
export type { FunnelSectionClasses } from "./funnelSectionClasses.js";
|
|
@@ -5,7 +5,7 @@ import { ChartsClipPathProps } from '@mui/x-charts/ChartsClipPath';
|
|
|
5
5
|
import { ChartsWrapperProps } from '@mui/x-charts/internals';
|
|
6
6
|
import { ChartsAxisHighlightProps } from '@mui/x-charts/ChartsAxisHighlight';
|
|
7
7
|
import { FunnelPlotProps } from "./FunnelPlot.js";
|
|
8
|
-
import type { FunnelChartProps } from
|
|
8
|
+
import type { FunnelChartProps } from "./FunnelChart.js";
|
|
9
9
|
import { ChartContainerProProps } from "../ChartContainerPro/index.js";
|
|
10
10
|
/**
|
|
11
11
|
* A helper function that extracts FunnelChartProps from the input props
|
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
4
4
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
5
|
-
const _excluded = ["categoryAxis", "series", "width", "height", "margin", "colors", "sx", "children", "slots", "slotProps", "skipAnimation", "loading", "onItemClick", "highlightedItem", "onHighlightChange", "className", "hideLegend", "axisHighlight", "apiRef"];
|
|
5
|
+
const _excluded = ["categoryAxis", "series", "width", "height", "margin", "colors", "sx", "children", "slots", "slotProps", "skipAnimation", "loading", "onItemClick", "highlightedItem", "onHighlightChange", "className", "hideLegend", "axisHighlight", "apiRef", "gap"];
|
|
6
6
|
import { DEFAULT_MARGINS, DEFAULT_X_AXIS_KEY, DEFAULT_Y_AXIS_KEY } from '@mui/x-charts/constants';
|
|
7
7
|
import useId from '@mui/utils/useId';
|
|
8
8
|
import { defaultizeMargin } from '@mui/x-charts/internals';
|
|
9
9
|
import { warnOnce } from '@mui/x-internals/warning';
|
|
10
|
+
import { strawberrySkyPalette } from '@mui/x-charts/colorPalettes';
|
|
10
11
|
function getCategoryAxisConfig(categoryAxis, series, isHorizontal, direction) {
|
|
11
12
|
const maxSeriesLength = Math.max(...series.map(s => (s.data ?? []).length), 0);
|
|
12
13
|
const maxSeriesValue = Array.from({
|
|
@@ -14,7 +15,7 @@ function getCategoryAxisConfig(categoryAxis, series, isHorizontal, direction) {
|
|
|
14
15
|
}, (_, index) => series.reduce((a, s) => a + (s.data?.[index]?.value ?? 0), 0));
|
|
15
16
|
if (process.env.NODE_ENV !== 'production') {
|
|
16
17
|
if ((categoryAxis?.position === 'left' || categoryAxis?.position === 'right') && isHorizontal || (categoryAxis?.position === 'top' || categoryAxis?.position === 'bottom') && !isHorizontal) {
|
|
17
|
-
warnOnce([`MUI X: the categoryAxis position is set to '${categoryAxis.position}' but the series layout is ${isHorizontal ? 'horizontal' : 'vertical'}.`, `Ensure that the categoryAxis position is set to '${isHorizontal ? 'top' : 'left'}' or '${isHorizontal ? 'bottom' : 'right'}' for ${isHorizontal ? 'horizontal' : 'vertical'} layout.\n`], 'warning');
|
|
18
|
+
warnOnce([`MUI X Charts: the categoryAxis position is set to '${categoryAxis.position}' but the series layout is ${isHorizontal ? 'horizontal' : 'vertical'}.`, `Ensure that the categoryAxis position is set to '${isHorizontal ? 'top' : 'left'}' or '${isHorizontal ? 'bottom' : 'right'}' for ${isHorizontal ? 'horizontal' : 'vertical'} layout.\n`], 'warning');
|
|
18
19
|
}
|
|
19
20
|
}
|
|
20
21
|
const side = isHorizontal ? 'bottom' : 'left';
|
|
@@ -84,7 +85,8 @@ export const useFunnelChartProps = props => {
|
|
|
84
85
|
onHighlightChange,
|
|
85
86
|
className,
|
|
86
87
|
axisHighlight,
|
|
87
|
-
apiRef
|
|
88
|
+
apiRef,
|
|
89
|
+
gap
|
|
88
90
|
} = props,
|
|
89
91
|
rest = _objectWithoutPropertiesLoose(props, _excluded);
|
|
90
92
|
const margin = defaultizeMargin(marginProps, DEFAULT_MARGINS);
|
|
@@ -107,7 +109,7 @@ export const useFunnelChartProps = props => {
|
|
|
107
109
|
width,
|
|
108
110
|
height,
|
|
109
111
|
margin,
|
|
110
|
-
colors,
|
|
112
|
+
colors: colors ?? strawberrySkyPalette,
|
|
111
113
|
xAxis: [xAxis],
|
|
112
114
|
yAxis: [yAxis],
|
|
113
115
|
sx,
|
|
@@ -117,6 +119,7 @@ export const useFunnelChartProps = props => {
|
|
|
117
119
|
apiRef
|
|
118
120
|
});
|
|
119
121
|
const funnelPlotProps = {
|
|
122
|
+
gap,
|
|
120
123
|
onItemClick,
|
|
121
124
|
slots,
|
|
122
125
|
slotProps
|
package/esm/Heatmap/Heatmap.js
CHANGED
|
@@ -167,6 +167,10 @@ process.env.NODE_ENV !== "production" ? Heatmap.propTypes = {
|
|
|
167
167
|
* @default false
|
|
168
168
|
*/
|
|
169
169
|
loading: PropTypes.bool,
|
|
170
|
+
/**
|
|
171
|
+
* Localized text for chart components.
|
|
172
|
+
*/
|
|
173
|
+
localeText: PropTypes.object,
|
|
170
174
|
/**
|
|
171
175
|
* The margin between the SVG and the drawing area.
|
|
172
176
|
* It's used for leaving some space for extra information such as the x- and y-axis or legend.
|
|
@@ -183,7 +187,7 @@ process.env.NODE_ENV !== "production" ? Heatmap.propTypes = {
|
|
|
183
187
|
* The function called for onClick events.
|
|
184
188
|
* The second argument contains information about all line/bar elements at the current mouse position.
|
|
185
189
|
* @param {MouseEvent} event The mouse event recorded on the `<svg/>` element.
|
|
186
|
-
* @param {null |
|
|
190
|
+
* @param {null | ChartsAxisData} data The data about the clicked axis and items associated with it.
|
|
187
191
|
*/
|
|
188
192
|
onAxisClick: PropTypes.func,
|
|
189
193
|
/**
|