@mui/x-charts-pro 8.5.2 → 8.5.3
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/CHANGELOG.md +96 -11
- package/ChartDataProviderPro/ChartDataProviderPro.js +1 -1
- package/ChartZoomSlider/internals/ChartAxisZoomSlider.js +1 -1
- package/ChartZoomSlider/internals/ChartAxisZoomSliderActiveTrack.js +20 -31
- package/ChartZoomSlider/internals/ChartAxisZoomSliderTrack.js +1 -8
- package/ChartZoomSlider/internals/zoom-utils.d.ts +3 -1
- package/ChartZoomSlider/internals/zoom-utils.js +19 -8
- package/FunnelChart/FunnelPlot.js +56 -40
- package/FunnelChart/FunnelSection.js +2 -0
- package/FunnelChart/curves/bump.d.ts +3 -3
- package/FunnelChart/curves/bump.js +3 -0
- package/FunnelChart/curves/curve.types.d.ts +14 -1
- package/FunnelChart/curves/getFunnelCurve.d.ts +7 -2
- package/FunnelChart/curves/linear.d.ts +3 -3
- package/FunnelChart/curves/linear.js +23 -18
- package/FunnelChart/curves/pyramid.d.ts +3 -3
- package/FunnelChart/curves/pyramid.js +17 -12
- package/FunnelChart/curves/step-pyramid.d.ts +5 -5
- package/FunnelChart/curves/step-pyramid.js +20 -18
- package/FunnelChart/curves/step.d.ts +3 -3
- package/FunnelChart/curves/step.js +14 -12
- package/FunnelChart/funnelAxisPlugin/useChartFunnelAxisRendering.selectors.d.ts +18 -1444
- package/FunnelChart/labelUtils.d.ts +4 -12
- package/FunnelChart/labelUtils.js +43 -44
- package/esm/ChartDataProviderPro/ChartDataProviderPro.js +1 -1
- package/esm/ChartZoomSlider/internals/ChartAxisZoomSlider.js +1 -1
- package/esm/ChartZoomSlider/internals/ChartAxisZoomSliderActiveTrack.js +21 -32
- package/esm/ChartZoomSlider/internals/ChartAxisZoomSliderTrack.js +1 -8
- package/esm/ChartZoomSlider/internals/zoom-utils.d.ts +3 -1
- package/esm/ChartZoomSlider/internals/zoom-utils.js +19 -9
- package/esm/FunnelChart/FunnelPlot.js +56 -40
- package/esm/FunnelChart/FunnelSection.js +2 -0
- package/esm/FunnelChart/curves/bump.d.ts +3 -3
- package/esm/FunnelChart/curves/bump.js +3 -0
- package/esm/FunnelChart/curves/curve.types.d.ts +14 -1
- package/esm/FunnelChart/curves/getFunnelCurve.d.ts +7 -2
- package/esm/FunnelChart/curves/linear.d.ts +3 -3
- package/esm/FunnelChart/curves/linear.js +23 -18
- package/esm/FunnelChart/curves/pyramid.d.ts +3 -3
- package/esm/FunnelChart/curves/pyramid.js +17 -12
- package/esm/FunnelChart/curves/step-pyramid.d.ts +5 -5
- package/esm/FunnelChart/curves/step-pyramid.js +20 -18
- package/esm/FunnelChart/curves/step.d.ts +3 -3
- package/esm/FunnelChart/curves/step.js +14 -12
- package/esm/FunnelChart/funnelAxisPlugin/useChartFunnelAxisRendering.selectors.d.ts +18 -1444
- package/esm/FunnelChart/labelUtils.d.ts +4 -12
- package/esm/FunnelChart/labelUtils.js +43 -44
- package/esm/index.js +1 -1
- package/esm/internals/plugins/useChartProZoom/useChartProZoom.selectors.d.ts +16 -595
- package/esm/internals/plugins/useChartProZoom/useChartProZoom.selectors.js +2 -2
- package/index.js +1 -1
- package/internals/plugins/useChartProZoom/useChartProZoom.selectors.d.ts +16 -595
- package/internals/plugins/useChartProZoom/useChartProZoom.selectors.js +2 -2
- package/package.json +5 -5
- package/FunnelChart/positionGetter.d.ts +0 -1
- package/FunnelChart/positionGetter.js +0 -5
- package/esm/FunnelChart/positionGetter.d.ts +0 -1
- package/esm/FunnelChart/positionGetter.js +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { FunnelLabelOptions } from "./funnel.types.js";
|
|
2
|
+
import { Point } from "./curves/index.js";
|
|
3
3
|
/**
|
|
4
4
|
* It tries to keep the label inside the bounds of the section based on the position.
|
|
5
5
|
*
|
|
@@ -24,19 +24,11 @@ export declare const alignLabel: ({
|
|
|
24
24
|
export declare const positionLabel: ({
|
|
25
25
|
position,
|
|
26
26
|
offset,
|
|
27
|
-
xPosition,
|
|
28
|
-
yPosition,
|
|
29
27
|
isHorizontal,
|
|
30
|
-
values
|
|
31
|
-
dataIndex,
|
|
32
|
-
baseScaleData
|
|
28
|
+
values
|
|
33
29
|
}: Omit<FunnelLabelOptions, "textAnchor" | "dominantBaseline"> & {
|
|
34
|
-
xPosition: PositionGetter;
|
|
35
|
-
yPosition: PositionGetter;
|
|
36
30
|
isHorizontal: boolean;
|
|
37
|
-
values: readonly
|
|
38
|
-
dataIndex: number;
|
|
39
|
-
baseScaleData: readonly number[];
|
|
31
|
+
values: readonly Point[];
|
|
40
32
|
}) => {
|
|
41
33
|
x: number;
|
|
42
34
|
y: number;
|
|
@@ -46,17 +46,21 @@ exports.alignLabel = alignLabel;
|
|
|
46
46
|
const positionLabel = ({
|
|
47
47
|
position,
|
|
48
48
|
offset,
|
|
49
|
-
xPosition,
|
|
50
|
-
yPosition,
|
|
51
49
|
isHorizontal,
|
|
52
|
-
values
|
|
53
|
-
dataIndex,
|
|
54
|
-
baseScaleData
|
|
50
|
+
values
|
|
55
51
|
}) => {
|
|
56
52
|
const vertical = position?.vertical ?? 'middle';
|
|
57
53
|
const horizontal = position?.horizontal ?? 'center';
|
|
58
54
|
let x = 0;
|
|
59
55
|
let y = 0;
|
|
56
|
+
|
|
57
|
+
// The min/max values are due to the sections possibly being sloped.
|
|
58
|
+
// Importance of values differs from the horizontal and vertical sections.
|
|
59
|
+
// Example (vertical):
|
|
60
|
+
// MaxL MaxT MaxR
|
|
61
|
+
// \ /
|
|
62
|
+
// \ /
|
|
63
|
+
// MinL MaxB MinR
|
|
60
64
|
let minTop = 0;
|
|
61
65
|
let maxTop = 0;
|
|
62
66
|
let minBottom = 0;
|
|
@@ -65,56 +69,51 @@ const positionLabel = ({
|
|
|
65
69
|
let maxLeft = 0;
|
|
66
70
|
let minRight = 0;
|
|
67
71
|
let maxRight = 0;
|
|
68
|
-
let center = 0;
|
|
69
|
-
let leftCenter = 0;
|
|
70
|
-
let rightCenter = 0;
|
|
71
72
|
let middle = 0;
|
|
72
|
-
let
|
|
73
|
-
let bottomMiddle = 0;
|
|
73
|
+
let center = 0;
|
|
74
74
|
const mv = typeof offset === 'number' ? offset : offset?.y ?? 0;
|
|
75
75
|
const mh = typeof offset === 'number' ? offset : offset?.x ?? 0;
|
|
76
|
-
|
|
76
|
+
|
|
77
|
+
// Min ... Max
|
|
78
|
+
const Ys = values.map(v => v.y).toSorted((a, b) => a - b);
|
|
79
|
+
const Xs = values.map(v => v.x).toSorted((a, b) => a - b);
|
|
80
|
+
|
|
81
|
+
// Visualization of the points in a hierarchical order:
|
|
82
|
+
// MaxT
|
|
83
|
+
// MinT
|
|
84
|
+
// MaxL MinL Cent/Mid MinR MaxR
|
|
85
|
+
// MinB
|
|
86
|
+
// MaxB
|
|
77
87
|
if (isHorizontal) {
|
|
78
|
-
maxTop =
|
|
79
|
-
minTop =
|
|
80
|
-
minBottom =
|
|
81
|
-
maxBottom =
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
leftCenter = 0;
|
|
88
|
-
rightCenter = 0;
|
|
89
|
-
middle = yPosition(0, dataIndex, baseScaleData[dataIndex], stackOffset) - mv;
|
|
90
|
-
topMiddle = yPosition(values[0].y - (values[0].y - values[1].y) / 2, dataIndex, baseScaleData[dataIndex], stackOffset) - mv;
|
|
91
|
-
bottomMiddle = yPosition(values[3].y - (values[3].y - values[2].y) / 2, dataIndex, baseScaleData[dataIndex], stackOffset) + mv;
|
|
88
|
+
maxTop = Ys.at(0) - mv;
|
|
89
|
+
minTop = Ys.at(1) - mv;
|
|
90
|
+
minBottom = Ys.at(2) + mv;
|
|
91
|
+
maxBottom = (Ys.at(3) ?? Ys.at(2)) + mv;
|
|
92
|
+
maxRight = (Xs.at(3) ?? Xs.at(2)) + mh;
|
|
93
|
+
// We don't need (minRight/minLeft) for horizontal
|
|
94
|
+
maxLeft = Xs.at(0) + mh;
|
|
95
|
+
center = (maxRight + maxLeft) / 2;
|
|
96
|
+
middle = (maxBottom + maxTop) / 2;
|
|
92
97
|
} else {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
rightCenter = xPosition(values[0].x - (values[0].x - values[1].x) / 2, dataIndex, baseScaleData[dataIndex], stackOffset) + mh;
|
|
103
|
-
leftCenter = xPosition(values[3].x - (values[3].x - values[2].x) / 2, dataIndex, baseScaleData[dataIndex], stackOffset) - mh;
|
|
104
|
-
middle = yPosition(values[0].y - (values[0].y - values[1].y) / 2, dataIndex, baseScaleData[dataIndex], stackOffset);
|
|
105
|
-
middle = maxTop - (maxTop - maxBottom) / 2;
|
|
106
|
-
topMiddle = 0;
|
|
107
|
-
bottomMiddle = 0;
|
|
98
|
+
maxTop = Ys.at(0) - mv;
|
|
99
|
+
// We don't need (minTop/minBottom) for vertical
|
|
100
|
+
maxBottom = (Ys.at(3) ?? Ys.at(2)) - mv;
|
|
101
|
+
maxRight = (Xs.at(3) ?? Xs.at(2)) + mh;
|
|
102
|
+
minRight = Xs.at(2) + mh;
|
|
103
|
+
minLeft = Xs.at(1) - mh;
|
|
104
|
+
maxLeft = Xs.at(0) - mh;
|
|
105
|
+
center = (maxRight + maxLeft) / 2;
|
|
106
|
+
middle = (maxBottom + maxTop) / 2;
|
|
108
107
|
}
|
|
109
108
|
if (isHorizontal) {
|
|
110
109
|
if (horizontal === 'center') {
|
|
111
110
|
x = center;
|
|
112
111
|
if (vertical === 'top') {
|
|
113
|
-
y =
|
|
112
|
+
y = (maxTop + minTop) / 2;
|
|
114
113
|
} else if (vertical === 'middle') {
|
|
115
114
|
y = middle;
|
|
116
115
|
} else if (vertical === 'bottom') {
|
|
117
|
-
y =
|
|
116
|
+
y = (maxBottom + minBottom) / 2;
|
|
118
117
|
}
|
|
119
118
|
} else if (horizontal === 'start') {
|
|
120
119
|
x = maxLeft;
|
|
@@ -140,11 +139,11 @@ const positionLabel = ({
|
|
|
140
139
|
if (vertical === 'middle') {
|
|
141
140
|
y = middle;
|
|
142
141
|
if (horizontal === 'start') {
|
|
143
|
-
x =
|
|
142
|
+
x = (maxLeft + minLeft) / 2;
|
|
144
143
|
} else if (horizontal === 'center') {
|
|
145
144
|
x = center;
|
|
146
145
|
} else if (horizontal === 'end') {
|
|
147
|
-
x =
|
|
146
|
+
x = (maxRight + minRight) / 2;
|
|
148
147
|
}
|
|
149
148
|
} else if (vertical === 'top') {
|
|
150
149
|
y = maxTop;
|
|
@@ -11,7 +11,7 @@ import { defaultSlotsMaterial } from "../internals/material/index.js";
|
|
|
11
11
|
import { DEFAULT_PLUGINS } from "../internals/plugins/allPlugins.js";
|
|
12
12
|
import { useChartDataProviderProProps } from "./useChartDataProviderProProps.js";
|
|
13
13
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
|
-
const releaseInfo = "
|
|
14
|
+
const releaseInfo = "MTc1MDI4NDAwMDAwMA==";
|
|
15
15
|
const packageIdentifier = 'x-charts-pro';
|
|
16
16
|
/**
|
|
17
17
|
* Orchestrates the data providers for the chart components and hooks.
|
|
@@ -18,7 +18,7 @@ export function ChartAxisZoomSlider({
|
|
|
18
18
|
}) {
|
|
19
19
|
const store = useStore();
|
|
20
20
|
const drawingArea = useDrawingArea();
|
|
21
|
-
const zoomData = useSelector(store, selectorChartAxisZoomData, axisId);
|
|
21
|
+
const zoomData = useSelector(store, selectorChartAxisZoomData, [axisId]);
|
|
22
22
|
const [showTooltip, setShowTooltip] = React.useState(false);
|
|
23
23
|
const {
|
|
24
24
|
xAxis
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import { styled } from '@mui/material/styles';
|
|
3
|
-
import { getSVGPoint, invertScale, selectorChartAxis, selectorChartAxisZoomOptionsLookup,
|
|
3
|
+
import { getSVGPoint, invertScale, selectorChartAxis, selectorChartAxisZoomOptionsLookup, useChartContext, useDrawingArea, useSelector, useStore } from '@mui/x-charts/internals';
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import { rafThrottle } from '@mui/x-internals/rafThrottle';
|
|
6
6
|
import { selectorChartAxisZoomData } from "../../internals/plugins/useChartProZoom/index.js";
|
|
@@ -32,7 +32,7 @@ export function ChartAxisZoomSliderActiveTrack({
|
|
|
32
32
|
svgRef
|
|
33
33
|
} = useChartContext();
|
|
34
34
|
const store = useStore();
|
|
35
|
-
const axis = useSelector(store, selectorChartAxis, axisId);
|
|
35
|
+
const axis = useSelector(store, selectorChartAxis, [axisId]);
|
|
36
36
|
const drawingArea = useDrawingArea();
|
|
37
37
|
const activePreviewRectRef = React.useRef(null);
|
|
38
38
|
const [startThumbEl, setStartThumbEl] = React.useState(null);
|
|
@@ -48,10 +48,6 @@ export function ChartAxisZoomSliderActiveTrack({
|
|
|
48
48
|
if (!activePreviewRect) {
|
|
49
49
|
return;
|
|
50
50
|
}
|
|
51
|
-
|
|
52
|
-
/* min and max values of zoom to ensure the pointer anchor in the slider is maintained */
|
|
53
|
-
let pointerZoomMin;
|
|
54
|
-
let pointerZoomMax;
|
|
55
51
|
let prevPointerZoom = 0;
|
|
56
52
|
const onPointerMove = rafThrottle(event => {
|
|
57
53
|
const element = svgRef.current;
|
|
@@ -59,11 +55,10 @@ export function ChartAxisZoomSliderActiveTrack({
|
|
|
59
55
|
return;
|
|
60
56
|
}
|
|
61
57
|
const point = getSVGPoint(element, event);
|
|
62
|
-
|
|
58
|
+
const pointerZoom = calculateZoomFromPoint(store.getSnapshot(), axisId, point);
|
|
63
59
|
if (pointerZoom === null) {
|
|
64
60
|
return;
|
|
65
61
|
}
|
|
66
|
-
pointerZoom = Math.max(pointerZoomMin, Math.min(pointerZoomMax, pointerZoom));
|
|
67
62
|
const deltaZoom = pointerZoom - prevPointerZoom;
|
|
68
63
|
prevPointerZoom = pointerZoom;
|
|
69
64
|
instance.moveZoomRange(axisId, deltaZoom);
|
|
@@ -87,8 +82,6 @@ export function ChartAxisZoomSliderActiveTrack({
|
|
|
87
82
|
return;
|
|
88
83
|
}
|
|
89
84
|
prevPointerZoom = pointerDownZoom;
|
|
90
|
-
pointerZoomMin = pointerDownZoom - axisZoomData.start;
|
|
91
|
-
pointerZoomMax = 100 - (axisZoomData.end - pointerDownZoom);
|
|
92
85
|
document.addEventListener('pointerup', onPointerUp);
|
|
93
86
|
activePreviewRect.addEventListener('pointermove', onPointerMove);
|
|
94
87
|
};
|
|
@@ -129,23 +122,12 @@ export function ChartAxisZoomSliderActiveTrack({
|
|
|
129
122
|
}
|
|
130
123
|
const point = getSVGPoint(element, event);
|
|
131
124
|
instance.setZoomData(prevZoomData => {
|
|
132
|
-
const {
|
|
133
|
-
left,
|
|
134
|
-
top,
|
|
135
|
-
width,
|
|
136
|
-
height
|
|
137
|
-
} = selectorChartDrawingArea(store.getSnapshot());
|
|
138
125
|
const zoomOptions = selectorChartAxisZoomOptionsLookup(store.getSnapshot(), axisId);
|
|
139
126
|
return prevZoomData.map(zoom => {
|
|
140
127
|
if (zoom.axisId === axisId) {
|
|
141
|
-
|
|
142
|
-
if (
|
|
143
|
-
|
|
144
|
-
} else {
|
|
145
|
-
newEnd = (top + height - point.y) / height * 100;
|
|
146
|
-
}
|
|
147
|
-
if (reverse) {
|
|
148
|
-
newEnd = 100 - newEnd;
|
|
128
|
+
const newEnd = calculateZoomFromPoint(store.getSnapshot(), axisId, point);
|
|
129
|
+
if (newEnd === null) {
|
|
130
|
+
return zoom;
|
|
149
131
|
}
|
|
150
132
|
return _extends({}, zoom, {
|
|
151
133
|
end: calculateZoomEnd(newEnd, zoom, zoomOptions)
|
|
@@ -163,14 +145,21 @@ export function ChartAxisZoomSliderActiveTrack({
|
|
|
163
145
|
let startThumbY;
|
|
164
146
|
let endThumbX;
|
|
165
147
|
let endThumbY;
|
|
148
|
+
const {
|
|
149
|
+
minStart,
|
|
150
|
+
maxEnd
|
|
151
|
+
} = selectorChartAxisZoomOptionsLookup(store.getSnapshot(), axisId);
|
|
152
|
+
const range = maxEnd - minStart;
|
|
153
|
+
const zoomStart = Math.max(minStart, zoomData.start);
|
|
154
|
+
const zoomEnd = Math.min(zoomData.end, maxEnd);
|
|
166
155
|
if (axisDirection === 'x') {
|
|
167
|
-
previewX =
|
|
156
|
+
previewX = (zoomStart - minStart) / range * drawingArea.width;
|
|
168
157
|
previewY = 0;
|
|
169
|
-
previewWidth = drawingArea.width * (
|
|
158
|
+
previewWidth = drawingArea.width * (zoomEnd - zoomStart) / range;
|
|
170
159
|
previewHeight = ZOOM_SLIDER_ACTIVE_TRACK_SIZE;
|
|
171
|
-
startThumbX =
|
|
160
|
+
startThumbX = (zoomStart - minStart) / range * drawingArea.width;
|
|
172
161
|
startThumbY = 0;
|
|
173
|
-
endThumbX =
|
|
162
|
+
endThumbX = (zoomEnd - minStart) / range * drawingArea.width;
|
|
174
163
|
endThumbY = 0;
|
|
175
164
|
if (reverse) {
|
|
176
165
|
previewX = drawingArea.width - previewX - previewWidth;
|
|
@@ -181,13 +170,13 @@ export function ChartAxisZoomSliderActiveTrack({
|
|
|
181
170
|
endThumbX -= previewThumbWidth / 2;
|
|
182
171
|
} else {
|
|
183
172
|
previewX = 0;
|
|
184
|
-
previewY = drawingArea.height -
|
|
173
|
+
previewY = drawingArea.height - (zoomEnd - minStart) / range * drawingArea.height;
|
|
185
174
|
previewWidth = ZOOM_SLIDER_ACTIVE_TRACK_SIZE;
|
|
186
|
-
previewHeight = drawingArea.height * (
|
|
175
|
+
previewHeight = drawingArea.height * (zoomEnd - zoomStart) / range;
|
|
187
176
|
startThumbX = 0;
|
|
188
|
-
startThumbY = drawingArea.height -
|
|
177
|
+
startThumbY = drawingArea.height - (zoomStart - minStart) / range * drawingArea.height;
|
|
189
178
|
endThumbX = 0;
|
|
190
|
-
endThumbY = drawingArea.height -
|
|
179
|
+
endThumbY = drawingArea.height - (zoomEnd - minStart) / range * drawingArea.height;
|
|
191
180
|
if (reverse) {
|
|
192
181
|
previewY = drawingArea.height - previewY - previewHeight;
|
|
193
182
|
startThumbY = drawingArea.height - startThumbY;
|
|
@@ -55,17 +55,10 @@ export function ChartAxisZoomSliderTrack(_ref) {
|
|
|
55
55
|
return;
|
|
56
56
|
}
|
|
57
57
|
const pointerDownPoint = getSVGPoint(element, event);
|
|
58
|
-
|
|
58
|
+
const zoomFromPointerDown = calculateZoomFromPoint(store.getSnapshot(), axisId, pointerDownPoint);
|
|
59
59
|
if (zoomFromPointerDown === null) {
|
|
60
60
|
return;
|
|
61
61
|
}
|
|
62
|
-
const {
|
|
63
|
-
minStart,
|
|
64
|
-
maxEnd
|
|
65
|
-
} = selectorChartAxisZoomOptionsLookup(store.getSnapshot(), axisId);
|
|
66
|
-
|
|
67
|
-
// Ensure the zoomFromPointerDown is within the min and max range
|
|
68
|
-
zoomFromPointerDown = Math.max(Math.min(zoomFromPointerDown, maxEnd), minStart);
|
|
69
62
|
const onPointerMove = rafThrottle(function onPointerMove(pointerMoveEvent) {
|
|
70
63
|
const pointerMovePoint = getSVGPoint(element, pointerMoveEvent);
|
|
71
64
|
const zoomFromPointerMove = calculateZoomFromPoint(store.getSnapshot(), axisId, pointerMovePoint);
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { AxisId, ChartState, DefaultizedZoomOptions, ZoomData } from '@mui/x-charts/internals';
|
|
1
|
+
import { AxisId, ChartState, DefaultedXAxis, DefaultedYAxis, DefaultizedZoomOptions, ZoomData } from '@mui/x-charts/internals';
|
|
2
|
+
import { ChartDrawingArea } from '@mui/x-charts/hooks';
|
|
2
3
|
export declare function calculateZoomFromPoint(state: ChartState<any>, axisId: AxisId, point: DOMPoint): number | null;
|
|
4
|
+
export declare function calculateZoomFromPointImpl(drawingArea: ChartDrawingArea, axis: Pick<DefaultedXAxis | DefaultedYAxis, 'position' | 'reverse'>, zoomOptions: Pick<DefaultizedZoomOptions, 'minStart' | 'maxEnd'>, point: Pick<DOMPoint, 'x' | 'y'>): number;
|
|
3
5
|
export declare function calculateZoomStart(newStart: number, currentZoom: ZoomData, options: Pick<DefaultizedZoomOptions, 'minStart' | 'minSpan' | 'maxSpan'>): number;
|
|
4
6
|
export declare function calculateZoomEnd(newEnd: number, currentZoom: ZoomData, options: Pick<DefaultizedZoomOptions, 'maxEnd' | 'minSpan' | 'maxSpan'>): number;
|
|
@@ -1,24 +1,34 @@
|
|
|
1
|
-
import { selectorChartDrawingArea, selectorChartRawAxis } from '@mui/x-charts/internals';
|
|
1
|
+
import { selectorChartAxisZoomOptionsLookup, selectorChartDrawingArea, selectorChartRawAxis } from '@mui/x-charts/internals';
|
|
2
2
|
export function calculateZoomFromPoint(state, axisId, point) {
|
|
3
|
+
const axis = selectorChartRawAxis(state, axisId);
|
|
4
|
+
if (!axis) {
|
|
5
|
+
return null;
|
|
6
|
+
}
|
|
7
|
+
return calculateZoomFromPointImpl(selectorChartDrawingArea(state), axis, selectorChartAxisZoomOptionsLookup(state, axisId), point);
|
|
8
|
+
}
|
|
9
|
+
export function calculateZoomFromPointImpl(drawingArea, axis, zoomOptions, point) {
|
|
3
10
|
const {
|
|
4
11
|
left,
|
|
5
12
|
top,
|
|
6
13
|
height,
|
|
7
14
|
width
|
|
8
|
-
} =
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
15
|
+
} = drawingArea;
|
|
16
|
+
const {
|
|
17
|
+
minStart,
|
|
18
|
+
maxEnd
|
|
19
|
+
} = zoomOptions;
|
|
13
20
|
const axisDirection = axis.position === 'right' || axis.position === 'left' ? 'y' : 'x';
|
|
21
|
+
const range = maxEnd - minStart;
|
|
14
22
|
let pointerZoom;
|
|
15
23
|
if (axisDirection === 'x') {
|
|
16
|
-
pointerZoom = (point.x - left) / width *
|
|
24
|
+
pointerZoom = (point.x - left) / width * range;
|
|
17
25
|
} else {
|
|
18
|
-
pointerZoom = (top + height - point.y) / height *
|
|
26
|
+
pointerZoom = (top + height - point.y) / height * range;
|
|
19
27
|
}
|
|
20
28
|
if (axis.reverse) {
|
|
21
|
-
pointerZoom =
|
|
29
|
+
pointerZoom = maxEnd - pointerZoom;
|
|
30
|
+
} else {
|
|
31
|
+
pointerZoom += minStart;
|
|
22
32
|
}
|
|
23
33
|
return pointerZoom;
|
|
24
34
|
}
|
|
@@ -97,21 +97,21 @@ const useAggregatedData = () => {
|
|
|
97
97
|
min: minPoint,
|
|
98
98
|
max: maxPoint
|
|
99
99
|
});
|
|
100
|
-
const
|
|
100
|
+
const bandPoints = curve({}).processPoints(values.map(v => ({
|
|
101
|
+
x: xPosition(v.x, dataIndex, baseScaleConfig.data?.[dataIndex], v.stackOffset, v.useBandWidth),
|
|
102
|
+
y: yPosition(v.y, dataIndex, baseScaleConfig.data?.[dataIndex], v.stackOffset, v.useBandWidth)
|
|
103
|
+
})));
|
|
104
|
+
const line = d3Line().x(v => v.x).y(v => v.y).curve(curve);
|
|
101
105
|
return {
|
|
102
|
-
d: line(
|
|
106
|
+
d: line(bandPoints),
|
|
103
107
|
color,
|
|
104
108
|
id,
|
|
105
109
|
seriesId,
|
|
106
110
|
dataIndex,
|
|
107
111
|
variant: currentSeries.variant,
|
|
108
112
|
label: sectionLabel !== false && _extends({}, positionLabel(_extends({}, sectionLabel, {
|
|
109
|
-
xPosition,
|
|
110
|
-
yPosition,
|
|
111
113
|
isHorizontal,
|
|
112
|
-
values
|
|
113
|
-
dataIndex,
|
|
114
|
-
baseScaleData: baseScaleConfig.data ?? []
|
|
114
|
+
values: bandPoints
|
|
115
115
|
})), alignLabel(sectionLabel ?? {}), {
|
|
116
116
|
value: valueFormatter ? valueFormatter(currentSeries.data[dataIndex], {
|
|
117
117
|
dataIndex
|
|
@@ -120,7 +120,7 @@ const useAggregatedData = () => {
|
|
|
120
120
|
};
|
|
121
121
|
});
|
|
122
122
|
});
|
|
123
|
-
return result
|
|
123
|
+
return result;
|
|
124
124
|
}, [seriesData, xAxis, xAxisIds, yAxis, yAxisIds, gap]);
|
|
125
125
|
return allData;
|
|
126
126
|
};
|
|
@@ -131,41 +131,57 @@ function FunnelPlot(props) {
|
|
|
131
131
|
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
132
132
|
const data = useAggregatedData();
|
|
133
133
|
return /*#__PURE__*/_jsxs(React.Fragment, {
|
|
134
|
-
children: [data.map(
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
key: id,
|
|
145
|
-
dataIndex: dataIndex,
|
|
146
|
-
seriesId: seriesId,
|
|
147
|
-
variant: variant,
|
|
148
|
-
onClick: onItemClick && (event => {
|
|
149
|
-
onItemClick(event, {
|
|
150
|
-
type: 'funnel',
|
|
134
|
+
children: [data.map(series => {
|
|
135
|
+
if (series.length === 0) {
|
|
136
|
+
return null;
|
|
137
|
+
}
|
|
138
|
+
return /*#__PURE__*/_jsx("g", {
|
|
139
|
+
"data-series": series[0].seriesId,
|
|
140
|
+
children: series.map(({
|
|
141
|
+
d,
|
|
142
|
+
color,
|
|
143
|
+
id,
|
|
151
144
|
seriesId,
|
|
152
|
-
dataIndex
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
145
|
+
dataIndex,
|
|
146
|
+
variant
|
|
147
|
+
}) => /*#__PURE__*/_createElement(FunnelSection, _extends({}, other, {
|
|
148
|
+
d: d,
|
|
149
|
+
color: color,
|
|
150
|
+
key: id,
|
|
151
|
+
dataIndex: dataIndex,
|
|
152
|
+
seriesId: seriesId,
|
|
153
|
+
variant: variant,
|
|
154
|
+
onClick: onItemClick && (event => {
|
|
155
|
+
onItemClick(event, {
|
|
156
|
+
type: 'funnel',
|
|
157
|
+
seriesId,
|
|
158
|
+
dataIndex
|
|
159
|
+
});
|
|
160
|
+
})
|
|
161
|
+
})))
|
|
162
|
+
}, series[0].seriesId);
|
|
163
|
+
}), data.map(series => {
|
|
164
|
+
if (series.length === 0) {
|
|
162
165
|
return null;
|
|
163
166
|
}
|
|
164
|
-
return /*#__PURE__*/_jsx(
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
167
|
+
return /*#__PURE__*/_jsx("g", {
|
|
168
|
+
"data-series": series[0].seriesId,
|
|
169
|
+
children: series.map(({
|
|
170
|
+
id,
|
|
171
|
+
label,
|
|
172
|
+
seriesId,
|
|
173
|
+
dataIndex
|
|
174
|
+
}) => {
|
|
175
|
+
if (!label || !label.value) {
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
178
|
+
return /*#__PURE__*/_jsx(FunnelSectionLabel, _extends({
|
|
179
|
+
label: label,
|
|
180
|
+
dataIndex: dataIndex,
|
|
181
|
+
seriesId: seriesId
|
|
182
|
+
}, other), id);
|
|
183
|
+
})
|
|
184
|
+
}, series[0].seriesId);
|
|
169
185
|
})]
|
|
170
186
|
});
|
|
171
187
|
}
|
|
@@ -53,6 +53,8 @@ const FunnelSection = consumeSlots('MuiFunnelSection', 'funnelSection', {
|
|
|
53
53
|
strokeWidth: isOutlined ? 1.5 : 0,
|
|
54
54
|
cursor: onClick ? 'pointer' : 'unset',
|
|
55
55
|
onClick: onClick,
|
|
56
|
+
"data-highlighted": isHighlighted || undefined,
|
|
57
|
+
"data-faded": isFaded || undefined,
|
|
56
58
|
className: clsx(classes?.root, className, isOutlined ? classes?.outlined : classes?.filled, isHighlighted && classes?.highlighted, isFaded && classes?.faded)
|
|
57
59
|
}, other, {
|
|
58
60
|
ref: ref
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { CurveOptions } from "./curve.types.js";
|
|
1
|
+
import { FunnelCurveGenerator, CurveOptions, Point } from "./curve.types.js";
|
|
3
2
|
/**
|
|
4
3
|
* This is a custom "bump" curve generator.
|
|
5
4
|
* It draws smooth curves for the 4 provided points,
|
|
@@ -8,7 +7,7 @@ import { CurveOptions } from "./curve.types.js";
|
|
|
8
7
|
* The implementation is based on the d3-shape bump curve generator.
|
|
9
8
|
* https://github.com/d3/d3-shape/blob/a82254af78f08799c71d7ab25df557c4872a3c51/src/curve/bump.js
|
|
10
9
|
*/
|
|
11
|
-
export declare class Bump implements
|
|
10
|
+
export declare class Bump implements FunnelCurveGenerator {
|
|
12
11
|
private context;
|
|
13
12
|
private isHorizontal;
|
|
14
13
|
private min;
|
|
@@ -24,6 +23,7 @@ export declare class Bump implements CurveGenerator {
|
|
|
24
23
|
areaEnd(): void;
|
|
25
24
|
lineStart(): void;
|
|
26
25
|
lineEnd(): void;
|
|
26
|
+
processPoints(points: Point[]): Point[];
|
|
27
27
|
point(x: number, y: number): void;
|
|
28
28
|
private drawPath;
|
|
29
29
|
private drawHorizontalPath;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CurveGenerator } from '@mui/x-charts-vendor/d3-shape';
|
|
1
2
|
export type CurveOptions = {
|
|
2
3
|
/**
|
|
3
4
|
* The gap between each segment.
|
|
@@ -44,4 +45,16 @@ export type FunnelPointShape = 'square' | 'sharp';
|
|
|
44
45
|
export type Point = {
|
|
45
46
|
x: number;
|
|
46
47
|
y: number;
|
|
47
|
-
};
|
|
48
|
+
};
|
|
49
|
+
export interface FunnelCurveGenerator extends CurveGenerator {
|
|
50
|
+
/**
|
|
51
|
+
* Processes the points to create a curve based on the provided options.
|
|
52
|
+
* This does not draw the curve but prepares the points for rendering.
|
|
53
|
+
*
|
|
54
|
+
* @param points The points to process.
|
|
55
|
+
* @param options The options for the curve.
|
|
56
|
+
* @returns The processed points.
|
|
57
|
+
*/
|
|
58
|
+
processPoints(points: Point[], xPosition: PositionGetter, yPosition: PositionGetter): Point[];
|
|
59
|
+
}
|
|
60
|
+
export type PositionGetter = (value: number, bandIndex: number, bandIdentifier: string | number, stackOffset?: number, useBand?: boolean) => number;
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Path } from '@mui/x-charts-vendor/d3-path';
|
|
2
2
|
import { CurveOptions, FunnelCurveType } from "./curve.types.js";
|
|
3
|
-
|
|
3
|
+
import { Step } from "./step.js";
|
|
4
|
+
import { Linear } from "./linear.js";
|
|
5
|
+
import { Bump } from "./bump.js";
|
|
6
|
+
import { Pyramid } from "./pyramid.js";
|
|
7
|
+
import { StepPyramid } from "./step-pyramid.js";
|
|
8
|
+
export declare const getFunnelCurve: (curve: FunnelCurveType | undefined, options: CurveOptions) => (context: CanvasRenderingContext2D | Path) => Step | Linear | Bump | Pyramid | StepPyramid;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { CurveOptions } from "./curve.types.js";
|
|
1
|
+
import { FunnelCurveGenerator, CurveOptions, Point } from "./curve.types.js";
|
|
3
2
|
/**
|
|
4
3
|
* This is a custom "linear" curve generator.
|
|
5
4
|
* It draws straight lines for the 4 provided points,
|
|
@@ -8,7 +7,7 @@ import { CurveOptions } from "./curve.types.js";
|
|
|
8
7
|
* The implementation is based on the d3-shape linear curve generator.
|
|
9
8
|
* https://github.com/d3/d3-shape/blob/a82254af78f08799c71d7ab25df557c4872a3c51/src/curve/linear.js
|
|
10
9
|
*/
|
|
11
|
-
export declare class Linear implements
|
|
10
|
+
export declare class Linear implements FunnelCurveGenerator {
|
|
12
11
|
private context;
|
|
13
12
|
private position;
|
|
14
13
|
private sections;
|
|
@@ -36,5 +35,6 @@ export declare class Linear implements CurveGenerator {
|
|
|
36
35
|
lineStart(): void;
|
|
37
36
|
lineEnd(): void;
|
|
38
37
|
protected getBorderRadius(): number | number[];
|
|
38
|
+
processPoints(points: Point[]): Point[];
|
|
39
39
|
point(xIn: number, yIn: number): void;
|
|
40
40
|
}
|