@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
|
@@ -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
|
|
@@ -4,6 +4,7 @@ import { useTheme } from '@mui/material/styles';
|
|
|
4
4
|
import barSeriesFormatter from '../BarChart/formatter';
|
|
5
5
|
import scatterSeriesFormatter from '../ScatterChart/formatter';
|
|
6
6
|
import lineSeriesFormatter from '../LineChart/formatter';
|
|
7
|
+
import pieSeriesFormatter from '../PieChart/formatter';
|
|
7
8
|
import { defaultizeColor } from '../internals/defaultizeColor';
|
|
8
9
|
import { blueberryTwilightPalette } from '../colorPalettes';
|
|
9
10
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
@@ -11,8 +12,17 @@ export var SeriesContext = /*#__PURE__*/React.createContext({});
|
|
|
11
12
|
var seriesTypeFormatter = {
|
|
12
13
|
bar: barSeriesFormatter,
|
|
13
14
|
scatter: scatterSeriesFormatter,
|
|
14
|
-
line: lineSeriesFormatter
|
|
15
|
+
line: lineSeriesFormatter,
|
|
16
|
+
pie: pieSeriesFormatter
|
|
15
17
|
};
|
|
18
|
+
/**
|
|
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
|
+
* It also add defaultized values such as the ids, colors
|
|
22
|
+
* @param series The array of series provided by devs
|
|
23
|
+
* @param colors The color palette used to defaultize series colors
|
|
24
|
+
* @returns An object structuring all the series by type.
|
|
25
|
+
*/
|
|
16
26
|
var formatSeries = function formatSeries(series, colors) {
|
|
17
27
|
// Group series by type
|
|
18
28
|
var seriesGroups = {};
|
|
@@ -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';
|
|
@@ -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';
|
|
@@ -2,6 +2,15 @@ import _extends from "@babel/runtime/helpers/esm/extends";
|
|
|
2
2
|
var DEFAULT_COLORS = ['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2', '#7f7f7f', '#bcbd22', '#17becf'];
|
|
3
3
|
export function defaultizeColor(series, seriesIndex) {
|
|
4
4
|
var colors = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : DEFAULT_COLORS;
|
|
5
|
+
if (series.type === 'pie') {
|
|
6
|
+
return _extends({}, series, {
|
|
7
|
+
data: series.data.map(function (d, index) {
|
|
8
|
+
return _extends({
|
|
9
|
+
color: colors[index % colors.length]
|
|
10
|
+
}, d);
|
|
11
|
+
})
|
|
12
|
+
});
|
|
13
|
+
}
|
|
5
14
|
return _extends({
|
|
6
15
|
color: colors[seriesIndex % colors.length]
|
|
7
16
|
}, 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/legacy/models/axis.js
CHANGED
package/models/axis.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { ScaleBand, ScaleLogarithmic, ScalePower, ScaleTime, ScaleLinear, ScalePoint } from 'd3-scale';
|
|
2
2
|
import { ChartsAxisClasses } from '../ChartsAxis/axisClasses';
|
|
3
3
|
import type { TickParams } from '../hooks/useTicks';
|
|
4
|
+
export type D3Scale = ScaleBand<any> | ScaleLogarithmic<any, any> | ScalePoint<any> | ScalePower<any, any> | ScaleTime<any, any> | ScaleLinear<any, any>;
|
|
5
|
+
export type D3ContinuouseScale = ScaleLogarithmic<any, any> | ScalePower<any, any> | ScaleTime<any, any> | ScaleLinear<any, any>;
|
|
4
6
|
export interface ChartsAxisProps {
|
|
5
7
|
/**
|
|
6
8
|
* Id of the axis to render.
|
|
@@ -68,51 +70,62 @@ interface AxisScaleConfig {
|
|
|
68
70
|
band: {
|
|
69
71
|
scaleType: 'band';
|
|
70
72
|
scale: ScaleBand<any>;
|
|
71
|
-
|
|
73
|
+
/**
|
|
74
|
+
* The ratio between the space allocated for padding between two categories and the category width.
|
|
75
|
+
* 0 means no gap, and 1 no data.
|
|
76
|
+
* @default 0.1
|
|
77
|
+
*/
|
|
78
|
+
categoryGapRatio: number;
|
|
79
|
+
/**
|
|
80
|
+
* The ratio between the width of a bar, and the gap between two bars.
|
|
81
|
+
* 0 means no gap, and 1 no bar.
|
|
82
|
+
* @default 0
|
|
83
|
+
*/
|
|
84
|
+
barGapRatio: number;
|
|
72
85
|
};
|
|
73
86
|
point: {
|
|
74
87
|
scaleType: 'point';
|
|
75
88
|
scale: ScalePoint<any>;
|
|
76
|
-
ticksNumber: number;
|
|
77
89
|
};
|
|
78
90
|
log: {
|
|
79
91
|
scaleType: 'log';
|
|
80
92
|
scale: ScaleLogarithmic<any, any>;
|
|
81
|
-
ticksNumber: number;
|
|
82
93
|
};
|
|
83
94
|
pow: {
|
|
84
95
|
scaleType: 'pow';
|
|
85
96
|
scale: ScalePower<any, any>;
|
|
86
|
-
ticksNumber: number;
|
|
87
97
|
};
|
|
88
98
|
sqrt: {
|
|
89
99
|
scaleType: 'sqrt';
|
|
90
100
|
scale: ScalePower<any, any>;
|
|
91
|
-
ticksNumber: number;
|
|
92
101
|
};
|
|
93
102
|
time: {
|
|
94
103
|
scaleType: 'time';
|
|
95
104
|
scale: ScaleTime<any, any>;
|
|
96
|
-
ticksNumber: number;
|
|
97
105
|
};
|
|
98
106
|
utc: {
|
|
99
107
|
scaleType: 'utc';
|
|
100
108
|
scale: ScaleTime<any, any>;
|
|
101
|
-
ticksNumber: number;
|
|
102
109
|
};
|
|
103
110
|
linear: {
|
|
104
111
|
scaleType: 'linear';
|
|
105
112
|
scale: ScaleLinear<any, any>;
|
|
106
|
-
ticksNumber: number;
|
|
107
113
|
};
|
|
108
114
|
}
|
|
109
|
-
export type AxisConfig<S = ScaleName, V = any> = {
|
|
115
|
+
export type AxisConfig<S extends ScaleName = ScaleName, V = any> = {
|
|
110
116
|
id: string;
|
|
111
|
-
scaleType?: S;
|
|
112
117
|
min?: number;
|
|
113
118
|
max?: number;
|
|
114
119
|
data?: V[];
|
|
115
120
|
valueFormatter?: (value: V) => string;
|
|
116
|
-
} & Partial<ChartsXAxisProps | ChartsYAxisProps> & TickParams;
|
|
117
|
-
export type AxisDefaultized<S extends ScaleName = ScaleName, V = any> = Omit<AxisConfig<S, V>, 'scaleType'> & AxisScaleConfig[S]
|
|
121
|
+
} & Partial<ChartsXAxisProps | ChartsYAxisProps> & Partial<Omit<AxisScaleConfig[S], 'scale'>> & TickParams;
|
|
122
|
+
export type AxisDefaultized<S extends ScaleName = ScaleName, V = any> = Omit<AxisConfig<S, V>, 'scaleType'> & AxisScaleConfig[S] & {
|
|
123
|
+
ticksNumber: number;
|
|
124
|
+
};
|
|
125
|
+
export declare function isBandScaleConfig(scaleConfig: AxisConfig<ScaleName>): scaleConfig is AxisConfig<'band'> & {
|
|
126
|
+
scaleType: 'band';
|
|
127
|
+
};
|
|
128
|
+
export declare function isPointScaleConfig(scaleConfig: AxisConfig<ScaleName>): scaleConfig is AxisConfig<'point'> & {
|
|
129
|
+
scaleType: 'point';
|
|
130
|
+
};
|
|
118
131
|
export {};
|
package/models/axis.js
CHANGED
|
@@ -2,4 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
|
-
});
|
|
5
|
+
});
|
|
6
|
+
exports.isBandScaleConfig = isBandScaleConfig;
|
|
7
|
+
exports.isPointScaleConfig = isPointScaleConfig;
|
|
8
|
+
function isBandScaleConfig(scaleConfig) {
|
|
9
|
+
return scaleConfig.scaleType === 'band';
|
|
10
|
+
}
|
|
11
|
+
function isPointScaleConfig(scaleConfig) {
|
|
12
|
+
return scaleConfig.scaleType === 'point';
|
|
13
|
+
}
|
|
@@ -14,5 +14,5 @@ export type BarItemIdentifier = {
|
|
|
14
14
|
seriesId: DefaultizedBarSeriesType['id'];
|
|
15
15
|
dataIndex: number;
|
|
16
16
|
};
|
|
17
|
-
export interface DefaultizedBarSeriesType extends DefaultizedProps<BarSeriesType, CommonDefaultizedProps> {
|
|
17
|
+
export interface DefaultizedBarSeriesType extends DefaultizedProps<BarSeriesType, CommonDefaultizedProps | 'color'> {
|
|
18
18
|
}
|
|
@@ -11,7 +11,7 @@ export type CommonSeriesType<TValue> = {
|
|
|
11
11
|
valueFormatter?: (value: TValue) => string;
|
|
12
12
|
highlightScope?: Partial<HighlightScope>;
|
|
13
13
|
};
|
|
14
|
-
export type CommonDefaultizedProps = 'id' | '
|
|
14
|
+
export type CommonDefaultizedProps = 'id' | 'valueFormatter';
|
|
15
15
|
export type CartesianSeriesType = {
|
|
16
16
|
xAxisKey?: string;
|
|
17
17
|
yAxisKey?: string;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { ScatterSeriesType, DefaultizedScatterSeriesType, ScatterItemIdentifier } from './scatter';
|
|
2
2
|
import { LineSeriesType, DefaultizedLineSeriesType, LineItemIdentifier } from './line';
|
|
3
3
|
import { BarItemIdentifier, BarSeriesType, DefaultizedBarSeriesType } from './bar';
|
|
4
|
+
import { PieSeriesType, DefaultizedPieSeriesType, PieItemIdentifier, PieValueType } from './pie';
|
|
4
5
|
import { AxisConfig } from '../axis';
|
|
5
|
-
import { DefaultizedProps } from '../helpers';
|
|
6
|
+
import { DefaultizedProps, MakeOptional } from '../helpers';
|
|
6
7
|
import { StackingGroupsType } from '../../internals/stackSeries';
|
|
7
8
|
interface ChartsSeriesConfig {
|
|
8
9
|
bar: {
|
|
@@ -28,8 +29,18 @@ interface ChartsSeriesConfig {
|
|
|
28
29
|
series: DefaultizedScatterSeriesType;
|
|
29
30
|
itemIdentifier: ScatterItemIdentifier;
|
|
30
31
|
};
|
|
32
|
+
pie: {
|
|
33
|
+
seriesInput: Omit<DefaultizedProps<PieSeriesType, 'id'>, 'data'> & {
|
|
34
|
+
data: (MakeOptional<PieValueType, 'id'> & {
|
|
35
|
+
color: string;
|
|
36
|
+
})[];
|
|
37
|
+
};
|
|
38
|
+
series: DefaultizedPieSeriesType;
|
|
39
|
+
itemIdentifier: PieItemIdentifier;
|
|
40
|
+
};
|
|
31
41
|
}
|
|
32
|
-
export type
|
|
42
|
+
export type CartesianChartSeriesType = 'bar' | 'line' | 'scatter';
|
|
43
|
+
export type ChartSeriesType = 'bar' | 'line' | 'scatter' | 'pie';
|
|
33
44
|
export type ChartSeries<T extends ChartSeriesType> = ChartsSeriesConfig[T] extends {
|
|
34
45
|
canBeStacked: true;
|
|
35
46
|
} ? ChartsSeriesConfig[T]['seriesInput'] & {
|
|
@@ -63,4 +74,20 @@ export type FormatterResult<T extends ChartSeriesType> = {
|
|
|
63
74
|
stackingGroups: StackingGroupsType;
|
|
64
75
|
} : {});
|
|
65
76
|
export type Formatter<T extends ChartSeriesType> = (params: FormatterParams<T>) => FormatterResult<T>;
|
|
77
|
+
export type LegendParams = {
|
|
78
|
+
/**
|
|
79
|
+
* The color used in the legend
|
|
80
|
+
*/
|
|
81
|
+
color: string;
|
|
82
|
+
/**
|
|
83
|
+
* The label displayed in the legend
|
|
84
|
+
*/
|
|
85
|
+
label: string;
|
|
86
|
+
/**
|
|
87
|
+
* The identifier of the legend element.
|
|
88
|
+
* Used for internal purpose such as `key` props
|
|
89
|
+
*/
|
|
90
|
+
id: string;
|
|
91
|
+
};
|
|
92
|
+
export type LegendGetter<T extends ChartSeriesType> = (series: FormatterResult<T>) => LegendParams[];
|
|
66
93
|
export {};
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import { BarItemIdentifier, BarSeriesType, DefaultizedBarSeriesType } from './bar';
|
|
2
2
|
import { DefaultizedLineSeriesType, LineItemIdentifier, LineSeriesType } from './line';
|
|
3
3
|
import { DefaultizedScatterSeriesType, ScatterItemIdentifier, ScatterSeriesType } from './scatter';
|
|
4
|
-
|
|
4
|
+
import { DefaultizedPieSeriesType, PieSeriesType, PieItemIdentifier, PieValueType } from './pie';
|
|
5
|
+
import { MakeOptional } from '../helpers';
|
|
6
|
+
type AllSeriesType = BarSeriesType | LineSeriesType | ScatterSeriesType | PieSeriesType<MakeOptional<PieValueType, 'id'>>;
|
|
5
7
|
type CartesianSeriesType = BarSeriesType | LineSeriesType | ScatterSeriesType;
|
|
6
8
|
type DefaultizedCartesianSeriesType = DefaultizedBarSeriesType | DefaultizedLineSeriesType | DefaultizedScatterSeriesType;
|
|
9
|
+
type DefaultizedSeriesType = DefaultizedCartesianSeriesType | DefaultizedPieSeriesType;
|
|
7
10
|
type StackableSeriesType = DefaultizedBarSeriesType | DefaultizedLineSeriesType;
|
|
8
|
-
export type SeriesItemIdentifier = BarItemIdentifier | LineItemIdentifier | ScatterItemIdentifier;
|
|
11
|
+
export type SeriesItemIdentifier = BarItemIdentifier | LineItemIdentifier | ScatterItemIdentifier | PieItemIdentifier;
|
|
9
12
|
export * from './line';
|
|
10
13
|
export * from './bar';
|
|
11
14
|
export * from './scatter';
|
|
15
|
+
export * from './pie';
|
|
12
16
|
export type { StackOrderType, StackOffsetType } from './common';
|
|
13
|
-
export type { AllSeriesType, CartesianSeriesType, DefaultizedCartesianSeriesType, StackableSeriesType, };
|
|
17
|
+
export type { AllSeriesType, CartesianSeriesType, DefaultizedSeriesType, DefaultizedCartesianSeriesType, StackableSeriesType, };
|
|
@@ -35,4 +35,15 @@ Object.keys(_scatter).forEach(function (key) {
|
|
|
35
35
|
return _scatter[key];
|
|
36
36
|
}
|
|
37
37
|
});
|
|
38
|
+
});
|
|
39
|
+
var _pie = require("./pie");
|
|
40
|
+
Object.keys(_pie).forEach(function (key) {
|
|
41
|
+
if (key === "default" || key === "__esModule") return;
|
|
42
|
+
if (key in exports && exports[key] === _pie[key]) return;
|
|
43
|
+
Object.defineProperty(exports, key, {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
get: function () {
|
|
46
|
+
return _pie[key];
|
|
47
|
+
}
|
|
48
|
+
});
|
|
38
49
|
});
|
|
@@ -21,5 +21,5 @@ export type LineItemIdentifier = {
|
|
|
21
21
|
*/
|
|
22
22
|
dataIndex?: number;
|
|
23
23
|
};
|
|
24
|
-
export interface DefaultizedLineSeriesType extends DefaultizedProps<LineSeriesType, CommonDefaultizedProps> {
|
|
24
|
+
export interface DefaultizedLineSeriesType extends DefaultizedProps<LineSeriesType, CommonDefaultizedProps | 'color'> {
|
|
25
25
|
}
|