@mui/x-charts 6.0.0-alpha.1 → 6.0.0-alpha.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/BarChart/BarChart.d.ts +1 -4
- package/BarChart/BarChart.js +6 -3
- package/BarChart/BarPlot.js +42 -8
- package/BarChart/legend.d.ts +3 -0
- package/BarChart/legend.js +20 -0
- package/CHANGELOG.md +287 -107
- package/ChartContainer/index.d.ts +3 -1
- package/ChartContainer/index.js +10 -6
- package/ChartsAxisHighlight/ChartsAxisHighlight.js +3 -2
- package/ChartsLegend/ChartsLegend.d.ts +5 -1
- package/ChartsLegend/ChartsLegend.js +5 -1
- package/ChartsLegend/utils.d.ts +1 -1
- package/ChartsLegend/utils.js +12 -1
- package/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
- package/ChartsTooltip/ChartsItemTooltipContent.js +11 -2
- package/LineChart/LineChart.d.ts +1 -4
- package/LineChart/LineChart.js +6 -3
- package/LineChart/legend.d.ts +3 -0
- package/LineChart/legend.js +20 -0
- package/PieChart/PieArc.d.ts +36 -0
- package/PieChart/PieArc.js +128 -0
- package/PieChart/PieArcLabel.d.ts +36 -0
- package/PieChart/PieArcLabel.js +113 -0
- package/PieChart/PieChart.d.ts +20 -0
- package/PieChart/PieChart.js +292 -0
- package/PieChart/PiePlot.d.ts +2 -0
- package/PieChart/PiePlot.js +98 -0
- package/PieChart/formatter.d.ts +3 -0
- package/PieChart/formatter.js +49 -0
- package/PieChart/index.d.ts +4 -0
- package/PieChart/index.js +47 -0
- package/PieChart/legend.d.ts +3 -0
- package/PieChart/legend.js +19 -0
- package/PieChart/package.json +6 -0
- package/README.md +2 -2
- package/ResponsiveChartContainer/index.d.ts +1 -1
- package/ResponsiveChartContainer/index.js +22 -9
- package/ScatterChart/Scatter.d.ts +1 -1
- package/ScatterChart/Scatter.js +1 -1
- package/ScatterChart/ScatterChart.d.ts +1 -4
- package/ScatterChart/ScatterChart.js +6 -3
- package/ScatterChart/legend.d.ts +3 -0
- package/ScatterChart/legend.js +20 -0
- package/context/CartesianContextProvider.js +31 -20
- package/context/SeriesContextProvider.js +11 -1
- package/esm/BarChart/BarChart.js +4 -2
- package/esm/BarChart/BarPlot.js +44 -8
- package/esm/BarChart/legend.js +13 -0
- package/esm/ChartContainer/index.js +7 -5
- package/esm/ChartsAxisHighlight/ChartsAxisHighlight.js +3 -2
- package/esm/ChartsLegend/ChartsLegend.js +5 -1
- package/esm/ChartsLegend/utils.js +11 -1
- package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
- package/esm/ChartsTooltip/ChartsItemTooltipContent.js +11 -3
- package/esm/LineChart/LineChart.js +4 -2
- package/esm/LineChart/legend.js +13 -0
- package/esm/PieChart/PieArc.js +117 -0
- package/esm/PieChart/PieArcLabel.js +101 -0
- package/esm/PieChart/PieChart.js +285 -0
- package/esm/PieChart/PiePlot.js +92 -0
- package/esm/PieChart/formatter.js +48 -0
- package/esm/PieChart/index.js +4 -0
- package/esm/PieChart/legend.js +12 -0
- package/esm/ResponsiveChartContainer/index.js +20 -8
- package/esm/ScatterChart/Scatter.js +1 -1
- package/esm/ScatterChart/ScatterChart.js +4 -2
- package/esm/ScatterChart/legend.js +13 -0
- package/esm/context/CartesianContextProvider.js +31 -18
- package/esm/context/SeriesContextProvider.js +11 -1
- package/esm/hooks/index.js +2 -0
- package/esm/hooks/useAxisEvents.js +12 -7
- package/esm/hooks/useDrawingArea.js +16 -0
- package/esm/hooks/useScale.js +19 -21
- package/esm/hooks/useTicks.js +26 -13
- package/esm/index.js +2 -0
- package/esm/internals/defaultizeColor.js +7 -0
- package/esm/internals/getScale.js +17 -0
- package/esm/internals/isBandScale.js +3 -0
- package/esm/models/axis.js +6 -1
- package/esm/models/seriesType/index.js +1 -8
- package/hooks/index.d.ts +2 -0
- package/hooks/index.js +27 -0
- package/hooks/package.json +6 -0
- package/hooks/useAxisEvents.js +14 -9
- package/hooks/useDrawingArea.d.ts +6 -0
- package/hooks/useDrawingArea.js +24 -0
- package/hooks/useScale.d.ts +3 -6
- package/hooks/useScale.js +24 -24
- package/hooks/useTicks.d.ts +1 -1
- package/hooks/useTicks.js +19 -9
- package/index.d.ts +2 -0
- package/index.js +23 -1
- package/internals/defaultizeColor.d.ts +35 -0
- package/internals/defaultizeColor.js +7 -0
- package/internals/getScale.d.ts +2 -0
- package/internals/getScale.js +23 -0
- package/internals/isBandScale.d.ts +3 -0
- package/internals/isBandScale.js +9 -0
- package/legacy/BarChart/BarChart.js +4 -2
- package/legacy/BarChart/BarPlot.js +44 -10
- package/legacy/BarChart/legend.js +15 -0
- package/legacy/ChartContainer/index.js +7 -5
- package/legacy/ChartsAxisHighlight/ChartsAxisHighlight.js +3 -2
- package/legacy/ChartsLegend/ChartsLegend.js +5 -1
- package/legacy/ChartsLegend/utils.js +12 -6
- package/legacy/ChartsTooltip/ChartsAxisTooltipContent.js +3 -1
- package/legacy/ChartsTooltip/ChartsItemTooltipContent.js +10 -3
- package/legacy/LineChart/LineChart.js +4 -2
- package/legacy/LineChart/legend.js +15 -0
- package/legacy/PieChart/PieArc.js +118 -0
- package/legacy/PieChart/PieArcLabel.js +101 -0
- package/legacy/PieChart/PieChart.js +297 -0
- package/legacy/PieChart/PiePlot.js +89 -0
- package/legacy/PieChart/formatter.js +55 -0
- package/legacy/PieChart/index.js +4 -0
- package/legacy/PieChart/legend.js +16 -0
- package/legacy/ResponsiveChartContainer/index.js +18 -8
- package/legacy/ScatterChart/Scatter.js +1 -1
- package/legacy/ScatterChart/ScatterChart.js +4 -2
- package/legacy/ScatterChart/legend.js +15 -0
- package/legacy/context/CartesianContextProvider.js +31 -18
- package/legacy/context/SeriesContextProvider.js +11 -1
- package/legacy/hooks/index.js +2 -0
- package/legacy/hooks/useAxisEvents.js +12 -7
- package/legacy/hooks/useDrawingArea.js +17 -0
- package/legacy/hooks/useScale.js +17 -21
- package/legacy/hooks/useTicks.js +26 -13
- package/legacy/index.js +3 -1
- package/legacy/internals/defaultizeColor.js +9 -0
- package/legacy/internals/getScale.js +17 -0
- package/legacy/internals/isBandScale.js +3 -0
- package/legacy/models/axis.js +6 -1
- package/legacy/models/seriesType/index.js +1 -8
- package/models/axis.d.ts +25 -12
- package/models/axis.js +9 -1
- package/models/seriesType/bar.d.ts +1 -1
- package/models/seriesType/common.d.ts +1 -1
- package/models/seriesType/config.d.ts +29 -2
- package/models/seriesType/index.d.ts +7 -3
- package/models/seriesType/index.js +11 -0
- package/models/seriesType/line.d.ts +1 -1
- package/models/seriesType/pie.d.ts +103 -3
- package/models/seriesType/scatter.d.ts +1 -1
- package/modern/BarChart/BarChart.js +4 -2
- package/modern/BarChart/BarPlot.js +44 -8
- package/modern/BarChart/legend.js +13 -0
- package/modern/ChartContainer/index.js +7 -5
- package/modern/ChartsAxisHighlight/ChartsAxisHighlight.js +3 -2
- package/modern/ChartsLegend/ChartsLegend.js +5 -1
- package/modern/ChartsLegend/utils.js +11 -1
- package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
- package/modern/ChartsTooltip/ChartsItemTooltipContent.js +11 -2
- package/modern/LineChart/LineChart.js +4 -2
- package/modern/LineChart/legend.js +13 -0
- package/modern/PieChart/PieArc.js +116 -0
- package/modern/PieChart/PieArcLabel.js +101 -0
- package/modern/PieChart/PieChart.js +285 -0
- package/modern/PieChart/PiePlot.js +91 -0
- package/modern/PieChart/formatter.js +41 -0
- package/modern/PieChart/index.js +4 -0
- package/modern/PieChart/legend.js +12 -0
- package/modern/ResponsiveChartContainer/index.js +20 -8
- package/modern/ScatterChart/Scatter.js +1 -1
- package/modern/ScatterChart/ScatterChart.js +4 -2
- package/modern/ScatterChart/legend.js +13 -0
- package/modern/context/CartesianContextProvider.js +29 -18
- package/modern/context/SeriesContextProvider.js +11 -1
- package/modern/hooks/index.js +2 -0
- package/modern/hooks/useAxisEvents.js +12 -7
- package/modern/hooks/useDrawingArea.js +16 -0
- package/modern/hooks/useScale.js +19 -21
- package/modern/hooks/useTicks.js +18 -8
- package/modern/index.js +3 -1
- package/modern/internals/defaultizeColor.js +7 -0
- package/modern/internals/getScale.js +17 -0
- package/modern/internals/isBandScale.js +3 -0
- package/modern/models/axis.js +6 -1
- package/modern/models/seriesType/index.js +1 -8
- package/package.json +1 -1
|
@@ -2,7 +2,7 @@ import * as React from 'react';
|
|
|
2
2
|
import { InteractionContext } from '../context/InteractionProvider';
|
|
3
3
|
import { CartesianContext } from '../context/CartesianContextProvider';
|
|
4
4
|
import { SVGContext, DrawingContext } from '../context/DrawingProvider';
|
|
5
|
-
import { isBandScale } from '
|
|
5
|
+
import { isBandScale } from '../internals/isBandScale';
|
|
6
6
|
export const useAxisEvents = disableAxisListener => {
|
|
7
7
|
const svgRef = React.useContext(SVGContext);
|
|
8
8
|
const {
|
|
@@ -109,12 +109,17 @@ export const useAxisEvents = disableAxisListener => {
|
|
|
109
109
|
});
|
|
110
110
|
};
|
|
111
111
|
const handleMouseMove = event => {
|
|
112
|
+
// Get mouse coordinate in global SVG space
|
|
113
|
+
const pt = svgRef.current.createSVGPoint();
|
|
114
|
+
pt.x = event.clientX;
|
|
115
|
+
pt.y = event.clientY;
|
|
116
|
+
const svgPt = pt.matrixTransform(svgRef.current.getScreenCTM().inverse());
|
|
112
117
|
mousePosition.current = {
|
|
113
|
-
x:
|
|
114
|
-
y:
|
|
118
|
+
x: svgPt.x,
|
|
119
|
+
y: svgPt.y
|
|
115
120
|
};
|
|
116
|
-
const outsideX =
|
|
117
|
-
const outsideY =
|
|
121
|
+
const outsideX = svgPt.x < left || svgPt.x > left + width;
|
|
122
|
+
const outsideY = svgPt.y < top || svgPt.y > top + height;
|
|
118
123
|
if (outsideX || outsideY) {
|
|
119
124
|
dispatch({
|
|
120
125
|
type: 'updateAxis',
|
|
@@ -125,8 +130,8 @@ export const useAxisEvents = disableAxisListener => {
|
|
|
125
130
|
});
|
|
126
131
|
return;
|
|
127
132
|
}
|
|
128
|
-
const newStateX = getUpdateX(
|
|
129
|
-
const newStateY = getUpdateY(
|
|
133
|
+
const newStateX = getUpdateX(svgPt.x);
|
|
134
|
+
const newStateY = getUpdateY(svgPt.y);
|
|
130
135
|
dispatch({
|
|
131
136
|
type: 'updateAxis',
|
|
132
137
|
data: {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { DrawingContext } from '../context/DrawingProvider';
|
|
3
|
+
export function useDrawingArea() {
|
|
4
|
+
const {
|
|
5
|
+
left,
|
|
6
|
+
top,
|
|
7
|
+
width,
|
|
8
|
+
height
|
|
9
|
+
} = React.useContext(DrawingContext);
|
|
10
|
+
return React.useMemo(() => ({
|
|
11
|
+
left,
|
|
12
|
+
top,
|
|
13
|
+
width,
|
|
14
|
+
height
|
|
15
|
+
}), [height, left, top, width]);
|
|
16
|
+
}
|
package/modern/hooks/useScale.js
CHANGED
|
@@ -1,24 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
case 'log':
|
|
5
|
-
return scaleLog(domain, range);
|
|
6
|
-
case 'pow':
|
|
7
|
-
return scalePow(domain, range);
|
|
8
|
-
case 'sqrt':
|
|
9
|
-
return scaleSqrt(domain, range);
|
|
10
|
-
case 'time':
|
|
11
|
-
return scaleTime(domain, range);
|
|
12
|
-
case 'utc':
|
|
13
|
-
return scaleUtc(domain, range);
|
|
14
|
-
default:
|
|
15
|
-
return scaleLinear(domain, range);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
export function isBandScale(scale) {
|
|
19
|
-
return scale.bandwidth !== undefined;
|
|
20
|
-
}
|
|
21
|
-
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { CartesianContext } from '../context/CartesianContextProvider';
|
|
3
|
+
import { isBandScale } from '../internals/isBandScale';
|
|
22
4
|
/**
|
|
23
5
|
* For a given scale return a function that map value to their position.
|
|
24
6
|
* Usefull when dealing with specific scale such as band.
|
|
@@ -30,4 +12,20 @@ export function getValueToPositionMapper(scale) {
|
|
|
30
12
|
return value => scale(value) + scale.bandwidth() / 2;
|
|
31
13
|
}
|
|
32
14
|
return value => scale(value);
|
|
15
|
+
}
|
|
16
|
+
export function useXScale(identifier) {
|
|
17
|
+
const {
|
|
18
|
+
xAxis,
|
|
19
|
+
xAxisIds
|
|
20
|
+
} = React.useContext(CartesianContext);
|
|
21
|
+
const id = typeof identifier === 'string' ? identifier : xAxisIds[identifier ?? 0];
|
|
22
|
+
return xAxis[id].scale;
|
|
23
|
+
}
|
|
24
|
+
export function useYScale(identifier) {
|
|
25
|
+
const {
|
|
26
|
+
yAxis,
|
|
27
|
+
yAxisIds
|
|
28
|
+
} = React.useContext(CartesianContext);
|
|
29
|
+
const id = typeof identifier === 'string' ? identifier : yAxisIds[identifier ?? 0];
|
|
30
|
+
return yAxis[id].scale;
|
|
33
31
|
}
|
package/modern/hooks/useTicks.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { isBandScale } from '
|
|
2
|
+
import { isBandScale } from '../internals/isBandScale';
|
|
3
3
|
export function getTicksNumber(params) {
|
|
4
4
|
const {
|
|
5
5
|
maxTicks = 999,
|
|
@@ -20,15 +20,25 @@ function useTicks(options) {
|
|
|
20
20
|
// band scale
|
|
21
21
|
if (isBandScale(scale)) {
|
|
22
22
|
const domain = scale.domain();
|
|
23
|
-
|
|
23
|
+
if (scale.bandwidth() > 0) {
|
|
24
|
+
// scale type = 'band'
|
|
25
|
+
return [...domain.map((value, index) => ({
|
|
26
|
+
formattedValue: valueFormatter?.(value) ?? value,
|
|
27
|
+
offset: index === 0 ? scale.range()[0] : scale(value) - (scale.step() - scale.bandwidth()) / 2,
|
|
28
|
+
labelOffset: scale.step() / 2
|
|
29
|
+
})), {
|
|
30
|
+
formattedValue: undefined,
|
|
31
|
+
offset: scale.range()[1],
|
|
32
|
+
labelOffset: 0
|
|
33
|
+
}];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// scale type = 'point'
|
|
37
|
+
return domain.map(value => ({
|
|
24
38
|
formattedValue: valueFormatter?.(value) ?? value,
|
|
25
|
-
offset: scale(value)
|
|
26
|
-
labelOffset: scale.bandwidth() / 2
|
|
27
|
-
})), ...(scale.bandwidth() > 0 ? [{
|
|
28
|
-
formattedValue: undefined,
|
|
29
|
-
offset: scale.range()[1],
|
|
39
|
+
offset: scale(value),
|
|
30
40
|
labelOffset: 0
|
|
31
|
-
}
|
|
41
|
+
}));
|
|
32
42
|
}
|
|
33
43
|
return scale.ticks(ticksNumber).map(value => ({
|
|
34
44
|
formattedValue: valueFormatter?.(value) ?? scale.tickFormat(ticksNumber)(value),
|
package/modern/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @mui/x-charts v6.0.0-alpha.
|
|
2
|
+
* @mui/x-charts v6.0.0-alpha.3
|
|
3
3
|
*
|
|
4
4
|
* @license MIT
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
export * from './constants';
|
|
9
9
|
export * from './context';
|
|
10
|
+
export * from './hooks';
|
|
10
11
|
export * from './colorPalettes';
|
|
11
12
|
export * from './models';
|
|
12
13
|
export * from './ChartsClipPath';
|
|
@@ -17,6 +18,7 @@ export * from './ChartsTooltip';
|
|
|
17
18
|
export * from './ChartsAxisHighlight';
|
|
18
19
|
export * from './BarChart';
|
|
19
20
|
export * from './LineChart';
|
|
21
|
+
export * from './PieChart';
|
|
20
22
|
export * from './ScatterChart';
|
|
21
23
|
export * from './ChartContainer';
|
|
22
24
|
export * from './ResponsiveChartContainer';
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
const DEFAULT_COLORS = ['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2', '#7f7f7f', '#bcbd22', '#17becf'];
|
|
3
3
|
export function defaultizeColor(series, seriesIndex, colors = DEFAULT_COLORS) {
|
|
4
|
+
if (series.type === 'pie') {
|
|
5
|
+
return _extends({}, series, {
|
|
6
|
+
data: series.data.map((d, index) => _extends({
|
|
7
|
+
color: colors[index % colors.length]
|
|
8
|
+
}, d))
|
|
9
|
+
});
|
|
10
|
+
}
|
|
4
11
|
return _extends({
|
|
5
12
|
color: colors[seriesIndex % colors.length]
|
|
6
13
|
}, series);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { scaleLog, scalePow, scaleSqrt, scaleTime, scaleUtc, scaleLinear } from 'd3-scale';
|
|
2
|
+
export function getScale(scaleType, domain, range) {
|
|
3
|
+
switch (scaleType) {
|
|
4
|
+
case 'log':
|
|
5
|
+
return scaleLog(domain, range);
|
|
6
|
+
case 'pow':
|
|
7
|
+
return scalePow(domain, range);
|
|
8
|
+
case 'sqrt':
|
|
9
|
+
return scaleSqrt(domain, range);
|
|
10
|
+
case 'time':
|
|
11
|
+
return scaleTime(domain, range);
|
|
12
|
+
case 'utc':
|
|
13
|
+
return scaleUtc(domain, range);
|
|
14
|
+
default:
|
|
15
|
+
return scaleLinear(domain, range);
|
|
16
|
+
}
|
|
17
|
+
}
|
package/modern/models/axis.js
CHANGED