@mui/x-charts 6.0.0-alpha.2 → 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 +5 -3
- package/BarChart/BarPlot.js +42 -8
- package/CHANGELOG.md +232 -114
- package/ChartContainer/index.d.ts +3 -1
- package/ChartContainer/index.js +10 -6
- package/ChartsAxisHighlight/ChartsAxisHighlight.js +3 -2
- package/LineChart/LineChart.d.ts +1 -4
- package/LineChart/LineChart.js +5 -3
- package/ResponsiveChartContainer/index.d.ts +1 -1
- package/ResponsiveChartContainer/index.js +11 -9
- package/ScatterChart/Scatter.d.ts +1 -1
- package/ScatterChart/ScatterChart.d.ts +1 -4
- package/ScatterChart/ScatterChart.js +5 -3
- package/context/CartesianContextProvider.js +31 -20
- package/context/SeriesContextProvider.js +2 -2
- package/esm/BarChart/BarChart.js +3 -2
- package/esm/BarChart/BarPlot.js +44 -8
- package/esm/ChartContainer/index.js +7 -5
- package/esm/ChartsAxisHighlight/ChartsAxisHighlight.js +3 -2
- package/esm/LineChart/LineChart.js +3 -2
- package/esm/ResponsiveChartContainer/index.js +9 -8
- package/esm/ScatterChart/ScatterChart.js +3 -2
- package/esm/context/CartesianContextProvider.js +31 -18
- package/esm/context/SeriesContextProvider.js +2 -2
- 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 +1 -0
- package/esm/internals/getScale.js +17 -0
- package/esm/internals/isBandScale.js +3 -0
- package/esm/models/axis.js +6 -1
- 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 +1 -0
- package/index.js +12 -1
- 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 +3 -2
- package/legacy/BarChart/BarPlot.js +44 -10
- package/legacy/ChartContainer/index.js +7 -5
- package/legacy/ChartsAxisHighlight/ChartsAxisHighlight.js +3 -2
- package/legacy/LineChart/LineChart.js +3 -2
- package/legacy/ResponsiveChartContainer/index.js +9 -8
- package/legacy/ScatterChart/ScatterChart.js +3 -2
- package/legacy/context/CartesianContextProvider.js +31 -18
- package/legacy/context/SeriesContextProvider.js +2 -2
- 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 +2 -1
- package/legacy/internals/getScale.js +17 -0
- package/legacy/internals/isBandScale.js +3 -0
- package/legacy/models/axis.js +6 -1
- package/models/axis.d.ts +25 -12
- package/models/axis.js +9 -1
- package/models/seriesType/pie.d.ts +2 -2
- package/modern/BarChart/BarChart.js +3 -2
- package/modern/BarChart/BarPlot.js +44 -8
- package/modern/ChartContainer/index.js +7 -5
- package/modern/ChartsAxisHighlight/ChartsAxisHighlight.js +3 -2
- package/modern/LineChart/LineChart.js +3 -2
- package/modern/ResponsiveChartContainer/index.js +9 -8
- package/modern/ScatterChart/ScatterChart.js +3 -2
- package/modern/context/CartesianContextProvider.js +29 -18
- package/modern/context/SeriesContextProvider.js +2 -2
- 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 +2 -1
- package/modern/internals/getScale.js +17 -0
- package/modern/internals/isBandScale.js +3 -0
- package/modern/models/axis.js +6 -1
- package/package.json +1 -1
|
@@ -13,7 +13,7 @@ import { ChartsAxisHighlight } from '../ChartsAxisHighlight';
|
|
|
13
13
|
import { ChartsClipPath } from '../ChartsClipPath';
|
|
14
14
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
15
15
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
16
|
-
function BarChart(props) {
|
|
16
|
+
var BarChart = /*#__PURE__*/React.forwardRef(function BarChart(props, ref) {
|
|
17
17
|
var xAxis = props.xAxis,
|
|
18
18
|
yAxis = props.yAxis,
|
|
19
19
|
series = props.series,
|
|
@@ -33,6 +33,7 @@ function BarChart(props) {
|
|
|
33
33
|
var id = useId();
|
|
34
34
|
var clipPathId = "".concat(id, "-clip-path");
|
|
35
35
|
return /*#__PURE__*/_jsxs(ResponsiveChartContainer, {
|
|
36
|
+
ref: ref,
|
|
36
37
|
series: series.map(function (s) {
|
|
37
38
|
return _extends({
|
|
38
39
|
type: 'bar'
|
|
@@ -70,7 +71,7 @@ function BarChart(props) {
|
|
|
70
71
|
id: clipPathId
|
|
71
72
|
}), children]
|
|
72
73
|
});
|
|
73
|
-
}
|
|
74
|
+
});
|
|
74
75
|
process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
75
76
|
// ----------------------------- Warning --------------------------------
|
|
76
77
|
// | These PropTypes are generated from the TypeScript type definitions |
|
|
@@ -2,9 +2,36 @@ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { SeriesContext } from '../context/SeriesContextProvider';
|
|
4
4
|
import { CartesianContext } from '../context/CartesianContextProvider';
|
|
5
|
-
import { isBandScale } from '../hooks/useScale';
|
|
6
5
|
import { BarElement } from './BarElement';
|
|
6
|
+
import { isBandScaleConfig } from '../models/axis';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Solution of the equations
|
|
10
|
+
* W = barWidth * N + offset * (N-1)
|
|
11
|
+
* offset / (offset + barWidth) = r
|
|
12
|
+
* @param bandWidth The width available to place bars.
|
|
13
|
+
* @param numberOfGroups The number of bars to place in that space.
|
|
14
|
+
* @param gapRatio The ratio of the gap between bars over the bar width.
|
|
15
|
+
* @returns The bar width and the offset between bars.
|
|
16
|
+
*/
|
|
7
17
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
18
|
+
function getBandSize(_ref) {
|
|
19
|
+
var W = _ref.bandWidth,
|
|
20
|
+
N = _ref.numberOfGroups,
|
|
21
|
+
r = _ref.gapRatio;
|
|
22
|
+
if (r === 0) {
|
|
23
|
+
return {
|
|
24
|
+
barWidth: W / N,
|
|
25
|
+
offset: 0
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
var barWidth = W / (N + (N - 1) * r);
|
|
29
|
+
var offset = r * barWidth;
|
|
30
|
+
return {
|
|
31
|
+
barWidth: barWidth,
|
|
32
|
+
offset: offset
|
|
33
|
+
};
|
|
34
|
+
}
|
|
8
35
|
export function BarPlot() {
|
|
9
36
|
var seriesData = React.useContext(SeriesContext).bar;
|
|
10
37
|
var axisData = React.useContext(CartesianContext);
|
|
@@ -20,25 +47,32 @@ export function BarPlot() {
|
|
|
20
47
|
var defaultXAxisId = xAxisIds[0];
|
|
21
48
|
var defaultYAxisId = yAxisIds[0];
|
|
22
49
|
return /*#__PURE__*/_jsx(React.Fragment, {
|
|
23
|
-
children: stackingGroups.flatMap(function (
|
|
24
|
-
var groupIds =
|
|
50
|
+
children: stackingGroups.flatMap(function (_ref2, groupIndex) {
|
|
51
|
+
var groupIds = _ref2.ids;
|
|
25
52
|
return groupIds.flatMap(function (seriesId) {
|
|
26
53
|
var _series$seriesId$xAxi, _series$seriesId$yAxi;
|
|
27
54
|
var xAxisKey = (_series$seriesId$xAxi = series[seriesId].xAxisKey) != null ? _series$seriesId$xAxi : defaultXAxisId;
|
|
28
55
|
var yAxisKey = (_series$seriesId$yAxi = series[seriesId].yAxisKey) != null ? _series$seriesId$yAxi : defaultYAxisId;
|
|
29
|
-
var
|
|
30
|
-
var
|
|
31
|
-
if (!
|
|
32
|
-
throw new Error("Axis with id \"".concat(xAxisKey, "\" shoud be of type \"band\" to display the bar series ").concat(
|
|
56
|
+
var xAxisConfig = xAxis[xAxisKey];
|
|
57
|
+
var yAxisConfig = yAxis[yAxisKey];
|
|
58
|
+
if (!isBandScaleConfig(xAxisConfig)) {
|
|
59
|
+
throw new Error("Axis with id \"".concat(xAxisKey, "\" shoud be of type \"band\" to display the bar series of id \"").concat(seriesId, "\""));
|
|
33
60
|
}
|
|
34
61
|
if (xAxis[xAxisKey].data === undefined) {
|
|
35
62
|
throw new Error("Axis with id \"".concat(xAxisKey, "\" shoud have data property"));
|
|
36
63
|
}
|
|
64
|
+
var xScale = xAxisConfig.scale;
|
|
65
|
+
var yScale = yAxisConfig.scale;
|
|
37
66
|
|
|
38
67
|
// Currently assuming all bars are vertical
|
|
39
68
|
var bandWidth = xScale.bandwidth();
|
|
40
|
-
var
|
|
41
|
-
|
|
69
|
+
var _getBandSize = getBandSize({
|
|
70
|
+
bandWidth: bandWidth,
|
|
71
|
+
numberOfGroups: stackingGroups.length,
|
|
72
|
+
gapRatio: xAxisConfig.barGapRatio
|
|
73
|
+
}),
|
|
74
|
+
barWidth = _getBandSize.barWidth,
|
|
75
|
+
offset = _getBandSize.offset;
|
|
42
76
|
|
|
43
77
|
// @ts-ignore TODO: fix when adding a correct API for customisation
|
|
44
78
|
var _series$seriesId = series[seriesId],
|
|
@@ -51,7 +85,7 @@ export function BarPlot() {
|
|
|
51
85
|
return /*#__PURE__*/_jsx(BarElement, {
|
|
52
86
|
id: seriesId,
|
|
53
87
|
dataIndex: dataIndex,
|
|
54
|
-
x: xScale((_xAxis$xAxisKey$data = xAxis[xAxisKey].data) == null ? void 0 : _xAxis$xAxisKey$data[dataIndex]) + groupIndex * barWidth + offset,
|
|
88
|
+
x: xScale((_xAxis$xAxisKey$data = xAxis[xAxisKey].data) == null ? void 0 : _xAxis$xAxisKey$data[dataIndex]) + groupIndex * (barWidth + offset),
|
|
55
89
|
y: yScale(value),
|
|
56
90
|
height: yScale(baseline) - yScale(value),
|
|
57
91
|
width: barWidth,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
+
import useForkRef from '@mui/utils/useForkRef';
|
|
2
3
|
import { DrawingProvider } from '../context/DrawingProvider';
|
|
3
4
|
import { SeriesContextProvider } from '../context/SeriesContextProvider';
|
|
4
5
|
import { InteractionProvider } from '../context/InteractionProvider';
|
|
@@ -6,7 +7,7 @@ import { ChartsSurface } from '../ChartsSurface';
|
|
|
6
7
|
import { CartesianContextProvider } from '../context/CartesianContextProvider';
|
|
7
8
|
import { HighlightProvider } from '../context/HighlightProvider';
|
|
8
9
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
|
-
export function ChartContainer(props) {
|
|
10
|
+
export var ChartContainer = /*#__PURE__*/React.forwardRef(function ChartContainer(props, ref) {
|
|
10
11
|
var width = props.width,
|
|
11
12
|
height = props.height,
|
|
12
13
|
series = props.series,
|
|
@@ -19,12 +20,13 @@ export function ChartContainer(props) {
|
|
|
19
20
|
desc = props.desc,
|
|
20
21
|
disableAxisListener = props.disableAxisListener,
|
|
21
22
|
children = props.children;
|
|
22
|
-
var
|
|
23
|
+
var svgRef = React.useRef(null);
|
|
24
|
+
var handleRef = useForkRef(ref, svgRef);
|
|
23
25
|
return /*#__PURE__*/_jsx(DrawingProvider, {
|
|
24
26
|
width: width,
|
|
25
27
|
height: height,
|
|
26
28
|
margin: margin,
|
|
27
|
-
svgRef:
|
|
29
|
+
svgRef: svgRef,
|
|
28
30
|
children: /*#__PURE__*/_jsx(SeriesContextProvider, {
|
|
29
31
|
series: series,
|
|
30
32
|
colors: colors,
|
|
@@ -36,7 +38,7 @@ export function ChartContainer(props) {
|
|
|
36
38
|
children: /*#__PURE__*/_jsx(ChartsSurface, {
|
|
37
39
|
width: width,
|
|
38
40
|
height: height,
|
|
39
|
-
ref:
|
|
41
|
+
ref: handleRef,
|
|
40
42
|
sx: sx,
|
|
41
43
|
title: title,
|
|
42
44
|
desc: desc,
|
|
@@ -48,4 +50,4 @@ export function ChartContainer(props) {
|
|
|
48
50
|
})
|
|
49
51
|
})
|
|
50
52
|
});
|
|
51
|
-
}
|
|
53
|
+
});
|
|
@@ -2,7 +2,8 @@ import * as React from 'react';
|
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import { InteractionContext } from '../context/InteractionProvider';
|
|
4
4
|
import { CartesianContext } from '../context/CartesianContextProvider';
|
|
5
|
-
import { getValueToPositionMapper
|
|
5
|
+
import { getValueToPositionMapper } from '../hooks/useScale';
|
|
6
|
+
import { isBandScale } from '../internals/isBandScale';
|
|
6
7
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
8
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
8
9
|
function ChartsAxisHighlight(props) {
|
|
@@ -22,7 +23,7 @@ function ChartsAxisHighlight(props) {
|
|
|
22
23
|
var getXPosition = getValueToPositionMapper(xScale);
|
|
23
24
|
return /*#__PURE__*/_jsxs(React.Fragment, {
|
|
24
25
|
children: [xAxisHighlight === 'band' && axis.x !== null && isBandScale(xScale) && /*#__PURE__*/_jsx("path", {
|
|
25
|
-
d: "M ".concat(xScale(axis.x.value)
|
|
26
|
+
d: "M ".concat(xScale(axis.x.value) - (xScale.step() - xScale.bandwidth()) / 2, " ").concat(yScale.range()[0], " l ").concat(xScale.step(), " 0 l 0 ").concat(yScale.range()[1] - yScale.range()[0], " l ").concat(-xScale.step(), " 0 Z"),
|
|
26
27
|
fill: "gray",
|
|
27
28
|
fillOpacity: 0.1,
|
|
28
29
|
style: {
|
|
@@ -15,7 +15,7 @@ import { ChartsAxisHighlight } from '../ChartsAxisHighlight';
|
|
|
15
15
|
import { ChartsClipPath } from '../ChartsClipPath';
|
|
16
16
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
17
17
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
18
|
-
function LineChart(props) {
|
|
18
|
+
var LineChart = /*#__PURE__*/React.forwardRef(function LineChart(props, ref) {
|
|
19
19
|
var xAxis = props.xAxis,
|
|
20
20
|
yAxis = props.yAxis,
|
|
21
21
|
series = props.series,
|
|
@@ -38,6 +38,7 @@ function LineChart(props) {
|
|
|
38
38
|
var id = useId();
|
|
39
39
|
var clipPathId = "".concat(id, "-clip-path");
|
|
40
40
|
return /*#__PURE__*/_jsxs(ResponsiveChartContainer, {
|
|
41
|
+
ref: ref,
|
|
41
42
|
series: series.map(function (s) {
|
|
42
43
|
return _extends({
|
|
43
44
|
type: 'line'
|
|
@@ -73,7 +74,7 @@ function LineChart(props) {
|
|
|
73
74
|
id: clipPathId
|
|
74
75
|
}), children]
|
|
75
76
|
});
|
|
76
|
-
}
|
|
77
|
+
});
|
|
77
78
|
process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
|
|
78
79
|
// ----------------------------- Warning --------------------------------
|
|
79
80
|
// | These PropTypes are generated from the TypeScript type definitions |
|
|
@@ -99,11 +99,11 @@ var ResizableContainer = styled('div', {
|
|
|
99
99
|
}
|
|
100
100
|
};
|
|
101
101
|
});
|
|
102
|
-
export function ResponsiveChartContainer(props) {
|
|
103
|
-
var
|
|
104
|
-
|
|
102
|
+
export var ResponsiveChartContainer = /*#__PURE__*/React.forwardRef(function ResponsiveChartContainer(props, ref) {
|
|
103
|
+
var inWidth = props.width,
|
|
104
|
+
inHeight = props.height,
|
|
105
105
|
other = _objectWithoutProperties(props, _excluded);
|
|
106
|
-
var _useChartDimensions = useChartDimensions(
|
|
106
|
+
var _useChartDimensions = useChartDimensions(inWidth, inHeight),
|
|
107
107
|
_useChartDimensions2 = _slicedToArray(_useChartDimensions, 3),
|
|
108
108
|
containerRef = _useChartDimensions2[0],
|
|
109
109
|
width = _useChartDimensions2[1],
|
|
@@ -111,12 +111,13 @@ export function ResponsiveChartContainer(props) {
|
|
|
111
111
|
return /*#__PURE__*/_jsx(ResizableContainer, {
|
|
112
112
|
ref: containerRef,
|
|
113
113
|
ownerState: {
|
|
114
|
-
width:
|
|
115
|
-
height:
|
|
114
|
+
width: inWidth,
|
|
115
|
+
height: inHeight
|
|
116
116
|
},
|
|
117
117
|
children: /*#__PURE__*/_jsx(ChartContainer, _extends({}, other, {
|
|
118
118
|
width: width,
|
|
119
|
-
height: height
|
|
119
|
+
height: height,
|
|
120
|
+
ref: ref
|
|
120
121
|
}))
|
|
121
122
|
});
|
|
122
|
-
}
|
|
123
|
+
});
|
|
@@ -9,7 +9,7 @@ import { ChartsLegend } from '../ChartsLegend';
|
|
|
9
9
|
import { ChartsAxisHighlight } from '../ChartsAxisHighlight';
|
|
10
10
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
11
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
12
|
-
function ScatterChart(props) {
|
|
12
|
+
var ScatterChart = /*#__PURE__*/React.forwardRef(function ScatterChart(props, ref) {
|
|
13
13
|
var xAxis = props.xAxis,
|
|
14
14
|
yAxis = props.yAxis,
|
|
15
15
|
series = props.series,
|
|
@@ -27,6 +27,7 @@ function ScatterChart(props) {
|
|
|
27
27
|
bottomAxis = props.bottomAxis,
|
|
28
28
|
children = props.children;
|
|
29
29
|
return /*#__PURE__*/_jsxs(ResponsiveChartContainer, {
|
|
30
|
+
ref: ref,
|
|
30
31
|
series: series.map(function (s) {
|
|
31
32
|
return _extends({
|
|
32
33
|
type: 'scatter'
|
|
@@ -51,7 +52,7 @@ function ScatterChart(props) {
|
|
|
51
52
|
trigger: "item"
|
|
52
53
|
}, tooltip)), children]
|
|
53
54
|
});
|
|
54
|
-
}
|
|
55
|
+
});
|
|
55
56
|
process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
|
|
56
57
|
// ----------------------------- Warning --------------------------------
|
|
57
58
|
// | These PropTypes are generated from the TypeScript type definitions |
|
|
@@ -7,12 +7,15 @@ import PropTypes from 'prop-types';
|
|
|
7
7
|
import { getExtremumX as getBarExtremumX, getExtremumY as getBarExtremumY } from '../BarChart/extremums';
|
|
8
8
|
import { getExtremumX as getScatterExtremumX, getExtremumY as getScatterExtremumY } from '../ScatterChart/extremums';
|
|
9
9
|
import { getExtremumX as getLineExtremumX, getExtremumY as getLineExtremumY } from '../LineChart/extremums';
|
|
10
|
-
import {
|
|
10
|
+
import { isBandScaleConfig, isPointScaleConfig } from '../models/axis';
|
|
11
|
+
import { getScale } from '../internals/getScale';
|
|
11
12
|
import { DrawingContext } from './DrawingProvider';
|
|
12
13
|
import { SeriesContext } from './SeriesContextProvider';
|
|
13
14
|
import { DEFAULT_X_AXIS_KEY, DEFAULT_Y_AXIS_KEY } from '../constants';
|
|
14
15
|
import { getTicksNumber } from '../hooks/useTicks';
|
|
15
16
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
17
|
+
var DEFAULT_CATEGORY_GAP_RATIO = 0.1;
|
|
18
|
+
|
|
16
19
|
// TODO: those might be better placed in a distinct file
|
|
17
20
|
var xExtremumGetters = {
|
|
18
21
|
bar: getBarExtremumX,
|
|
@@ -86,24 +89,29 @@ function CartesianContextProvider(_ref) {
|
|
|
86
89
|
_getAxisExtremum2 = _slicedToArray(_getAxisExtremum, 2),
|
|
87
90
|
minData = _getAxisExtremum2[0],
|
|
88
91
|
maxData = _getAxisExtremum2[1];
|
|
89
|
-
var scaleType = (_axis$scaleType = axis.scaleType) != null ? _axis$scaleType : 'linear';
|
|
90
92
|
var range = [drawingArea.left, drawingArea.left + drawingArea.width];
|
|
91
|
-
if (
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
93
|
+
if (isBandScaleConfig(axis)) {
|
|
94
|
+
var _axis$categoryGapRati;
|
|
95
|
+
var categoryGapRatio = (_axis$categoryGapRati = axis.categoryGapRatio) != null ? _axis$categoryGapRati : DEFAULT_CATEGORY_GAP_RATIO;
|
|
96
|
+
completedXAxis[axis.id] = _extends({
|
|
97
|
+
categoryGapRatio: categoryGapRatio,
|
|
98
|
+
barGapRatio: 0
|
|
99
|
+
}, axis, {
|
|
100
|
+
scale: scaleBand(axis.data, range).paddingInner(categoryGapRatio).paddingOuter(categoryGapRatio / 2),
|
|
95
101
|
ticksNumber: axis.data.length
|
|
96
102
|
});
|
|
97
|
-
return;
|
|
98
103
|
}
|
|
99
|
-
if (
|
|
104
|
+
if (isPointScaleConfig(axis)) {
|
|
100
105
|
completedXAxis[axis.id] = _extends({}, axis, {
|
|
101
|
-
scaleType: scaleType,
|
|
102
106
|
scale: scalePoint(axis.data, range),
|
|
103
107
|
ticksNumber: axis.data.length
|
|
104
108
|
});
|
|
109
|
+
}
|
|
110
|
+
if (axis.scaleType === 'band' || axis.scaleType === 'point') {
|
|
111
|
+
// Could be merged with the two previous "if conditions" but then TS does not get that `axis.scaleType` can't be `band` or `point`.
|
|
105
112
|
return;
|
|
106
113
|
}
|
|
114
|
+
var scaleType = (_axis$scaleType = axis.scaleType) != null ? _axis$scaleType : 'linear';
|
|
107
115
|
var extremums = [(_axis$min = axis.min) != null ? _axis$min : minData, (_axis$max = axis.max) != null ? _axis$max : maxData];
|
|
108
116
|
var ticksNumber = getTicksNumber(_extends({}, axis, {
|
|
109
117
|
range: range
|
|
@@ -137,23 +145,28 @@ function CartesianContextProvider(_ref) {
|
|
|
137
145
|
minData = _getAxisExtremum4[0],
|
|
138
146
|
maxData = _getAxisExtremum4[1];
|
|
139
147
|
var range = [drawingArea.top + drawingArea.height, drawingArea.top];
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
148
|
+
if (isBandScaleConfig(axis)) {
|
|
149
|
+
var _axis$categoryGapRati2;
|
|
150
|
+
var categoryGapRatio = (_axis$categoryGapRati2 = axis.categoryGapRatio) != null ? _axis$categoryGapRati2 : DEFAULT_CATEGORY_GAP_RATIO;
|
|
151
|
+
completedXAxis[axis.id] = _extends({
|
|
152
|
+
categoryGapRatio: categoryGapRatio,
|
|
153
|
+
barGapRatio: 0
|
|
154
|
+
}, axis, {
|
|
155
|
+
scale: scaleBand(axis.data, range).paddingInner(categoryGapRatio).paddingOuter(categoryGapRatio / 2),
|
|
145
156
|
ticksNumber: axis.data.length
|
|
146
157
|
});
|
|
147
|
-
return;
|
|
148
158
|
}
|
|
149
|
-
if (
|
|
150
|
-
|
|
151
|
-
scaleType: scaleType,
|
|
159
|
+
if (isPointScaleConfig(axis)) {
|
|
160
|
+
completedXAxis[axis.id] = _extends({}, axis, {
|
|
152
161
|
scale: scalePoint(axis.data, range),
|
|
153
162
|
ticksNumber: axis.data.length
|
|
154
163
|
});
|
|
164
|
+
}
|
|
165
|
+
if (axis.scaleType === 'band' || axis.scaleType === 'point') {
|
|
166
|
+
// Could be merged with the two previous "if conditions" but then TS does not get that `axis.scaleType` can't be `band` or `point`.
|
|
155
167
|
return;
|
|
156
168
|
}
|
|
169
|
+
var scaleType = (_axis$scaleType2 = axis.scaleType) != null ? _axis$scaleType2 : 'linear';
|
|
157
170
|
var extremums = [(_axis$min3 = axis.min) != null ? _axis$min3 : minData, (_axis$max3 = axis.max) != null ? _axis$max3 : maxData];
|
|
158
171
|
var ticksNumber = getTicksNumber(_extends({}, axis, {
|
|
159
172
|
range: range
|
|
@@ -16,8 +16,8 @@ var seriesTypeFormatter = {
|
|
|
16
16
|
pie: pieSeriesFormatter
|
|
17
17
|
};
|
|
18
18
|
/**
|
|
19
|
-
* This methods is the interface between what the
|
|
20
|
-
* To simplify the components behaviors, it groups series by type, such that LinePlots props are not updated if
|
|
19
|
+
* This methods is the interface between what the developer is providing and what components receives
|
|
20
|
+
* To simplify the components behaviors, it groups series by type, such that LinePlots props are not updated if some line data are modified
|
|
21
21
|
* It also add defaultized values such as the ids, colors
|
|
22
22
|
* @param series The array of series provided by devs
|
|
23
23
|
* @param colors The color palette used to defaultize series colors
|
|
@@ -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 var useAxisEvents = function useAxisEvents(disableAxisListener) {
|
|
7
7
|
var svgRef = React.useContext(SVGContext);
|
|
8
8
|
var _React$useContext = React.useContext(DrawingContext),
|
|
@@ -104,12 +104,17 @@ export var useAxisEvents = function useAxisEvents(disableAxisListener) {
|
|
|
104
104
|
});
|
|
105
105
|
};
|
|
106
106
|
var handleMouseMove = function handleMouseMove(event) {
|
|
107
|
+
// Get mouse coordinate in global SVG space
|
|
108
|
+
var pt = svgRef.current.createSVGPoint();
|
|
109
|
+
pt.x = event.clientX;
|
|
110
|
+
pt.y = event.clientY;
|
|
111
|
+
var svgPt = pt.matrixTransform(svgRef.current.getScreenCTM().inverse());
|
|
107
112
|
mousePosition.current = {
|
|
108
|
-
x:
|
|
109
|
-
y:
|
|
113
|
+
x: svgPt.x,
|
|
114
|
+
y: svgPt.y
|
|
110
115
|
};
|
|
111
|
-
var outsideX =
|
|
112
|
-
var outsideY =
|
|
116
|
+
var outsideX = svgPt.x < left || svgPt.x > left + width;
|
|
117
|
+
var outsideY = svgPt.y < top || svgPt.y > top + height;
|
|
113
118
|
if (outsideX || outsideY) {
|
|
114
119
|
dispatch({
|
|
115
120
|
type: 'updateAxis',
|
|
@@ -120,8 +125,8 @@ export var useAxisEvents = function useAxisEvents(disableAxisListener) {
|
|
|
120
125
|
});
|
|
121
126
|
return;
|
|
122
127
|
}
|
|
123
|
-
var newStateX = getUpdateX(
|
|
124
|
-
var newStateY = getUpdateY(
|
|
128
|
+
var newStateX = getUpdateX(svgPt.x);
|
|
129
|
+
var newStateY = getUpdateY(svgPt.y);
|
|
125
130
|
dispatch({
|
|
126
131
|
type: 'updateAxis',
|
|
127
132
|
data: {
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { DrawingContext } from '../context/DrawingProvider';
|
|
3
|
+
export function useDrawingArea() {
|
|
4
|
+
var _React$useContext = React.useContext(DrawingContext),
|
|
5
|
+
left = _React$useContext.left,
|
|
6
|
+
top = _React$useContext.top,
|
|
7
|
+
width = _React$useContext.width,
|
|
8
|
+
height = _React$useContext.height;
|
|
9
|
+
return React.useMemo(function () {
|
|
10
|
+
return {
|
|
11
|
+
left: left,
|
|
12
|
+
top: top,
|
|
13
|
+
width: width,
|
|
14
|
+
height: height
|
|
15
|
+
};
|
|
16
|
+
}, [height, left, top, width]);
|
|
17
|
+
}
|
package/legacy/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.
|
|
@@ -34,4 +16,18 @@ export function getValueToPositionMapper(scale) {
|
|
|
34
16
|
return function (value) {
|
|
35
17
|
return scale(value);
|
|
36
18
|
};
|
|
19
|
+
}
|
|
20
|
+
export function useXScale(identifier) {
|
|
21
|
+
var _React$useContext = React.useContext(CartesianContext),
|
|
22
|
+
xAxis = _React$useContext.xAxis,
|
|
23
|
+
xAxisIds = _React$useContext.xAxisIds;
|
|
24
|
+
var id = typeof identifier === 'string' ? identifier : xAxisIds[identifier != null ? identifier : 0];
|
|
25
|
+
return xAxis[id].scale;
|
|
26
|
+
}
|
|
27
|
+
export function useYScale(identifier) {
|
|
28
|
+
var _React$useContext2 = React.useContext(CartesianContext),
|
|
29
|
+
yAxis = _React$useContext2.yAxis,
|
|
30
|
+
yAxisIds = _React$useContext2.yAxisIds;
|
|
31
|
+
var id = typeof identifier === 'string' ? identifier : yAxisIds[identifier != null ? identifier : 0];
|
|
32
|
+
return yAxis[id].scale;
|
|
37
33
|
}
|
package/legacy/hooks/useTicks.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
2
|
import * as React from 'react';
|
|
3
|
-
import { isBandScale } from '
|
|
3
|
+
import { isBandScale } from '../internals/isBandScale';
|
|
4
4
|
export function getTicksNumber(params) {
|
|
5
5
|
var _params$maxTicks = params.maxTicks,
|
|
6
6
|
maxTicks = _params$maxTicks === void 0 ? 999 : _params$maxTicks,
|
|
@@ -20,23 +20,36 @@ function useTicks(options) {
|
|
|
20
20
|
// band scale
|
|
21
21
|
if (isBandScale(scale)) {
|
|
22
22
|
var domain = scale.domain();
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
if (scale.bandwidth() > 0) {
|
|
24
|
+
// scale type = 'band'
|
|
25
|
+
return [].concat(_toConsumableArray(domain.map(function (value, index) {
|
|
26
|
+
var _valueFormatter;
|
|
27
|
+
return {
|
|
28
|
+
formattedValue: (_valueFormatter = valueFormatter == null ? void 0 : valueFormatter(value)) != null ? _valueFormatter : value,
|
|
29
|
+
offset: index === 0 ? scale.range()[0] : scale(value) - (scale.step() - scale.bandwidth()) / 2,
|
|
30
|
+
labelOffset: scale.step() / 2
|
|
31
|
+
};
|
|
32
|
+
})), [{
|
|
33
|
+
formattedValue: undefined,
|
|
34
|
+
offset: scale.range()[1],
|
|
35
|
+
labelOffset: 0
|
|
36
|
+
}]);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// scale type = 'point'
|
|
40
|
+
return domain.map(function (value) {
|
|
41
|
+
var _valueFormatter2;
|
|
25
42
|
return {
|
|
26
|
-
formattedValue: (
|
|
27
|
-
offset:
|
|
28
|
-
labelOffset:
|
|
43
|
+
formattedValue: (_valueFormatter2 = valueFormatter == null ? void 0 : valueFormatter(value)) != null ? _valueFormatter2 : value,
|
|
44
|
+
offset: scale(value),
|
|
45
|
+
labelOffset: 0
|
|
29
46
|
};
|
|
30
|
-
})
|
|
31
|
-
formattedValue: undefined,
|
|
32
|
-
offset: scale.range()[1],
|
|
33
|
-
labelOffset: 0
|
|
34
|
-
}] : []));
|
|
47
|
+
});
|
|
35
48
|
}
|
|
36
49
|
return scale.ticks(ticksNumber).map(function (value) {
|
|
37
|
-
var
|
|
50
|
+
var _valueFormatter3;
|
|
38
51
|
return {
|
|
39
|
-
formattedValue: (
|
|
52
|
+
formattedValue: (_valueFormatter3 = valueFormatter == null ? void 0 : valueFormatter(value)) != null ? _valueFormatter3 : scale.tickFormat(ticksNumber)(value),
|
|
40
53
|
offset: scale(value),
|
|
41
54
|
labelOffset: 0
|
|
42
55
|
};
|
package/legacy/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';
|
|
@@ -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
|
+
}
|