@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
package/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from './constants';
|
|
2
2
|
export * from './context';
|
|
3
|
+
export * from './hooks';
|
|
3
4
|
export * from './colorPalettes';
|
|
4
5
|
export * from './models';
|
|
5
6
|
export * from './ChartsClipPath';
|
|
@@ -10,6 +11,7 @@ export * from './ChartsTooltip';
|
|
|
10
11
|
export * from './ChartsAxisHighlight';
|
|
11
12
|
export * from './BarChart';
|
|
12
13
|
export * from './LineChart';
|
|
14
|
+
export * from './PieChart';
|
|
13
15
|
export * from './ScatterChart';
|
|
14
16
|
export * from './ChartContainer';
|
|
15
17
|
export * from './ResponsiveChartContainer';
|
package/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
|
|
@@ -32,6 +32,17 @@ Object.keys(_context).forEach(function (key) {
|
|
|
32
32
|
}
|
|
33
33
|
});
|
|
34
34
|
});
|
|
35
|
+
var _hooks = require("./hooks");
|
|
36
|
+
Object.keys(_hooks).forEach(function (key) {
|
|
37
|
+
if (key === "default" || key === "__esModule") return;
|
|
38
|
+
if (key in exports && exports[key] === _hooks[key]) return;
|
|
39
|
+
Object.defineProperty(exports, key, {
|
|
40
|
+
enumerable: true,
|
|
41
|
+
get: function () {
|
|
42
|
+
return _hooks[key];
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
});
|
|
35
46
|
var _colorPalettes = require("./colorPalettes");
|
|
36
47
|
Object.keys(_colorPalettes).forEach(function (key) {
|
|
37
48
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -142,6 +153,17 @@ Object.keys(_LineChart).forEach(function (key) {
|
|
|
142
153
|
}
|
|
143
154
|
});
|
|
144
155
|
});
|
|
156
|
+
var _PieChart = require("./PieChart");
|
|
157
|
+
Object.keys(_PieChart).forEach(function (key) {
|
|
158
|
+
if (key === "default" || key === "__esModule") return;
|
|
159
|
+
if (key in exports && exports[key] === _PieChart[key]) return;
|
|
160
|
+
Object.defineProperty(exports, key, {
|
|
161
|
+
enumerable: true,
|
|
162
|
+
get: function () {
|
|
163
|
+
return _PieChart[key];
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
});
|
|
145
167
|
var _ScatterChart = require("./ScatterChart");
|
|
146
168
|
Object.keys(_ScatterChart).forEach(function (key) {
|
|
147
169
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -1,5 +1,40 @@
|
|
|
1
1
|
import { AllSeriesType } from '../models/seriesType';
|
|
2
2
|
export declare function defaultizeColor(series: AllSeriesType, seriesIndex: number, colors?: string[]): {
|
|
3
|
+
data: {
|
|
4
|
+
color: string;
|
|
5
|
+
label?: string | undefined;
|
|
6
|
+
value: number;
|
|
7
|
+
id?: string | number | undefined;
|
|
8
|
+
}[];
|
|
9
|
+
type: "pie";
|
|
10
|
+
innerRadius?: number | undefined;
|
|
11
|
+
outerRadius?: number | undefined;
|
|
12
|
+
cornerRadius?: number | undefined;
|
|
13
|
+
startAngle?: number | undefined;
|
|
14
|
+
endAngle?: number | undefined;
|
|
15
|
+
paddingAngle?: number | undefined;
|
|
16
|
+
sortingValues?: import("../models/seriesType").ChartsPieSorting | undefined;
|
|
17
|
+
arcLabel?: "label" | "value" | "formattedValue" | ((item: import("../models/seriesType").DefaultizedPieValueType) => string) | undefined;
|
|
18
|
+
arcLabelMinAngle?: number | undefined;
|
|
19
|
+
cx?: number | undefined;
|
|
20
|
+
cy?: number | undefined;
|
|
21
|
+
highlighted?: {
|
|
22
|
+
additionalRadius?: number | undefined;
|
|
23
|
+
innerRadius?: number | undefined;
|
|
24
|
+
outerRadius?: number | undefined;
|
|
25
|
+
cornerRadius?: number | undefined;
|
|
26
|
+
} | undefined;
|
|
27
|
+
faded?: {
|
|
28
|
+
additionalRadius?: number | undefined;
|
|
29
|
+
innerRadius?: number | undefined;
|
|
30
|
+
outerRadius?: number | undefined;
|
|
31
|
+
cornerRadius?: number | undefined;
|
|
32
|
+
} | undefined;
|
|
33
|
+
id?: string | undefined;
|
|
34
|
+
color?: string | undefined;
|
|
35
|
+
valueFormatter?: ((value: import("../models/helpers").MakeOptional<import("../models/seriesType").PieValueType, "id">) => string) | undefined;
|
|
36
|
+
highlightScope?: Partial<import("..").HighlightScope> | undefined;
|
|
37
|
+
} | {
|
|
3
38
|
type: "bar";
|
|
4
39
|
data: number[];
|
|
5
40
|
label?: string | undefined;
|
|
@@ -8,6 +8,13 @@ exports.defaultizeColor = defaultizeColor;
|
|
|
8
8
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
9
9
|
const DEFAULT_COLORS = ['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2', '#7f7f7f', '#bcbd22', '#17becf'];
|
|
10
10
|
function defaultizeColor(series, seriesIndex, colors = DEFAULT_COLORS) {
|
|
11
|
+
if (series.type === 'pie') {
|
|
12
|
+
return (0, _extends2.default)({}, series, {
|
|
13
|
+
data: series.data.map((d, index) => (0, _extends2.default)({
|
|
14
|
+
color: colors[index % colors.length]
|
|
15
|
+
}, d))
|
|
16
|
+
});
|
|
17
|
+
}
|
|
11
18
|
return (0, _extends2.default)({
|
|
12
19
|
color: colors[seriesIndex % colors.length]
|
|
13
20
|
}, series);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getScale = getScale;
|
|
7
|
+
var _d3Scale = require("d3-scale");
|
|
8
|
+
function getScale(scaleType, domain, range) {
|
|
9
|
+
switch (scaleType) {
|
|
10
|
+
case 'log':
|
|
11
|
+
return (0, _d3Scale.scaleLog)(domain, range);
|
|
12
|
+
case 'pow':
|
|
13
|
+
return (0, _d3Scale.scalePow)(domain, range);
|
|
14
|
+
case 'sqrt':
|
|
15
|
+
return (0, _d3Scale.scaleSqrt)(domain, range);
|
|
16
|
+
case 'time':
|
|
17
|
+
return (0, _d3Scale.scaleTime)(domain, range);
|
|
18
|
+
case 'utc':
|
|
19
|
+
return (0, _d3Scale.scaleUtc)(domain, range);
|
|
20
|
+
default:
|
|
21
|
+
return (0, _d3Scale.scaleLinear)(domain, range);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -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 |
|
|
@@ -128,6 +129,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
128
129
|
legend: PropTypes.shape({
|
|
129
130
|
classes: PropTypes.object,
|
|
130
131
|
direction: PropTypes.oneOf(['column', 'row']),
|
|
132
|
+
hidden: PropTypes.bool,
|
|
131
133
|
itemWidth: PropTypes.number,
|
|
132
134
|
markSize: PropTypes.number,
|
|
133
135
|
offset: PropTypes.shape({
|
|
@@ -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,
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
var legendGetter = function legendGetter(params) {
|
|
2
|
+
var seriesOrder = params.seriesOrder,
|
|
3
|
+
series = params.series;
|
|
4
|
+
var data = seriesOrder.map(function (seriesId) {
|
|
5
|
+
return {
|
|
6
|
+
color: series[seriesId].color,
|
|
7
|
+
label: series[seriesId].label,
|
|
8
|
+
id: seriesId
|
|
9
|
+
};
|
|
10
|
+
});
|
|
11
|
+
return data.filter(function (item) {
|
|
12
|
+
return item.label !== undefined;
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
export default legendGetter;
|
|
@@ -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: {
|
|
@@ -143,13 +143,17 @@ export function ChartsLegend(inProps) {
|
|
|
143
143
|
});
|
|
144
144
|
var position = props.position,
|
|
145
145
|
direction = props.direction,
|
|
146
|
-
offset = props.offset
|
|
146
|
+
offset = props.offset,
|
|
147
|
+
hidden = props.hidden;
|
|
147
148
|
var theme = useTheme();
|
|
148
149
|
var classes = useUtilityClasses(_extends({}, props, {
|
|
149
150
|
theme: theme
|
|
150
151
|
}));
|
|
151
152
|
var drawingArea = React.useContext(DrawingContext);
|
|
152
153
|
var series = React.useContext(SeriesContext);
|
|
154
|
+
if (hidden) {
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
153
157
|
var seriesToDisplay = getSeriesToDisplay(series);
|
|
154
158
|
return /*#__PURE__*/_jsx(ChartsLegendRoot, {
|
|
155
159
|
ownerState: {
|
|
@@ -1,9 +1,15 @@
|
|
|
1
|
+
import getBarLegend from '../BarChart/legend';
|
|
2
|
+
import getScatterLegend from '../ScatterChart/legend';
|
|
3
|
+
import getLineLegend from '../LineChart/legend';
|
|
4
|
+
import getPieLegend from '../PieChart/legend';
|
|
5
|
+
var legendGetter = {
|
|
6
|
+
bar: getBarLegend,
|
|
7
|
+
scatter: getScatterLegend,
|
|
8
|
+
line: getLineLegend,
|
|
9
|
+
pie: getPieLegend
|
|
10
|
+
};
|
|
1
11
|
export function getSeriesToDisplay(series) {
|
|
2
|
-
return Object.
|
|
3
|
-
return
|
|
4
|
-
return s.series[seriesId];
|
|
5
|
-
});
|
|
6
|
-
}).filter(function (s) {
|
|
7
|
-
return s.label !== undefined;
|
|
12
|
+
return Object.keys(series).flatMap(function (seriesType) {
|
|
13
|
+
return legendGetter[seriesType](series[seriesType]);
|
|
8
14
|
});
|
|
9
15
|
}
|
|
@@ -80,7 +80,9 @@ export function ChartsAxisTooltipContent(props) {
|
|
|
80
80
|
var USED_X_AXIS_ID = xAxisIds[0];
|
|
81
81
|
var relevantSeries = React.useMemo(function () {
|
|
82
82
|
var rep = [];
|
|
83
|
-
Object.keys(series).
|
|
83
|
+
Object.keys(series).filter(function (seriesType) {
|
|
84
|
+
return ['bar', 'line', 'scatter'].includes(seriesType);
|
|
85
|
+
}).forEach(function (seriesType) {
|
|
84
86
|
series[seriesType].seriesOrder.forEach(function (seriesId) {
|
|
85
87
|
var axisKey = series[seriesType].series[seriesId].xAxisKey;
|
|
86
88
|
if (axisKey === undefined || axisKey === USED_X_AXIS_ID) {
|
|
@@ -4,7 +4,6 @@ import { ChartsTooltipTable, ChartsTooltipCell, ChartsTooltipMark, ChartsTooltip
|
|
|
4
4
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
5
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
6
6
|
export function DefaultChartsItemContent(props) {
|
|
7
|
-
var _series$label;
|
|
8
7
|
var series = props.series,
|
|
9
8
|
itemData = props.itemData,
|
|
10
9
|
sx = props.sx,
|
|
@@ -12,8 +11,16 @@ export function DefaultChartsItemContent(props) {
|
|
|
12
11
|
if (itemData.dataIndex === undefined) {
|
|
13
12
|
return null;
|
|
14
13
|
}
|
|
15
|
-
var
|
|
16
|
-
|
|
14
|
+
var _ref = series.type === 'pie' ? {
|
|
15
|
+
color: series.data[itemData.dataIndex].color,
|
|
16
|
+
displayedLabel: series.data[itemData.dataIndex].label
|
|
17
|
+
} : {
|
|
18
|
+
color: series.color,
|
|
19
|
+
displayedLabel: series.label
|
|
20
|
+
},
|
|
21
|
+
displayedLabel = _ref.displayedLabel,
|
|
22
|
+
color = _ref.color;
|
|
23
|
+
|
|
17
24
|
// TODO: Manage to let TS understand series.data and series.valueFormatter are coherent
|
|
18
25
|
// @ts-ignore
|
|
19
26
|
var formattedValue = series.valueFormatter(series.data[itemData.dataIndex]);
|
|
@@ -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 |
|
|
@@ -131,6 +132,7 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
|
|
|
131
132
|
legend: PropTypes.shape({
|
|
132
133
|
classes: PropTypes.object,
|
|
133
134
|
direction: PropTypes.oneOf(['column', 'row']),
|
|
135
|
+
hidden: PropTypes.bool,
|
|
134
136
|
itemWidth: PropTypes.number,
|
|
135
137
|
markSize: PropTypes.number,
|
|
136
138
|
offset: PropTypes.shape({
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
var legendGetter = function legendGetter(params) {
|
|
2
|
+
var seriesOrder = params.seriesOrder,
|
|
3
|
+
series = params.series;
|
|
4
|
+
var data = seriesOrder.map(function (seriesId) {
|
|
5
|
+
return {
|
|
6
|
+
color: series[seriesId].color,
|
|
7
|
+
label: series[seriesId].label,
|
|
8
|
+
id: seriesId
|
|
9
|
+
};
|
|
10
|
+
});
|
|
11
|
+
return data.filter(function (item) {
|
|
12
|
+
return item.label !== undefined;
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
export default legendGetter;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
3
|
+
var _excluded = ["id", "dataIndex", "classes", "color", "highlightScope", "innerRadius", "outerRadius", "cornerRadius", "highlighted", "faded"];
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import { arc as d3Arc } from 'd3-shape';
|
|
6
|
+
import PropTypes from 'prop-types';
|
|
7
|
+
import composeClasses from '@mui/utils/composeClasses';
|
|
8
|
+
import generateUtilityClass from '@mui/utils/generateUtilityClass';
|
|
9
|
+
import { styled } from '@mui/material/styles';
|
|
10
|
+
import generateUtilityClasses from '@mui/utils/generateUtilityClasses';
|
|
11
|
+
import { InteractionContext } from '../context/InteractionProvider';
|
|
12
|
+
import { getIsFaded, getIsHighlighted, useInteractionItemProps } from '../hooks/useInteractionItemProps';
|
|
13
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
+
export function getPieArcUtilityClass(slot) {
|
|
15
|
+
return generateUtilityClass('MuiPieArc', slot);
|
|
16
|
+
}
|
|
17
|
+
export var pieArcClasses = generateUtilityClasses('MuiPieArc', ['root', 'highlighted', 'faded']);
|
|
18
|
+
var useUtilityClasses = function useUtilityClasses(ownerState) {
|
|
19
|
+
var classes = ownerState.classes,
|
|
20
|
+
id = ownerState.id,
|
|
21
|
+
isFaded = ownerState.isFaded,
|
|
22
|
+
isHighlighted = ownerState.isHighlighted;
|
|
23
|
+
var slots = {
|
|
24
|
+
root: ['root', "series-".concat(id), isHighlighted && 'highlighted', isFaded && 'faded']
|
|
25
|
+
};
|
|
26
|
+
return composeClasses(slots, getPieArcUtilityClass, classes);
|
|
27
|
+
};
|
|
28
|
+
var PieArcRoot = styled('path', {
|
|
29
|
+
name: 'MuiPieArc',
|
|
30
|
+
slot: 'Root',
|
|
31
|
+
overridesResolver: function overridesResolver(_, styles) {
|
|
32
|
+
return styles.arc;
|
|
33
|
+
}
|
|
34
|
+
})(function (_ref) {
|
|
35
|
+
var ownerState = _ref.ownerState,
|
|
36
|
+
theme = _ref.theme;
|
|
37
|
+
return {
|
|
38
|
+
stroke: theme.palette.background.paper,
|
|
39
|
+
strokeWidth: 1,
|
|
40
|
+
strokeLinejoin: 'round',
|
|
41
|
+
fill: ownerState.color,
|
|
42
|
+
opacity: ownerState.isFaded ? 0.3 : 1
|
|
43
|
+
};
|
|
44
|
+
});
|
|
45
|
+
export default function PieArc(props) {
|
|
46
|
+
var _attibuesOverride$inn, _attibuesOverride$out, _attibuesOverride$cor;
|
|
47
|
+
var id = props.id,
|
|
48
|
+
dataIndex = props.dataIndex,
|
|
49
|
+
innerClasses = props.classes,
|
|
50
|
+
color = props.color,
|
|
51
|
+
highlightScope = props.highlightScope,
|
|
52
|
+
_props$innerRadius = props.innerRadius,
|
|
53
|
+
baseInnerRadius = _props$innerRadius === void 0 ? 0 : _props$innerRadius,
|
|
54
|
+
baseOuterRadius = props.outerRadius,
|
|
55
|
+
_props$cornerRadius = props.cornerRadius,
|
|
56
|
+
baseCornerRadius = _props$cornerRadius === void 0 ? 0 : _props$cornerRadius,
|
|
57
|
+
highlighted = props.highlighted,
|
|
58
|
+
_props$faded = props.faded,
|
|
59
|
+
faded = _props$faded === void 0 ? {
|
|
60
|
+
additionalRadius: -5
|
|
61
|
+
} : _props$faded,
|
|
62
|
+
other = _objectWithoutProperties(props, _excluded);
|
|
63
|
+
var getInteractionItemProps = useInteractionItemProps(highlightScope);
|
|
64
|
+
var _React$useContext = React.useContext(InteractionContext),
|
|
65
|
+
item = _React$useContext.item;
|
|
66
|
+
var isHighlighted = getIsHighlighted(item, {
|
|
67
|
+
type: 'pie',
|
|
68
|
+
seriesId: id,
|
|
69
|
+
dataIndex: dataIndex
|
|
70
|
+
}, highlightScope);
|
|
71
|
+
var isFaded = !isHighlighted && getIsFaded(item, {
|
|
72
|
+
type: 'pie',
|
|
73
|
+
seriesId: id,
|
|
74
|
+
dataIndex: dataIndex
|
|
75
|
+
}, highlightScope);
|
|
76
|
+
var ownerState = {
|
|
77
|
+
id: id,
|
|
78
|
+
dataIndex: dataIndex,
|
|
79
|
+
classes: innerClasses,
|
|
80
|
+
color: color,
|
|
81
|
+
isFaded: isFaded,
|
|
82
|
+
isHighlighted: isHighlighted
|
|
83
|
+
};
|
|
84
|
+
var classes = useUtilityClasses(ownerState);
|
|
85
|
+
var attibuesOverride = _extends({
|
|
86
|
+
additionalRadius: 0
|
|
87
|
+
}, isFaded && faded || isHighlighted && highlighted || {});
|
|
88
|
+
var innerRadius = Math.max(0, (_attibuesOverride$inn = attibuesOverride.innerRadius) != null ? _attibuesOverride$inn : baseInnerRadius);
|
|
89
|
+
var outerRadius = Math.max(0, (_attibuesOverride$out = attibuesOverride.outerRadius) != null ? _attibuesOverride$out : baseOuterRadius + attibuesOverride.additionalRadius);
|
|
90
|
+
var cornerRadius = (_attibuesOverride$cor = attibuesOverride.cornerRadius) != null ? _attibuesOverride$cor : baseCornerRadius;
|
|
91
|
+
return /*#__PURE__*/_jsx(PieArcRoot, _extends({
|
|
92
|
+
d: d3Arc().cornerRadius(cornerRadius)(_extends({}, other, {
|
|
93
|
+
innerRadius: innerRadius,
|
|
94
|
+
outerRadius: outerRadius
|
|
95
|
+
})),
|
|
96
|
+
ownerState: ownerState,
|
|
97
|
+
className: classes.root
|
|
98
|
+
}, getInteractionItemProps({
|
|
99
|
+
type: 'pie',
|
|
100
|
+
seriesId: id,
|
|
101
|
+
dataIndex: dataIndex
|
|
102
|
+
})));
|
|
103
|
+
}
|
|
104
|
+
process.env.NODE_ENV !== "production" ? PieArc.propTypes = {
|
|
105
|
+
// ----------------------------- Warning --------------------------------
|
|
106
|
+
// | These PropTypes are generated from the TypeScript type definitions |
|
|
107
|
+
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
108
|
+
// ----------------------------------------------------------------------
|
|
109
|
+
classes: PropTypes.object,
|
|
110
|
+
cornerRadius: PropTypes.number,
|
|
111
|
+
dataIndex: PropTypes.number.isRequired,
|
|
112
|
+
highlightScope: PropTypes.shape({
|
|
113
|
+
faded: PropTypes.oneOf(['global', 'none', 'series']),
|
|
114
|
+
highlighted: PropTypes.oneOf(['item', 'none', 'series'])
|
|
115
|
+
}),
|
|
116
|
+
innerRadius: PropTypes.number,
|
|
117
|
+
outerRadius: PropTypes.number.isRequired
|
|
118
|
+
} : void 0;
|