@mui/x-charts 6.0.0-alpha.14 → 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 +3 -0
- package/BarChart/BarChart.js +4 -8
- package/CHANGELOG.md +104 -0
- package/ChartsLegend/ChartsLegend.d.ts +43 -24
- package/ChartsLegend/ChartsLegend.js +185 -143
- package/ChartsLegend/utils.d.ts +1 -6
- package/ChartsSurface.js +3 -11
- package/ChartsXAxis/ChartsXAxis.js +48 -25
- package/ChartsYAxis/ChartsYAxis.js +47 -26
- package/LineChart/LineChart.d.ts +3 -0
- package/LineChart/LineChart.js +4 -8
- package/PieChart/PieChart.d.ts +3 -0
- package/PieChart/PieChart.js +4 -8
- package/ScatterChart/ScatterChart.d.ts +3 -0
- package/ScatterChart/ScatterChart.js +4 -8
- package/constants.js +1 -1
- package/context/CartesianContextProvider.js +10 -10
- package/context/DrawingProvider.d.ts +2 -0
- package/context/DrawingProvider.js +2 -0
- package/esm/BarChart/BarChart.js +4 -8
- package/esm/ChartsLegend/ChartsLegend.js +184 -142
- package/esm/ChartsSurface.js +3 -11
- package/esm/ChartsXAxis/ChartsXAxis.js +47 -24
- package/esm/ChartsYAxis/ChartsYAxis.js +46 -25
- package/esm/LineChart/LineChart.js +4 -8
- package/esm/PieChart/PieChart.js +4 -8
- package/esm/ScatterChart/ScatterChart.js +4 -8
- 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 +2 -0
- package/hooks/useTicks.d.ts +2 -3
- package/hooks/useTicks.js +6 -6
- package/index.js +1 -1
- package/internals/components/AxisSharedComponents.d.ts +0 -4
- package/internals/components/AxisSharedComponents.js +16 -71
- package/internals/components/ChartsText.d.ts +32 -0
- package/internals/components/ChartsText.js +81 -0
- package/internals/domUtils.d.ts +14 -0
- package/internals/domUtils.js +122 -0
- package/legacy/BarChart/BarChart.js +4 -8
- package/legacy/ChartsLegend/ChartsLegend.js +196 -140
- package/legacy/ChartsSurface.js +2 -11
- package/legacy/ChartsXAxis/ChartsXAxis.js +47 -24
- package/legacy/ChartsYAxis/ChartsYAxis.js +46 -25
- package/legacy/LineChart/LineChart.js +4 -8
- package/legacy/PieChart/PieChart.js +4 -8
- package/legacy/ScatterChart/ScatterChart.js +4 -8
- 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 +4 -8
- package/modern/ChartsLegend/ChartsLegend.js +184 -142
- package/modern/ChartsSurface.js +3 -11
- package/modern/ChartsXAxis/ChartsXAxis.js +47 -24
- package/modern/ChartsYAxis/ChartsYAxis.js +46 -25
- package/modern/LineChart/LineChart.js +4 -8
- package/modern/PieChart/PieChart.js +4 -8
- package/modern/ScatterChart/ScatterChart.js +4 -8
- 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 +1 -1
|
@@ -160,23 +160,19 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
|
|
|
160
160
|
tickNumber: PropTypes.number,
|
|
161
161
|
tickSize: PropTypes.number
|
|
162
162
|
}), PropTypes.string]),
|
|
163
|
+
/**
|
|
164
|
+
* @deprecated Consider using `slotProps.legend` instead.
|
|
165
|
+
*/
|
|
163
166
|
legend: PropTypes.shape({
|
|
164
167
|
classes: PropTypes.object,
|
|
165
168
|
direction: PropTypes.oneOf(['column', 'row']),
|
|
166
169
|
hidden: PropTypes.bool,
|
|
167
|
-
itemWidth: PropTypes.number,
|
|
168
|
-
markSize: PropTypes.number,
|
|
169
|
-
offset: PropTypes.shape({
|
|
170
|
-
x: PropTypes.number,
|
|
171
|
-
y: PropTypes.number
|
|
172
|
-
}),
|
|
173
170
|
position: PropTypes.shape({
|
|
174
171
|
horizontal: PropTypes.oneOf(['left', 'middle', 'right']).isRequired,
|
|
175
172
|
vertical: PropTypes.oneOf(['bottom', 'middle', 'top']).isRequired
|
|
176
173
|
}),
|
|
177
174
|
slotProps: PropTypes.object,
|
|
178
|
-
slots: PropTypes.object
|
|
179
|
-
spacing: PropTypes.number
|
|
175
|
+
slots: PropTypes.object
|
|
180
176
|
}),
|
|
181
177
|
margin: PropTypes.shape({
|
|
182
178
|
bottom: PropTypes.number,
|
|
@@ -128,23 +128,19 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
|
|
|
128
128
|
tickNumber: PropTypes.number,
|
|
129
129
|
tickSize: PropTypes.number
|
|
130
130
|
}), PropTypes.string]),
|
|
131
|
+
/**
|
|
132
|
+
* @deprecated Consider using `slotProps.legend` instead.
|
|
133
|
+
*/
|
|
131
134
|
legend: PropTypes.shape({
|
|
132
135
|
classes: PropTypes.object,
|
|
133
136
|
direction: PropTypes.oneOf(['column', 'row']),
|
|
134
137
|
hidden: PropTypes.bool,
|
|
135
|
-
itemWidth: PropTypes.number,
|
|
136
|
-
markSize: PropTypes.number,
|
|
137
|
-
offset: PropTypes.shape({
|
|
138
|
-
x: PropTypes.number,
|
|
139
|
-
y: PropTypes.number
|
|
140
|
-
}),
|
|
141
138
|
position: PropTypes.shape({
|
|
142
139
|
horizontal: PropTypes.oneOf(['left', 'middle', 'right']).isRequired,
|
|
143
140
|
vertical: PropTypes.oneOf(['bottom', 'middle', 'top']).isRequired
|
|
144
141
|
}),
|
|
145
142
|
slotProps: PropTypes.object,
|
|
146
|
-
slots: PropTypes.object
|
|
147
|
-
spacing: PropTypes.number
|
|
143
|
+
slots: PropTypes.object
|
|
148
144
|
}),
|
|
149
145
|
margin: PropTypes.shape({
|
|
150
146
|
bottom: PropTypes.number,
|
package/legacy/constants.js
CHANGED
|
@@ -12,7 +12,7 @@ import { getScale } from '../internals/getScale';
|
|
|
12
12
|
import { DrawingContext } from './DrawingProvider';
|
|
13
13
|
import { SeriesContext } from './SeriesContextProvider';
|
|
14
14
|
import { DEFAULT_X_AXIS_KEY, DEFAULT_Y_AXIS_KEY } from '../constants';
|
|
15
|
-
import {
|
|
15
|
+
import { getTickNumber } from '../hooks/useTicks';
|
|
16
16
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
17
17
|
var DEFAULT_CATEGORY_GAP_RATIO = 0.2;
|
|
18
18
|
var DEFAULT_BAR_GAP_RATIO = 0.1;
|
|
@@ -133,13 +133,13 @@ function CartesianContextProvider(_ref) {
|
|
|
133
133
|
barGapRatio: barGapRatio
|
|
134
134
|
}, axis, {
|
|
135
135
|
scale: scaleBand(axis.data, range).paddingInner(categoryGapRatio).paddingOuter(categoryGapRatio / 2),
|
|
136
|
-
|
|
136
|
+
tickNumber: axis.data.length
|
|
137
137
|
});
|
|
138
138
|
}
|
|
139
139
|
if (isPointScaleConfig(axis)) {
|
|
140
140
|
completedXAxis[axis.id] = _extends({}, axis, {
|
|
141
141
|
scale: scalePoint(axis.data, range),
|
|
142
|
-
|
|
142
|
+
tickNumber: axis.data.length
|
|
143
143
|
});
|
|
144
144
|
}
|
|
145
145
|
if (axis.scaleType === 'band' || axis.scaleType === 'point') {
|
|
@@ -148,17 +148,17 @@ function CartesianContextProvider(_ref) {
|
|
|
148
148
|
}
|
|
149
149
|
var scaleType = (_axis$scaleType = axis.scaleType) != null ? _axis$scaleType : 'linear';
|
|
150
150
|
var extremums = [(_axis$min = axis.min) != null ? _axis$min : minData, (_axis$max = axis.max) != null ? _axis$max : maxData];
|
|
151
|
-
var
|
|
151
|
+
var tickNumber = getTickNumber(_extends({}, axis, {
|
|
152
152
|
range: range,
|
|
153
153
|
domain: extremums
|
|
154
154
|
}));
|
|
155
|
-
var niceScale = getScale(scaleType, extremums, range).nice(
|
|
155
|
+
var niceScale = getScale(scaleType, extremums, range).nice(tickNumber);
|
|
156
156
|
var niceDomain = niceScale.domain();
|
|
157
157
|
var domain = [(_axis$min2 = axis.min) != null ? _axis$min2 : niceDomain[0], (_axis$max2 = axis.max) != null ? _axis$max2 : niceDomain[1]];
|
|
158
158
|
completedXAxis[axis.id] = _extends({}, axis, {
|
|
159
159
|
scaleType: scaleType,
|
|
160
160
|
scale: niceScale.domain(domain),
|
|
161
|
-
|
|
161
|
+
tickNumber: tickNumber
|
|
162
162
|
});
|
|
163
163
|
});
|
|
164
164
|
var allYAxis = [].concat(_toConsumableArray((_yAxis$map = yAxis == null ? void 0 : yAxis.map(function (axis, index) {
|
|
@@ -189,13 +189,13 @@ function CartesianContextProvider(_ref) {
|
|
|
189
189
|
barGapRatio: 0
|
|
190
190
|
}, axis, {
|
|
191
191
|
scale: scaleBand(axis.data, [range[1], range[0]]).paddingInner(categoryGapRatio).paddingOuter(categoryGapRatio / 2),
|
|
192
|
-
|
|
192
|
+
tickNumber: axis.data.length
|
|
193
193
|
});
|
|
194
194
|
}
|
|
195
195
|
if (isPointScaleConfig(axis)) {
|
|
196
196
|
completedYAxis[axis.id] = _extends({}, axis, {
|
|
197
197
|
scale: scalePoint(axis.data, [range[1], range[0]]),
|
|
198
|
-
|
|
198
|
+
tickNumber: axis.data.length
|
|
199
199
|
});
|
|
200
200
|
}
|
|
201
201
|
if (axis.scaleType === 'band' || axis.scaleType === 'point') {
|
|
@@ -204,17 +204,17 @@ function CartesianContextProvider(_ref) {
|
|
|
204
204
|
}
|
|
205
205
|
var scaleType = (_axis$scaleType2 = axis.scaleType) != null ? _axis$scaleType2 : 'linear';
|
|
206
206
|
var extremums = [(_axis$min3 = axis.min) != null ? _axis$min3 : minData, (_axis$max3 = axis.max) != null ? _axis$max3 : maxData];
|
|
207
|
-
var
|
|
207
|
+
var tickNumber = getTickNumber(_extends({}, axis, {
|
|
208
208
|
range: range,
|
|
209
209
|
domain: extremums
|
|
210
210
|
}));
|
|
211
|
-
var niceScale = getScale(scaleType, extremums, range).nice(
|
|
211
|
+
var niceScale = getScale(scaleType, extremums, range).nice(tickNumber);
|
|
212
212
|
var niceDomain = niceScale.domain();
|
|
213
213
|
var domain = [(_axis$min4 = axis.min) != null ? _axis$min4 : niceDomain[0], (_axis$max4 = axis.max) != null ? _axis$max4 : niceDomain[1]];
|
|
214
214
|
completedYAxis[axis.id] = _extends({}, axis, {
|
|
215
215
|
scaleType: scaleType,
|
|
216
216
|
scale: niceScale.domain(domain),
|
|
217
|
-
|
|
217
|
+
tickNumber: tickNumber
|
|
218
218
|
});
|
|
219
219
|
});
|
|
220
220
|
return {
|
|
@@ -7,6 +7,8 @@ var useChartDimensions = function useChartDimensions(width, height, margin) {
|
|
|
7
7
|
return {
|
|
8
8
|
left: defaultizedMargin.left,
|
|
9
9
|
top: defaultizedMargin.top,
|
|
10
|
+
right: defaultizedMargin.right,
|
|
11
|
+
bottom: defaultizedMargin.bottom,
|
|
10
12
|
width: Math.max(0, width - defaultizedMargin.left - defaultizedMargin.right),
|
|
11
13
|
height: Math.max(0, height - defaultizedMargin.top - defaultizedMargin.bottom)
|
|
12
14
|
};
|
package/legacy/hooks/useTicks.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { isBandScale } from '../internals/isBandScale';
|
|
4
|
-
export function
|
|
4
|
+
export function getTickNumber(params) {
|
|
5
5
|
var tickMaxStep = params.tickMaxStep,
|
|
6
6
|
tickMinStep = params.tickMinStep,
|
|
7
7
|
tickNumber = params.tickNumber,
|
|
@@ -14,7 +14,7 @@ export function getTicksNumber(params) {
|
|
|
14
14
|
}
|
|
15
15
|
function useTicks(options) {
|
|
16
16
|
var scale = options.scale,
|
|
17
|
-
|
|
17
|
+
tickNumber = options.tickNumber,
|
|
18
18
|
valueFormatter = options.valueFormatter;
|
|
19
19
|
return React.useMemo(function () {
|
|
20
20
|
// band scale
|
|
@@ -46,14 +46,14 @@ function useTicks(options) {
|
|
|
46
46
|
};
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
|
-
return scale.ticks(
|
|
49
|
+
return scale.ticks(tickNumber).map(function (value) {
|
|
50
50
|
var _valueFormatter3;
|
|
51
51
|
return {
|
|
52
|
-
formattedValue: (_valueFormatter3 = valueFormatter == null ? void 0 : valueFormatter(value)) != null ? _valueFormatter3 : scale.tickFormat(
|
|
52
|
+
formattedValue: (_valueFormatter3 = valueFormatter == null ? void 0 : valueFormatter(value)) != null ? _valueFormatter3 : scale.tickFormat(tickNumber)(value),
|
|
53
53
|
offset: scale(value),
|
|
54
54
|
labelOffset: 0
|
|
55
55
|
};
|
|
56
56
|
});
|
|
57
|
-
}, [
|
|
57
|
+
}, [tickNumber, scale, valueFormatter]);
|
|
58
58
|
}
|
|
59
59
|
export default useTicks;
|
package/legacy/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
1
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
3
|
-
|
|
2
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
4
3
|
import { styled } from '@mui/material/styles';
|
|
5
4
|
import { axisClasses } from '../../ChartsAxis/axisClasses';
|
|
6
5
|
export var AxisRoot = styled('g', {
|
|
@@ -9,72 +8,19 @@ export var AxisRoot = styled('g', {
|
|
|
9
8
|
overridesResolver: function overridesResolver(props, styles) {
|
|
10
9
|
return styles.root;
|
|
11
10
|
}
|
|
12
|
-
})((_styled = {}, _defineProperty(_styled, "&.".concat(axisClasses.directionY), (_$concat = {}, _defineProperty(_$concat, ".".concat(axisClasses.tickLabel), {
|
|
13
|
-
dominantBaseline: 'middle'
|
|
14
|
-
}), _defineProperty(_$concat, ".".concat(axisClasses.label), {
|
|
15
|
-
dominantBaseline: 'auto',
|
|
16
|
-
textAnchor: 'middle'
|
|
17
|
-
}), _$concat)), _defineProperty(_styled, "&.".concat(axisClasses.left), _defineProperty({}, ".".concat(axisClasses.tickLabel), {
|
|
18
|
-
dominantBaseline: 'central',
|
|
19
|
-
textAnchor: 'end'
|
|
20
|
-
})), _defineProperty(_styled, "&.".concat(axisClasses.right), _defineProperty({}, ".".concat(axisClasses.tickLabel), {
|
|
21
|
-
dominantBaseline: 'central',
|
|
22
|
-
textAnchor: 'start'
|
|
23
|
-
})), _defineProperty(_styled, "&.".concat(axisClasses.bottom), _defineProperty({}, ".".concat(axisClasses.tickLabel, ", .").concat(axisClasses.label), {
|
|
24
|
-
dominantBaseline: 'hanging',
|
|
25
|
-
textAnchor: 'middle'
|
|
26
|
-
})), _defineProperty(_styled, "&.".concat(axisClasses.top), _defineProperty({}, ".".concat(axisClasses.tickLabel, ", .").concat(axisClasses.label), {
|
|
27
|
-
dominantBaseline: 'baseline',
|
|
28
|
-
textAnchor: 'middle'
|
|
29
|
-
})), _styled));
|
|
30
|
-
export var ChartsLine = styled('line', {
|
|
31
|
-
name: 'MuiChartsAxis',
|
|
32
|
-
slot: 'Line',
|
|
33
|
-
overridesResolver: function overridesResolver(props, styles) {
|
|
34
|
-
return styles.line;
|
|
35
|
-
}
|
|
36
11
|
})(function (_ref) {
|
|
12
|
+
var _ref2;
|
|
37
13
|
var theme = _ref.theme;
|
|
38
|
-
return {
|
|
14
|
+
return _ref2 = {}, _defineProperty(_ref2, "& .".concat(axisClasses.tickLabel), _extends({}, theme.typography.caption, {
|
|
15
|
+
fill: (theme.vars || theme).palette.text.primary
|
|
16
|
+
})), _defineProperty(_ref2, "& .".concat(axisClasses.label), _extends({}, theme.typography.body1, {
|
|
17
|
+
fill: (theme.vars || theme).palette.text.primary
|
|
18
|
+
})), _defineProperty(_ref2, "& .".concat(axisClasses.line), {
|
|
39
19
|
stroke: (theme.vars || theme).palette.text.primary,
|
|
40
20
|
shapeRendering: 'crispEdges',
|
|
41
21
|
strokeWidth: 1
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
export var ChartsTick = styled('line', {
|
|
45
|
-
name: 'MuiChartsAxis',
|
|
46
|
-
slot: 'Tick',
|
|
47
|
-
overridesResolver: function overridesResolver(props, styles) {
|
|
48
|
-
return styles.tick;
|
|
49
|
-
}
|
|
50
|
-
})(function (_ref2) {
|
|
51
|
-
var theme = _ref2.theme;
|
|
52
|
-
return {
|
|
22
|
+
}), _defineProperty(_ref2, "& .".concat(axisClasses.tick), {
|
|
53
23
|
stroke: (theme.vars || theme).palette.text.primary,
|
|
54
24
|
shapeRendering: 'crispEdges'
|
|
55
|
-
};
|
|
56
|
-
});
|
|
57
|
-
export var ChartsTickLabel = styled('text', {
|
|
58
|
-
name: 'MuiChartsAxis',
|
|
59
|
-
slot: 'TickLabel',
|
|
60
|
-
overridesResolver: function overridesResolver(props, styles) {
|
|
61
|
-
return styles.tickLabel;
|
|
62
|
-
}
|
|
63
|
-
})(function (_ref3) {
|
|
64
|
-
var theme = _ref3.theme;
|
|
65
|
-
return _extends({}, theme.typography.caption, {
|
|
66
|
-
fill: (theme.vars || theme).palette.text.primary
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
export var ChartsLabel = styled('text', {
|
|
70
|
-
name: 'MuiChartsAxis',
|
|
71
|
-
slot: 'Label',
|
|
72
|
-
overridesResolver: function overridesResolver(props, styles) {
|
|
73
|
-
return styles.label;
|
|
74
|
-
}
|
|
75
|
-
})(function (_ref4) {
|
|
76
|
-
var theme = _ref4.theme;
|
|
77
|
-
return _extends({}, theme.typography.body1, {
|
|
78
|
-
fill: (theme.vars || theme).palette.text.primary
|
|
79
|
-
});
|
|
25
|
+
}), _ref2;
|
|
80
26
|
});
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
2
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
|
+
var _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(_ref) {
|
|
8
|
+
var style = _ref.style,
|
|
9
|
+
needsComputation = _ref.needsComputation,
|
|
10
|
+
text = _ref.text;
|
|
11
|
+
return text.split('\n').map(function (subText) {
|
|
12
|
+
return _extends({
|
|
13
|
+
text: subText
|
|
14
|
+
}, needsComputation ? getStringSize(subText, style) : {
|
|
15
|
+
width: 0,
|
|
16
|
+
height: 0
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
export function ChartsText(props) {
|
|
21
|
+
var x = props.x,
|
|
22
|
+
y = props.y,
|
|
23
|
+
_props$textAnchor = props.textAnchor,
|
|
24
|
+
textAnchor = _props$textAnchor === void 0 ? 'start' : _props$textAnchor,
|
|
25
|
+
_props$dominantBaseli = props.dominantBaseline,
|
|
26
|
+
dominantBaseline = _props$dominantBaseli === void 0 ? 'central' : _props$dominantBaseli,
|
|
27
|
+
style = props.style,
|
|
28
|
+
text = props.text,
|
|
29
|
+
ownerState = props.ownerState,
|
|
30
|
+
textProps = _objectWithoutProperties(props, _excluded);
|
|
31
|
+
var wordsByLines = React.useMemo(function () {
|
|
32
|
+
return getWordsByLines({
|
|
33
|
+
style: style,
|
|
34
|
+
needsComputation: text.includes('\n'),
|
|
35
|
+
text: text
|
|
36
|
+
});
|
|
37
|
+
}, [style, text]);
|
|
38
|
+
var startDy;
|
|
39
|
+
switch (dominantBaseline) {
|
|
40
|
+
case 'hanging':
|
|
41
|
+
startDy = 0;
|
|
42
|
+
break;
|
|
43
|
+
case 'central':
|
|
44
|
+
startDy = (wordsByLines.length - 1) / 2 * -wordsByLines[0].height;
|
|
45
|
+
break;
|
|
46
|
+
default:
|
|
47
|
+
startDy = (wordsByLines.length - 1) * -wordsByLines[0].height;
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// const transforms = [];
|
|
52
|
+
// if (scaleToFit) {
|
|
53
|
+
// const lineWidth = wordsByLines[0].width;
|
|
54
|
+
// transforms.push(`scale(${(isNumber(width as number) ? (width as number) / lineWidth : 1) / lineWidth})`);
|
|
55
|
+
// }
|
|
56
|
+
// if (angle) {
|
|
57
|
+
// transforms.push(`rotate(${angle}, ${x}, ${y})`);
|
|
58
|
+
// }
|
|
59
|
+
// if (transforms.length) {
|
|
60
|
+
// textProps.transform = transforms.join(' ');
|
|
61
|
+
// }
|
|
62
|
+
|
|
63
|
+
return /*#__PURE__*/_jsx("text", _extends({}, textProps, {
|
|
64
|
+
x: x,
|
|
65
|
+
y: y,
|
|
66
|
+
textAnchor: textAnchor,
|
|
67
|
+
dominantBaseline: dominantBaseline,
|
|
68
|
+
style: style,
|
|
69
|
+
children: wordsByLines.map(function (line, index) {
|
|
70
|
+
return /*#__PURE__*/_jsx("tspan", {
|
|
71
|
+
x: x,
|
|
72
|
+
dy: "".concat(index === 0 ? startDy : wordsByLines[0].height, "px"),
|
|
73
|
+
children: line.text
|
|
74
|
+
}, index);
|
|
75
|
+
})
|
|
76
|
+
}));
|
|
77
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
3
|
+
// DOM utils taken from
|
|
4
|
+
// https://github.com/recharts/recharts/blob/master/src/util/DOMUtils.ts
|
|
5
|
+
|
|
6
|
+
var isSsr = function isSsr() {
|
|
7
|
+
return !(typeof window !== 'undefined' && window.document && window.setTimeout);
|
|
8
|
+
};
|
|
9
|
+
var stringCache = {
|
|
10
|
+
widthCache: {},
|
|
11
|
+
cacheCount: 0
|
|
12
|
+
};
|
|
13
|
+
var MAX_CACHE_NUM = 2000;
|
|
14
|
+
var SPAN_STYLE = {
|
|
15
|
+
position: 'absolute',
|
|
16
|
+
top: '-20000px',
|
|
17
|
+
left: 0,
|
|
18
|
+
padding: 0,
|
|
19
|
+
margin: 0,
|
|
20
|
+
border: 'none',
|
|
21
|
+
whiteSpace: 'pre'
|
|
22
|
+
};
|
|
23
|
+
var STYLE_LIST = ['minWidth', 'maxWidth', 'width', 'minHeight', 'maxHeight', 'height', 'top', 'left', 'fontSize', 'padding', 'margin', 'paddingLeft', 'paddingRight', 'paddingTop', 'paddingBottom', 'marginLeft', 'marginRight', 'marginTop', 'marginBottom'];
|
|
24
|
+
var MEASUREMENT_SPAN_ID = 'mui_measurement_span';
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
*
|
|
28
|
+
* @param name CSS property name
|
|
29
|
+
* @param value
|
|
30
|
+
* @returns add 'px' for distance properties
|
|
31
|
+
*/
|
|
32
|
+
function autoCompleteStyle(name, value) {
|
|
33
|
+
if (STYLE_LIST.indexOf(name) >= 0 && value === +value) {
|
|
34
|
+
return "".concat(value, "px");
|
|
35
|
+
}
|
|
36
|
+
return value;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
*
|
|
41
|
+
* @param text camelcase css property
|
|
42
|
+
* @returns css property
|
|
43
|
+
*/
|
|
44
|
+
function camelToMiddleLine(text) {
|
|
45
|
+
var strs = text.split('');
|
|
46
|
+
var formatStrs = strs.reduce(function (result, entry) {
|
|
47
|
+
if (entry === entry.toUpperCase()) {
|
|
48
|
+
return [].concat(_toConsumableArray(result), ['-', entry.toLowerCase()]);
|
|
49
|
+
}
|
|
50
|
+
return [].concat(_toConsumableArray(result), [entry]);
|
|
51
|
+
}, []);
|
|
52
|
+
return formatStrs.join('');
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
*
|
|
57
|
+
* @param style React style object
|
|
58
|
+
* @returns CSS styling string
|
|
59
|
+
*/
|
|
60
|
+
export var getStyleString = function getStyleString(style) {
|
|
61
|
+
return Object.keys(style).sort().reduce(function (result, s) {
|
|
62
|
+
return "".concat(result).concat(camelToMiddleLine(s), ":").concat(autoCompleteStyle(s, style[s]), ";");
|
|
63
|
+
}, '');
|
|
64
|
+
};
|
|
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
|
+
export var getStringSize = function getStringSize(text) {
|
|
73
|
+
var style = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
74
|
+
if (text === undefined || text === null || isSsr()) {
|
|
75
|
+
return {
|
|
76
|
+
width: 0,
|
|
77
|
+
height: 0
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
var str = "".concat(text);
|
|
81
|
+
var styleString = getStyleString(style);
|
|
82
|
+
var cacheKey = "".concat(str, "-").concat(styleString);
|
|
83
|
+
if (stringCache.widthCache[cacheKey]) {
|
|
84
|
+
return stringCache.widthCache[cacheKey];
|
|
85
|
+
}
|
|
86
|
+
try {
|
|
87
|
+
var 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
|
+
var measurementSpanStyle = _extends({}, SPAN_STYLE, style);
|
|
97
|
+
Object.keys(measurementSpanStyle).map(function (styleKey) {
|
|
98
|
+
measurementSpan.style[camelToMiddleLine(styleKey)] = autoCompleteStyle(styleKey, measurementSpanStyle[styleKey]);
|
|
99
|
+
return styleKey;
|
|
100
|
+
});
|
|
101
|
+
measurementSpan.textContent = str;
|
|
102
|
+
var rect = measurementSpan.getBoundingClientRect();
|
|
103
|
+
var 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
|
+
};
|
package/models/axis.d.ts
CHANGED
|
@@ -2,19 +2,20 @@
|
|
|
2
2
|
import type { ScaleBand, ScaleLogarithmic, ScalePower, ScaleTime, ScaleLinear, ScalePoint } from 'd3-scale';
|
|
3
3
|
import { ChartsAxisClasses } from '../ChartsAxis/axisClasses';
|
|
4
4
|
import type { TickParams } from '../hooks/useTicks';
|
|
5
|
+
import { ChartsTextProps } from '../internals/components/ChartsText';
|
|
5
6
|
export type D3Scale = ScaleBand<any> | ScaleLogarithmic<any, any> | ScalePoint<any> | ScalePower<any, any> | ScaleTime<any, any> | ScaleLinear<any, any>;
|
|
6
7
|
export type D3ContinuouseScale = ScaleLogarithmic<any, any> | ScalePower<any, any> | ScaleTime<any, any> | ScaleLinear<any, any>;
|
|
7
8
|
export interface ChartsAxisSlotsComponent {
|
|
8
9
|
axisLine?: React.JSXElementConstructor<React.SVGAttributes<SVGPathElement>>;
|
|
9
10
|
axisTick?: React.JSXElementConstructor<React.SVGAttributes<SVGPathElement>>;
|
|
10
|
-
axisTickLabel?: React.JSXElementConstructor<
|
|
11
|
-
axisLabel?: React.JSXElementConstructor<
|
|
11
|
+
axisTickLabel?: React.JSXElementConstructor<ChartsTextProps>;
|
|
12
|
+
axisLabel?: React.JSXElementConstructor<ChartsTextProps>;
|
|
12
13
|
}
|
|
13
14
|
export interface ChartsAxisSlotComponentProps {
|
|
14
15
|
axisLine?: Partial<React.SVGAttributes<SVGPathElement>>;
|
|
15
16
|
axisTick?: Partial<React.SVGAttributes<SVGPathElement>>;
|
|
16
|
-
axisTickLabel?: Partial<
|
|
17
|
-
axisLabel?: Partial<
|
|
17
|
+
axisTickLabel?: Partial<ChartsTextProps>;
|
|
18
|
+
axisLabel?: Partial<ChartsTextProps>;
|
|
18
19
|
}
|
|
19
20
|
export interface ChartsAxisProps extends TickParams {
|
|
20
21
|
/**
|
|
@@ -151,7 +152,7 @@ export type AxisConfig<S extends ScaleName = ScaleName, V = any> = {
|
|
|
151
152
|
hideTooltip?: boolean;
|
|
152
153
|
} & Partial<ChartsXAxisProps | ChartsYAxisProps> & Partial<Omit<AxisScaleConfig[S], 'scale'>> & TickParams;
|
|
153
154
|
export type AxisDefaultized<S extends ScaleName = ScaleName, V = any> = Omit<AxisConfig<S, V>, 'scaleType'> & AxisScaleConfig[S] & {
|
|
154
|
-
|
|
155
|
+
tickNumber: number;
|
|
155
156
|
};
|
|
156
157
|
export declare function isBandScaleConfig(scaleConfig: AxisConfig<ScaleName>): scaleConfig is AxisConfig<'band'> & {
|
|
157
158
|
scaleType: 'band';
|
package/models/layout.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
export interface CardinalDirections<T> {
|
|
2
|
+
top?: T;
|
|
3
|
+
bottom?: T;
|
|
4
|
+
left?: T;
|
|
5
|
+
right?: T;
|
|
6
|
+
}
|
|
1
7
|
export type LayoutConfig = {
|
|
2
8
|
width: number;
|
|
3
9
|
height: number;
|
|
4
|
-
margin?:
|
|
5
|
-
top?: number;
|
|
6
|
-
bottom?: number;
|
|
7
|
-
left?: number;
|
|
8
|
-
right?: number;
|
|
9
|
-
};
|
|
10
|
+
margin?: Partial<CardinalDirections<number>>;
|
|
10
11
|
};
|
|
@@ -159,23 +159,19 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
159
159
|
tickNumber: PropTypes.number,
|
|
160
160
|
tickSize: PropTypes.number
|
|
161
161
|
}), PropTypes.string]),
|
|
162
|
+
/**
|
|
163
|
+
* @deprecated Consider using `slotProps.legend` instead.
|
|
164
|
+
*/
|
|
162
165
|
legend: PropTypes.shape({
|
|
163
166
|
classes: PropTypes.object,
|
|
164
167
|
direction: PropTypes.oneOf(['column', 'row']),
|
|
165
168
|
hidden: PropTypes.bool,
|
|
166
|
-
itemWidth: PropTypes.number,
|
|
167
|
-
markSize: PropTypes.number,
|
|
168
|
-
offset: PropTypes.shape({
|
|
169
|
-
x: PropTypes.number,
|
|
170
|
-
y: PropTypes.number
|
|
171
|
-
}),
|
|
172
169
|
position: PropTypes.shape({
|
|
173
170
|
horizontal: PropTypes.oneOf(['left', 'middle', 'right']).isRequired,
|
|
174
171
|
vertical: PropTypes.oneOf(['bottom', 'middle', 'top']).isRequired
|
|
175
172
|
}),
|
|
176
173
|
slotProps: PropTypes.object,
|
|
177
|
-
slots: PropTypes.object
|
|
178
|
-
spacing: PropTypes.number
|
|
174
|
+
slots: PropTypes.object
|
|
179
175
|
}),
|
|
180
176
|
margin: PropTypes.shape({
|
|
181
177
|
bottom: PropTypes.number,
|