@mui/x-charts 6.18.2 → 6.18.4
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/BarElement.d.ts +5 -1
- package/BarChart/BarElement.js +24 -1
- package/BarChart/BarPlot.js +7 -6
- package/BarChart/formatter.js +15 -3
- package/BarChart/index.d.ts +3 -2
- package/BarChart/index.js +31 -12
- package/CHANGELOG.md +192 -1
- package/ChartsAxis/ChartsAxis.js +4 -4
- package/ChartsLegend/ChartsLegend.d.ts +1 -1
- package/ChartsLegend/ChartsLegend.js +3 -2
- package/ChartsLegend/index.d.ts +1 -0
- package/ChartsLegend/index.js +11 -0
- package/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
- package/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
- package/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
- package/ChartsReferenceLine/common.d.ts +1 -1
- package/ChartsText/ChartsText.d.ts +17 -0
- package/{internals/components → ChartsText}/ChartsText.js +32 -17
- package/ChartsText/index.d.ts +3 -0
- package/ChartsText/index.js +12 -0
- package/ChartsText/package.json +6 -0
- package/ChartsTooltip/ChartsAxisTooltipContent.d.ts +5 -2
- package/ChartsTooltip/ChartsAxisTooltipContent.js +93 -73
- package/ChartsTooltip/ChartsItemTooltipContent.d.ts +5 -2
- package/ChartsTooltip/ChartsItemTooltipContent.js +38 -57
- package/ChartsTooltip/DefaultChartsAxisTooltipContent.d.ts +7 -0
- package/ChartsTooltip/DefaultChartsAxisTooltipContent.js +174 -0
- package/ChartsTooltip/DefaultChartsItemTooltipContent.d.ts +8 -0
- package/ChartsTooltip/DefaultChartsItemTooltipContent.js +99 -0
- package/ChartsTooltip/index.d.ts +4 -0
- package/ChartsTooltip/index.js +44 -0
- package/ChartsXAxis/ChartsXAxis.js +3 -2
- package/ChartsYAxis/ChartsYAxis.js +7 -5
- package/LineChart/AreaPlot.js +3 -2
- package/LineChart/LineHighlightPlot.js +2 -1
- package/LineChart/LinePlot.js +3 -2
- package/LineChart/MarkPlot.js +2 -1
- package/LineChart/extremums.js +25 -8
- package/LineChart/formatter.js +14 -2
- package/LineChart/index.d.ts +5 -5
- package/LineChart/index.js +50 -41
- package/PieChart/PieArcLabelPlot.d.ts +7 -4
- package/PieChart/PieArcLabelPlot.js +88 -1
- package/PieChart/PieArcPlot.d.ts +7 -4
- package/PieChart/PieArcPlot.js +87 -1
- package/PieChart/PieChart.js +4 -4
- package/PieChart/PiePlot.js +20 -15
- package/PieChart/dataTransform/useTransformData.d.ts +2 -3
- package/PieChart/index.d.ts +6 -6
- package/PieChart/index.js +60 -46
- package/ResponsiveChartContainer/index.js +2 -2
- package/ScatterChart/Scatter.js +1 -1
- package/ScatterChart/index.d.ts +3 -3
- package/ScatterChart/index.js +31 -19
- package/context/CartesianContextProvider.js +2 -2
- package/context/SeriesContextProvider.js +1 -1
- package/esm/BarChart/BarElement.js +26 -2
- package/esm/BarChart/BarPlot.js +7 -5
- package/esm/BarChart/formatter.js +20 -4
- package/esm/BarChart/index.js +3 -2
- package/esm/ChartsAxis/ChartsAxis.js +4 -4
- package/esm/ChartsLegend/ChartsLegend.js +2 -1
- package/esm/ChartsLegend/index.js +2 -1
- package/esm/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
- package/esm/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
- package/esm/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
- package/esm/{internals/components → ChartsText}/ChartsText.js +33 -16
- package/esm/ChartsText/index.js +1 -0
- package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +95 -75
- package/esm/ChartsTooltip/ChartsItemTooltipContent.js +40 -58
- package/esm/ChartsTooltip/DefaultChartsAxisTooltipContent.js +168 -0
- package/esm/ChartsTooltip/DefaultChartsItemTooltipContent.js +92 -0
- package/esm/ChartsTooltip/index.js +5 -1
- package/esm/ChartsXAxis/ChartsXAxis.js +2 -1
- package/esm/ChartsYAxis/ChartsYAxis.js +7 -5
- package/esm/LineChart/AreaPlot.js +3 -2
- package/esm/LineChart/LineHighlightPlot.js +2 -1
- package/esm/LineChart/LinePlot.js +3 -2
- package/esm/LineChart/MarkPlot.js +2 -1
- package/esm/LineChart/extremums.js +25 -8
- package/esm/LineChart/formatter.js +16 -3
- package/esm/LineChart/index.js +5 -5
- package/esm/PieChart/PieArcLabelPlot.js +90 -2
- package/esm/PieChart/PieArcPlot.js +89 -2
- package/esm/PieChart/PieChart.js +4 -4
- package/esm/PieChart/PiePlot.js +20 -15
- package/esm/PieChart/index.js +6 -4
- package/esm/ResponsiveChartContainer/index.js +2 -2
- package/esm/ScatterChart/Scatter.js +1 -1
- package/esm/ScatterChart/index.js +3 -3
- package/esm/context/CartesianContextProvider.js +2 -2
- package/esm/context/SeriesContextProvider.js +1 -1
- package/esm/index.js +1 -0
- package/esm/internals/defaultizeValueFormatter.js +4 -3
- package/esm/internals/getWordsByLines.js +14 -0
- package/esm/internals/utils.js +40 -0
- package/index.d.ts +1 -0
- package/index.js +12 -1
- package/internals/defaultizeColor.d.ts +4 -4
- package/internals/defaultizeValueFormatter.d.ts +3 -1
- package/internals/defaultizeValueFormatter.js +3 -3
- package/internals/{components/ChartsText.d.ts → getWordsByLines.d.ts} +2 -11
- package/internals/getWordsByLines.js +21 -0
- package/internals/utils.d.ts +13 -0
- package/internals/utils.js +42 -0
- package/legacy/BarChart/BarElement.js +26 -2
- package/legacy/BarChart/BarPlot.js +7 -5
- package/legacy/BarChart/formatter.js +23 -9
- package/legacy/BarChart/index.js +3 -2
- package/legacy/ChartsAxis/ChartsAxis.js +4 -4
- package/legacy/ChartsLegend/ChartsLegend.js +2 -1
- package/legacy/ChartsLegend/index.js +2 -1
- package/legacy/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
- package/legacy/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
- package/legacy/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
- package/legacy/{internals/components → ChartsText}/ChartsText.js +38 -22
- package/legacy/ChartsText/index.js +1 -0
- package/legacy/ChartsTooltip/ChartsAxisTooltipContent.js +95 -74
- package/legacy/ChartsTooltip/ChartsItemTooltipContent.js +40 -55
- package/legacy/ChartsTooltip/DefaultChartsAxisTooltipContent.js +167 -0
- package/legacy/ChartsTooltip/DefaultChartsItemTooltipContent.js +89 -0
- package/legacy/ChartsTooltip/index.js +5 -1
- package/legacy/ChartsXAxis/ChartsXAxis.js +2 -1
- package/legacy/ChartsYAxis/ChartsYAxis.js +7 -5
- package/legacy/LineChart/AreaPlot.js +3 -2
- package/legacy/LineChart/LineHighlightPlot.js +2 -1
- package/legacy/LineChart/LinePlot.js +3 -2
- package/legacy/LineChart/MarkPlot.js +2 -1
- package/legacy/LineChart/extremums.js +29 -14
- package/legacy/LineChart/formatter.js +19 -8
- package/legacy/LineChart/index.js +5 -5
- package/legacy/PieChart/PieArcLabelPlot.js +90 -2
- package/legacy/PieChart/PieArcPlot.js +89 -2
- package/legacy/PieChart/PieChart.js +4 -4
- package/legacy/PieChart/PiePlot.js +20 -15
- package/legacy/PieChart/index.js +6 -4
- package/legacy/ResponsiveChartContainer/index.js +2 -2
- package/legacy/ScatterChart/Scatter.js +1 -1
- package/legacy/ScatterChart/index.js +3 -3
- package/legacy/context/CartesianContextProvider.js +2 -2
- package/legacy/context/SeriesContextProvider.js +1 -1
- package/legacy/index.js +2 -1
- package/legacy/internals/defaultizeValueFormatter.js +4 -3
- package/legacy/internals/getWordsByLines.js +15 -0
- package/legacy/internals/utils.js +40 -0
- package/models/axis.d.ts +1 -1
- package/models/seriesType/config.d.ts +9 -4
- package/models/seriesType/pie.d.ts +29 -7
- package/models/seriesType/scatter.d.ts +1 -1
- package/modern/BarChart/BarElement.js +26 -2
- package/modern/BarChart/BarPlot.js +7 -5
- package/modern/BarChart/formatter.js +15 -3
- package/modern/BarChart/index.js +3 -2
- package/modern/ChartsAxis/ChartsAxis.js +4 -4
- package/modern/ChartsLegend/ChartsLegend.js +2 -1
- package/modern/ChartsLegend/index.js +2 -1
- package/modern/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
- package/modern/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
- package/modern/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
- package/modern/{internals/components → ChartsText}/ChartsText.js +33 -16
- package/modern/ChartsText/index.js +1 -0
- package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +95 -74
- package/modern/ChartsTooltip/ChartsItemTooltipContent.js +40 -58
- package/modern/ChartsTooltip/DefaultChartsAxisTooltipContent.js +167 -0
- package/modern/ChartsTooltip/DefaultChartsItemTooltipContent.js +92 -0
- package/modern/ChartsTooltip/index.js +5 -1
- package/modern/ChartsXAxis/ChartsXAxis.js +2 -1
- package/modern/ChartsYAxis/ChartsYAxis.js +7 -5
- package/modern/LineChart/AreaPlot.js +3 -2
- package/modern/LineChart/LineHighlightPlot.js +2 -1
- package/modern/LineChart/LinePlot.js +3 -2
- package/modern/LineChart/MarkPlot.js +2 -1
- package/modern/LineChart/extremums.js +25 -8
- package/modern/LineChart/formatter.js +14 -2
- package/modern/LineChart/index.js +5 -5
- package/modern/PieChart/PieArcLabelPlot.js +90 -2
- package/modern/PieChart/PieArcPlot.js +89 -2
- package/modern/PieChart/PieChart.js +4 -4
- package/modern/PieChart/PiePlot.js +20 -15
- package/modern/PieChart/index.js +6 -4
- package/modern/ResponsiveChartContainer/index.js +2 -2
- package/modern/ScatterChart/Scatter.js +1 -1
- package/modern/ScatterChart/index.js +3 -3
- package/modern/context/CartesianContextProvider.js +2 -2
- package/modern/context/SeriesContextProvider.js +1 -1
- package/modern/index.js +2 -1
- package/modern/internals/defaultizeValueFormatter.js +3 -3
- package/modern/internals/getWordsByLines.js +14 -0
- package/modern/internals/utils.js +40 -0
- package/package.json +1 -1
|
@@ -2,9 +2,10 @@ import _extends from "@babel/runtime/helpers/esm/extends";
|
|
|
2
2
|
function defaultizeValueFormatter(series, defaultValueFormatter) {
|
|
3
3
|
const defaultizedSeries = {};
|
|
4
4
|
Object.keys(series).forEach(seriesId => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
var _series$seriesId$valu;
|
|
6
|
+
defaultizedSeries[seriesId] = _extends({}, series[seriesId], {
|
|
7
|
+
valueFormatter: (_series$seriesId$valu = series[seriesId].valueFormatter) != null ? _series$seriesId$valu : defaultValueFormatter
|
|
8
|
+
});
|
|
8
9
|
});
|
|
9
10
|
return defaultizedSeries;
|
|
10
11
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import { getStringSize } from './domUtils';
|
|
3
|
+
export function getWordsByLines({
|
|
4
|
+
style,
|
|
5
|
+
needsComputation,
|
|
6
|
+
text
|
|
7
|
+
}) {
|
|
8
|
+
return text.split('\n').map(subText => _extends({
|
|
9
|
+
text: subText
|
|
10
|
+
}, needsComputation ? getStringSize(subText, style) : {
|
|
11
|
+
width: 0,
|
|
12
|
+
height: 0
|
|
13
|
+
}));
|
|
14
|
+
}
|
package/esm/internals/utils.js
CHANGED
|
@@ -2,4 +2,44 @@
|
|
|
2
2
|
export function getSymbol(shape) {
|
|
3
3
|
const symbolNames = 'circle cross diamond square star triangle wye'.split(/ /);
|
|
4
4
|
return symbolNames.indexOf(shape) || 0;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Transform mouse event position to corrdinates inside the SVG.
|
|
8
|
+
* @param svg The SVG element
|
|
9
|
+
* @param event The mouseEvent to transform
|
|
10
|
+
*/
|
|
11
|
+
export function getSVGPoint(svg, event) {
|
|
12
|
+
const pt = svg.createSVGPoint();
|
|
13
|
+
pt.x = event.clientX;
|
|
14
|
+
pt.y = event.clientY;
|
|
15
|
+
return pt.matrixTransform(svg.getScreenCTM().inverse());
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Helper that converts values and percentages into values.
|
|
20
|
+
* @param value The value provided by the developer. Can either be a number or a string with '%' or 'px'.
|
|
21
|
+
* @param refValue The numerical value associated to 100%.
|
|
22
|
+
* @returns The numerical value associated to the provided value.
|
|
23
|
+
*/
|
|
24
|
+
export function getPercentageValue(value, refValue) {
|
|
25
|
+
if (typeof value === 'number') {
|
|
26
|
+
return value;
|
|
27
|
+
}
|
|
28
|
+
if (value === '100%') {
|
|
29
|
+
// Avoid potential rounding issues
|
|
30
|
+
return refValue;
|
|
31
|
+
}
|
|
32
|
+
if (value.endsWith('%')) {
|
|
33
|
+
const percentage = Number.parseFloat(value.slice(0, value.length - 1));
|
|
34
|
+
if (!Number.isNaN(percentage)) {
|
|
35
|
+
return percentage * refValue / 100;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (value.endsWith('px')) {
|
|
39
|
+
const val = Number.parseFloat(value.slice(0, value.length - 2));
|
|
40
|
+
if (!Number.isNaN(val)) {
|
|
41
|
+
return val;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
throw Error(`MUI-Charts: Received an unknown value "${value}". It should be a number, or a string with a percentage value.`);
|
|
5
45
|
}
|
package/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export * from './ChartsReferenceLine';
|
|
|
8
8
|
export * from './ChartsAxis';
|
|
9
9
|
export * from './ChartsXAxis';
|
|
10
10
|
export * from './ChartsYAxis';
|
|
11
|
+
export * from './ChartsText';
|
|
11
12
|
export * from './ChartsTooltip';
|
|
12
13
|
export * from './ChartsAxisHighlight';
|
|
13
14
|
export * from './BarChart';
|
package/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @mui/x-charts v6.18.
|
|
2
|
+
* @mui/x-charts v6.18.4
|
|
3
3
|
*
|
|
4
4
|
* @license MIT
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
@@ -120,6 +120,17 @@ Object.keys(_ChartsYAxis).forEach(function (key) {
|
|
|
120
120
|
}
|
|
121
121
|
});
|
|
122
122
|
});
|
|
123
|
+
var _ChartsText = require("./ChartsText");
|
|
124
|
+
Object.keys(_ChartsText).forEach(function (key) {
|
|
125
|
+
if (key === "default" || key === "__esModule") return;
|
|
126
|
+
if (key in exports && exports[key] === _ChartsText[key]) return;
|
|
127
|
+
Object.defineProperty(exports, key, {
|
|
128
|
+
enumerable: true,
|
|
129
|
+
get: function () {
|
|
130
|
+
return _ChartsText[key];
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
});
|
|
123
134
|
var _ChartsTooltip = require("./ChartsTooltip");
|
|
124
135
|
Object.keys(_ChartsTooltip).forEach(function (key) {
|
|
125
136
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -7,8 +7,8 @@ export declare function defaultizeColor(series: AllSeriesType, seriesIndex: numb
|
|
|
7
7
|
id?: string | number | undefined;
|
|
8
8
|
}[];
|
|
9
9
|
type: "pie";
|
|
10
|
-
innerRadius?: number | undefined;
|
|
11
|
-
outerRadius?: number | undefined;
|
|
10
|
+
innerRadius?: string | number | undefined;
|
|
11
|
+
outerRadius?: string | number | undefined;
|
|
12
12
|
cornerRadius?: number | undefined;
|
|
13
13
|
startAngle?: number | undefined;
|
|
14
14
|
endAngle?: number | undefined;
|
|
@@ -16,8 +16,8 @@ export declare function defaultizeColor(series: AllSeriesType, seriesIndex: numb
|
|
|
16
16
|
sortingValues?: import("../models/seriesType").ChartsPieSorting | undefined;
|
|
17
17
|
arcLabel?: "label" | "value" | "formattedValue" | ((item: import("../models/seriesType").DefaultizedPieValueType) => string) | undefined;
|
|
18
18
|
arcLabelMinAngle?: number | undefined;
|
|
19
|
-
cx?: number | undefined;
|
|
20
|
-
cy?: number | undefined;
|
|
19
|
+
cx?: string | number | undefined;
|
|
20
|
+
cy?: string | number | undefined;
|
|
21
21
|
highlighted?: {
|
|
22
22
|
additionalRadius?: number | undefined;
|
|
23
23
|
innerRadius?: number | undefined;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
declare function defaultizeValueFormatter<ISeries extends {
|
|
1
|
+
declare function defaultizeValueFormatter<ISeries extends {
|
|
2
|
+
valueFormatter?: IFormatter;
|
|
3
|
+
}, IFormatter extends (v: any) => string>(series: {
|
|
2
4
|
[id: string]: ISeries;
|
|
3
5
|
}, defaultValueFormatter: IFormatter): {
|
|
4
6
|
[id: string]: ISeries & {
|
|
@@ -9,9 +9,9 @@ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")
|
|
|
9
9
|
function defaultizeValueFormatter(series, defaultValueFormatter) {
|
|
10
10
|
const defaultizedSeries = {};
|
|
11
11
|
Object.keys(series).forEach(seriesId => {
|
|
12
|
-
defaultizedSeries[seriesId] = (0, _extends2.default)({
|
|
13
|
-
valueFormatter: defaultValueFormatter
|
|
14
|
-
}
|
|
12
|
+
defaultizedSeries[seriesId] = (0, _extends2.default)({}, series[seriesId], {
|
|
13
|
+
valueFormatter: series[seriesId].valueFormatter ?? defaultValueFormatter
|
|
14
|
+
});
|
|
15
15
|
});
|
|
16
16
|
return defaultizedSeries;
|
|
17
17
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="react" />
|
|
2
2
|
export type ChartsTextBaseline = 'hanging' | 'central' | 'auto';
|
|
3
3
|
export interface ChartsTextStyle extends React.CSSProperties {
|
|
4
4
|
angle?: number;
|
|
@@ -8,7 +8,7 @@ export interface ChartsTextStyle extends React.CSSProperties {
|
|
|
8
8
|
*/
|
|
9
9
|
dominantBaseline?: ChartsTextBaseline;
|
|
10
10
|
}
|
|
11
|
-
interface GetWordsByLinesParams {
|
|
11
|
+
export interface GetWordsByLinesParams {
|
|
12
12
|
/**
|
|
13
13
|
* Text displayed.
|
|
14
14
|
*/
|
|
@@ -23,13 +23,4 @@ interface GetWordsByLinesParams {
|
|
|
23
23
|
*/
|
|
24
24
|
needsComputation?: boolean;
|
|
25
25
|
}
|
|
26
|
-
export interface ChartsTextProps extends Omit<React.SVGTextElementAttributes<SVGTextElement>, 'width' | 'ref' | 'style' | 'dominantBaseline'>, GetWordsByLinesParams {
|
|
27
|
-
/**
|
|
28
|
-
* Height of a text line (in `em`).
|
|
29
|
-
*/
|
|
30
|
-
lineHeight?: number;
|
|
31
|
-
ownerState?: any;
|
|
32
|
-
}
|
|
33
26
|
export declare function getWordsByLines({ style, needsComputation, text }: GetWordsByLinesParams): any[];
|
|
34
|
-
export declare function ChartsText(props: ChartsTextProps): React.JSX.Element;
|
|
35
|
-
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.getWordsByLines = getWordsByLines;
|
|
8
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
9
|
+
var _domUtils = require("./domUtils");
|
|
10
|
+
function getWordsByLines({
|
|
11
|
+
style,
|
|
12
|
+
needsComputation,
|
|
13
|
+
text
|
|
14
|
+
}) {
|
|
15
|
+
return text.split('\n').map(subText => (0, _extends2.default)({
|
|
16
|
+
text: subText
|
|
17
|
+
}, needsComputation ? (0, _domUtils.getStringSize)(subText, style) : {
|
|
18
|
+
width: 0,
|
|
19
|
+
height: 0
|
|
20
|
+
}));
|
|
21
|
+
}
|
package/internals/utils.d.ts
CHANGED
|
@@ -4,4 +4,17 @@ type Without<T, U> = {
|
|
|
4
4
|
[P in Exclude<keyof T, keyof U>]?: never;
|
|
5
5
|
};
|
|
6
6
|
export type XOR<T, U> = T | U extends object ? (Without<T, U> & U) | (Without<U, T> & T) : T | U;
|
|
7
|
+
/**
|
|
8
|
+
* Transform mouse event position to corrdinates inside the SVG.
|
|
9
|
+
* @param svg The SVG element
|
|
10
|
+
* @param event The mouseEvent to transform
|
|
11
|
+
*/
|
|
12
|
+
export declare function getSVGPoint(svg: SVGSVGElement, event: MouseEvent): DOMPoint;
|
|
13
|
+
/**
|
|
14
|
+
* Helper that converts values and percentages into values.
|
|
15
|
+
* @param value The value provided by the developer. Can either be a number or a string with '%' or 'px'.
|
|
16
|
+
* @param refValue The numerical value associated to 100%.
|
|
17
|
+
* @returns The numerical value associated to the provided value.
|
|
18
|
+
*/
|
|
19
|
+
export declare function getPercentageValue(value: number | string, refValue: number): number;
|
|
7
20
|
export {};
|
package/internals/utils.js
CHANGED
|
@@ -3,9 +3,51 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.getPercentageValue = getPercentageValue;
|
|
7
|
+
exports.getSVGPoint = getSVGPoint;
|
|
6
8
|
exports.getSymbol = getSymbol;
|
|
7
9
|
// Returns the index of a defined shape
|
|
8
10
|
function getSymbol(shape) {
|
|
9
11
|
const symbolNames = 'circle cross diamond square star triangle wye'.split(/ /);
|
|
10
12
|
return symbolNames.indexOf(shape) || 0;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Transform mouse event position to corrdinates inside the SVG.
|
|
16
|
+
* @param svg The SVG element
|
|
17
|
+
* @param event The mouseEvent to transform
|
|
18
|
+
*/
|
|
19
|
+
function getSVGPoint(svg, event) {
|
|
20
|
+
const pt = svg.createSVGPoint();
|
|
21
|
+
pt.x = event.clientX;
|
|
22
|
+
pt.y = event.clientY;
|
|
23
|
+
return pt.matrixTransform(svg.getScreenCTM().inverse());
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Helper that converts values and percentages into values.
|
|
28
|
+
* @param value The value provided by the developer. Can either be a number or a string with '%' or 'px'.
|
|
29
|
+
* @param refValue The numerical value associated to 100%.
|
|
30
|
+
* @returns The numerical value associated to the provided value.
|
|
31
|
+
*/
|
|
32
|
+
function getPercentageValue(value, refValue) {
|
|
33
|
+
if (typeof value === 'number') {
|
|
34
|
+
return value;
|
|
35
|
+
}
|
|
36
|
+
if (value === '100%') {
|
|
37
|
+
// Avoid potential rounding issues
|
|
38
|
+
return refValue;
|
|
39
|
+
}
|
|
40
|
+
if (value.endsWith('%')) {
|
|
41
|
+
const percentage = Number.parseFloat(value.slice(0, value.length - 1));
|
|
42
|
+
if (!Number.isNaN(percentage)) {
|
|
43
|
+
return percentage * refValue / 100;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (value.endsWith('px')) {
|
|
47
|
+
const val = Number.parseFloat(value.slice(0, value.length - 2));
|
|
48
|
+
if (!Number.isNaN(val)) {
|
|
49
|
+
return val;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
throw Error(`MUI-Charts: Received an unknown value "${value}". It should be a number, or a string with a percentage value.`);
|
|
11
53
|
}
|
|
@@ -2,6 +2,7 @@ import _extends from "@babel/runtime/helpers/esm/extends";
|
|
|
2
2
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
3
3
|
var _excluded = ["id", "dataIndex", "classes", "color", "highlightScope", "slots", "slotProps", "style"];
|
|
4
4
|
import * as React from 'react';
|
|
5
|
+
import PropTypes from 'prop-types';
|
|
5
6
|
import composeClasses from '@mui/utils/composeClasses';
|
|
6
7
|
import { useSlotProps } from '@mui/base/utils';
|
|
7
8
|
import generateUtilityClass from '@mui/utils/generateUtilityClass';
|
|
@@ -40,7 +41,7 @@ export var BarElementPath = styled(animated.rect, {
|
|
|
40
41
|
opacity: ownerState.isFaded && 0.3 || 1
|
|
41
42
|
};
|
|
42
43
|
});
|
|
43
|
-
|
|
44
|
+
function BarElement(props) {
|
|
44
45
|
var _slots$bar;
|
|
45
46
|
var id = props.id,
|
|
46
47
|
dataIndex = props.dataIndex,
|
|
@@ -88,4 +89,27 @@ export function BarElement(props) {
|
|
|
88
89
|
ownerState: ownerState
|
|
89
90
|
});
|
|
90
91
|
return /*#__PURE__*/_jsx(Bar, _extends({}, barProps));
|
|
91
|
-
}
|
|
92
|
+
}
|
|
93
|
+
process.env.NODE_ENV !== "production" ? BarElement.propTypes = {
|
|
94
|
+
// ----------------------------- Warning --------------------------------
|
|
95
|
+
// | These PropTypes are generated from the TypeScript type definitions |
|
|
96
|
+
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
97
|
+
// ----------------------------------------------------------------------
|
|
98
|
+
classes: PropTypes.object,
|
|
99
|
+
dataIndex: PropTypes.number.isRequired,
|
|
100
|
+
highlightScope: PropTypes.shape({
|
|
101
|
+
faded: PropTypes.oneOf(['global', 'none', 'series']),
|
|
102
|
+
highlighted: PropTypes.oneOf(['item', 'none', 'series'])
|
|
103
|
+
}),
|
|
104
|
+
/**
|
|
105
|
+
* The props used for each component slot.
|
|
106
|
+
* @default {}
|
|
107
|
+
*/
|
|
108
|
+
slotProps: PropTypes.object,
|
|
109
|
+
/**
|
|
110
|
+
* Overridable component slots.
|
|
111
|
+
* @default {}
|
|
112
|
+
*/
|
|
113
|
+
slots: PropTypes.object
|
|
114
|
+
} : void 0;
|
|
115
|
+
export { BarElement };
|
|
@@ -9,7 +9,8 @@ import { SeriesContext } from '../context/SeriesContextProvider';
|
|
|
9
9
|
import { CartesianContext } from '../context/CartesianContextProvider';
|
|
10
10
|
import { BarElement } from './BarElement';
|
|
11
11
|
import { isBandScaleConfig } from '../models/axis';
|
|
12
|
-
import {
|
|
12
|
+
import { DEFAULT_X_AXIS_KEY, DEFAULT_Y_AXIS_KEY } from '../constants';
|
|
13
|
+
|
|
13
14
|
/**
|
|
14
15
|
* Solution of the equations
|
|
15
16
|
* W = barWidth * N + offset * (N-1)
|
|
@@ -19,6 +20,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
19
20
|
* @param gapRatio The ratio of the gap between bars over the bar width.
|
|
20
21
|
* @returns The bar width and the offset between bars.
|
|
21
22
|
*/
|
|
23
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
22
24
|
function getBandSize(_ref) {
|
|
23
25
|
var W = _ref.bandWidth,
|
|
24
26
|
N = _ref.numberOfGroups,
|
|
@@ -64,18 +66,18 @@ var useCompletedData = function useCompletedData() {
|
|
|
64
66
|
var baseScaleConfig;
|
|
65
67
|
if (verticalLayout) {
|
|
66
68
|
if (!isBandScaleConfig(xAxisConfig)) {
|
|
67
|
-
throw new Error("
|
|
69
|
+
throw new Error("MUI-X-Charts: ".concat(xAxisKey === DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : "The x-axis with id \"".concat(xAxisKey, "\""), " shoud be of type \"band\" to display the bar series of id \"").concat(seriesId, "\""));
|
|
68
70
|
}
|
|
69
71
|
if (xAxis[xAxisKey].data === undefined) {
|
|
70
|
-
throw new Error("
|
|
72
|
+
throw new Error("MUI-X-Charts: ".concat(xAxisKey === DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : "The x-axis with id \"".concat(xAxisKey, "\""), " shoud have data property"));
|
|
71
73
|
}
|
|
72
74
|
baseScaleConfig = xAxisConfig;
|
|
73
75
|
} else {
|
|
74
76
|
if (!isBandScaleConfig(yAxisConfig)) {
|
|
75
|
-
throw new Error("
|
|
77
|
+
throw new Error("MUI-X-Charts: ".concat(yAxisKey === DEFAULT_Y_AXIS_KEY ? 'The first `yAxis`' : "The y-axis with id \"".concat(yAxisKey, "\""), " shoud be of type \"band\" to display the bar series of id \"").concat(seriesId, "\""));
|
|
76
78
|
}
|
|
77
79
|
if (yAxis[yAxisKey].data === undefined) {
|
|
78
|
-
throw new Error("
|
|
80
|
+
throw new Error("MUI-X-Charts: ".concat(yAxisKey === DEFAULT_Y_AXIS_KEY ? 'The first `yAxis`' : "The y-axis with id \"".concat(yAxisKey, "\""), " shoud have data property"));
|
|
79
81
|
}
|
|
80
82
|
baseScaleConfig = yAxisConfig;
|
|
81
83
|
}
|
|
@@ -4,13 +4,15 @@ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
|
4
4
|
import { stack as d3Stack } from 'd3-shape';
|
|
5
5
|
import { getStackingGroups } from '../internals/stackSeries';
|
|
6
6
|
import defaultizeValueFormatter from '../internals/defaultizeValueFormatter';
|
|
7
|
+
var warnOnce = false;
|
|
7
8
|
var formatter = function formatter(params, dataset) {
|
|
9
|
+
var _ref;
|
|
8
10
|
var seriesOrder = params.seriesOrder,
|
|
9
11
|
series = params.series;
|
|
10
12
|
var stackingGroups = getStackingGroups(params);
|
|
11
13
|
|
|
12
14
|
// Create a data set with format adapted to d3
|
|
13
|
-
var d3Dataset = dataset != null ?
|
|
15
|
+
var d3Dataset = (_ref = dataset) != null ? _ref : [];
|
|
14
16
|
seriesOrder.forEach(function (id) {
|
|
15
17
|
var data = series[id].data;
|
|
16
18
|
if (data !== undefined) {
|
|
@@ -22,7 +24,7 @@ var formatter = function formatter(params, dataset) {
|
|
|
22
24
|
}
|
|
23
25
|
});
|
|
24
26
|
} else if (dataset === undefined) {
|
|
25
|
-
throw new Error(["MUI: bar series with id='".concat(id, "' has no data."), 'Either provide a data property to the series or use the dataset prop.'].join('\n'));
|
|
27
|
+
throw new Error(["MUI-X-Charts: bar series with id='".concat(id, "' has no data."), 'Either provide a data property to the series or use the dataset prop.'].join('\n'));
|
|
26
28
|
}
|
|
27
29
|
});
|
|
28
30
|
var completedSeries = {};
|
|
@@ -35,19 +37,31 @@ var formatter = function formatter(params, dataset) {
|
|
|
35
37
|
// Use dataKey if needed and available
|
|
36
38
|
var dataKey = series[id].dataKey;
|
|
37
39
|
return series[id].data === undefined && dataKey !== undefined ? dataKey : id;
|
|
38
|
-
})).
|
|
40
|
+
})).value(function (d, key) {
|
|
41
|
+
var _d$key;
|
|
42
|
+
return (_d$key = d[key]) != null ? _d$key : 0;
|
|
43
|
+
}) // defaultize null value to 0
|
|
44
|
+
.order(stackingOrder).offset(stackingOffset)(d3Dataset);
|
|
39
45
|
ids.forEach(function (id, index) {
|
|
40
46
|
var dataKey = series[id].dataKey;
|
|
41
47
|
completedSeries[id] = _extends({
|
|
42
48
|
layout: 'vertical'
|
|
43
49
|
}, series[id], {
|
|
44
|
-
data: dataKey ? dataset.map(function (
|
|
45
|
-
|
|
50
|
+
data: dataKey ? dataset.map(function (data) {
|
|
51
|
+
var value = data[dataKey];
|
|
52
|
+
if (typeof value !== 'number') {
|
|
53
|
+
if (process.env.NODE_ENV !== 'production' && !warnOnce && value !== null) {
|
|
54
|
+
warnOnce = true;
|
|
55
|
+
console.error(["MUI-X charts: your dataset key \"".concat(dataKey, "\" is used for plotting bars, but contains nonnumerical elements."), 'Bar plots only support numbers and null values.']);
|
|
56
|
+
}
|
|
57
|
+
return 0;
|
|
58
|
+
}
|
|
59
|
+
return value;
|
|
46
60
|
}) : series[id].data,
|
|
47
|
-
stackedData: stackedSeries[index].map(function (
|
|
48
|
-
var
|
|
49
|
-
a =
|
|
50
|
-
b =
|
|
61
|
+
stackedData: stackedSeries[index].map(function (_ref2) {
|
|
62
|
+
var _ref3 = _slicedToArray(_ref2, 2),
|
|
63
|
+
a = _ref3[0],
|
|
64
|
+
b = _ref3[1];
|
|
51
65
|
return [a, b];
|
|
52
66
|
})
|
|
53
67
|
});
|
package/legacy/BarChart/index.js
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
1
|
+
export * from './BarChart';
|
|
2
|
+
export * from './BarPlot';
|
|
3
|
+
export * from './BarElement';
|
|
@@ -57,16 +57,16 @@ function ChartsAxis(props) {
|
|
|
57
57
|
var topId = getAxisId(topAxis);
|
|
58
58
|
var rightId = getAxisId(rightAxis);
|
|
59
59
|
if (topId !== null && !xAxis[topId]) {
|
|
60
|
-
throw Error("MUI: id used for top axis \"".concat(topId, "\" is not defined"));
|
|
60
|
+
throw Error(["MUI-X-Charts: id used for top axis \"".concat(topId, "\" is not defined."), "Available ids are: ".concat(xAxisIds.join(', '), ".")].join('\n'));
|
|
61
61
|
}
|
|
62
62
|
if (leftId !== null && !yAxis[leftId]) {
|
|
63
|
-
throw Error("MUI: id used for left axis \"".concat(leftId, "\" is not defined"));
|
|
63
|
+
throw Error(["MUI-X-Charts: id used for left axis \"".concat(leftId, "\" is not defined."), "Available ids are: ".concat(yAxisIds.join(', '), ".")].join('\n'));
|
|
64
64
|
}
|
|
65
65
|
if (rightId !== null && !yAxis[rightId]) {
|
|
66
|
-
throw Error("MUI: id used for right axis \"".concat(rightId, "\" is not defined"));
|
|
66
|
+
throw Error(["MUI-X-Charts: id used for right axis \"".concat(rightId, "\" is not defined."), "Available ids are: ".concat(yAxisIds.join(', '), ".")].join('\n'));
|
|
67
67
|
}
|
|
68
68
|
if (bottomId !== null && !xAxis[bottomId]) {
|
|
69
|
-
throw Error("MUI: id used for bottom axis \"".concat(bottomId, "\" is not defined"));
|
|
69
|
+
throw Error(["MUI-X-Charts: id used for bottom axis \"".concat(bottomId, "\" is not defined."), "Available ids are: ".concat(xAxisIds.join(', '), ".")].join('\n'));
|
|
70
70
|
}
|
|
71
71
|
var topAxisProps = mergeProps(topAxis, slots, slotProps);
|
|
72
72
|
var bottomAxisProps = mergeProps(bottomAxis, slots, slotProps);
|
|
@@ -12,7 +12,8 @@ import { DrawingContext } from '../context/DrawingProvider';
|
|
|
12
12
|
import { getSeriesToDisplay } from './utils';
|
|
13
13
|
import { SeriesContext } from '../context/SeriesContextProvider';
|
|
14
14
|
import { getLegendUtilityClass } from './chartsLegendClasses';
|
|
15
|
-
import { ChartsText
|
|
15
|
+
import { ChartsText } from '../ChartsText';
|
|
16
|
+
import { getWordsByLines } from '../internals/getWordsByLines';
|
|
16
17
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
17
18
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
18
19
|
var useUtilityClasses = function useUtilityClasses(ownerState) {
|
|
@@ -6,10 +6,10 @@ import { ChartsYReferenceLine } from './ChartsYReferenceLine';
|
|
|
6
6
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
7
|
function ChartsReferenceLine(props) {
|
|
8
8
|
if (props.x !== undefined && props.y !== undefined) {
|
|
9
|
-
throw new Error('MUI-X: The ChartsReferenceLine can not have both `x` and `y` props set.');
|
|
9
|
+
throw new Error('MUI-X-Charts: The ChartsReferenceLine can not have both `x` and `y` props set.');
|
|
10
10
|
}
|
|
11
11
|
if (props.x === undefined && props.y === undefined) {
|
|
12
|
-
throw new Error('MUI-X: The ChartsReferenceLine should have a value in `x` or `y` prop.');
|
|
12
|
+
throw new Error('MUI-X-Charts: The ChartsReferenceLine should have a value in `x` or `y` prop.');
|
|
13
13
|
}
|
|
14
14
|
if (props.x !== undefined) {
|
|
15
15
|
return /*#__PURE__*/_jsx(ChartsXReferenceLine, _extends({}, props));
|
|
@@ -4,7 +4,7 @@ import * as React from 'react';
|
|
|
4
4
|
import composeClasses from '@mui/utils/composeClasses';
|
|
5
5
|
import { useDrawingArea, useXScale } from '../hooks';
|
|
6
6
|
import { ReferenceLineRoot } from './common';
|
|
7
|
-
import { ChartsText } from '../
|
|
7
|
+
import { ChartsText } from '../ChartsText';
|
|
8
8
|
import { getReferenceLineUtilityClass } from './chartsReferenceLineClasses';
|
|
9
9
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
10
10
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
@@ -4,7 +4,7 @@ import * as React from 'react';
|
|
|
4
4
|
import composeClasses from '@mui/utils/composeClasses';
|
|
5
5
|
import { useDrawingArea, useYScale } from '../hooks';
|
|
6
6
|
import { ReferenceLineRoot } from './common';
|
|
7
|
-
import { ChartsText } from '../
|
|
7
|
+
import { ChartsText } from '../ChartsText';
|
|
8
8
|
import { getReferenceLineUtilityClass } from './chartsReferenceLineClasses';
|
|
9
9
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
10
10
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
@@ -1,35 +1,26 @@
|
|
|
1
|
-
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
2
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
3
3
|
var _excluded = ["x", "y", "style", "text", "ownerState"],
|
|
4
4
|
_excluded2 = ["angle", "textAnchor", "dominantBaseline"];
|
|
5
5
|
import * as React from 'react';
|
|
6
|
-
import
|
|
6
|
+
import PropTypes from 'prop-types';
|
|
7
|
+
import { getWordsByLines } from '../internals/getWordsByLines';
|
|
7
8
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return text.split('\n').map(function (subText) {
|
|
13
|
-
return _extends({
|
|
14
|
-
text: subText
|
|
15
|
-
}, needsComputation ? getStringSize(subText, style) : {
|
|
16
|
-
width: 0,
|
|
17
|
-
height: 0
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
export function ChartsText(props) {
|
|
9
|
+
/**
|
|
10
|
+
* Helper component to manage multiline text in SVG
|
|
11
|
+
*/
|
|
12
|
+
function ChartsText(props) {
|
|
22
13
|
var x = props.x,
|
|
23
14
|
y = props.y,
|
|
24
15
|
styleProps = props.style,
|
|
25
16
|
text = props.text,
|
|
26
17
|
ownerState = props.ownerState,
|
|
27
18
|
textProps = _objectWithoutProperties(props, _excluded);
|
|
28
|
-
var
|
|
29
|
-
angle =
|
|
30
|
-
textAnchor =
|
|
31
|
-
dominantBaseline =
|
|
32
|
-
style = _objectWithoutProperties(
|
|
19
|
+
var _ref = styleProps != null ? styleProps : {},
|
|
20
|
+
angle = _ref.angle,
|
|
21
|
+
textAnchor = _ref.textAnchor,
|
|
22
|
+
dominantBaseline = _ref.dominantBaseline,
|
|
23
|
+
style = _objectWithoutProperties(_ref, _excluded2);
|
|
33
24
|
var wordsByLines = React.useMemo(function () {
|
|
34
25
|
return getWordsByLines({
|
|
35
26
|
style: style,
|
|
@@ -76,4 +67,29 @@ export function ChartsText(props) {
|
|
|
76
67
|
}, index);
|
|
77
68
|
})
|
|
78
69
|
}));
|
|
79
|
-
}
|
|
70
|
+
}
|
|
71
|
+
process.env.NODE_ENV !== "production" ? ChartsText.propTypes = {
|
|
72
|
+
// ----------------------------- Warning --------------------------------
|
|
73
|
+
// | These PropTypes are generated from the TypeScript type definitions |
|
|
74
|
+
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
75
|
+
// ----------------------------------------------------------------------
|
|
76
|
+
/**
|
|
77
|
+
* Height of a text line (in `em`).
|
|
78
|
+
*/
|
|
79
|
+
lineHeight: PropTypes.number,
|
|
80
|
+
/**
|
|
81
|
+
* If `true`, the line width is computed.
|
|
82
|
+
* @default false
|
|
83
|
+
*/
|
|
84
|
+
needsComputation: PropTypes.bool,
|
|
85
|
+
ownerState: PropTypes.any,
|
|
86
|
+
/**
|
|
87
|
+
* Style applied to text elements.
|
|
88
|
+
*/
|
|
89
|
+
style: PropTypes.object,
|
|
90
|
+
/**
|
|
91
|
+
* Text displayed.
|
|
92
|
+
*/
|
|
93
|
+
text: PropTypes.string.isRequired
|
|
94
|
+
} : void 0;
|
|
95
|
+
export { ChartsText };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { ChartsText } from './ChartsText';
|