@mui/x-charts 7.7.0 → 7.8.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.js +21 -104
- package/BarChart/BarElement.d.ts +225 -228
- package/BarChart/BarLabel/BarLabel.d.ts +225 -228
- package/BarChart/BarLabel/BarLabelPlot.d.ts +0 -3
- package/BarChart/BarLabel/BarLabelPlot.js +1 -24
- package/BarChart/BarLabel/getBarLabel.d.ts +1 -1
- package/BarChart/BarPlot.js +2 -2
- package/BarChart/checkScaleErrors.d.ts +5 -9
- package/BarChart/types.d.ts +2 -2
- package/BarChart/useBarChartProps.d.ts +34 -0
- package/BarChart/useBarChartProps.js +143 -0
- package/CHANGELOG.md +181 -0
- package/ChartContainer/ChartContainer.d.ts +2 -2
- package/ChartContainer/ChartContainer.js +6 -10
- package/ChartContainer/useChartContainerHooks.d.ts +11 -0
- package/ChartContainer/useChartContainerHooks.js +34 -0
- package/ChartContainer/usePluginsMerge.d.ts +1 -2
- package/ChartsAxis/ChartsAxis.js +2 -2
- package/ChartsAxisHighlight/ChartsAxisHighlight.js +21 -6
- package/ChartsGrid/ChartsGrid.js +2 -2
- package/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +2 -2
- package/ChartsReferenceLine/common.d.ts +0 -1
- package/ChartsTooltip/ChartsAxisTooltipContent.js +2 -2
- package/ChartsTooltip/ChartsItemTooltipContent.js +2 -2
- package/ChartsTooltip/ChartsTooltipTable.d.ts +0 -1
- package/ChartsVoronoiHandler/ChartsVoronoiHandler.js +4 -4
- package/ChartsXAxis/ChartsXAxis.js +2 -2
- package/ChartsYAxis/ChartsYAxis.js +5 -3
- package/Gauge/GaugeProvider.d.ts +1 -1
- package/LineChart/AnimatedArea.d.ts +225 -228
- package/LineChart/AnimatedLine.d.ts +225 -228
- package/LineChart/AreaPlot.js +2 -2
- package/LineChart/LineChart.js +24 -106
- package/LineChart/LineHighlightPlot.js +2 -2
- package/LineChart/LinePlot.js +2 -2
- package/LineChart/MarkPlot.js +2 -2
- package/LineChart/useLineChartProps.d.ts +40 -0
- package/LineChart/useLineChartProps.js +152 -0
- package/PieChart/PieArc.d.ts +0 -1
- package/PieChart/PieArcLabel.d.ts +0 -1
- package/PieChart/dataTransform/transition.d.ts +0 -1
- package/ResponsiveChartContainer/ResizableContainer.d.ts +1 -2
- package/ScatterChart/ScatterChart.js +20 -75
- package/ScatterChart/ScatterPlot.js +2 -2
- package/ScatterChart/useScatterChartProps.d.ts +31 -0
- package/ScatterChart/useScatterChartProps.js +116 -0
- package/context/CartesianProvider/CartesianContext.d.ts +25 -0
- package/context/CartesianProvider/CartesianContext.js +21 -0
- package/context/CartesianProvider/CartesianProvider.d.ts +34 -0
- package/context/CartesianProvider/CartesianProvider.js +44 -0
- package/context/CartesianProvider/computeValue.d.ts +19 -0
- package/context/CartesianProvider/computeValue.js +104 -0
- package/context/CartesianProvider/getAxisExtremum.d.ts +4 -0
- package/context/CartesianProvider/getAxisExtremum.js +28 -0
- package/context/CartesianProvider/index.d.ts +9 -0
- package/context/CartesianProvider/index.js +51 -0
- package/context/CartesianProvider/normalizeAxis.d.ts +5 -0
- package/context/CartesianProvider/normalizeAxis.js +23 -0
- package/context/CartesianProvider/useCartesianContext.d.ts +2 -0
- package/context/CartesianProvider/useCartesianContext.js +17 -0
- package/context/ColorProvider.d.ts +2 -2
- package/esm/BarChart/BarChart.js +21 -104
- package/esm/BarChart/BarLabel/BarLabelPlot.js +0 -23
- package/esm/BarChart/BarPlot.js +2 -2
- package/esm/BarChart/useBarChartProps.js +135 -0
- package/esm/ChartContainer/ChartContainer.js +5 -9
- package/esm/ChartContainer/useChartContainerHooks.js +24 -0
- package/esm/ChartsAxis/ChartsAxis.js +2 -2
- package/esm/ChartsAxisHighlight/ChartsAxisHighlight.js +21 -6
- package/esm/ChartsGrid/ChartsGrid.js +2 -2
- package/esm/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +2 -2
- package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +2 -2
- package/esm/ChartsTooltip/ChartsItemTooltipContent.js +2 -2
- package/esm/ChartsVoronoiHandler/ChartsVoronoiHandler.js +3 -3
- package/esm/ChartsXAxis/ChartsXAxis.js +2 -2
- package/esm/ChartsYAxis/ChartsYAxis.js +5 -3
- package/esm/LineChart/AreaPlot.js +2 -2
- package/esm/LineChart/LineChart.js +24 -106
- package/esm/LineChart/LineHighlightPlot.js +2 -2
- package/esm/LineChart/LinePlot.js +2 -2
- package/esm/LineChart/MarkPlot.js +2 -2
- package/esm/LineChart/useLineChartProps.js +144 -0
- package/esm/ScatterChart/ScatterChart.js +20 -75
- package/esm/ScatterChart/ScatterPlot.js +2 -2
- package/esm/ScatterChart/useScatterChartProps.js +108 -0
- package/esm/context/CartesianProvider/CartesianContext.js +13 -0
- package/esm/context/CartesianProvider/CartesianProvider.js +37 -0
- package/esm/context/CartesianProvider/computeValue.js +97 -0
- package/esm/context/CartesianProvider/getAxisExtremum.js +21 -0
- package/esm/context/CartesianProvider/index.js +10 -0
- package/esm/context/CartesianProvider/normalizeAxis.js +15 -0
- package/esm/context/CartesianProvider/useCartesianContext.js +8 -0
- package/esm/hooks/useAxisEvents.js +7 -10
- package/esm/hooks/useColorScale.js +3 -3
- package/esm/hooks/useScale.js +4 -5
- package/esm/hooks/useTicks.js +2 -1
- package/esm/internals/components/ChartsAxesGradients/ChartsAxesGradients.js +2 -2
- package/esm/internals/getSVGPoint.js +11 -0
- package/esm/internals/index.js +8 -2
- package/esm/internals/utils.js +0 -12
- package/hooks/useAxisEvents.js +8 -11
- package/hooks/useChartDimensions.d.ts +1 -1
- package/hooks/useColor.d.ts +1 -1
- package/hooks/useColorScale.js +3 -3
- package/hooks/useDrawingArea.d.ts +2 -8
- package/hooks/useScale.js +4 -7
- 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 +2 -1
- package/internals/components/ChartsAxesGradients/ChartsAxesGradients.js +2 -2
- 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 +9 -1
- package/internals/index.js +69 -5
- 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/plugin.d.ts +4 -1
- package/modern/BarChart/BarChart.js +21 -104
- package/modern/BarChart/BarLabel/BarLabelPlot.js +0 -23
- package/modern/BarChart/BarPlot.js +2 -2
- package/modern/BarChart/useBarChartProps.js +135 -0
- package/modern/ChartContainer/ChartContainer.js +5 -9
- package/modern/ChartContainer/useChartContainerHooks.js +24 -0
- package/modern/ChartsAxis/ChartsAxis.js +2 -2
- package/modern/ChartsAxisHighlight/ChartsAxisHighlight.js +21 -6
- package/modern/ChartsGrid/ChartsGrid.js +2 -2
- package/modern/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +2 -2
- package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +2 -2
- package/modern/ChartsTooltip/ChartsItemTooltipContent.js +2 -2
- package/modern/ChartsVoronoiHandler/ChartsVoronoiHandler.js +3 -3
- package/modern/ChartsXAxis/ChartsXAxis.js +2 -2
- package/modern/ChartsYAxis/ChartsYAxis.js +5 -3
- package/modern/LineChart/AreaPlot.js +2 -2
- package/modern/LineChart/LineChart.js +24 -106
- package/modern/LineChart/LineHighlightPlot.js +2 -2
- package/modern/LineChart/LinePlot.js +2 -2
- package/modern/LineChart/MarkPlot.js +2 -2
- package/modern/LineChart/useLineChartProps.js +144 -0
- package/modern/ScatterChart/ScatterChart.js +20 -75
- package/modern/ScatterChart/ScatterPlot.js +2 -2
- package/modern/ScatterChart/useScatterChartProps.js +108 -0
- package/modern/context/CartesianProvider/CartesianContext.js +13 -0
- package/modern/context/CartesianProvider/CartesianProvider.js +37 -0
- package/modern/context/CartesianProvider/computeValue.js +97 -0
- package/modern/context/CartesianProvider/getAxisExtremum.js +21 -0
- package/modern/context/CartesianProvider/index.js +10 -0
- package/modern/context/CartesianProvider/normalizeAxis.js +15 -0
- package/modern/context/CartesianProvider/useCartesianContext.js +8 -0
- package/modern/hooks/useAxisEvents.js +7 -10
- package/modern/hooks/useColorScale.js +3 -3
- package/modern/hooks/useScale.js +4 -5
- package/modern/hooks/useTicks.js +2 -1
- package/modern/index.js +1 -1
- package/modern/internals/components/ChartsAxesGradients/ChartsAxesGradients.js +2 -2
- package/modern/internals/getSVGPoint.js +11 -0
- package/modern/internals/index.js +8 -2
- package/modern/internals/utils.js +0 -12
- package/package.json +3 -3
- package/context/CartesianContextProvider.d.ts +0 -61
- package/context/CartesianContextProvider.js +0 -220
- package/esm/context/CartesianContextProvider.js +0 -211
- package/modern/context/CartesianContextProvider.js +0 -211
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import { scaleBand, scalePoint, scaleTime } from 'd3-scale';
|
|
3
|
+
import { DEFAULT_X_AXIS_KEY, DEFAULT_Y_AXIS_KEY } from '../../constants';
|
|
4
|
+
import { isBandScaleConfig, isPointScaleConfig } from '../../models/axis';
|
|
5
|
+
import { getColorScale, getOrdinalColorScale } from '../../internals/colorScale';
|
|
6
|
+
import { getTickNumber } from '../../hooks/useTicks';
|
|
7
|
+
import { getScale } from '../../internals/getScale';
|
|
8
|
+
import { getAxisExtremum } from './getAxisExtremum';
|
|
9
|
+
const getRange = (drawingArea, axisName, isReverse) => {
|
|
10
|
+
const range = axisName === 'x' ? [drawingArea.left, drawingArea.left + drawingArea.width] : [drawingArea.top + drawingArea.height, drawingArea.top];
|
|
11
|
+
return isReverse ? range.reverse() : range;
|
|
12
|
+
};
|
|
13
|
+
const isDateData = data => data?.[0] instanceof Date;
|
|
14
|
+
function createDateFormatter(axis, range) {
|
|
15
|
+
const timeScale = scaleTime(axis.data, range);
|
|
16
|
+
return (v, {
|
|
17
|
+
location
|
|
18
|
+
}) => location === 'tick' ? timeScale.tickFormat(axis.tickNumber)(v) : `${v.toLocaleString()}`;
|
|
19
|
+
}
|
|
20
|
+
const DEFAULT_CATEGORY_GAP_RATIO = 0.2;
|
|
21
|
+
const DEFAULT_BAR_GAP_RATIO = 0.1;
|
|
22
|
+
export function computeValue(drawingArea, formattedSeries, inAxis, extremumGetters, axisName) {
|
|
23
|
+
const DEFAULT_AXIS_KEY = axisName === 'x' ? DEFAULT_X_AXIS_KEY : DEFAULT_Y_AXIS_KEY;
|
|
24
|
+
const allAxis = [...(inAxis?.map((axis, index) => _extends({
|
|
25
|
+
id: `defaultized-${axisName}-axis-${index}`
|
|
26
|
+
}, axis)) ?? []), ...(inAxis === undefined || inAxis.findIndex(({
|
|
27
|
+
id
|
|
28
|
+
}) => id === DEFAULT_AXIS_KEY) === -1 ? [{
|
|
29
|
+
id: DEFAULT_AXIS_KEY,
|
|
30
|
+
scaleType: 'linear'
|
|
31
|
+
}] : [])];
|
|
32
|
+
const completeAxis = {};
|
|
33
|
+
allAxis.forEach((axis, axisIndex) => {
|
|
34
|
+
const isDefaultAxis = axisIndex === 0;
|
|
35
|
+
const [minData, maxData] = getAxisExtremum(axis, extremumGetters, isDefaultAxis, formattedSeries);
|
|
36
|
+
const range = getRange(drawingArea, axisName, axis.reverse);
|
|
37
|
+
if (isBandScaleConfig(axis)) {
|
|
38
|
+
const categoryGapRatio = axis.categoryGapRatio ?? DEFAULT_CATEGORY_GAP_RATIO;
|
|
39
|
+
const barGapRatio = axis.barGapRatio ?? DEFAULT_BAR_GAP_RATIO;
|
|
40
|
+
// Reverse range because ordinal scales are presented from top to bottom on y-axis
|
|
41
|
+
const scaleRange = axisName === 'x' ? range : [range[1], range[0]];
|
|
42
|
+
completeAxis[axis.id] = _extends({
|
|
43
|
+
categoryGapRatio,
|
|
44
|
+
barGapRatio
|
|
45
|
+
}, axis, {
|
|
46
|
+
scale: scaleBand(axis.data, scaleRange).paddingInner(categoryGapRatio).paddingOuter(categoryGapRatio / 2),
|
|
47
|
+
tickNumber: axis.data.length,
|
|
48
|
+
colorScale: axis.colorMap && (axis.colorMap.type === 'ordinal' ? getOrdinalColorScale(_extends({
|
|
49
|
+
values: axis.data
|
|
50
|
+
}, axis.colorMap)) : getColorScale(axis.colorMap))
|
|
51
|
+
});
|
|
52
|
+
if (isDateData(axis.data)) {
|
|
53
|
+
const dateFormatter = createDateFormatter(axis, scaleRange);
|
|
54
|
+
completeAxis[axis.id].valueFormatter = axis.valueFormatter ?? dateFormatter;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (isPointScaleConfig(axis)) {
|
|
58
|
+
const scaleRange = axisName === 'x' ? range : [...range].reverse();
|
|
59
|
+
completeAxis[axis.id] = _extends({}, axis, {
|
|
60
|
+
scale: scalePoint(axis.data, scaleRange),
|
|
61
|
+
tickNumber: axis.data.length,
|
|
62
|
+
colorScale: axis.colorMap && (axis.colorMap.type === 'ordinal' ? getOrdinalColorScale(_extends({
|
|
63
|
+
values: axis.data
|
|
64
|
+
}, axis.colorMap)) : getColorScale(axis.colorMap))
|
|
65
|
+
});
|
|
66
|
+
if (isDateData(axis.data)) {
|
|
67
|
+
const dateFormatter = createDateFormatter(axis, scaleRange);
|
|
68
|
+
completeAxis[axis.id].valueFormatter = axis.valueFormatter ?? dateFormatter;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (axis.scaleType === 'band' || axis.scaleType === 'point') {
|
|
72
|
+
// Could be merged with the two previous "if conditions" but then TS does not get that `axis.scaleType` can't be `band` or `point`.
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const scaleType = axis.scaleType ?? 'linear';
|
|
76
|
+
const extremums = [axis.min ?? minData, axis.max ?? maxData];
|
|
77
|
+
const tickNumber = getTickNumber(_extends({}, axis, {
|
|
78
|
+
range,
|
|
79
|
+
domain: extremums
|
|
80
|
+
}));
|
|
81
|
+
const scale = getScale(scaleType, extremums, range).nice(tickNumber);
|
|
82
|
+
const [minDomain, maxDomain] = scale.domain();
|
|
83
|
+
const domain = [axis.min ?? minDomain, axis.max ?? maxDomain];
|
|
84
|
+
completeAxis[axis.id] = _extends({}, axis, {
|
|
85
|
+
scaleType: scaleType,
|
|
86
|
+
scale: scale.domain(domain),
|
|
87
|
+
tickNumber,
|
|
88
|
+
colorScale: axis.colorMap && getColorScale(axis.colorMap)
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
return {
|
|
92
|
+
axis: completeAxis,
|
|
93
|
+
axisIds: allAxis.map(({
|
|
94
|
+
id
|
|
95
|
+
}) => id)
|
|
96
|
+
};
|
|
97
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const axisExtremumCallback = (acc, chartType, axis, getters, isDefaultAxis, formattedSeries) => {
|
|
2
|
+
const getter = getters[chartType];
|
|
3
|
+
const series = formattedSeries[chartType]?.series ?? {};
|
|
4
|
+
const [minChartTypeData, maxChartTypeData] = getter?.({
|
|
5
|
+
series,
|
|
6
|
+
axis,
|
|
7
|
+
isDefaultAxis
|
|
8
|
+
}) ?? [null, null];
|
|
9
|
+
const [minData, maxData] = acc;
|
|
10
|
+
if (minData === null || maxData === null) {
|
|
11
|
+
return [minChartTypeData, maxChartTypeData];
|
|
12
|
+
}
|
|
13
|
+
if (minChartTypeData === null || maxChartTypeData === null) {
|
|
14
|
+
return [minData, maxData];
|
|
15
|
+
}
|
|
16
|
+
return [Math.min(minChartTypeData, minData), Math.max(maxChartTypeData, maxData)];
|
|
17
|
+
};
|
|
18
|
+
export const getAxisExtremum = (axis, getters, isDefaultAxis, formattedSeries) => {
|
|
19
|
+
const charTypes = Object.keys(getters);
|
|
20
|
+
return charTypes.reduce((acc, charType) => axisExtremumCallback(acc, charType, axis, getters, isDefaultAxis, formattedSeries), [null, null]);
|
|
21
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { computeValue } from './computeValue';
|
|
2
|
+
import { normalizeAxis } from './normalizeAxis';
|
|
3
|
+
export * from './CartesianProvider';
|
|
4
|
+
export * from './CartesianContext';
|
|
5
|
+
export * from './useCartesianContext';
|
|
6
|
+
const cartesianProviderUtils = {
|
|
7
|
+
computeValue,
|
|
8
|
+
normalizeAxis
|
|
9
|
+
};
|
|
10
|
+
export { cartesianProviderUtils };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
export const normalizeAxis = (axis, dataset, axisName) => {
|
|
3
|
+
return axis?.map(axisConfig => {
|
|
4
|
+
const dataKey = axisConfig.dataKey;
|
|
5
|
+
if (dataKey === undefined || axisConfig.data !== undefined) {
|
|
6
|
+
return axisConfig;
|
|
7
|
+
}
|
|
8
|
+
if (dataset === undefined) {
|
|
9
|
+
throw Error(`MUI X Charts: ${axisName}-axis uses \`dataKey\` but no \`dataset\` is provided.`);
|
|
10
|
+
}
|
|
11
|
+
return _extends({}, axisConfig, {
|
|
12
|
+
data: dataset.map(d => d[dataKey])
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { InteractionContext } from '../context/InteractionProvider';
|
|
3
|
-
import {
|
|
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) {
|
|
@@ -21,7 +21,7 @@ export const useAxisEvents = disableAxisListener => {
|
|
|
21
21
|
yAxis,
|
|
22
22
|
xAxisIds,
|
|
23
23
|
yAxisIds
|
|
24
|
-
} =
|
|
24
|
+
} = useCartesianContext();
|
|
25
25
|
const {
|
|
26
26
|
dispatch
|
|
27
27
|
} = React.useContext(InteractionContext);
|
|
@@ -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,
|
|
@@ -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: {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { useCartesianContext } from '../context/CartesianProvider';
|
|
3
3
|
import { ZAxisContext } from '../context/ZAxisContextProvider';
|
|
4
4
|
export function useXColorScale(identifier) {
|
|
5
5
|
const {
|
|
6
6
|
xAxis,
|
|
7
7
|
xAxisIds
|
|
8
|
-
} =
|
|
8
|
+
} = useCartesianContext();
|
|
9
9
|
const id = typeof identifier === 'string' ? identifier : xAxisIds[identifier ?? 0];
|
|
10
10
|
return xAxis[id].colorScale;
|
|
11
11
|
}
|
|
@@ -13,7 +13,7 @@ export function useYColorScale(identifier) {
|
|
|
13
13
|
const {
|
|
14
14
|
yAxis,
|
|
15
15
|
yAxisIds
|
|
16
|
-
} =
|
|
16
|
+
} = useCartesianContext();
|
|
17
17
|
const id = typeof identifier === 'string' ? identifier : yAxisIds[identifier ?? 0];
|
|
18
18
|
return yAxis[id].colorScale;
|
|
19
19
|
}
|
package/esm/hooks/useScale.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { CartesianContext } from '../context/CartesianContextProvider';
|
|
1
|
+
import { useCartesianContext } from '../context/CartesianProvider';
|
|
3
2
|
import { isBandScale } from '../internals/isBandScale';
|
|
4
3
|
/**
|
|
5
4
|
* For a given scale return a function that map value to their position.
|
|
@@ -9,7 +8,7 @@ import { isBandScale } from '../internals/isBandScale';
|
|
|
9
8
|
*/
|
|
10
9
|
export function getValueToPositionMapper(scale) {
|
|
11
10
|
if (isBandScale(scale)) {
|
|
12
|
-
return value => scale(value) + scale.bandwidth() / 2;
|
|
11
|
+
return value => (scale(value) ?? 0) + scale.bandwidth() / 2;
|
|
13
12
|
}
|
|
14
13
|
return value => scale(value);
|
|
15
14
|
}
|
|
@@ -17,7 +16,7 @@ export function useXScale(identifier) {
|
|
|
17
16
|
const {
|
|
18
17
|
xAxis,
|
|
19
18
|
xAxisIds
|
|
20
|
-
} =
|
|
19
|
+
} = useCartesianContext();
|
|
21
20
|
const id = typeof identifier === 'string' ? identifier : xAxisIds[identifier ?? 0];
|
|
22
21
|
return xAxis[id].scale;
|
|
23
22
|
}
|
|
@@ -25,7 +24,7 @@ export function useYScale(identifier) {
|
|
|
25
24
|
const {
|
|
26
25
|
yAxis,
|
|
27
26
|
yAxisIds
|
|
28
|
-
} =
|
|
27
|
+
} = useCartesianContext();
|
|
29
28
|
const id = typeof identifier === 'string' ? identifier : yAxisIds[identifier ?? 0];
|
|
30
29
|
return yAxis[id].scale;
|
|
31
30
|
}
|
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'
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { useCartesianContext } from '../../../context/CartesianProvider';
|
|
3
3
|
import { DrawingContext } from '../../../context/DrawingProvider';
|
|
4
4
|
import { useDrawingArea } from '../../../hooks';
|
|
5
5
|
import ChartsPiecewiseGradient from './ChartsPiecewiseGradient';
|
|
@@ -28,7 +28,7 @@ export function ChartsAxesGradients() {
|
|
|
28
28
|
xAxis,
|
|
29
29
|
yAxisIds,
|
|
30
30
|
yAxis
|
|
31
|
-
} =
|
|
31
|
+
} = useCartesianContext();
|
|
32
32
|
return /*#__PURE__*/_jsxs("defs", {
|
|
33
33
|
children: [yAxisIds.filter(axisId => yAxis[axisId].colorMap !== undefined).map(axisId => {
|
|
34
34
|
const gradientId = getGradientId(axisId, 'y');
|
|
@@ -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,19 +6,25 @@ export * from '../ResponsiveChartContainer/ResizableContainer';
|
|
|
6
6
|
// hooks
|
|
7
7
|
export { useReducedMotion } from '../hooks/useReducedMotion';
|
|
8
8
|
export { useSeries } from '../hooks/useSeries';
|
|
9
|
+
export { useDrawingArea } from '../hooks/useDrawingArea';
|
|
10
|
+
export { useChartContainerHooks } from '../ChartContainer/useChartContainerHooks';
|
|
11
|
+
export { useScatterChartProps } from '../ScatterChart/useScatterChartProps';
|
|
12
|
+
export { useLineChartProps } from '../LineChart/useLineChartProps';
|
|
13
|
+
export { useBarChartProps } from '../BarChart/useBarChartProps';
|
|
9
14
|
|
|
10
15
|
// utils
|
|
11
16
|
export * from './defaultizeValueFormatter';
|
|
12
17
|
export * from './configInit';
|
|
18
|
+
export * from './getSVGPoint';
|
|
13
19
|
|
|
14
20
|
// contexts
|
|
15
21
|
|
|
16
|
-
export * from '../context/
|
|
22
|
+
export * from '../context/CartesianProvider';
|
|
17
23
|
export * from '../context/DrawingProvider';
|
|
24
|
+
export * from '../context/ColorProvider';
|
|
18
25
|
export * from '../context/InteractionProvider';
|
|
19
26
|
export * from '../context/SeriesContextProvider';
|
|
20
27
|
export * from '../context/ZAxisContextProvider';
|
|
21
|
-
|
|
22
28
|
// series configuration
|
|
23
29
|
export * from '../models/seriesType/config';
|
|
24
30
|
export * from '../models/seriesType/common';
|
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/useAxisEvents.js
CHANGED
|
@@ -6,9 +6,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.useAxisEvents = void 0;
|
|
7
7
|
var React = _interopRequireWildcard(require("react"));
|
|
8
8
|
var _InteractionProvider = require("../context/InteractionProvider");
|
|
9
|
-
var
|
|
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); }
|
|
@@ -29,7 +29,7 @@ const useAxisEvents = disableAxisListener => {
|
|
|
29
29
|
yAxis,
|
|
30
30
|
xAxisIds,
|
|
31
31
|
yAxisIds
|
|
32
|
-
} =
|
|
32
|
+
} = (0, _CartesianProvider.useCartesianContext)();
|
|
33
33
|
const {
|
|
34
34
|
dispatch
|
|
35
35
|
} = React.useContext(_InteractionProvider.InteractionContext);
|
|
@@ -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)(svgRef.current, 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: {
|
|
@@ -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>;
|
package/hooks/useColorScale.js
CHANGED
|
@@ -7,7 +7,7 @@ exports.useXColorScale = useXColorScale;
|
|
|
7
7
|
exports.useYColorScale = useYColorScale;
|
|
8
8
|
exports.useZColorScale = useZColorScale;
|
|
9
9
|
var React = _interopRequireWildcard(require("react"));
|
|
10
|
-
var
|
|
10
|
+
var _CartesianProvider = require("../context/CartesianProvider");
|
|
11
11
|
var _ZAxisContextProvider = require("../context/ZAxisContextProvider");
|
|
12
12
|
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); }
|
|
13
13
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
@@ -15,7 +15,7 @@ function useXColorScale(identifier) {
|
|
|
15
15
|
const {
|
|
16
16
|
xAxis,
|
|
17
17
|
xAxisIds
|
|
18
|
-
} =
|
|
18
|
+
} = (0, _CartesianProvider.useCartesianContext)();
|
|
19
19
|
const id = typeof identifier === 'string' ? identifier : xAxisIds[identifier ?? 0];
|
|
20
20
|
return xAxis[id].colorScale;
|
|
21
21
|
}
|
|
@@ -23,7 +23,7 @@ function useYColorScale(identifier) {
|
|
|
23
23
|
const {
|
|
24
24
|
yAxis,
|
|
25
25
|
yAxisIds
|
|
26
|
-
} =
|
|
26
|
+
} = (0, _CartesianProvider.useCartesianContext)();
|
|
27
27
|
const id = typeof identifier === 'string' ? identifier : yAxisIds[identifier ?? 0];
|
|
28
28
|
return yAxis[id].colorScale;
|
|
29
29
|
}
|
|
@@ -1,8 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
top: number;
|
|
4
|
-
width: number;
|
|
5
|
-
height: number;
|
|
6
|
-
bottom: number;
|
|
7
|
-
right: number;
|
|
8
|
-
};
|
|
1
|
+
import { DrawingArea } from '../context/DrawingProvider';
|
|
2
|
+
export declare function useDrawingArea(): DrawingArea;
|
package/hooks/useScale.js
CHANGED
|
@@ -6,11 +6,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.getValueToPositionMapper = getValueToPositionMapper;
|
|
7
7
|
exports.useXScale = useXScale;
|
|
8
8
|
exports.useYScale = useYScale;
|
|
9
|
-
var
|
|
10
|
-
var _CartesianContextProvider = require("../context/CartesianContextProvider");
|
|
9
|
+
var _CartesianProvider = require("../context/CartesianProvider");
|
|
11
10
|
var _isBandScale = require("../internals/isBandScale");
|
|
12
|
-
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); }
|
|
13
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
14
11
|
/**
|
|
15
12
|
* For a given scale return a function that map value to their position.
|
|
16
13
|
* Useful when dealing with specific scale such as band.
|
|
@@ -19,7 +16,7 @@ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e;
|
|
|
19
16
|
*/
|
|
20
17
|
function getValueToPositionMapper(scale) {
|
|
21
18
|
if ((0, _isBandScale.isBandScale)(scale)) {
|
|
22
|
-
return value => scale(value) + scale.bandwidth() / 2;
|
|
19
|
+
return value => (scale(value) ?? 0) + scale.bandwidth() / 2;
|
|
23
20
|
}
|
|
24
21
|
return value => scale(value);
|
|
25
22
|
}
|
|
@@ -27,7 +24,7 @@ function useXScale(identifier) {
|
|
|
27
24
|
const {
|
|
28
25
|
xAxis,
|
|
29
26
|
xAxisIds
|
|
30
|
-
} =
|
|
27
|
+
} = (0, _CartesianProvider.useCartesianContext)();
|
|
31
28
|
const id = typeof identifier === 'string' ? identifier : xAxisIds[identifier ?? 0];
|
|
32
29
|
return xAxis[id].scale;
|
|
33
30
|
}
|
|
@@ -35,7 +32,7 @@ function useYScale(identifier) {
|
|
|
35
32
|
const {
|
|
36
33
|
yAxis,
|
|
37
34
|
yAxisIds
|
|
38
|
-
} =
|
|
35
|
+
} = (0, _CartesianProvider.useCartesianContext)();
|
|
39
36
|
const id = typeof identifier === 'string' ? identifier : yAxisIds[identifier ?? 0];
|
|
40
37
|
return yAxis[id].scale;
|
|
41
38
|
}
|
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,3 +1,4 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
|
|
2
|
+
import { AxisId } from '../../../models/axis';
|
|
3
|
+
export declare function useChartGradient(): (axisId: AxisId, direction: "x" | "y") => string;
|
|
3
4
|
export declare function ChartsAxesGradients(): React.JSX.Element;
|
|
@@ -7,7 +7,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.ChartsAxesGradients = ChartsAxesGradients;
|
|
8
8
|
exports.useChartGradient = useChartGradient;
|
|
9
9
|
var React = _interopRequireWildcard(require("react"));
|
|
10
|
-
var
|
|
10
|
+
var _CartesianProvider = require("../../../context/CartesianProvider");
|
|
11
11
|
var _DrawingProvider = require("../../../context/DrawingProvider");
|
|
12
12
|
var _hooks = require("../../../hooks");
|
|
13
13
|
var _ChartsPiecewiseGradient = _interopRequireDefault(require("./ChartsPiecewiseGradient"));
|
|
@@ -38,7 +38,7 @@ function ChartsAxesGradients() {
|
|
|
38
38
|
xAxis,
|
|
39
39
|
yAxisIds,
|
|
40
40
|
yAxis
|
|
41
|
-
} =
|
|
41
|
+
} = (0, _CartesianProvider.useCartesianContext)();
|
|
42
42
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)("defs", {
|
|
43
43
|
children: [yAxisIds.filter(axisId => yAxis[axisId].colorMap !== undefined).map(axisId => {
|
|
44
44
|
const gradientId = getGradientId(axisId, 'y');
|