@mui/x-charts 6.0.0-alpha.13 → 6.0.0-alpha.15
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 +6 -3
- package/BarChart/BarChart.js +7 -10
- package/BarChart/BarElement.js +2 -4
- package/BarChart/formatter.js +1 -2
- package/BarChart/legend.js +1 -2
- package/CHANGELOG.md +165 -1
- package/ChartContainer/index.js +2 -3
- package/ChartsAxis/axisClasses.js +1 -2
- package/ChartsLegend/ChartsLegend.d.ts +43 -24
- package/ChartsLegend/ChartsLegend.js +186 -148
- package/ChartsLegend/chartsLegendClasses.js +1 -2
- package/ChartsLegend/utils.d.ts +1 -6
- package/ChartsSurface.js +5 -14
- package/ChartsTooltip/ChartsAxisTooltipContent.d.ts +1 -0
- package/ChartsTooltip/ChartsAxisTooltipContent.js +17 -8
- package/ChartsTooltip/ChartsItemTooltipContent.d.ts +3 -2
- package/ChartsTooltip/ChartsItemTooltipContent.js +16 -6
- package/ChartsTooltip/ChartsTooltip.d.ts +23 -0
- package/ChartsTooltip/ChartsTooltip.js +47 -13
- package/ChartsTooltip/ChartsTooltipTable.js +6 -11
- package/ChartsTooltip/tooltipClasses.js +1 -2
- package/ChartsXAxis/ChartsXAxis.js +48 -25
- package/ChartsYAxis/ChartsYAxis.js +47 -26
- package/LineChart/AreaElement.js +2 -4
- package/LineChart/LineChart.d.ts +6 -3
- package/LineChart/LineChart.js +11 -11
- package/LineChart/LineElement.js +2 -4
- package/LineChart/LineHighlightElement.js +1 -2
- package/LineChart/MarkElement.js +1 -2
- package/LineChart/formatter.js +1 -2
- package/LineChart/legend.js +1 -2
- package/PieChart/PieArc.d.ts +1 -0
- package/PieChart/PieArc.js +6 -4
- package/PieChart/PieArcLabel.js +1 -2
- package/PieChart/PieChart.d.ts +8 -4
- package/PieChart/PieChart.js +11 -10
- package/PieChart/PiePlot.d.ts +8 -0
- package/PieChart/PiePlot.js +21 -5
- package/PieChart/formatter.js +1 -2
- package/PieChart/legend.js +1 -2
- package/ResponsiveChartContainer/index.js +2 -3
- package/ScatterChart/ScatterChart.d.ts +6 -3
- package/ScatterChart/ScatterChart.js +7 -10
- package/ScatterChart/formatter.js +1 -2
- package/ScatterChart/legend.js +1 -2
- package/SparkLineChart/SparkLineChart.d.ts +3 -3
- package/SparkLineChart/SparkLineChart.js +7 -3
- package/colorPalettes/colorPalettes.js +6 -12
- package/constants.js +5 -8
- package/context/CartesianContextProvider.js +11 -12
- package/context/DrawingProvider.d.ts +2 -0
- package/context/DrawingProvider.js +4 -4
- package/context/HighlightProvider.js +1 -2
- package/context/InteractionProvider.js +1 -2
- package/context/SeriesContextProvider.js +1 -2
- package/esm/BarChart/BarChart.js +6 -8
- package/esm/ChartsLegend/ChartsLegend.js +184 -142
- package/esm/ChartsSurface.js +3 -11
- package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +17 -8
- package/esm/ChartsTooltip/ChartsItemTooltipContent.js +15 -6
- package/esm/ChartsTooltip/ChartsTooltip.js +47 -12
- package/esm/ChartsXAxis/ChartsXAxis.js +47 -24
- package/esm/ChartsYAxis/ChartsYAxis.js +46 -25
- package/esm/LineChart/LineChart.js +10 -9
- package/esm/PieChart/PieArc.js +5 -2
- package/esm/PieChart/PieChart.js +11 -10
- package/esm/PieChart/PiePlot.js +17 -2
- package/esm/ScatterChart/ScatterChart.js +6 -8
- package/esm/SparkLineChart/SparkLineChart.js +6 -1
- package/esm/constants.js +1 -1
- package/esm/context/CartesianContextProvider.js +11 -11
- package/esm/context/DrawingProvider.js +2 -0
- package/esm/hooks/useChartDimensions.js +2 -0
- package/esm/hooks/useTicks.js +5 -5
- package/esm/internals/components/AxisSharedComponents.js +15 -70
- package/esm/internals/components/ChartsText.js +71 -0
- package/esm/internals/domUtils.js +113 -0
- package/hooks/useChartDimensions.d.ts +2 -0
- package/hooks/useChartDimensions.js +3 -2
- package/hooks/useTicks.d.ts +2 -3
- package/hooks/useTicks.js +7 -8
- package/index.js +1 -1
- package/internals/components/AxisSharedComponents.d.ts +0 -4
- package/internals/components/AxisSharedComponents.js +18 -78
- package/internals/components/ChartsText.d.ts +32 -0
- package/internals/components/ChartsText.js +81 -0
- package/internals/defaultizeValueFormatter.js +1 -2
- package/internals/domUtils.d.ts +14 -0
- package/internals/domUtils.js +122 -0
- package/internals/stackSeries.js +2 -4
- package/legacy/BarChart/BarChart.js +6 -8
- package/legacy/ChartsLegend/ChartsLegend.js +196 -140
- package/legacy/ChartsSurface.js +2 -11
- package/legacy/ChartsTooltip/ChartsAxisTooltipContent.js +17 -8
- package/legacy/ChartsTooltip/ChartsItemTooltipContent.js +15 -6
- package/legacy/ChartsTooltip/ChartsTooltip.js +50 -12
- package/legacy/ChartsXAxis/ChartsXAxis.js +47 -24
- package/legacy/ChartsYAxis/ChartsYAxis.js +46 -25
- package/legacy/LineChart/LineChart.js +10 -9
- package/legacy/PieChart/PieArc.js +4 -1
- package/legacy/PieChart/PieChart.js +11 -10
- package/legacy/PieChart/PiePlot.js +17 -2
- package/legacy/ScatterChart/ScatterChart.js +6 -8
- package/legacy/SparkLineChart/SparkLineChart.js +6 -1
- package/legacy/constants.js +1 -1
- package/legacy/context/CartesianContextProvider.js +11 -11
- package/legacy/context/DrawingProvider.js +2 -0
- package/legacy/hooks/useChartDimensions.js +2 -0
- package/legacy/hooks/useTicks.js +5 -5
- package/legacy/index.js +1 -1
- package/legacy/internals/components/AxisSharedComponents.js +9 -63
- package/legacy/internals/components/ChartsText.js +77 -0
- package/legacy/internals/domUtils.js +121 -0
- package/models/axis.d.ts +6 -5
- package/models/layout.d.ts +7 -6
- package/modern/BarChart/BarChart.js +6 -8
- package/modern/ChartsLegend/ChartsLegend.js +184 -142
- package/modern/ChartsSurface.js +3 -11
- package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +17 -8
- package/modern/ChartsTooltip/ChartsItemTooltipContent.js +15 -6
- package/modern/ChartsTooltip/ChartsTooltip.js +46 -12
- package/modern/ChartsXAxis/ChartsXAxis.js +47 -24
- package/modern/ChartsYAxis/ChartsYAxis.js +46 -25
- package/modern/LineChart/LineChart.js +10 -9
- package/modern/PieChart/PieArc.js +5 -2
- package/modern/PieChart/PieChart.js +11 -10
- package/modern/PieChart/PiePlot.js +17 -2
- package/modern/ScatterChart/ScatterChart.js +6 -8
- package/modern/SparkLineChart/SparkLineChart.js +6 -1
- package/modern/constants.js +1 -1
- package/modern/context/CartesianContextProvider.js +11 -11
- package/modern/context/DrawingProvider.js +2 -0
- package/modern/hooks/useChartDimensions.js +2 -0
- package/modern/hooks/useTicks.js +5 -5
- package/modern/index.js +1 -1
- package/modern/internals/components/AxisSharedComponents.js +15 -70
- package/modern/internals/components/ChartsText.js +71 -0
- package/modern/internals/domUtils.js +113 -0
- package/package.json +3 -3
|
@@ -5,77 +5,22 @@ export const AxisRoot = styled('g', {
|
|
|
5
5
|
name: 'MuiChartsAxis',
|
|
6
6
|
slot: 'Root',
|
|
7
7
|
overridesResolver: (props, styles) => styles.root
|
|
8
|
-
})({
|
|
9
|
-
[`&.${axisClasses.directionY}`]: {
|
|
10
|
-
[`.${axisClasses.tickLabel}`]: {
|
|
11
|
-
dominantBaseline: 'middle'
|
|
12
|
-
},
|
|
13
|
-
[`.${axisClasses.label}`]: {
|
|
14
|
-
dominantBaseline: 'auto',
|
|
15
|
-
textAnchor: 'middle'
|
|
16
|
-
}
|
|
17
|
-
},
|
|
18
|
-
[`&.${axisClasses.left}`]: {
|
|
19
|
-
[`.${axisClasses.tickLabel}`]: {
|
|
20
|
-
dominantBaseline: 'central',
|
|
21
|
-
textAnchor: 'end'
|
|
22
|
-
}
|
|
23
|
-
},
|
|
24
|
-
[`&.${axisClasses.right}`]: {
|
|
25
|
-
[`.${axisClasses.tickLabel}`]: {
|
|
26
|
-
dominantBaseline: 'central',
|
|
27
|
-
textAnchor: 'start'
|
|
28
|
-
}
|
|
29
|
-
},
|
|
30
|
-
[`&.${axisClasses.bottom}`]: {
|
|
31
|
-
[`.${axisClasses.tickLabel}, .${axisClasses.label}`]: {
|
|
32
|
-
dominantBaseline: 'hanging',
|
|
33
|
-
textAnchor: 'middle'
|
|
34
|
-
}
|
|
35
|
-
},
|
|
36
|
-
[`&.${axisClasses.top}`]: {
|
|
37
|
-
[`.${axisClasses.tickLabel}, .${axisClasses.label}`]: {
|
|
38
|
-
dominantBaseline: 'baseline',
|
|
39
|
-
textAnchor: 'middle'
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
export const ChartsLine = styled('line', {
|
|
44
|
-
name: 'MuiChartsAxis',
|
|
45
|
-
slot: 'Line',
|
|
46
|
-
overridesResolver: (props, styles) => styles.line
|
|
47
|
-
})(({
|
|
48
|
-
theme
|
|
49
|
-
}) => ({
|
|
50
|
-
stroke: (theme.vars || theme).palette.text.primary,
|
|
51
|
-
shapeRendering: 'crispEdges',
|
|
52
|
-
strokeWidth: 1
|
|
53
|
-
}));
|
|
54
|
-
export const ChartsTick = styled('line', {
|
|
55
|
-
name: 'MuiChartsAxis',
|
|
56
|
-
slot: 'Tick',
|
|
57
|
-
overridesResolver: (props, styles) => styles.tick
|
|
58
8
|
})(({
|
|
59
9
|
theme
|
|
60
10
|
}) => ({
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
overridesResolver: (props, styles) => styles.label
|
|
77
|
-
})(({
|
|
78
|
-
theme
|
|
79
|
-
}) => _extends({}, theme.typography.body1, {
|
|
80
|
-
fill: (theme.vars || theme).palette.text.primary
|
|
11
|
+
[`& .${axisClasses.tickLabel}`]: _extends({}, theme.typography.caption, {
|
|
12
|
+
fill: (theme.vars || theme).palette.text.primary
|
|
13
|
+
}),
|
|
14
|
+
[`& .${axisClasses.label}`]: _extends({}, theme.typography.body1, {
|
|
15
|
+
fill: (theme.vars || theme).palette.text.primary
|
|
16
|
+
}),
|
|
17
|
+
[`& .${axisClasses.line}`]: {
|
|
18
|
+
stroke: (theme.vars || theme).palette.text.primary,
|
|
19
|
+
shapeRendering: 'crispEdges',
|
|
20
|
+
strokeWidth: 1
|
|
21
|
+
},
|
|
22
|
+
[`& .${axisClasses.tick}`]: {
|
|
23
|
+
stroke: (theme.vars || theme).palette.text.primary,
|
|
24
|
+
shapeRendering: 'crispEdges'
|
|
25
|
+
}
|
|
81
26
|
}));
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
2
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
|
+
const _excluded = ["x", "y", "textAnchor", "dominantBaseline", "style", "text", "ownerState"];
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import { getStringSize } from '../domUtils';
|
|
6
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
|
+
export function getWordsByLines({
|
|
8
|
+
style,
|
|
9
|
+
needsComputation,
|
|
10
|
+
text
|
|
11
|
+
}) {
|
|
12
|
+
return text.split('\n').map(subText => _extends({
|
|
13
|
+
text: subText
|
|
14
|
+
}, needsComputation ? getStringSize(subText, style) : {
|
|
15
|
+
width: 0,
|
|
16
|
+
height: 0
|
|
17
|
+
}));
|
|
18
|
+
}
|
|
19
|
+
export function ChartsText(props) {
|
|
20
|
+
const {
|
|
21
|
+
x,
|
|
22
|
+
y,
|
|
23
|
+
textAnchor = 'start',
|
|
24
|
+
dominantBaseline = 'central',
|
|
25
|
+
style,
|
|
26
|
+
text
|
|
27
|
+
} = props,
|
|
28
|
+
textProps = _objectWithoutPropertiesLoose(props, _excluded);
|
|
29
|
+
const wordsByLines = React.useMemo(() => getWordsByLines({
|
|
30
|
+
style,
|
|
31
|
+
needsComputation: text.includes('\n'),
|
|
32
|
+
text
|
|
33
|
+
}), [style, text]);
|
|
34
|
+
let startDy;
|
|
35
|
+
switch (dominantBaseline) {
|
|
36
|
+
case 'hanging':
|
|
37
|
+
startDy = 0;
|
|
38
|
+
break;
|
|
39
|
+
case 'central':
|
|
40
|
+
startDy = (wordsByLines.length - 1) / 2 * -wordsByLines[0].height;
|
|
41
|
+
break;
|
|
42
|
+
default:
|
|
43
|
+
startDy = (wordsByLines.length - 1) * -wordsByLines[0].height;
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// const transforms = [];
|
|
48
|
+
// if (scaleToFit) {
|
|
49
|
+
// const lineWidth = wordsByLines[0].width;
|
|
50
|
+
// transforms.push(`scale(${(isNumber(width as number) ? (width as number) / lineWidth : 1) / lineWidth})`);
|
|
51
|
+
// }
|
|
52
|
+
// if (angle) {
|
|
53
|
+
// transforms.push(`rotate(${angle}, ${x}, ${y})`);
|
|
54
|
+
// }
|
|
55
|
+
// if (transforms.length) {
|
|
56
|
+
// textProps.transform = transforms.join(' ');
|
|
57
|
+
// }
|
|
58
|
+
|
|
59
|
+
return /*#__PURE__*/_jsx("text", _extends({}, textProps, {
|
|
60
|
+
x: x,
|
|
61
|
+
y: y,
|
|
62
|
+
textAnchor: textAnchor,
|
|
63
|
+
dominantBaseline: dominantBaseline,
|
|
64
|
+
style: style,
|
|
65
|
+
children: wordsByLines.map((line, index) => /*#__PURE__*/_jsx("tspan", {
|
|
66
|
+
x: x,
|
|
67
|
+
dy: `${index === 0 ? startDy : wordsByLines[0].height}px`,
|
|
68
|
+
children: line.text
|
|
69
|
+
}, index))
|
|
70
|
+
}));
|
|
71
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
// DOM utils taken from
|
|
3
|
+
// https://github.com/recharts/recharts/blob/master/src/util/DOMUtils.ts
|
|
4
|
+
|
|
5
|
+
const isSsr = () => !(typeof window !== 'undefined' && window.document && window.setTimeout);
|
|
6
|
+
const stringCache = {
|
|
7
|
+
widthCache: {},
|
|
8
|
+
cacheCount: 0
|
|
9
|
+
};
|
|
10
|
+
const MAX_CACHE_NUM = 2000;
|
|
11
|
+
const SPAN_STYLE = {
|
|
12
|
+
position: 'absolute',
|
|
13
|
+
top: '-20000px',
|
|
14
|
+
left: 0,
|
|
15
|
+
padding: 0,
|
|
16
|
+
margin: 0,
|
|
17
|
+
border: 'none',
|
|
18
|
+
whiteSpace: 'pre'
|
|
19
|
+
};
|
|
20
|
+
const STYLE_LIST = ['minWidth', 'maxWidth', 'width', 'minHeight', 'maxHeight', 'height', 'top', 'left', 'fontSize', 'padding', 'margin', 'paddingLeft', 'paddingRight', 'paddingTop', 'paddingBottom', 'marginLeft', 'marginRight', 'marginTop', 'marginBottom'];
|
|
21
|
+
const MEASUREMENT_SPAN_ID = 'mui_measurement_span';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
*
|
|
25
|
+
* @param name CSS property name
|
|
26
|
+
* @param value
|
|
27
|
+
* @returns add 'px' for distance properties
|
|
28
|
+
*/
|
|
29
|
+
function autoCompleteStyle(name, value) {
|
|
30
|
+
if (STYLE_LIST.indexOf(name) >= 0 && value === +value) {
|
|
31
|
+
return `${value}px`;
|
|
32
|
+
}
|
|
33
|
+
return value;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
*
|
|
38
|
+
* @param text camelcase css property
|
|
39
|
+
* @returns css property
|
|
40
|
+
*/
|
|
41
|
+
function camelToMiddleLine(text) {
|
|
42
|
+
const strs = text.split('');
|
|
43
|
+
const formatStrs = strs.reduce((result, entry) => {
|
|
44
|
+
if (entry === entry.toUpperCase()) {
|
|
45
|
+
return [...result, '-', entry.toLowerCase()];
|
|
46
|
+
}
|
|
47
|
+
return [...result, entry];
|
|
48
|
+
}, []);
|
|
49
|
+
return formatStrs.join('');
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
*
|
|
54
|
+
* @param style React style object
|
|
55
|
+
* @returns CSS styling string
|
|
56
|
+
*/
|
|
57
|
+
export const getStyleString = style => Object.keys(style).sort().reduce((result, s) => `${result}${camelToMiddleLine(s)}:${autoCompleteStyle(s, style[s])};`, '');
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
*
|
|
61
|
+
* @param text The string to estimate
|
|
62
|
+
* @param style The style applied
|
|
63
|
+
* @returns width and height of the text
|
|
64
|
+
*/
|
|
65
|
+
export const getStringSize = (text, style = {}) => {
|
|
66
|
+
if (text === undefined || text === null || isSsr()) {
|
|
67
|
+
return {
|
|
68
|
+
width: 0,
|
|
69
|
+
height: 0
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
const str = `${text}`;
|
|
73
|
+
const styleString = getStyleString(style);
|
|
74
|
+
const cacheKey = `${str}-${styleString}`;
|
|
75
|
+
if (stringCache.widthCache[cacheKey]) {
|
|
76
|
+
return stringCache.widthCache[cacheKey];
|
|
77
|
+
}
|
|
78
|
+
try {
|
|
79
|
+
let measurementSpan = document.getElementById(MEASUREMENT_SPAN_ID);
|
|
80
|
+
if (measurementSpan === null) {
|
|
81
|
+
measurementSpan = document.createElement('span');
|
|
82
|
+
measurementSpan.setAttribute('id', MEASUREMENT_SPAN_ID);
|
|
83
|
+
measurementSpan.setAttribute('aria-hidden', 'true');
|
|
84
|
+
document.body.appendChild(measurementSpan);
|
|
85
|
+
}
|
|
86
|
+
// Need to use CSS Object Model (CSSOM) to be able to comply with Content Security Policy (CSP)
|
|
87
|
+
// https://en.wikipedia.org/wiki/Content_Security_Policy
|
|
88
|
+
const measurementSpanStyle = _extends({}, SPAN_STYLE, style);
|
|
89
|
+
Object.keys(measurementSpanStyle).map(styleKey => {
|
|
90
|
+
measurementSpan.style[camelToMiddleLine(styleKey)] = autoCompleteStyle(styleKey, measurementSpanStyle[styleKey]);
|
|
91
|
+
return styleKey;
|
|
92
|
+
});
|
|
93
|
+
measurementSpan.textContent = str;
|
|
94
|
+
const rect = measurementSpan.getBoundingClientRect();
|
|
95
|
+
const result = {
|
|
96
|
+
width: rect.width,
|
|
97
|
+
height: rect.height
|
|
98
|
+
};
|
|
99
|
+
stringCache.widthCache[cacheKey] = result;
|
|
100
|
+
if (stringCache.cacheCount + 1 > MAX_CACHE_NUM) {
|
|
101
|
+
stringCache.cacheCount = 0;
|
|
102
|
+
stringCache.widthCache = {};
|
|
103
|
+
} else {
|
|
104
|
+
stringCache.cacheCount += 1;
|
|
105
|
+
}
|
|
106
|
+
return result;
|
|
107
|
+
} catch (e) {
|
|
108
|
+
return {
|
|
109
|
+
width: 0,
|
|
110
|
+
height: 0
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/x-charts",
|
|
3
|
-
"version": "6.0.0-alpha.
|
|
3
|
+
"version": "6.0.0-alpha.15",
|
|
4
4
|
"description": "The community edition of the charts components (MUI X).",
|
|
5
5
|
"author": "MUI Team",
|
|
6
6
|
"main": "./index.js",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"directory": "packages/x-charts"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@babel/runtime": "^7.
|
|
31
|
-
"@mui/base": "^5.0.0-beta.
|
|
30
|
+
"@babel/runtime": "^7.23.1",
|
|
31
|
+
"@mui/base": "^5.0.0-beta.17",
|
|
32
32
|
"clsx": "^2.0.0",
|
|
33
33
|
"d3-color": "^3.1.0",
|
|
34
34
|
"d3-scale": "^4.0.2",
|