@mui/x-charts 7.7.1 → 7.9.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/BarChart/BarChart.d.ts +3 -3
- package/BarChart/BarElement.d.ts +225 -228
- package/BarChart/BarLabel/BarLabel.d.ts +225 -228
- package/BarChart/BarLabel/getBarLabel.d.ts +1 -1
- package/BarChart/useBarChartProps.d.ts +20 -88
- package/CHANGELOG.md +166 -1
- package/ChartContainer/ChartContainer.d.ts +1 -1
- package/ChartContainer/ChartContainer.js +3 -1
- package/ChartContainer/useChartContainerHooks.d.ts +1 -1
- package/ChartsAxisHighlight/ChartsAxisHighlight.js +19 -4
- package/ChartsReferenceLine/common.d.ts +0 -1
- package/ChartsSurface.js +5 -1
- package/ChartsTooltip/ChartsAxisTooltipContent.d.ts +3 -3
- package/ChartsTooltip/ChartsAxisTooltipContent.js +4 -39
- package/ChartsTooltip/ChartsItemTooltipContent.d.ts +7 -6
- package/ChartsTooltip/ChartsItemTooltipContent.js +4 -27
- package/ChartsTooltip/ChartsTooltip.d.ts +10 -9
- package/ChartsTooltip/ChartsTooltip.js +8 -2
- package/ChartsTooltip/ChartsTooltipTable.d.ts +15 -1
- package/ChartsTooltip/ChartsTooltipTable.js +19 -0
- package/ChartsTooltip/index.d.ts +1 -0
- package/ChartsTooltip/index.js +11 -0
- package/ChartsTooltip/utils.d.ts +7 -6
- package/ChartsTooltip/utils.js +24 -30
- package/ChartsVoronoiHandler/ChartsVoronoiHandler.js +6 -6
- package/ChartsXAxis/ChartsXAxis.js +7 -5
- package/ChartsYAxis/ChartsYAxis.js +3 -1
- package/Gauge/GaugeProvider.d.ts +1 -1
- package/LineChart/AnimatedArea.d.ts +225 -228
- package/LineChart/AnimatedLine.d.ts +225 -228
- package/LineChart/LineChart.d.ts +3 -3
- package/LineChart/MarkPlot.js +6 -2
- package/LineChart/useLineChartProps.d.ts +26 -103
- package/LineChart/useLineChartProps.js +3 -3
- package/PieChart/PieArc.d.ts +0 -1
- package/PieChart/PieArcLabel.d.ts +0 -1
- package/PieChart/PieChart.d.ts +3 -3
- package/PieChart/dataTransform/transition.d.ts +0 -1
- package/ResponsiveChartContainer/ResizableContainer.d.ts +1 -2
- package/ResponsiveChartContainer/ResponsiveChartContainer.js +3 -1
- package/ScatterChart/Scatter.js +7 -5
- package/ScatterChart/ScatterChart.d.ts +3 -3
- package/ScatterChart/ScatterChart.js +3 -1
- package/ScatterChart/useScatterChartProps.d.ts +20 -75
- package/SparkLineChart/SparkLineChart.d.ts +3 -3
- package/context/CartesianProvider/computeValue.d.ts +2 -2
- package/context/CartesianProvider/computeValue.js +36 -5
- package/context/CartesianProvider/normalizeAxis.d.ts +1 -1
- package/context/ZAxisContextProvider.js +7 -2
- package/esm/BarChart/useBarChartProps.js +0 -1
- package/esm/ChartContainer/ChartContainer.js +3 -1
- package/esm/ChartsAxisHighlight/ChartsAxisHighlight.js +19 -4
- package/esm/ChartsSurface.js +5 -1
- package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +3 -38
- package/esm/ChartsTooltip/ChartsItemTooltipContent.js +3 -26
- package/esm/ChartsTooltip/ChartsTooltip.js +8 -2
- package/esm/ChartsTooltip/ChartsTooltipTable.js +20 -0
- package/esm/ChartsTooltip/index.js +2 -1
- package/esm/ChartsTooltip/utils.js +23 -30
- package/esm/ChartsVoronoiHandler/ChartsVoronoiHandler.js +6 -6
- package/esm/ChartsXAxis/ChartsXAxis.js +7 -5
- package/esm/ChartsYAxis/ChartsYAxis.js +3 -1
- package/esm/LineChart/MarkPlot.js +6 -2
- package/esm/LineChart/useLineChartProps.js +3 -3
- package/esm/ResponsiveChartContainer/ResponsiveChartContainer.js +3 -1
- package/esm/ScatterChart/Scatter.js +7 -5
- package/esm/ScatterChart/ScatterChart.js +3 -1
- package/esm/context/CartesianProvider/computeValue.js +37 -6
- package/esm/context/ZAxisContextProvider.js +7 -2
- package/esm/hooks/index.js +1 -0
- package/esm/hooks/useAxis.js +17 -0
- package/esm/hooks/useAxisEvents.js +25 -17
- package/esm/hooks/useInteractionItemProps.js +11 -4
- package/esm/hooks/useScale.js +7 -14
- package/esm/hooks/useTicks.js +2 -1
- package/esm/internals/getSVGPoint.js +11 -0
- package/esm/internals/index.js +4 -0
- package/esm/internals/utils.js +0 -12
- package/hooks/index.d.ts +1 -0
- package/hooks/index.js +12 -0
- package/hooks/useAxis.d.ts +2 -0
- package/hooks/useAxis.js +24 -0
- package/hooks/useAxisEvents.js +25 -17
- package/hooks/useChartDimensions.d.ts +1 -1
- package/hooks/useColor.d.ts +1 -1
- package/hooks/useInteractionItemProps.d.ts +4 -2
- package/hooks/useInteractionItemProps.js +11 -4
- package/hooks/useScale.js +6 -14
- package/hooks/useTicks.js +2 -1
- package/index.js +1 -1
- package/internals/components/AxisSharedComponents.d.ts +0 -1
- package/internals/components/ChartsAxesGradients/ChartsAxesGradients.d.ts +1 -1
- package/internals/defaultizeColor.d.ts +68 -68
- package/internals/getSVGPoint.d.ts +6 -0
- package/internals/getSVGPoint.js +17 -0
- package/internals/getWordsByLines.d.ts +0 -1
- package/internals/index.d.ts +4 -0
- package/internals/index.js +40 -0
- package/internals/useAnimatedPath.d.ts +0 -1
- package/internals/utils.d.ts +0 -6
- package/internals/utils.js +0 -13
- package/models/axis.d.ts +1 -2
- package/models/colorMapping.d.ts +1 -1
- package/models/z-axis.d.ts +8 -0
- package/modern/BarChart/useBarChartProps.js +0 -1
- package/modern/ChartContainer/ChartContainer.js +3 -1
- package/modern/ChartsAxisHighlight/ChartsAxisHighlight.js +19 -4
- package/modern/ChartsSurface.js +5 -1
- package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +3 -38
- package/modern/ChartsTooltip/ChartsItemTooltipContent.js +3 -26
- package/modern/ChartsTooltip/ChartsTooltip.js +8 -2
- package/modern/ChartsTooltip/ChartsTooltipTable.js +20 -0
- package/modern/ChartsTooltip/index.js +2 -1
- package/modern/ChartsTooltip/utils.js +23 -30
- package/modern/ChartsVoronoiHandler/ChartsVoronoiHandler.js +6 -6
- package/modern/ChartsXAxis/ChartsXAxis.js +7 -5
- package/modern/ChartsYAxis/ChartsYAxis.js +3 -1
- package/modern/LineChart/MarkPlot.js +6 -2
- package/modern/LineChart/useLineChartProps.js +3 -3
- package/modern/ResponsiveChartContainer/ResponsiveChartContainer.js +3 -1
- package/modern/ScatterChart/Scatter.js +7 -5
- package/modern/ScatterChart/ScatterChart.js +3 -1
- package/modern/context/CartesianProvider/computeValue.js +37 -6
- package/modern/context/ZAxisContextProvider.js +7 -2
- package/modern/hooks/index.js +1 -0
- package/modern/hooks/useAxis.js +17 -0
- package/modern/hooks/useAxisEvents.js +25 -17
- package/modern/hooks/useInteractionItemProps.js +11 -4
- package/modern/hooks/useScale.js +7 -14
- package/modern/hooks/useTicks.js +2 -1
- package/modern/index.js +1 -1
- package/modern/internals/getSVGPoint.js +11 -0
- package/modern/internals/index.js +4 -0
- package/modern/internals/utils.js +0 -12
- package/package.json +3 -3
- package/themeAugmentation/props.d.ts +2 -1
|
@@ -37,7 +37,10 @@ function ZAxisContextProvider(props) {
|
|
|
37
37
|
completedZAxis[axis.id] = _extends({}, axis, {
|
|
38
38
|
colorScale: axis.colorMap && (axis.colorMap.type === 'ordinal' && axis.data ? getOrdinalColorScale(_extends({
|
|
39
39
|
values: axis.data
|
|
40
|
-
}, axis.colorMap)) : getColorScale(axis.colorMap
|
|
40
|
+
}, axis.colorMap)) : getColorScale(axis.colorMap.type === 'continuous' ? _extends({
|
|
41
|
+
min: axis.min,
|
|
42
|
+
max: axis.max
|
|
43
|
+
}, axis.colorMap) : axis.colorMap))
|
|
41
44
|
});
|
|
42
45
|
});
|
|
43
46
|
return {
|
|
@@ -83,7 +86,9 @@ process.env.NODE_ENV !== "production" ? ZAxisContextProvider.propTypes = {
|
|
|
83
86
|
})]),
|
|
84
87
|
data: PropTypes.array,
|
|
85
88
|
dataKey: PropTypes.string,
|
|
86
|
-
id: PropTypes.string
|
|
89
|
+
id: PropTypes.string,
|
|
90
|
+
max: PropTypes.number,
|
|
91
|
+
min: PropTypes.number
|
|
87
92
|
}))
|
|
88
93
|
} : void 0;
|
|
89
94
|
export { ZAxisContextProvider };
|
package/esm/hooks/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from './useDrawingArea';
|
|
2
2
|
export * from './useChartId';
|
|
3
3
|
export * from './useScale';
|
|
4
|
+
export * from './useAxis';
|
|
4
5
|
export * from './useColorScale';
|
|
5
6
|
export * from './useSvgRef';
|
|
6
7
|
export { useSeries as unstable_useSeries, usePieSeries as unstable_usePieSeries, useLineSeries as unstable_useLineSeries, useBarSeries as unstable_useBarSeries, useScatterSeries as unstable_useScatterSeries } from './useSeries';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { useCartesianContext } from '../context/CartesianProvider';
|
|
2
|
+
export function useXAxis(identifier) {
|
|
3
|
+
const {
|
|
4
|
+
xAxis,
|
|
5
|
+
xAxisIds
|
|
6
|
+
} = useCartesianContext();
|
|
7
|
+
const id = typeof identifier === 'string' ? identifier : xAxisIds[identifier ?? 0];
|
|
8
|
+
return xAxis[id];
|
|
9
|
+
}
|
|
10
|
+
export function useYAxis(identifier) {
|
|
11
|
+
const {
|
|
12
|
+
yAxis,
|
|
13
|
+
yAxisIds
|
|
14
|
+
} = useCartesianContext();
|
|
15
|
+
const id = typeof identifier === 'string' ? identifier : yAxisIds[identifier ?? 0];
|
|
16
|
+
return yAxis[id];
|
|
17
|
+
}
|
|
@@ -2,7 +2,7 @@ import * as React from 'react';
|
|
|
2
2
|
import { InteractionContext } from '../context/InteractionProvider';
|
|
3
3
|
import { useCartesianContext } from '../context/CartesianProvider';
|
|
4
4
|
import { isBandScale } from '../internals/isBandScale';
|
|
5
|
-
import { getSVGPoint } from '../internals/
|
|
5
|
+
import { getSVGPoint } from '../internals/getSVGPoint';
|
|
6
6
|
import { useSvgRef } from './useSvgRef';
|
|
7
7
|
import { useDrawingArea } from './useDrawingArea';
|
|
8
8
|
function getAsANumber(value) {
|
|
@@ -38,10 +38,7 @@ export const useAxisEvents = disableAxisListener => {
|
|
|
38
38
|
if (element === null || disableAxisListener) {
|
|
39
39
|
return () => {};
|
|
40
40
|
}
|
|
41
|
-
|
|
42
|
-
if (usedXAxis === null) {
|
|
43
|
-
return null;
|
|
44
|
-
}
|
|
41
|
+
function getNewAxisState(axisConfig, mouseValue) {
|
|
45
42
|
const {
|
|
46
43
|
scale,
|
|
47
44
|
data: axisData,
|
|
@@ -89,7 +86,7 @@ export const useAxisEvents = disableAxisListener => {
|
|
|
89
86
|
index: dataIndex,
|
|
90
87
|
value: axisData[dataIndex]
|
|
91
88
|
};
|
|
92
|
-
}
|
|
89
|
+
}
|
|
93
90
|
const handleOut = () => {
|
|
94
91
|
mousePosition.current = {
|
|
95
92
|
x: -1,
|
|
@@ -101,7 +98,7 @@ export const useAxisEvents = disableAxisListener => {
|
|
|
101
98
|
};
|
|
102
99
|
const handleMove = event => {
|
|
103
100
|
const target = 'targetTouches' in event ? event.targetTouches[0] : event;
|
|
104
|
-
const svgPoint = getSVGPoint(
|
|
101
|
+
const svgPoint = getSVGPoint(element, target);
|
|
105
102
|
mousePosition.current = {
|
|
106
103
|
x: svgPoint.x,
|
|
107
104
|
y: svgPoint.y
|
|
@@ -114,8 +111,8 @@ export const useAxisEvents = disableAxisListener => {
|
|
|
114
111
|
});
|
|
115
112
|
return;
|
|
116
113
|
}
|
|
117
|
-
const newStateX =
|
|
118
|
-
const newStateY =
|
|
114
|
+
const newStateX = getNewAxisState(xAxis[usedXAxis], svgPoint.x);
|
|
115
|
+
const newStateY = getNewAxisState(yAxis[usedYAxis], svgPoint.y);
|
|
119
116
|
dispatch({
|
|
120
117
|
type: 'updateAxis',
|
|
121
118
|
data: {
|
|
@@ -124,15 +121,26 @@ export const useAxisEvents = disableAxisListener => {
|
|
|
124
121
|
}
|
|
125
122
|
});
|
|
126
123
|
};
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
124
|
+
const handleDown = event => {
|
|
125
|
+
const target = event.currentTarget;
|
|
126
|
+
if (!target) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
if (target.hasPointerCapture(event.pointerId)) {
|
|
130
|
+
target.releasePointerCapture(event.pointerId);
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
element.addEventListener('pointerdown', handleDown);
|
|
134
|
+
element.addEventListener('pointermove', handleMove);
|
|
135
|
+
element.addEventListener('pointerout', handleOut);
|
|
136
|
+
element.addEventListener('pointercancel', handleOut);
|
|
137
|
+
element.addEventListener('pointerleave', handleOut);
|
|
131
138
|
return () => {
|
|
132
|
-
element.removeEventListener('
|
|
133
|
-
element.removeEventListener('
|
|
134
|
-
element.removeEventListener('
|
|
135
|
-
element.removeEventListener('
|
|
139
|
+
element.removeEventListener('pointerdown', handleDown);
|
|
140
|
+
element.removeEventListener('pointermove', handleMove);
|
|
141
|
+
element.removeEventListener('pointerout', handleOut);
|
|
142
|
+
element.removeEventListener('pointercancel', handleOut);
|
|
143
|
+
element.removeEventListener('pointerleave', handleOut);
|
|
136
144
|
};
|
|
137
145
|
}, [svgRef, dispatch, left, width, top, height, usedYAxis, yAxis, usedXAxis, xAxis, disableAxisListener]);
|
|
138
146
|
};
|
|
@@ -13,7 +13,12 @@ export const useInteractionItemProps = skip => {
|
|
|
13
13
|
return () => ({});
|
|
14
14
|
}
|
|
15
15
|
const getInteractionItemProps = data => {
|
|
16
|
-
const
|
|
16
|
+
const onPointerDown = event => {
|
|
17
|
+
if (event.currentTarget.hasPointerCapture(event.pointerId)) {
|
|
18
|
+
event.currentTarget.releasePointerCapture(event.pointerId);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
const onPointerEnter = () => {
|
|
17
22
|
dispatchInteraction({
|
|
18
23
|
type: 'enterItem',
|
|
19
24
|
data
|
|
@@ -23,7 +28,8 @@ export const useInteractionItemProps = skip => {
|
|
|
23
28
|
dataIndex: data.dataIndex
|
|
24
29
|
});
|
|
25
30
|
};
|
|
26
|
-
const
|
|
31
|
+
const onPointerLeave = event => {
|
|
32
|
+
event.currentTarget.releasePointerCapture(event.pointerId);
|
|
27
33
|
dispatchInteraction({
|
|
28
34
|
type: 'leaveItem',
|
|
29
35
|
data
|
|
@@ -31,8 +37,9 @@ export const useInteractionItemProps = skip => {
|
|
|
31
37
|
clearHighlighted();
|
|
32
38
|
};
|
|
33
39
|
return {
|
|
34
|
-
|
|
35
|
-
|
|
40
|
+
onPointerEnter,
|
|
41
|
+
onPointerLeave,
|
|
42
|
+
onPointerDown
|
|
36
43
|
};
|
|
37
44
|
};
|
|
38
45
|
return getInteractionItemProps;
|
package/esm/hooks/useScale.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { useCartesianContext } from '../context/CartesianProvider';
|
|
2
1
|
import { isBandScale } from '../internals/isBandScale';
|
|
2
|
+
import { useXAxis, useYAxis } from './useAxis';
|
|
3
|
+
|
|
3
4
|
/**
|
|
4
5
|
* For a given scale return a function that map value to their position.
|
|
5
6
|
* Useful when dealing with specific scale such as band.
|
|
@@ -8,23 +9,15 @@ import { isBandScale } from '../internals/isBandScale';
|
|
|
8
9
|
*/
|
|
9
10
|
export function getValueToPositionMapper(scale) {
|
|
10
11
|
if (isBandScale(scale)) {
|
|
11
|
-
return value => scale(value) + scale.bandwidth() / 2;
|
|
12
|
+
return value => (scale(value) ?? 0) + scale.bandwidth() / 2;
|
|
12
13
|
}
|
|
13
14
|
return value => scale(value);
|
|
14
15
|
}
|
|
15
16
|
export function useXScale(identifier) {
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
xAxisIds
|
|
19
|
-
} = useCartesianContext();
|
|
20
|
-
const id = typeof identifier === 'string' ? identifier : xAxisIds[identifier ?? 0];
|
|
21
|
-
return xAxis[id].scale;
|
|
17
|
+
const axis = useXAxis(identifier);
|
|
18
|
+
return axis.scale;
|
|
22
19
|
}
|
|
23
20
|
export function useYScale(identifier) {
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
yAxisIds
|
|
27
|
-
} = useCartesianContext();
|
|
28
|
-
const id = typeof identifier === 'string' ? identifier : yAxisIds[identifier ?? 0];
|
|
29
|
-
return yAxis[id].scale;
|
|
21
|
+
const axis = useYAxis(identifier);
|
|
22
|
+
return axis.scale;
|
|
30
23
|
}
|
package/esm/hooks/useTicks.js
CHANGED
|
@@ -34,7 +34,8 @@ export function useTicks(options) {
|
|
|
34
34
|
const domain = scale.domain();
|
|
35
35
|
if (scale.bandwidth() > 0) {
|
|
36
36
|
// scale type = 'band'
|
|
37
|
-
|
|
37
|
+
const filteredDomain = typeof tickInterval === 'function' && domain.filter(tickInterval) || typeof tickInterval === 'object' && tickInterval || domain;
|
|
38
|
+
return [...filteredDomain.map(value => ({
|
|
38
39
|
value,
|
|
39
40
|
formattedValue: valueFormatter?.(value, {
|
|
40
41
|
location: 'tick'
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transform mouse event position to coordinates inside the SVG.
|
|
3
|
+
* @param svg The SVG element
|
|
4
|
+
* @param event The mouseEvent to transform
|
|
5
|
+
*/
|
|
6
|
+
export function getSVGPoint(svg, event) {
|
|
7
|
+
const pt = svg.createSVGPoint();
|
|
8
|
+
pt.x = event.clientX;
|
|
9
|
+
pt.y = event.clientY;
|
|
10
|
+
return pt.matrixTransform(svg.getScreenCTM().inverse());
|
|
11
|
+
}
|
package/esm/internals/index.js
CHANGED
|
@@ -6,6 +6,8 @@ export * from '../ResponsiveChartContainer/ResizableContainer';
|
|
|
6
6
|
// hooks
|
|
7
7
|
export { useReducedMotion } from '../hooks/useReducedMotion';
|
|
8
8
|
export { useSeries } from '../hooks/useSeries';
|
|
9
|
+
export { useInteractionItemProps } from '../hooks/useInteractionItemProps';
|
|
10
|
+
export { useDrawingArea } from '../hooks/useDrawingArea';
|
|
9
11
|
export { useChartContainerHooks } from '../ChartContainer/useChartContainerHooks';
|
|
10
12
|
export { useScatterChartProps } from '../ScatterChart/useScatterChartProps';
|
|
11
13
|
export { useLineChartProps } from '../LineChart/useLineChartProps';
|
|
@@ -14,6 +16,8 @@ export { useBarChartProps } from '../BarChart/useBarChartProps';
|
|
|
14
16
|
// utils
|
|
15
17
|
export * from './defaultizeValueFormatter';
|
|
16
18
|
export * from './configInit';
|
|
19
|
+
export * from './getLabel';
|
|
20
|
+
export * from './getSVGPoint';
|
|
17
21
|
|
|
18
22
|
// contexts
|
|
19
23
|
|
package/esm/internals/utils.js
CHANGED
|
@@ -3,18 +3,6 @@ export function getSymbol(shape) {
|
|
|
3
3
|
const symbolNames = 'circle cross diamond square star triangle wye'.split(/ /);
|
|
4
4
|
return symbolNames.indexOf(shape) || 0;
|
|
5
5
|
}
|
|
6
|
-
/**
|
|
7
|
-
* Transform mouse event position to coordinates inside the SVG.
|
|
8
|
-
* @param svg The SVG element
|
|
9
|
-
* @param event The mouseEvent to transform
|
|
10
|
-
*/
|
|
11
|
-
export function getSVGPoint(svg, event) {
|
|
12
|
-
const pt = svg.createSVGPoint();
|
|
13
|
-
pt.x = event.clientX;
|
|
14
|
-
pt.y = event.clientY;
|
|
15
|
-
return pt.matrixTransform(svg.getScreenCTM().inverse());
|
|
16
|
-
}
|
|
17
|
-
|
|
18
6
|
/**
|
|
19
7
|
* Helper that converts values and percentages into values.
|
|
20
8
|
* @param value The value provided by the developer. Can either be a number or a string with '%' or 'px'.
|
package/hooks/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from './useDrawingArea';
|
|
2
2
|
export * from './useChartId';
|
|
3
3
|
export * from './useScale';
|
|
4
|
+
export * from './useAxis';
|
|
4
5
|
export * from './useColorScale';
|
|
5
6
|
export * from './useSvgRef';
|
|
6
7
|
export { useSeries as unstable_useSeries, usePieSeries as unstable_usePieSeries, useLineSeries as unstable_useLineSeries, useBarSeries as unstable_useBarSeries, useScatterSeries as unstable_useScatterSeries, } from './useSeries';
|
package/hooks/index.js
CHANGED
|
@@ -76,6 +76,18 @@ Object.keys(_useScale).forEach(function (key) {
|
|
|
76
76
|
}
|
|
77
77
|
});
|
|
78
78
|
});
|
|
79
|
+
var _useAxis = require("./useAxis");
|
|
80
|
+
Object.keys(_useAxis).forEach(function (key) {
|
|
81
|
+
if (key === "default" || key === "__esModule") return;
|
|
82
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
83
|
+
if (key in exports && exports[key] === _useAxis[key]) return;
|
|
84
|
+
Object.defineProperty(exports, key, {
|
|
85
|
+
enumerable: true,
|
|
86
|
+
get: function () {
|
|
87
|
+
return _useAxis[key];
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
});
|
|
79
91
|
var _useColorScale = require("./useColorScale");
|
|
80
92
|
Object.keys(_useColorScale).forEach(function (key) {
|
|
81
93
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export declare function useXAxis(identifier?: number | string): import("../internals").AxisDefaultized<keyof import("../internals").AxisScaleConfig, any, import("..").ChartsXAxisProps>;
|
|
2
|
+
export declare function useYAxis(identifier?: number | string): import("../internals").AxisDefaultized<keyof import("../internals").AxisScaleConfig, any, import("..").ChartsYAxisProps>;
|
package/hooks/useAxis.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useXAxis = useXAxis;
|
|
7
|
+
exports.useYAxis = useYAxis;
|
|
8
|
+
var _CartesianProvider = require("../context/CartesianProvider");
|
|
9
|
+
function useXAxis(identifier) {
|
|
10
|
+
const {
|
|
11
|
+
xAxis,
|
|
12
|
+
xAxisIds
|
|
13
|
+
} = (0, _CartesianProvider.useCartesianContext)();
|
|
14
|
+
const id = typeof identifier === 'string' ? identifier : xAxisIds[identifier ?? 0];
|
|
15
|
+
return xAxis[id];
|
|
16
|
+
}
|
|
17
|
+
function useYAxis(identifier) {
|
|
18
|
+
const {
|
|
19
|
+
yAxis,
|
|
20
|
+
yAxisIds
|
|
21
|
+
} = (0, _CartesianProvider.useCartesianContext)();
|
|
22
|
+
const id = typeof identifier === 'string' ? identifier : yAxisIds[identifier ?? 0];
|
|
23
|
+
return yAxis[id];
|
|
24
|
+
}
|
package/hooks/useAxisEvents.js
CHANGED
|
@@ -8,7 +8,7 @@ var React = _interopRequireWildcard(require("react"));
|
|
|
8
8
|
var _InteractionProvider = require("../context/InteractionProvider");
|
|
9
9
|
var _CartesianProvider = require("../context/CartesianProvider");
|
|
10
10
|
var _isBandScale = require("../internals/isBandScale");
|
|
11
|
-
var
|
|
11
|
+
var _getSVGPoint = require("../internals/getSVGPoint");
|
|
12
12
|
var _useSvgRef = require("./useSvgRef");
|
|
13
13
|
var _useDrawingArea = require("./useDrawingArea");
|
|
14
14
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
@@ -46,10 +46,7 @@ const useAxisEvents = disableAxisListener => {
|
|
|
46
46
|
if (element === null || disableAxisListener) {
|
|
47
47
|
return () => {};
|
|
48
48
|
}
|
|
49
|
-
|
|
50
|
-
if (usedXAxis === null) {
|
|
51
|
-
return null;
|
|
52
|
-
}
|
|
49
|
+
function getNewAxisState(axisConfig, mouseValue) {
|
|
53
50
|
const {
|
|
54
51
|
scale,
|
|
55
52
|
data: axisData,
|
|
@@ -97,7 +94,7 @@ const useAxisEvents = disableAxisListener => {
|
|
|
97
94
|
index: dataIndex,
|
|
98
95
|
value: axisData[dataIndex]
|
|
99
96
|
};
|
|
100
|
-
}
|
|
97
|
+
}
|
|
101
98
|
const handleOut = () => {
|
|
102
99
|
mousePosition.current = {
|
|
103
100
|
x: -1,
|
|
@@ -109,7 +106,7 @@ const useAxisEvents = disableAxisListener => {
|
|
|
109
106
|
};
|
|
110
107
|
const handleMove = event => {
|
|
111
108
|
const target = 'targetTouches' in event ? event.targetTouches[0] : event;
|
|
112
|
-
const svgPoint = (0,
|
|
109
|
+
const svgPoint = (0, _getSVGPoint.getSVGPoint)(element, target);
|
|
113
110
|
mousePosition.current = {
|
|
114
111
|
x: svgPoint.x,
|
|
115
112
|
y: svgPoint.y
|
|
@@ -122,8 +119,8 @@ const useAxisEvents = disableAxisListener => {
|
|
|
122
119
|
});
|
|
123
120
|
return;
|
|
124
121
|
}
|
|
125
|
-
const newStateX =
|
|
126
|
-
const newStateY =
|
|
122
|
+
const newStateX = getNewAxisState(xAxis[usedXAxis], svgPoint.x);
|
|
123
|
+
const newStateY = getNewAxisState(yAxis[usedYAxis], svgPoint.y);
|
|
127
124
|
dispatch({
|
|
128
125
|
type: 'updateAxis',
|
|
129
126
|
data: {
|
|
@@ -132,15 +129,26 @@ const useAxisEvents = disableAxisListener => {
|
|
|
132
129
|
}
|
|
133
130
|
});
|
|
134
131
|
};
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
132
|
+
const handleDown = event => {
|
|
133
|
+
const target = event.currentTarget;
|
|
134
|
+
if (!target) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
if (target.hasPointerCapture(event.pointerId)) {
|
|
138
|
+
target.releasePointerCapture(event.pointerId);
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
element.addEventListener('pointerdown', handleDown);
|
|
142
|
+
element.addEventListener('pointermove', handleMove);
|
|
143
|
+
element.addEventListener('pointerout', handleOut);
|
|
144
|
+
element.addEventListener('pointercancel', handleOut);
|
|
145
|
+
element.addEventListener('pointerleave', handleOut);
|
|
139
146
|
return () => {
|
|
140
|
-
element.removeEventListener('
|
|
141
|
-
element.removeEventListener('
|
|
142
|
-
element.removeEventListener('
|
|
143
|
-
element.removeEventListener('
|
|
147
|
+
element.removeEventListener('pointerdown', handleDown);
|
|
148
|
+
element.removeEventListener('pointermove', handleMove);
|
|
149
|
+
element.removeEventListener('pointerout', handleOut);
|
|
150
|
+
element.removeEventListener('pointercancel', handleOut);
|
|
151
|
+
element.removeEventListener('pointerleave', handleOut);
|
|
144
152
|
};
|
|
145
153
|
}, [svgRef, dispatch, left, width, top, height, usedYAxis, yAxis, usedXAxis, xAxis, disableAxisListener]);
|
|
146
154
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LayoutConfig } from '../models/layout';
|
|
2
|
-
declare const useChartDimensions: (width: number, height: number, margin: LayoutConfig[
|
|
2
|
+
declare const useChartDimensions: (width: number, height: number, margin: LayoutConfig["margin"]) => {
|
|
3
3
|
left: number;
|
|
4
4
|
top: number;
|
|
5
5
|
right: number;
|
package/hooks/useColor.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ChartSeriesType } from '../
|
|
1
|
+
import { ChartSeriesType } from '../models/seriesType/config';
|
|
2
2
|
import { ColorProcessorsConfig } from '../models/plugin';
|
|
3
3
|
export declare function useColorProcessor<T extends ChartSeriesType>(seriesType: T): ColorProcessorsConfig<ChartSeriesType>;
|
|
4
4
|
export declare function useColorProcessor(): ColorProcessorsConfig<ChartSeriesType>;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
1
2
|
import { SeriesItemIdentifier } from '../models';
|
|
2
3
|
export declare const useInteractionItemProps: (skip?: boolean) => (() => {}) | ((data: SeriesItemIdentifier) => {
|
|
3
|
-
|
|
4
|
-
|
|
4
|
+
onPointerEnter: () => void;
|
|
5
|
+
onPointerLeave: (event: React.PointerEvent) => void;
|
|
6
|
+
onPointerDown: (event: React.PointerEvent) => void;
|
|
5
7
|
});
|
|
@@ -21,7 +21,12 @@ const useInteractionItemProps = skip => {
|
|
|
21
21
|
return () => ({});
|
|
22
22
|
}
|
|
23
23
|
const getInteractionItemProps = data => {
|
|
24
|
-
const
|
|
24
|
+
const onPointerDown = event => {
|
|
25
|
+
if (event.currentTarget.hasPointerCapture(event.pointerId)) {
|
|
26
|
+
event.currentTarget.releasePointerCapture(event.pointerId);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
const onPointerEnter = () => {
|
|
25
30
|
dispatchInteraction({
|
|
26
31
|
type: 'enterItem',
|
|
27
32
|
data
|
|
@@ -31,7 +36,8 @@ const useInteractionItemProps = skip => {
|
|
|
31
36
|
dataIndex: data.dataIndex
|
|
32
37
|
});
|
|
33
38
|
};
|
|
34
|
-
const
|
|
39
|
+
const onPointerLeave = event => {
|
|
40
|
+
event.currentTarget.releasePointerCapture(event.pointerId);
|
|
35
41
|
dispatchInteraction({
|
|
36
42
|
type: 'leaveItem',
|
|
37
43
|
data
|
|
@@ -39,8 +45,9 @@ const useInteractionItemProps = skip => {
|
|
|
39
45
|
clearHighlighted();
|
|
40
46
|
};
|
|
41
47
|
return {
|
|
42
|
-
|
|
43
|
-
|
|
48
|
+
onPointerEnter,
|
|
49
|
+
onPointerLeave,
|
|
50
|
+
onPointerDown
|
|
44
51
|
};
|
|
45
52
|
};
|
|
46
53
|
return getInteractionItemProps;
|
package/hooks/useScale.js
CHANGED
|
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.getValueToPositionMapper = getValueToPositionMapper;
|
|
7
7
|
exports.useXScale = useXScale;
|
|
8
8
|
exports.useYScale = useYScale;
|
|
9
|
-
var _CartesianProvider = require("../context/CartesianProvider");
|
|
10
9
|
var _isBandScale = require("../internals/isBandScale");
|
|
10
|
+
var _useAxis = require("./useAxis");
|
|
11
11
|
/**
|
|
12
12
|
* For a given scale return a function that map value to their position.
|
|
13
13
|
* Useful when dealing with specific scale such as band.
|
|
@@ -16,23 +16,15 @@ var _isBandScale = require("../internals/isBandScale");
|
|
|
16
16
|
*/
|
|
17
17
|
function getValueToPositionMapper(scale) {
|
|
18
18
|
if ((0, _isBandScale.isBandScale)(scale)) {
|
|
19
|
-
return value => scale(value) + scale.bandwidth() / 2;
|
|
19
|
+
return value => (scale(value) ?? 0) + scale.bandwidth() / 2;
|
|
20
20
|
}
|
|
21
21
|
return value => scale(value);
|
|
22
22
|
}
|
|
23
23
|
function useXScale(identifier) {
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
xAxisIds
|
|
27
|
-
} = (0, _CartesianProvider.useCartesianContext)();
|
|
28
|
-
const id = typeof identifier === 'string' ? identifier : xAxisIds[identifier ?? 0];
|
|
29
|
-
return xAxis[id].scale;
|
|
24
|
+
const axis = (0, _useAxis.useXAxis)(identifier);
|
|
25
|
+
return axis.scale;
|
|
30
26
|
}
|
|
31
27
|
function useYScale(identifier) {
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
yAxisIds
|
|
35
|
-
} = (0, _CartesianProvider.useCartesianContext)();
|
|
36
|
-
const id = typeof identifier === 'string' ? identifier : yAxisIds[identifier ?? 0];
|
|
37
|
-
return yAxis[id].scale;
|
|
28
|
+
const axis = (0, _useAxis.useYAxis)(identifier);
|
|
29
|
+
return axis.scale;
|
|
38
30
|
}
|
package/hooks/useTicks.js
CHANGED
|
@@ -43,7 +43,8 @@ function useTicks(options) {
|
|
|
43
43
|
const domain = scale.domain();
|
|
44
44
|
if (scale.bandwidth() > 0) {
|
|
45
45
|
// scale type = 'band'
|
|
46
|
-
|
|
46
|
+
const filteredDomain = typeof tickInterval === 'function' && domain.filter(tickInterval) || typeof tickInterval === 'object' && tickInterval || domain;
|
|
47
|
+
return [...filteredDomain.map(value => ({
|
|
47
48
|
value,
|
|
48
49
|
formattedValue: valueFormatter?.(value, {
|
|
49
50
|
location: 'tick'
|
package/index.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
export declare const AxisRoot: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, Pick<import("react").SVGProps<SVGGElement>, keyof import("react").SVGProps<SVGGElement>>, {}>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { AxisId } from '../../../models/axis';
|
|
3
|
-
export declare function useChartGradient(): (axisId: AxisId, direction:
|
|
3
|
+
export declare function useChartGradient(): (axisId: AxisId, direction: "x" | "y") => string;
|
|
4
4
|
export declare function ChartsAxesGradients(): React.JSX.Element;
|