@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
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.getStyleString = exports.getStringSize = void 0;
|
|
8
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
9
|
+
// DOM utils taken from
|
|
10
|
+
// https://github.com/recharts/recharts/blob/master/src/util/DOMUtils.ts
|
|
11
|
+
|
|
12
|
+
const isSsr = () => !(typeof window !== 'undefined' && window.document && window.setTimeout);
|
|
13
|
+
const stringCache = {
|
|
14
|
+
widthCache: {},
|
|
15
|
+
cacheCount: 0
|
|
16
|
+
};
|
|
17
|
+
const MAX_CACHE_NUM = 2000;
|
|
18
|
+
const SPAN_STYLE = {
|
|
19
|
+
position: 'absolute',
|
|
20
|
+
top: '-20000px',
|
|
21
|
+
left: 0,
|
|
22
|
+
padding: 0,
|
|
23
|
+
margin: 0,
|
|
24
|
+
border: 'none',
|
|
25
|
+
whiteSpace: 'pre'
|
|
26
|
+
};
|
|
27
|
+
const STYLE_LIST = ['minWidth', 'maxWidth', 'width', 'minHeight', 'maxHeight', 'height', 'top', 'left', 'fontSize', 'padding', 'margin', 'paddingLeft', 'paddingRight', 'paddingTop', 'paddingBottom', 'marginLeft', 'marginRight', 'marginTop', 'marginBottom'];
|
|
28
|
+
const MEASUREMENT_SPAN_ID = 'mui_measurement_span';
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
*
|
|
32
|
+
* @param name CSS property name
|
|
33
|
+
* @param value
|
|
34
|
+
* @returns add 'px' for distance properties
|
|
35
|
+
*/
|
|
36
|
+
function autoCompleteStyle(name, value) {
|
|
37
|
+
if (STYLE_LIST.indexOf(name) >= 0 && value === +value) {
|
|
38
|
+
return `${value}px`;
|
|
39
|
+
}
|
|
40
|
+
return value;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
*
|
|
45
|
+
* @param text camelcase css property
|
|
46
|
+
* @returns css property
|
|
47
|
+
*/
|
|
48
|
+
function camelToMiddleLine(text) {
|
|
49
|
+
const strs = text.split('');
|
|
50
|
+
const formatStrs = strs.reduce((result, entry) => {
|
|
51
|
+
if (entry === entry.toUpperCase()) {
|
|
52
|
+
return [...result, '-', entry.toLowerCase()];
|
|
53
|
+
}
|
|
54
|
+
return [...result, entry];
|
|
55
|
+
}, []);
|
|
56
|
+
return formatStrs.join('');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
*
|
|
61
|
+
* @param style React style object
|
|
62
|
+
* @returns CSS styling string
|
|
63
|
+
*/
|
|
64
|
+
const getStyleString = style => Object.keys(style).sort().reduce((result, s) => `${result}${camelToMiddleLine(s)}:${autoCompleteStyle(s, style[s])};`, '');
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
*
|
|
68
|
+
* @param text The string to estimate
|
|
69
|
+
* @param style The style applied
|
|
70
|
+
* @returns width and height of the text
|
|
71
|
+
*/
|
|
72
|
+
exports.getStyleString = getStyleString;
|
|
73
|
+
const getStringSize = (text, style = {}) => {
|
|
74
|
+
if (text === undefined || text === null || isSsr()) {
|
|
75
|
+
return {
|
|
76
|
+
width: 0,
|
|
77
|
+
height: 0
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
const str = `${text}`;
|
|
81
|
+
const styleString = getStyleString(style);
|
|
82
|
+
const cacheKey = `${str}-${styleString}`;
|
|
83
|
+
if (stringCache.widthCache[cacheKey]) {
|
|
84
|
+
return stringCache.widthCache[cacheKey];
|
|
85
|
+
}
|
|
86
|
+
try {
|
|
87
|
+
let measurementSpan = document.getElementById(MEASUREMENT_SPAN_ID);
|
|
88
|
+
if (measurementSpan === null) {
|
|
89
|
+
measurementSpan = document.createElement('span');
|
|
90
|
+
measurementSpan.setAttribute('id', MEASUREMENT_SPAN_ID);
|
|
91
|
+
measurementSpan.setAttribute('aria-hidden', 'true');
|
|
92
|
+
document.body.appendChild(measurementSpan);
|
|
93
|
+
}
|
|
94
|
+
// Need to use CSS Object Model (CSSOM) to be able to comply with Content Security Policy (CSP)
|
|
95
|
+
// https://en.wikipedia.org/wiki/Content_Security_Policy
|
|
96
|
+
const measurementSpanStyle = (0, _extends2.default)({}, SPAN_STYLE, style);
|
|
97
|
+
Object.keys(measurementSpanStyle).map(styleKey => {
|
|
98
|
+
measurementSpan.style[camelToMiddleLine(styleKey)] = autoCompleteStyle(styleKey, measurementSpanStyle[styleKey]);
|
|
99
|
+
return styleKey;
|
|
100
|
+
});
|
|
101
|
+
measurementSpan.textContent = str;
|
|
102
|
+
const rect = measurementSpan.getBoundingClientRect();
|
|
103
|
+
const result = {
|
|
104
|
+
width: rect.width,
|
|
105
|
+
height: rect.height
|
|
106
|
+
};
|
|
107
|
+
stringCache.widthCache[cacheKey] = result;
|
|
108
|
+
if (stringCache.cacheCount + 1 > MAX_CACHE_NUM) {
|
|
109
|
+
stringCache.cacheCount = 0;
|
|
110
|
+
stringCache.widthCache = {};
|
|
111
|
+
} else {
|
|
112
|
+
stringCache.cacheCount += 1;
|
|
113
|
+
}
|
|
114
|
+
return result;
|
|
115
|
+
} catch (e) {
|
|
116
|
+
return {
|
|
117
|
+
width: 0,
|
|
118
|
+
height: 0
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
exports.getStringSize = getStringSize;
|
package/internals/stackSeries.js
CHANGED
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.getStackingGroups = exports.StackOrder = exports.StackOffset = void 0;
|
|
7
7
|
var _d3Shape = require("d3-shape");
|
|
8
|
-
const StackOrder = {
|
|
8
|
+
const StackOrder = exports.StackOrder = {
|
|
9
9
|
/**
|
|
10
10
|
* Series order such that the earliest series (according to the maximum value) is at the bottom.
|
|
11
11
|
* */
|
|
@@ -31,8 +31,7 @@ const StackOrder = {
|
|
|
31
31
|
*/
|
|
32
32
|
reverse: _d3Shape.stackOrderReverse
|
|
33
33
|
};
|
|
34
|
-
exports.
|
|
35
|
-
const StackOffset = {
|
|
34
|
+
const StackOffset = exports.StackOffset = {
|
|
36
35
|
/**
|
|
37
36
|
* Applies a zero baseline and normalizes the values for each point such that the topline is always one.
|
|
38
37
|
* */
|
|
@@ -60,7 +59,6 @@ const StackOffset = {
|
|
|
60
59
|
* @param series the object of all bars series
|
|
61
60
|
* @returns an array of groups, including the ids, the stacking order, and the stacking offset.
|
|
62
61
|
*/
|
|
63
|
-
exports.StackOffset = StackOffset;
|
|
64
62
|
const getStackingGroups = params => {
|
|
65
63
|
const {
|
|
66
64
|
series,
|
|
@@ -167,23 +167,19 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
167
167
|
tickNumber: PropTypes.number,
|
|
168
168
|
tickSize: PropTypes.number
|
|
169
169
|
}), PropTypes.string]),
|
|
170
|
+
/**
|
|
171
|
+
* @deprecated Consider using `slotProps.legend` instead.
|
|
172
|
+
*/
|
|
170
173
|
legend: PropTypes.shape({
|
|
171
174
|
classes: PropTypes.object,
|
|
172
175
|
direction: PropTypes.oneOf(['column', 'row']),
|
|
173
176
|
hidden: PropTypes.bool,
|
|
174
|
-
itemWidth: PropTypes.number,
|
|
175
|
-
markSize: PropTypes.number,
|
|
176
|
-
offset: PropTypes.shape({
|
|
177
|
-
x: PropTypes.number,
|
|
178
|
-
y: PropTypes.number
|
|
179
|
-
}),
|
|
180
177
|
position: PropTypes.shape({
|
|
181
178
|
horizontal: PropTypes.oneOf(['left', 'middle', 'right']).isRequired,
|
|
182
179
|
vertical: PropTypes.oneOf(['bottom', 'middle', 'top']).isRequired
|
|
183
180
|
}),
|
|
184
181
|
slotProps: PropTypes.object,
|
|
185
|
-
slots: PropTypes.object
|
|
186
|
-
spacing: PropTypes.number
|
|
182
|
+
slots: PropTypes.object
|
|
187
183
|
}),
|
|
188
184
|
margin: PropTypes.shape({
|
|
189
185
|
bottom: PropTypes.number,
|
|
@@ -249,6 +245,8 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
249
245
|
axisContent: PropTypes.elementType,
|
|
250
246
|
classes: PropTypes.object,
|
|
251
247
|
itemContent: PropTypes.elementType,
|
|
248
|
+
slotProps: PropTypes.object,
|
|
249
|
+
slots: PropTypes.object,
|
|
252
250
|
trigger: PropTypes.oneOf(['axis', 'item', 'none'])
|
|
253
251
|
}),
|
|
254
252
|
/**
|
|
@@ -1,12 +1,17 @@
|
|
|
1
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
2
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
1
3
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
4
|
+
var _excluded = ["label"];
|
|
2
5
|
import * as React from 'react';
|
|
3
6
|
import { useSlotProps } from '@mui/base/utils';
|
|
7
|
+
import { NoSsr } from '@mui/base/NoSsr';
|
|
4
8
|
import { unstable_composeClasses as composeClasses } from '@mui/utils';
|
|
5
9
|
import { useThemeProps, useTheme, styled } from '@mui/material/styles';
|
|
6
10
|
import { DrawingContext } from '../context/DrawingProvider';
|
|
7
11
|
import { getSeriesToDisplay } from './utils';
|
|
8
12
|
import { SeriesContext } from '../context/SeriesContextProvider';
|
|
9
13
|
import { getChartsLegendUtilityClass } from './chartsLegendClasses';
|
|
14
|
+
import { ChartsText, getWordsByLines } from '../internals/components/ChartsText';
|
|
10
15
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
16
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
12
17
|
var useUtilityClasses = function useUtilityClasses(ownerState) {
|
|
@@ -20,165 +25,218 @@ var useUtilityClasses = function useUtilityClasses(ownerState) {
|
|
|
20
25
|
};
|
|
21
26
|
return composeClasses(slots, getChartsLegendUtilityClass, classes);
|
|
22
27
|
};
|
|
23
|
-
function getTranslePosition(_ref) {
|
|
24
|
-
var position = _ref.position,
|
|
25
|
-
drawingArea = _ref.drawingArea;
|
|
26
|
-
var xValue;
|
|
27
|
-
switch (position.horizontal) {
|
|
28
|
-
case 'left':
|
|
29
|
-
xValue = "calc(var(--ChartsLegend-rootOffsetX, 0px) + ".concat(drawingArea.left, "px - var(--ChartsLegend-rootWidth))");
|
|
30
|
-
break;
|
|
31
|
-
case 'middle':
|
|
32
|
-
xValue = "calc(var(--ChartsLegend-rootOffsetX, 0px) + ".concat(drawingArea.left + drawingArea.width / 2, "px - 0.5 * var(--ChartsLegend-rootWidth))");
|
|
33
|
-
break;
|
|
34
|
-
default:
|
|
35
|
-
xValue = "calc(var(--ChartsLegend-rootOffsetX, 0px) + ".concat(drawingArea.left + drawingArea.width, "px)");
|
|
36
|
-
break;
|
|
37
|
-
}
|
|
38
|
-
var yValue;
|
|
39
|
-
switch (position.vertical) {
|
|
40
|
-
case 'top':
|
|
41
|
-
yValue = "calc(var(--ChartsLegend-rootOffsetY, 0px) + ".concat(drawingArea.top, "px - var(--ChartsLegend-rootHeight))");
|
|
42
|
-
break;
|
|
43
|
-
case 'middle':
|
|
44
|
-
yValue = "calc(var(--ChartsLegend-rootOffsetY, 0px) + ".concat(drawingArea.top + drawingArea.height / 2, "px - 0.5 * var(--ChartsLegend-rootHeight))");
|
|
45
|
-
break;
|
|
46
|
-
default:
|
|
47
|
-
yValue = "calc(var(--ChartsLegend-rootOffsetY, 0px) + ".concat(drawingArea.top + drawingArea.height, "px)");
|
|
48
|
-
break;
|
|
49
|
-
}
|
|
50
|
-
return {
|
|
51
|
-
transform: "translate(".concat(xValue, ", ").concat(yValue, ")")
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
28
|
export var ChartsLegendRoot = styled('g', {
|
|
55
29
|
name: 'MuiChartsLegend',
|
|
56
30
|
slot: 'Root',
|
|
57
31
|
overridesResolver: function overridesResolver(props, styles) {
|
|
58
32
|
return styles.root;
|
|
59
33
|
}
|
|
60
|
-
})(
|
|
61
|
-
var ownerState = _ref2.ownerState;
|
|
62
|
-
var direction = ownerState.direction,
|
|
63
|
-
drawingArea = ownerState.drawingArea,
|
|
64
|
-
offsetX = ownerState.offsetX,
|
|
65
|
-
offsetY = ownerState.offsetY,
|
|
66
|
-
seriesNumber = ownerState.seriesNumber,
|
|
67
|
-
position = ownerState.position;
|
|
68
|
-
return _extends({
|
|
69
|
-
'--ChartsLegend-rootOffsetX': typeof offsetX === 'number' ? "".concat(offsetX, "px") : undefined,
|
|
70
|
-
'--ChartsLegend-rootOffsetY': typeof offsetY === 'number' ? "".concat(offsetY, "px") : undefined,
|
|
71
|
-
'--ChartsLegend-rootWidth': direction === 'row' ? "calc(var(--ChartsLegend-itemWidth) * ".concat(seriesNumber, " + var(--ChartsLegend-rootSpacing) * ").concat(seriesNumber - 1, " )") : 'var(--ChartsLegend-itemWidth)',
|
|
72
|
-
'--ChartsLegend-rootHeight': direction === 'row' ? 'var(--ChartsLegend-itemMarkSize)' : "calc(var(--ChartsLegend-itemMarkSize) * ".concat(seriesNumber, " + var(--ChartsLegend-rootSpacing) * ").concat(seriesNumber - 1, " )")
|
|
73
|
-
}, getTranslePosition({
|
|
74
|
-
position: position,
|
|
75
|
-
drawingArea: drawingArea,
|
|
76
|
-
offsetX: offsetX,
|
|
77
|
-
offsetY: offsetY
|
|
78
|
-
}));
|
|
79
|
-
});
|
|
80
|
-
export var ChartsSeriesLegendGroup = styled('g', {
|
|
81
|
-
name: 'MuiChartsLegend',
|
|
82
|
-
slot: 'ChartsSeriesLegendGroup',
|
|
83
|
-
overridesResolver: function overridesResolver(props, styles) {
|
|
84
|
-
return styles.series;
|
|
85
|
-
}
|
|
86
|
-
})(function (_ref3) {
|
|
87
|
-
var ownerState = _ref3.ownerState;
|
|
88
|
-
var direction = ownerState.direction,
|
|
89
|
-
seriesIndex = ownerState.seriesIndex;
|
|
90
|
-
if (direction === 'row') {
|
|
91
|
-
return {
|
|
92
|
-
transform: "translate(calc(".concat(seriesIndex, " * (var(--ChartsLegend-itemWidth) + var(--ChartsLegend-rootSpacing))), 0)")
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
return {
|
|
96
|
-
transform: "translate(0, calc(".concat(seriesIndex, " * (var(--ChartsLegend-itemMarkSize) + var(--ChartsLegend-rootSpacing))))")
|
|
97
|
-
};
|
|
98
|
-
});
|
|
99
|
-
export var ChartsLegendMark = styled('rect', {
|
|
100
|
-
name: 'MuiChartsLegend',
|
|
101
|
-
slot: 'Mark',
|
|
102
|
-
overridesResolver: function overridesResolver(props, styles) {
|
|
103
|
-
return styles.mark;
|
|
104
|
-
}
|
|
105
|
-
})(function (_ref4) {
|
|
106
|
-
var ownerState = _ref4.ownerState;
|
|
107
|
-
return {
|
|
108
|
-
x: 0,
|
|
109
|
-
y: 0,
|
|
110
|
-
width: 'var(--ChartsLegend-itemMarkSize)',
|
|
111
|
-
height: 'var(--ChartsLegend-itemMarkSize)',
|
|
112
|
-
fill: ownerState.color
|
|
113
|
-
};
|
|
114
|
-
});
|
|
115
|
-
export var ChartsLegendLabel = styled('text', {
|
|
116
|
-
name: 'MuiChartsLegend',
|
|
117
|
-
slot: 'Label',
|
|
118
|
-
overridesResolver: function overridesResolver(props, styles) {
|
|
119
|
-
return styles.label;
|
|
120
|
-
}
|
|
121
|
-
})(function (_ref5) {
|
|
122
|
-
var theme = _ref5.theme;
|
|
123
|
-
return _extends({}, theme.typography.body1, {
|
|
124
|
-
color: 'inherit',
|
|
125
|
-
transform: "translate(\n calc(var(--ChartsLegend-itemMarkSize) + var(--ChartsLegend-labelSpacing)),\n calc(0.5 * var(--ChartsLegend-itemMarkSize))\n )",
|
|
126
|
-
fill: (theme.vars || theme).palette.text.primary,
|
|
127
|
-
dominantBaseline: 'central'
|
|
128
|
-
});
|
|
129
|
-
});
|
|
34
|
+
})({});
|
|
130
35
|
var defaultProps = {
|
|
131
36
|
position: {
|
|
132
37
|
horizontal: 'middle',
|
|
133
38
|
vertical: 'top'
|
|
134
39
|
},
|
|
135
|
-
direction: 'row'
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
40
|
+
direction: 'row'
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Transforms number or partial padding object to a defaultized padding object.
|
|
44
|
+
*/
|
|
45
|
+
var getStandardizedPadding = function getStandardizedPadding(padding) {
|
|
46
|
+
if (typeof padding === 'number') {
|
|
47
|
+
return {
|
|
48
|
+
left: padding,
|
|
49
|
+
right: padding,
|
|
50
|
+
top: padding,
|
|
51
|
+
bottom: padding
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
return _extends({
|
|
55
|
+
left: 0,
|
|
56
|
+
right: 0,
|
|
57
|
+
top: 0,
|
|
58
|
+
bottom: 0
|
|
59
|
+
}, padding);
|
|
139
60
|
};
|
|
140
61
|
function DefaultChartsLegend(props) {
|
|
141
62
|
var hidden = props.hidden,
|
|
142
63
|
position = props.position,
|
|
143
64
|
direction = props.direction,
|
|
144
|
-
offset = props.offset,
|
|
145
|
-
series = props.series,
|
|
146
65
|
seriesToDisplay = props.seriesToDisplay,
|
|
147
66
|
drawingArea = props.drawingArea,
|
|
148
|
-
classes = props.classes
|
|
67
|
+
classes = props.classes,
|
|
68
|
+
_props$itemMarkWidth = props.itemMarkWidth,
|
|
69
|
+
itemMarkWidth = _props$itemMarkWidth === void 0 ? 20 : _props$itemMarkWidth,
|
|
70
|
+
_props$itemMarkHeight = props.itemMarkHeight,
|
|
71
|
+
itemMarkHeight = _props$itemMarkHeight === void 0 ? 20 : _props$itemMarkHeight,
|
|
72
|
+
_props$markGap = props.markGap,
|
|
73
|
+
markGap = _props$markGap === void 0 ? 5 : _props$markGap,
|
|
74
|
+
_props$itemGap = props.itemGap,
|
|
75
|
+
itemGap = _props$itemGap === void 0 ? 10 : _props$itemGap,
|
|
76
|
+
_props$padding = props.padding,
|
|
77
|
+
paddingProps = _props$padding === void 0 ? 10 : _props$padding,
|
|
78
|
+
inLabelStyle = props.labelStyle;
|
|
79
|
+
var theme = useTheme();
|
|
80
|
+
var labelStyle = React.useMemo(function () {
|
|
81
|
+
return _extends({}, theme.typography.subtitle1, {
|
|
82
|
+
color: 'inherit',
|
|
83
|
+
fill: (theme.vars || theme).palette.text.primary,
|
|
84
|
+
lineHeight: 1
|
|
85
|
+
}, inLabelStyle);
|
|
86
|
+
}, [inLabelStyle, theme]);
|
|
87
|
+
var padding = React.useMemo(function () {
|
|
88
|
+
return getStandardizedPadding(paddingProps);
|
|
89
|
+
}, [paddingProps]);
|
|
90
|
+
var getItemSpace = React.useCallback(function (label, style) {
|
|
91
|
+
var linesSize = getWordsByLines({
|
|
92
|
+
style: style,
|
|
93
|
+
needsComputation: true,
|
|
94
|
+
text: label
|
|
95
|
+
});
|
|
96
|
+
var innerSize = {
|
|
97
|
+
innerWidth: itemMarkWidth + markGap + Math.max.apply(Math, _toConsumableArray(linesSize.map(function (size) {
|
|
98
|
+
return size.width;
|
|
99
|
+
}))),
|
|
100
|
+
innerHeight: Math.max(itemMarkHeight, linesSize.length * linesSize[0].height)
|
|
101
|
+
};
|
|
102
|
+
return _extends({}, innerSize, {
|
|
103
|
+
outerWidth: innerSize.innerWidth + itemGap,
|
|
104
|
+
outerHeight: innerSize.innerHeight + itemGap
|
|
105
|
+
});
|
|
106
|
+
}, [itemGap, itemMarkHeight, itemMarkWidth, markGap]);
|
|
107
|
+
var totalWidth = drawingArea.left + drawingArea.width + drawingArea.right;
|
|
108
|
+
var totalHeight = drawingArea.top + drawingArea.height + drawingArea.bottom;
|
|
109
|
+
var availableWidth = totalWidth - padding.left - padding.right;
|
|
110
|
+
var availableHeight = totalHeight - padding.top - padding.bottom;
|
|
111
|
+
var seriesWithPosition = React.useMemo(function () {
|
|
112
|
+
// Start at 0, 0. Will be modified later by padding and position.
|
|
113
|
+
var x = 0;
|
|
114
|
+
var y = 0;
|
|
115
|
+
|
|
116
|
+
// total values used to align legend later.
|
|
117
|
+
var totalWidthUsed = 0;
|
|
118
|
+
var totalHeightUsed = 0;
|
|
119
|
+
var rowIndex = 0;
|
|
120
|
+
var rowMaxHeight = [0];
|
|
121
|
+
var seriesWithRawPosition = seriesToDisplay.map(function (_ref) {
|
|
122
|
+
var label = _ref.label,
|
|
123
|
+
other = _objectWithoutProperties(_ref, _excluded);
|
|
124
|
+
var itemSpace = getItemSpace(label, labelStyle);
|
|
125
|
+
var rep = _extends({}, other, {
|
|
126
|
+
label: label,
|
|
127
|
+
positionX: x,
|
|
128
|
+
positionY: y,
|
|
129
|
+
innerHeight: itemSpace.innerHeight,
|
|
130
|
+
innerWidth: itemSpace.innerWidth,
|
|
131
|
+
outerHeight: itemSpace.outerHeight,
|
|
132
|
+
outerWidth: itemSpace.outerWidth,
|
|
133
|
+
rowIndex: rowIndex
|
|
134
|
+
});
|
|
135
|
+
if (direction === 'row') {
|
|
136
|
+
if (x + itemSpace.innerWidth > availableWidth) {
|
|
137
|
+
// This legend item would create overflow along the x-axis, so we start a new row.
|
|
138
|
+
x = 0;
|
|
139
|
+
y += rowMaxHeight[rowIndex];
|
|
140
|
+
rowIndex += 1;
|
|
141
|
+
if (rowMaxHeight.length <= rowIndex) {
|
|
142
|
+
rowMaxHeight.push(0);
|
|
143
|
+
}
|
|
144
|
+
rep.positionX = x;
|
|
145
|
+
rep.positionY = y;
|
|
146
|
+
rep.rowIndex = rowIndex;
|
|
147
|
+
}
|
|
148
|
+
totalWidthUsed = Math.max(totalWidthUsed, x + itemSpace.outerWidth);
|
|
149
|
+
totalHeightUsed = Math.max(totalHeightUsed, y + itemSpace.outerHeight);
|
|
150
|
+
rowMaxHeight[rowIndex] = Math.max(rowMaxHeight[rowIndex], itemSpace.outerHeight);
|
|
151
|
+
x += itemSpace.outerWidth;
|
|
152
|
+
}
|
|
153
|
+
if (direction === 'column') {
|
|
154
|
+
if (y + itemSpace.innerHeight > availableHeight) {
|
|
155
|
+
// This legend item would create overflow along the y-axis, so we start a new column.
|
|
156
|
+
x = totalWidthUsed + itemGap;
|
|
157
|
+
y = 0;
|
|
158
|
+
rowIndex = 0;
|
|
159
|
+
rep.positionX = x;
|
|
160
|
+
rep.positionY = y;
|
|
161
|
+
rep.rowIndex = rowIndex;
|
|
162
|
+
}
|
|
163
|
+
if (rowMaxHeight.length <= rowIndex) {
|
|
164
|
+
rowMaxHeight.push(0);
|
|
165
|
+
}
|
|
166
|
+
totalWidthUsed = Math.max(totalWidthUsed, x + itemSpace.outerWidth);
|
|
167
|
+
totalHeightUsed = Math.max(totalHeightUsed, y + itemSpace.outerHeight);
|
|
168
|
+
rowIndex += 1;
|
|
169
|
+
y += itemSpace.outerHeight;
|
|
170
|
+
}
|
|
171
|
+
return rep;
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
// Move the legend according to padding and position
|
|
175
|
+
var gapX = 0;
|
|
176
|
+
var gapY = 0;
|
|
177
|
+
switch (position.horizontal) {
|
|
178
|
+
case 'left':
|
|
179
|
+
gapX = padding.left;
|
|
180
|
+
break;
|
|
181
|
+
case 'right':
|
|
182
|
+
gapX = totalWidth - padding.right - totalWidthUsed;
|
|
183
|
+
break;
|
|
184
|
+
default:
|
|
185
|
+
gapX = (totalWidth - totalWidthUsed) / 2;
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
188
|
+
switch (position.vertical) {
|
|
189
|
+
case 'top':
|
|
190
|
+
gapY = padding.top;
|
|
191
|
+
break;
|
|
192
|
+
case 'bottom':
|
|
193
|
+
gapY = totalHeight - padding.bottom - totalHeightUsed;
|
|
194
|
+
break;
|
|
195
|
+
default:
|
|
196
|
+
gapY = (totalHeight - totalHeightUsed) / 2;
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
return seriesWithRawPosition.map(function (item) {
|
|
200
|
+
return _extends({}, item, {
|
|
201
|
+
// Add the gap due to the position
|
|
202
|
+
positionX: item.positionX + gapX,
|
|
203
|
+
// Add the gap due to the position
|
|
204
|
+
positionY: item.positionY + gapY + (direction === 'row' ? rowMaxHeight[item.rowIndex] / 2 // Get the center of the entire row
|
|
205
|
+
: item.outerHeight / 2) // Get the center of the item
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
}, [seriesToDisplay, position.horizontal, position.vertical, getItemSpace, labelStyle, direction, availableWidth, availableHeight, itemGap, padding.left, padding.right, padding.top, padding.bottom, totalWidth, totalHeight]);
|
|
149
209
|
if (hidden) {
|
|
150
210
|
return null;
|
|
151
211
|
}
|
|
152
|
-
return /*#__PURE__*/_jsx(
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
})]
|
|
181
|
-
}, id);
|
|
212
|
+
return /*#__PURE__*/_jsx(NoSsr, {
|
|
213
|
+
children: /*#__PURE__*/_jsx(ChartsLegendRoot, {
|
|
214
|
+
className: classes.root,
|
|
215
|
+
children: seriesWithPosition.map(function (_ref2) {
|
|
216
|
+
var id = _ref2.id,
|
|
217
|
+
label = _ref2.label,
|
|
218
|
+
color = _ref2.color,
|
|
219
|
+
positionX = _ref2.positionX,
|
|
220
|
+
positionY = _ref2.positionY;
|
|
221
|
+
return /*#__PURE__*/_jsxs("g", {
|
|
222
|
+
className: classes.series,
|
|
223
|
+
transform: "translate(".concat(positionX, " ").concat(positionY, ")"),
|
|
224
|
+
children: [/*#__PURE__*/_jsx("rect", {
|
|
225
|
+
className: classes.mark,
|
|
226
|
+
y: -itemMarkHeight / 2,
|
|
227
|
+
width: itemMarkWidth,
|
|
228
|
+
height: itemMarkHeight,
|
|
229
|
+
fill: color
|
|
230
|
+
}), /*#__PURE__*/_jsx(ChartsText, {
|
|
231
|
+
style: labelStyle,
|
|
232
|
+
dominantBaseline: "central",
|
|
233
|
+
textAnchor: "start",
|
|
234
|
+
text: label,
|
|
235
|
+
x: itemMarkWidth + markGap,
|
|
236
|
+
y: 0
|
|
237
|
+
})]
|
|
238
|
+
}, id);
|
|
239
|
+
})
|
|
182
240
|
})
|
|
183
241
|
});
|
|
184
242
|
}
|
|
@@ -190,7 +248,6 @@ export function ChartsLegend(inProps) {
|
|
|
190
248
|
});
|
|
191
249
|
var position = props.position,
|
|
192
250
|
direction = props.direction,
|
|
193
|
-
offset = props.offset,
|
|
194
251
|
hidden = props.hidden,
|
|
195
252
|
slots = props.slots,
|
|
196
253
|
slotProps = props.slotProps;
|
|
@@ -208,7 +265,6 @@ export function ChartsLegend(inProps) {
|
|
|
208
265
|
additionalProps: {
|
|
209
266
|
position: position,
|
|
210
267
|
direction: direction,
|
|
211
|
-
offset: offset,
|
|
212
268
|
classes: classes,
|
|
213
269
|
drawingArea: drawingArea,
|
|
214
270
|
series: series,
|
package/legacy/ChartsSurface.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
2
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
4
|
-
var _excluded = ["children", "width", "height", "viewBox", "disableAxisListener", "className"
|
|
3
|
+
var _excluded = ["children", "width", "height", "viewBox", "disableAxisListener", "className"];
|
|
5
4
|
import { styled } from '@mui/material/styles';
|
|
6
5
|
import * as React from 'react';
|
|
7
6
|
import { useAxisEvents } from './hooks/useAxisEvents';
|
|
@@ -21,7 +20,6 @@ export var ChartsSurface = /*#__PURE__*/React.forwardRef(function ChartsSurface(
|
|
|
21
20
|
_props$disableAxisLis = props.disableAxisListener,
|
|
22
21
|
disableAxisListener = _props$disableAxisLis === void 0 ? false : _props$disableAxisLis,
|
|
23
22
|
className = props.className,
|
|
24
|
-
sx = props.sx,
|
|
25
23
|
other = _objectWithoutProperties(props, _excluded);
|
|
26
24
|
var svgView = _extends({
|
|
27
25
|
width: width,
|
|
@@ -34,14 +32,7 @@ export var ChartsSurface = /*#__PURE__*/React.forwardRef(function ChartsSurface(
|
|
|
34
32
|
width: width,
|
|
35
33
|
height: height,
|
|
36
34
|
viewBox: "".concat(svgView.x, " ").concat(svgView.y, " ").concat(svgView.width, " ").concat(svgView.height),
|
|
37
|
-
ref: ref
|
|
38
|
-
sx: [{
|
|
39
|
-
'--ChartsLegend-itemWidth': '100px',
|
|
40
|
-
'--ChartsLegend-itemMarkSize': '20px',
|
|
41
|
-
'--ChartsLegend-rootSpacing': '5px',
|
|
42
|
-
'--ChartsLegend-labelSpacing': '5px',
|
|
43
|
-
'--ChartsLegend-rootOffsetY': '-20px'
|
|
44
|
-
}].concat(_toConsumableArray(Array.isArray(sx) ? sx : [sx]))
|
|
35
|
+
ref: ref
|
|
45
36
|
}, other, {
|
|
46
37
|
children: [/*#__PURE__*/_jsx("title", {
|
|
47
38
|
children: props.title
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
1
2
|
import * as React from 'react';
|
|
2
3
|
import Typography from '@mui/material/Typography';
|
|
4
|
+
import { useSlotProps } from '@mui/base/utils';
|
|
3
5
|
import { SeriesContext } from '../context/SeriesContextProvider';
|
|
4
6
|
import { CartesianContext } from '../context/CartesianContextProvider';
|
|
5
7
|
import { ChartsTooltipCell, ChartsTooltipPaper, ChartsTooltipTable, ChartsTooltipMark, ChartsTooltipRow } from './ChartsTooltipTable';
|
|
@@ -67,6 +69,7 @@ export function DefaultChartsAxisContent(props) {
|
|
|
67
69
|
}
|
|
68
70
|
export function ChartsAxisTooltipContent(props) {
|
|
69
71
|
var content = props.content,
|
|
72
|
+
contentProps = props.contentProps,
|
|
70
73
|
axisData = props.axisData,
|
|
71
74
|
sx = props.sx,
|
|
72
75
|
classes = props.classes;
|
|
@@ -99,13 +102,19 @@ export function ChartsAxisTooltipContent(props) {
|
|
|
99
102
|
return isXaxis ? xAxis[USED_AXIS_ID] : yAxis[USED_AXIS_ID];
|
|
100
103
|
}, [USED_AXIS_ID, isXaxis, xAxis, yAxis]);
|
|
101
104
|
var Content = content != null ? content : DefaultChartsAxisContent;
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
105
|
+
var chartTooltipContentProps = useSlotProps({
|
|
106
|
+
elementType: Content,
|
|
107
|
+
externalSlotProps: contentProps,
|
|
108
|
+
additionalProps: {
|
|
109
|
+
axisData: axisData,
|
|
110
|
+
series: relevantSeries,
|
|
111
|
+
axis: relevantAxis,
|
|
112
|
+
dataIndex: dataIndex,
|
|
113
|
+
axisValue: axisValue,
|
|
114
|
+
sx: sx,
|
|
115
|
+
classes: classes
|
|
116
|
+
},
|
|
117
|
+
ownerState: {}
|
|
110
118
|
});
|
|
119
|
+
return /*#__PURE__*/_jsx(Content, _extends({}, chartTooltipContentProps));
|
|
111
120
|
}
|