@mui/x-charts 6.0.0-alpha.9 → 6.18.0
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 +19 -5
- package/BarChart/BarChart.js +52 -13
- package/BarChart/BarElement.d.ts +1319 -4
- package/BarChart/BarElement.js +10 -10
- package/BarChart/BarPlot.d.ts +17 -1
- package/BarChart/BarPlot.js +152 -66
- package/BarChart/formatter.js +2 -3
- package/BarChart/legend.js +1 -2
- package/CHANGELOG.md +735 -55
- package/ChartContainer/index.js +7 -5
- package/ChartsAxis/ChartsAxis.d.ts +9 -0
- package/ChartsAxis/ChartsAxis.js +28 -2
- package/ChartsAxis/axisClasses.d.ts +1 -1
- package/ChartsAxis/axisClasses.js +1 -2
- package/ChartsAxisHighlight/ChartsAxisHighlight.d.ts +21 -0
- package/ChartsAxisHighlight/ChartsAxisHighlight.js +61 -22
- package/ChartsClipPath/ChartsClipPath.d.ts +5 -0
- package/ChartsClipPath/ChartsClipPath.js +7 -2
- package/ChartsLegend/ChartsLegend.d.ts +44 -24
- package/ChartsLegend/ChartsLegend.js +192 -150
- package/ChartsLegend/chartsLegendClasses.js +1 -2
- package/ChartsLegend/utils.d.ts +1 -6
- package/ChartsSurface.d.ts +1 -1
- package/ChartsSurface.js +9 -18
- package/ChartsTooltip/ChartsAxisTooltipContent.d.ts +1 -0
- package/ChartsTooltip/ChartsAxisTooltipContent.js +46 -32
- package/ChartsTooltip/ChartsItemTooltipContent.d.ts +3 -2
- package/ChartsTooltip/ChartsItemTooltipContent.js +18 -9
- package/ChartsTooltip/ChartsTooltip.d.ts +32 -0
- package/ChartsTooltip/ChartsTooltip.js +62 -18
- package/ChartsTooltip/ChartsTooltipTable.d.ts +3 -10
- package/ChartsTooltip/ChartsTooltipTable.js +22 -20
- package/ChartsTooltip/tooltipClasses.js +1 -2
- package/ChartsTooltip/utils.js +2 -2
- package/ChartsXAxis/ChartsXAxis.d.ts +9 -0
- package/ChartsXAxis/ChartsXAxis.js +161 -40
- package/ChartsYAxis/ChartsYAxis.d.ts +9 -0
- package/ChartsYAxis/ChartsYAxis.js +86 -33
- package/LineChart/AreaElement.d.ts +11 -1
- package/LineChart/AreaElement.js +14 -6
- package/LineChart/AreaPlot.d.ts +11 -0
- package/LineChart/AreaPlot.js +27 -8
- package/LineChart/LineChart.d.ts +16 -3
- package/LineChart/LineChart.js +48 -13
- package/LineChart/LineElement.d.ts +11 -1
- package/LineChart/LineElement.js +14 -6
- package/LineChart/LineHighlightElement.d.ts +10 -0
- package/LineChart/LineHighlightElement.js +13 -4
- package/LineChart/LineHighlightPlot.d.ts +10 -0
- package/LineChart/LineHighlightPlot.js +14 -3
- package/LineChart/LinePlot.d.ts +10 -0
- package/LineChart/LinePlot.js +25 -12
- package/LineChart/MarkElement.d.ts +10 -0
- package/LineChart/MarkElement.js +14 -5
- package/LineChart/MarkPlot.d.ts +10 -0
- package/LineChart/MarkPlot.js +40 -9
- package/LineChart/formatter.js +5 -5
- package/LineChart/legend.js +1 -2
- package/PieChart/PieArc.d.ts +11 -13
- package/PieChart/PieArc.js +28 -60
- package/PieChart/PieArcLabel.d.ts +8 -9
- package/PieChart/PieArcLabel.js +46 -38
- package/PieChart/PieArcLabelPlot.d.ts +28 -0
- package/PieChart/PieArcLabelPlot.js +99 -0
- package/PieChart/PieArcPlot.d.ts +35 -0
- package/PieChart/PieArcPlot.js +92 -0
- package/PieChart/PieChart.d.ts +19 -5
- package/PieChart/PieChart.js +61 -14
- package/PieChart/PiePlot.d.ts +15 -9
- package/PieChart/PiePlot.js +77 -55
- package/PieChart/dataTransform/transition.d.ts +4 -0
- package/PieChart/dataTransform/transition.js +136 -0
- package/PieChart/dataTransform/useTransformData.d.ts +15 -0
- package/PieChart/dataTransform/useTransformData.js +67 -0
- package/PieChart/formatter.js +1 -2
- package/PieChart/legend.js +1 -2
- package/README.md +8 -14
- package/ResponsiveChartContainer/index.js +7 -8
- package/ScatterChart/Scatter.d.ts +10 -0
- package/ScatterChart/Scatter.js +12 -2
- package/ScatterChart/ScatterChart.d.ts +16 -3
- package/ScatterChart/ScatterChart.js +43 -12
- package/ScatterChart/ScatterPlot.d.ts +10 -0
- package/ScatterChart/ScatterPlot.js +12 -2
- package/ScatterChart/formatter.js +1 -2
- package/ScatterChart/legend.js +1 -2
- package/SparkLineChart/SparkLineChart.d.ts +12 -3
- package/SparkLineChart/SparkLineChart.js +28 -7
- package/colorPalettes/colorPalettes.js +6 -12
- package/constants.js +5 -8
- package/context/CartesianContextProvider.d.ts +5 -0
- package/context/CartesianContextProvider.js +31 -16
- package/context/DrawingProvider.d.ts +7 -0
- package/context/DrawingProvider.js +12 -6
- package/context/HighlightProvider.js +3 -4
- package/context/InteractionProvider.js +3 -4
- package/context/SeriesContextProvider.js +3 -4
- package/esm/BarChart/BarChart.js +49 -9
- package/esm/BarChart/BarElement.js +7 -4
- package/esm/BarChart/BarPlot.js +152 -67
- package/esm/BarChart/formatter.js +1 -1
- package/esm/ChartContainer/index.js +3 -0
- package/esm/ChartsAxis/ChartsAxis.js +26 -0
- package/esm/ChartsAxisHighlight/ChartsAxisHighlight.js +57 -20
- package/esm/ChartsClipPath/ChartsClipPath.js +5 -0
- package/esm/ChartsLegend/ChartsLegend.js +188 -142
- package/esm/ChartsSurface.js +4 -12
- package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +44 -30
- package/esm/ChartsTooltip/ChartsItemTooltipContent.js +15 -7
- package/esm/ChartsTooltip/ChartsTooltip.js +59 -14
- package/esm/ChartsTooltip/ChartsTooltipTable.js +17 -10
- package/esm/ChartsXAxis/ChartsXAxis.js +158 -37
- package/esm/ChartsYAxis/ChartsYAxis.js +83 -30
- package/esm/LineChart/AreaElement.js +10 -0
- package/esm/LineChart/AreaPlot.js +26 -6
- package/esm/LineChart/LineChart.js +45 -9
- package/esm/LineChart/LineElement.js +10 -0
- package/esm/LineChart/LineHighlightElement.js +10 -0
- package/esm/LineChart/LineHighlightPlot.js +12 -1
- package/esm/LineChart/LinePlot.js +25 -14
- package/esm/LineChart/MarkElement.js +11 -1
- package/esm/LineChart/MarkPlot.js +38 -7
- package/esm/LineChart/formatter.js +7 -3
- package/esm/PieChart/PieArc.js +26 -58
- package/esm/PieChart/PieArcLabel.js +43 -34
- package/esm/PieChart/PieArcLabelPlot.js +92 -0
- package/esm/PieChart/PieArcPlot.js +84 -0
- package/esm/PieChart/PieChart.js +59 -12
- package/esm/PieChart/PiePlot.js +76 -57
- package/esm/PieChart/dataTransform/transition.js +130 -0
- package/esm/PieChart/dataTransform/useTransformData.js +59 -0
- package/esm/ResponsiveChartContainer/index.js +3 -3
- package/esm/ScatterChart/Scatter.js +10 -0
- package/esm/ScatterChart/ScatterChart.js +40 -8
- package/esm/ScatterChart/ScatterPlot.js +10 -0
- package/esm/SparkLineChart/SparkLineChart.js +25 -3
- package/esm/constants.js +1 -1
- package/esm/context/CartesianContextProvider.js +30 -14
- package/esm/context/DrawingProvider.js +8 -0
- package/esm/hooks/useChartDimensions.js +2 -0
- package/esm/hooks/useMounted.js +16 -0
- package/esm/hooks/useReducedMotion.js +27 -0
- package/esm/hooks/useTicks.js +15 -9
- package/esm/internals/components/AxisSharedComponents.js +15 -70
- package/esm/internals/components/ChartsText.js +77 -0
- package/esm/internals/domUtils.js +113 -0
- package/esm/internals/geometry.js +36 -0
- package/hooks/useAxisEvents.js +2 -2
- package/hooks/useChartDimensions.d.ts +2 -0
- package/hooks/useChartDimensions.js +5 -4
- package/hooks/useDrawingArea.js +2 -2
- package/hooks/useInteractionItemProps.js +2 -2
- package/hooks/useMounted.d.ts +1 -0
- package/hooks/useMounted.js +25 -0
- package/hooks/useReducedMotion.d.ts +8 -0
- package/hooks/useReducedMotion.js +33 -0
- package/hooks/useScale.d.ts +2 -2
- package/hooks/useScale.js +2 -2
- package/hooks/useTicks.d.ts +19 -11
- package/hooks/useTicks.js +19 -14
- 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 +35 -0
- package/internals/components/ChartsText.js +87 -0
- package/internals/defaultizeColor.d.ts +7 -2
- package/internals/defaultizeValueFormatter.js +1 -2
- package/internals/domUtils.d.ts +13 -0
- package/internals/domUtils.js +122 -0
- package/internals/geometry.d.ts +9 -0
- package/internals/geometry.js +42 -0
- package/internals/stackSeries.js +2 -4
- package/legacy/BarChart/BarChart.js +49 -9
- package/legacy/BarChart/BarElement.js +6 -3
- package/legacy/BarChart/BarPlot.js +151 -63
- package/legacy/BarChart/formatter.js +1 -1
- package/legacy/ChartContainer/index.js +3 -0
- package/legacy/ChartsAxis/ChartsAxis.js +26 -0
- package/legacy/ChartsAxisHighlight/ChartsAxisHighlight.js +60 -20
- package/legacy/ChartsClipPath/ChartsClipPath.js +5 -0
- package/legacy/ChartsLegend/ChartsLegend.js +203 -140
- package/legacy/ChartsSurface.js +3 -12
- package/legacy/ChartsTooltip/ChartsAxisTooltipContent.js +22 -10
- package/legacy/ChartsTooltip/ChartsItemTooltipContent.js +15 -7
- package/legacy/ChartsTooltip/ChartsTooltip.js +62 -14
- package/legacy/ChartsTooltip/ChartsTooltipTable.js +34 -26
- package/legacy/ChartsXAxis/ChartsXAxis.js +162 -39
- package/legacy/ChartsYAxis/ChartsYAxis.js +83 -30
- package/legacy/LineChart/AreaElement.js +10 -0
- package/legacy/LineChart/AreaPlot.js +31 -7
- package/legacy/LineChart/LineChart.js +45 -9
- package/legacy/LineChart/LineElement.js +10 -0
- package/legacy/LineChart/LineHighlightElement.js +10 -0
- package/legacy/LineChart/LineHighlightPlot.js +12 -1
- package/legacy/LineChart/LinePlot.js +29 -12
- package/legacy/LineChart/MarkElement.js +11 -1
- package/legacy/LineChart/MarkPlot.js +37 -7
- package/legacy/LineChart/formatter.js +7 -3
- package/legacy/PieChart/PieArc.js +30 -62
- package/legacy/PieChart/PieArcLabel.js +48 -34
- package/legacy/PieChart/PieArcLabelPlot.js +93 -0
- package/legacy/PieChart/PieArcPlot.js +84 -0
- package/legacy/PieChart/PieChart.js +59 -12
- package/legacy/PieChart/PiePlot.js +76 -59
- package/legacy/PieChart/dataTransform/transition.js +142 -0
- package/legacy/PieChart/dataTransform/useTransformData.js +60 -0
- package/legacy/ResponsiveChartContainer/index.js +3 -3
- package/legacy/ScatterChart/Scatter.js +10 -0
- package/legacy/ScatterChart/ScatterChart.js +40 -8
- package/legacy/ScatterChart/ScatterPlot.js +10 -0
- package/legacy/SparkLineChart/SparkLineChart.js +25 -3
- package/legacy/constants.js +1 -1
- package/legacy/context/CartesianContextProvider.js +30 -14
- package/legacy/context/DrawingProvider.js +8 -0
- package/legacy/hooks/useChartDimensions.js +2 -0
- package/legacy/hooks/useMounted.js +21 -0
- package/legacy/hooks/useReducedMotion.js +27 -0
- package/legacy/hooks/useTicks.js +16 -9
- package/legacy/index.js +1 -1
- package/legacy/internals/components/AxisSharedComponents.js +11 -65
- package/legacy/internals/components/ChartsText.js +79 -0
- package/legacy/internals/domUtils.js +121 -0
- package/legacy/internals/geometry.js +37 -0
- package/models/axis.d.ts +27 -9
- package/models/layout.d.ts +7 -6
- package/models/seriesType/line.d.ts +8 -3
- package/models/seriesType/pie.d.ts +5 -1
- package/modern/BarChart/BarChart.js +49 -9
- package/modern/BarChart/BarElement.js +7 -4
- package/modern/BarChart/BarPlot.js +149 -65
- package/modern/BarChart/formatter.js +1 -1
- package/modern/ChartContainer/index.js +3 -0
- package/modern/ChartsAxis/ChartsAxis.js +26 -0
- package/modern/ChartsAxisHighlight/ChartsAxisHighlight.js +57 -20
- package/modern/ChartsClipPath/ChartsClipPath.js +5 -0
- package/modern/ChartsLegend/ChartsLegend.js +188 -142
- package/modern/ChartsSurface.js +4 -12
- package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +44 -30
- package/modern/ChartsTooltip/ChartsItemTooltipContent.js +15 -7
- package/modern/ChartsTooltip/ChartsTooltip.js +58 -14
- package/modern/ChartsTooltip/ChartsTooltipTable.js +17 -10
- package/modern/ChartsXAxis/ChartsXAxis.js +158 -37
- package/modern/ChartsYAxis/ChartsYAxis.js +83 -30
- package/modern/LineChart/AreaElement.js +10 -0
- package/modern/LineChart/AreaPlot.js +25 -6
- package/modern/LineChart/LineChart.js +45 -9
- package/modern/LineChart/LineElement.js +10 -0
- package/modern/LineChart/LineHighlightElement.js +10 -0
- package/modern/LineChart/LineHighlightPlot.js +12 -1
- package/modern/LineChart/LinePlot.js +23 -10
- package/modern/LineChart/MarkElement.js +11 -1
- package/modern/LineChart/MarkPlot.js +38 -7
- package/modern/LineChart/formatter.js +4 -3
- package/modern/PieChart/PieArc.js +26 -57
- package/modern/PieChart/PieArcLabel.js +43 -34
- package/modern/PieChart/PieArcLabelPlot.js +90 -0
- package/modern/PieChart/PieArcPlot.js +83 -0
- package/modern/PieChart/PieChart.js +59 -12
- package/modern/PieChart/PiePlot.js +76 -55
- package/modern/PieChart/dataTransform/transition.js +130 -0
- package/modern/PieChart/dataTransform/useTransformData.js +58 -0
- package/modern/ResponsiveChartContainer/index.js +3 -3
- package/modern/ScatterChart/Scatter.js +10 -0
- package/modern/ScatterChart/ScatterChart.js +40 -8
- package/modern/ScatterChart/ScatterPlot.js +10 -0
- package/modern/SparkLineChart/SparkLineChart.js +25 -3
- package/modern/constants.js +1 -1
- package/modern/context/CartesianContextProvider.js +29 -13
- package/modern/context/DrawingProvider.js +8 -0
- package/modern/hooks/useChartDimensions.js +2 -0
- package/modern/hooks/useMounted.js +16 -0
- package/modern/hooks/useReducedMotion.js +27 -0
- package/modern/hooks/useTicks.js +15 -9
- package/modern/index.js +1 -1
- package/modern/internals/components/AxisSharedComponents.js +15 -70
- package/modern/internals/components/ChartsText.js +77 -0
- package/modern/internals/domUtils.js +113 -0
- package/modern/internals/geometry.js +36 -0
- package/package.json +9 -6
- package/themeAugmentation/components.d.ts +1 -0
- package/themeAugmentation/overrides.d.ts +2 -0
|
@@ -12,9 +12,10 @@ 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
|
-
var DEFAULT_CATEGORY_GAP_RATIO = 0.
|
|
17
|
+
var DEFAULT_CATEGORY_GAP_RATIO = 0.2;
|
|
18
|
+
var DEFAULT_BAR_GAP_RATIO = 0.1;
|
|
18
19
|
|
|
19
20
|
// TODO: those might be better placed in a distinct file
|
|
20
21
|
var xExtremumGetters = {
|
|
@@ -33,6 +34,12 @@ export var CartesianContext = /*#__PURE__*/React.createContext({
|
|
|
33
34
|
xAxisIds: [],
|
|
34
35
|
yAxisIds: []
|
|
35
36
|
});
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* API:
|
|
40
|
+
*
|
|
41
|
+
* - [CartesianContextProvider API](https://mui.com/x/api/charts/cartesian-context-provider/)
|
|
42
|
+
*/
|
|
36
43
|
function CartesianContextProvider(_ref) {
|
|
37
44
|
var inXAxis = _ref.xAxis,
|
|
38
45
|
inYAxis = _ref.yAxis,
|
|
@@ -124,20 +131,21 @@ function CartesianContextProvider(_ref) {
|
|
|
124
131
|
maxData = _getAxisExtremum2[1];
|
|
125
132
|
var range = [drawingArea.left, drawingArea.left + drawingArea.width];
|
|
126
133
|
if (isBandScaleConfig(axis)) {
|
|
127
|
-
var _axis$categoryGapRati;
|
|
134
|
+
var _axis$categoryGapRati, _axis$barGapRatio;
|
|
128
135
|
var categoryGapRatio = (_axis$categoryGapRati = axis.categoryGapRatio) != null ? _axis$categoryGapRati : DEFAULT_CATEGORY_GAP_RATIO;
|
|
136
|
+
var barGapRatio = (_axis$barGapRatio = axis.barGapRatio) != null ? _axis$barGapRatio : DEFAULT_BAR_GAP_RATIO;
|
|
129
137
|
completedXAxis[axis.id] = _extends({
|
|
130
138
|
categoryGapRatio: categoryGapRatio,
|
|
131
|
-
barGapRatio:
|
|
139
|
+
barGapRatio: barGapRatio
|
|
132
140
|
}, axis, {
|
|
133
141
|
scale: scaleBand(axis.data, range).paddingInner(categoryGapRatio).paddingOuter(categoryGapRatio / 2),
|
|
134
|
-
|
|
142
|
+
tickNumber: axis.data.length
|
|
135
143
|
});
|
|
136
144
|
}
|
|
137
145
|
if (isPointScaleConfig(axis)) {
|
|
138
146
|
completedXAxis[axis.id] = _extends({}, axis, {
|
|
139
147
|
scale: scalePoint(axis.data, range),
|
|
140
|
-
|
|
148
|
+
tickNumber: axis.data.length
|
|
141
149
|
});
|
|
142
150
|
}
|
|
143
151
|
if (axis.scaleType === 'band' || axis.scaleType === 'point') {
|
|
@@ -146,17 +154,17 @@ function CartesianContextProvider(_ref) {
|
|
|
146
154
|
}
|
|
147
155
|
var scaleType = (_axis$scaleType = axis.scaleType) != null ? _axis$scaleType : 'linear';
|
|
148
156
|
var extremums = [(_axis$min = axis.min) != null ? _axis$min : minData, (_axis$max = axis.max) != null ? _axis$max : maxData];
|
|
149
|
-
var
|
|
157
|
+
var tickNumber = getTickNumber(_extends({}, axis, {
|
|
150
158
|
range: range,
|
|
151
159
|
domain: extremums
|
|
152
160
|
}));
|
|
153
|
-
var niceScale = getScale(scaleType, extremums, range).nice(
|
|
161
|
+
var niceScale = getScale(scaleType, extremums, range).nice(tickNumber);
|
|
154
162
|
var niceDomain = niceScale.domain();
|
|
155
163
|
var domain = [(_axis$min2 = axis.min) != null ? _axis$min2 : niceDomain[0], (_axis$max2 = axis.max) != null ? _axis$max2 : niceDomain[1]];
|
|
156
164
|
completedXAxis[axis.id] = _extends({}, axis, {
|
|
157
165
|
scaleType: scaleType,
|
|
158
166
|
scale: niceScale.domain(domain),
|
|
159
|
-
|
|
167
|
+
tickNumber: tickNumber
|
|
160
168
|
});
|
|
161
169
|
});
|
|
162
170
|
var allYAxis = [].concat(_toConsumableArray((_yAxis$map = yAxis == null ? void 0 : yAxis.map(function (axis, index) {
|
|
@@ -187,13 +195,13 @@ function CartesianContextProvider(_ref) {
|
|
|
187
195
|
barGapRatio: 0
|
|
188
196
|
}, axis, {
|
|
189
197
|
scale: scaleBand(axis.data, [range[1], range[0]]).paddingInner(categoryGapRatio).paddingOuter(categoryGapRatio / 2),
|
|
190
|
-
|
|
198
|
+
tickNumber: axis.data.length
|
|
191
199
|
});
|
|
192
200
|
}
|
|
193
201
|
if (isPointScaleConfig(axis)) {
|
|
194
202
|
completedYAxis[axis.id] = _extends({}, axis, {
|
|
195
203
|
scale: scalePoint(axis.data, [range[1], range[0]]),
|
|
196
|
-
|
|
204
|
+
tickNumber: axis.data.length
|
|
197
205
|
});
|
|
198
206
|
}
|
|
199
207
|
if (axis.scaleType === 'band' || axis.scaleType === 'point') {
|
|
@@ -202,17 +210,17 @@ function CartesianContextProvider(_ref) {
|
|
|
202
210
|
}
|
|
203
211
|
var scaleType = (_axis$scaleType2 = axis.scaleType) != null ? _axis$scaleType2 : 'linear';
|
|
204
212
|
var extremums = [(_axis$min3 = axis.min) != null ? _axis$min3 : minData, (_axis$max3 = axis.max) != null ? _axis$max3 : maxData];
|
|
205
|
-
var
|
|
213
|
+
var tickNumber = getTickNumber(_extends({}, axis, {
|
|
206
214
|
range: range,
|
|
207
215
|
domain: extremums
|
|
208
216
|
}));
|
|
209
|
-
var niceScale = getScale(scaleType, extremums, range).nice(
|
|
217
|
+
var niceScale = getScale(scaleType, extremums, range).nice(tickNumber);
|
|
210
218
|
var niceDomain = niceScale.domain();
|
|
211
219
|
var domain = [(_axis$min4 = axis.min) != null ? _axis$min4 : niceDomain[0], (_axis$max4 = axis.max) != null ? _axis$max4 : niceDomain[1]];
|
|
212
220
|
completedYAxis[axis.id] = _extends({}, axis, {
|
|
213
221
|
scaleType: scaleType,
|
|
214
222
|
scale: niceScale.domain(domain),
|
|
215
|
-
|
|
223
|
+
tickNumber: tickNumber
|
|
216
224
|
});
|
|
217
225
|
});
|
|
218
226
|
return {
|
|
@@ -254,6 +262,7 @@ process.env.NODE_ENV !== "production" ? CartesianContextProvider.propTypes = {
|
|
|
254
262
|
id: PropTypes.string,
|
|
255
263
|
label: PropTypes.string,
|
|
256
264
|
labelFontSize: PropTypes.number,
|
|
265
|
+
labelStyle: PropTypes.object,
|
|
257
266
|
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
258
267
|
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
259
268
|
position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
|
|
@@ -262,6 +271,9 @@ process.env.NODE_ENV !== "production" ? CartesianContextProvider.propTypes = {
|
|
|
262
271
|
slots: PropTypes.object,
|
|
263
272
|
stroke: PropTypes.string,
|
|
264
273
|
tickFontSize: PropTypes.number,
|
|
274
|
+
tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
|
|
275
|
+
tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
|
|
276
|
+
tickLabelStyle: PropTypes.object,
|
|
265
277
|
tickMaxStep: PropTypes.number,
|
|
266
278
|
tickMinStep: PropTypes.number,
|
|
267
279
|
tickNumber: PropTypes.number,
|
|
@@ -280,6 +292,7 @@ process.env.NODE_ENV !== "production" ? CartesianContextProvider.propTypes = {
|
|
|
280
292
|
id: PropTypes.string,
|
|
281
293
|
label: PropTypes.string,
|
|
282
294
|
labelFontSize: PropTypes.number,
|
|
295
|
+
labelStyle: PropTypes.object,
|
|
283
296
|
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
284
297
|
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
285
298
|
position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
|
|
@@ -288,6 +301,9 @@ process.env.NODE_ENV !== "production" ? CartesianContextProvider.propTypes = {
|
|
|
288
301
|
slots: PropTypes.object,
|
|
289
302
|
stroke: PropTypes.string,
|
|
290
303
|
tickFontSize: PropTypes.number,
|
|
304
|
+
tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
|
|
305
|
+
tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
|
|
306
|
+
tickLabelStyle: PropTypes.object,
|
|
291
307
|
tickMaxStep: PropTypes.number,
|
|
292
308
|
tickMinStep: PropTypes.number,
|
|
293
309
|
tickNumber: PropTypes.number,
|
|
@@ -9,12 +9,20 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
9
9
|
export var DrawingContext = /*#__PURE__*/React.createContext({
|
|
10
10
|
top: 0,
|
|
11
11
|
left: 0,
|
|
12
|
+
bottom: 0,
|
|
13
|
+
right: 0,
|
|
12
14
|
height: 300,
|
|
13
15
|
width: 400
|
|
14
16
|
});
|
|
15
17
|
export var SVGContext = /*#__PURE__*/React.createContext({
|
|
16
18
|
current: null
|
|
17
19
|
});
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* API:
|
|
23
|
+
*
|
|
24
|
+
* - [DrawingProvider API](https://mui.com/x/api/charts/drawing-provider/)
|
|
25
|
+
*/
|
|
18
26
|
function DrawingProvider(_ref) {
|
|
19
27
|
var width = _ref.width,
|
|
20
28
|
height = _ref.height,
|
|
@@ -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
|
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
|
|
4
|
+
export function useMounted() {
|
|
5
|
+
var defer = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
6
|
+
var _React$useState = React.useState(false),
|
|
7
|
+
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
8
|
+
mountedState = _React$useState2[0],
|
|
9
|
+
setMountedState = _React$useState2[1];
|
|
10
|
+
useEnhancedEffect(function () {
|
|
11
|
+
if (!defer) {
|
|
12
|
+
setMountedState(true);
|
|
13
|
+
}
|
|
14
|
+
}, [defer]);
|
|
15
|
+
React.useEffect(function () {
|
|
16
|
+
if (defer) {
|
|
17
|
+
setMountedState(true);
|
|
18
|
+
}
|
|
19
|
+
}, [defer]);
|
|
20
|
+
return mountedState;
|
|
21
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { useIsomorphicLayoutEffect, Globals } from '@react-spring/web';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns `boolean` or `null`, used to automatically
|
|
5
|
+
* set skipAnimations to the value of the user's
|
|
6
|
+
* `prefers-reduced-motion` query.
|
|
7
|
+
*
|
|
8
|
+
* The return value, post-effect, is the value of their prefered setting
|
|
9
|
+
*/
|
|
10
|
+
export var useReducedMotion = function useReducedMotion() {
|
|
11
|
+
// Taken from: https://github.com/pmndrs/react-spring/blob/02ec877bbfab0df46da0e4a47d5f68d3e731206a/packages/shared/src/hooks/useReducedMotion.ts#L13
|
|
12
|
+
|
|
13
|
+
useIsomorphicLayoutEffect(function () {
|
|
14
|
+
var mql = window.matchMedia('(prefers-reduced-motion)');
|
|
15
|
+
var handleMediaChange = function handleMediaChange(e) {
|
|
16
|
+
Globals.assign({
|
|
17
|
+
// Modification such the react-spring implementation such that this hook can remove animation but never activate animation.
|
|
18
|
+
skipAnimation: e.matches || undefined
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
handleMediaChange(mql);
|
|
22
|
+
mql.addEventListener('change', handleMediaChange);
|
|
23
|
+
return function () {
|
|
24
|
+
mql.removeEventListener('change', handleMediaChange);
|
|
25
|
+
};
|
|
26
|
+
}, []);
|
|
27
|
+
};
|
package/legacy/hooks/useTicks.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
|
1
2
|
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
3
|
import * as React from 'react';
|
|
3
4
|
import { isBandScale } from '../internals/isBandScale';
|
|
4
|
-
export function
|
|
5
|
+
export function getTickNumber(params) {
|
|
5
6
|
var tickMaxStep = params.tickMaxStep,
|
|
6
7
|
tickMinStep = params.tickMinStep,
|
|
7
8
|
tickNumber = params.tickNumber,
|
|
@@ -14,8 +15,9 @@ export function getTicksNumber(params) {
|
|
|
14
15
|
}
|
|
15
16
|
function useTicks(options) {
|
|
16
17
|
var scale = options.scale,
|
|
17
|
-
|
|
18
|
-
valueFormatter = options.valueFormatter
|
|
18
|
+
tickNumber = options.tickNumber,
|
|
19
|
+
valueFormatter = options.valueFormatter,
|
|
20
|
+
tickInterval = options.tickInterval;
|
|
19
21
|
return React.useMemo(function () {
|
|
20
22
|
// band scale
|
|
21
23
|
if (isBandScale(scale)) {
|
|
@@ -25,7 +27,8 @@ function useTicks(options) {
|
|
|
25
27
|
return [].concat(_toConsumableArray(domain.map(function (value) {
|
|
26
28
|
var _valueFormatter;
|
|
27
29
|
return {
|
|
28
|
-
|
|
30
|
+
value: value,
|
|
31
|
+
formattedValue: (_valueFormatter = valueFormatter == null ? void 0 : valueFormatter(value)) != null ? _valueFormatter : "".concat(value),
|
|
29
32
|
offset: scale(value) - (scale.step() - scale.bandwidth()) / 2,
|
|
30
33
|
labelOffset: scale.step() / 2
|
|
31
34
|
};
|
|
@@ -37,23 +40,27 @@ function useTicks(options) {
|
|
|
37
40
|
}
|
|
38
41
|
|
|
39
42
|
// scale type = 'point'
|
|
40
|
-
|
|
43
|
+
var filteredDomain = typeof tickInterval === 'function' && domain.filter(tickInterval) || _typeof(tickInterval) === 'object' && tickInterval || domain;
|
|
44
|
+
return filteredDomain.map(function (value) {
|
|
41
45
|
var _valueFormatter2;
|
|
42
46
|
return {
|
|
43
|
-
|
|
47
|
+
value: value,
|
|
48
|
+
formattedValue: (_valueFormatter2 = valueFormatter == null ? void 0 : valueFormatter(value)) != null ? _valueFormatter2 : "".concat(value),
|
|
44
49
|
offset: scale(value),
|
|
45
50
|
labelOffset: 0
|
|
46
51
|
};
|
|
47
52
|
});
|
|
48
53
|
}
|
|
49
|
-
|
|
54
|
+
var ticks = _typeof(tickInterval) === 'object' ? tickInterval : scale.ticks(tickNumber);
|
|
55
|
+
return ticks.map(function (value) {
|
|
50
56
|
var _valueFormatter3;
|
|
51
57
|
return {
|
|
52
|
-
|
|
58
|
+
value: value,
|
|
59
|
+
formattedValue: (_valueFormatter3 = valueFormatter == null ? void 0 : valueFormatter(value)) != null ? _valueFormatter3 : scale.tickFormat(tickNumber)(value),
|
|
53
60
|
offset: scale(value),
|
|
54
61
|
labelOffset: 0
|
|
55
62
|
};
|
|
56
63
|
});
|
|
57
|
-
}, [
|
|
64
|
+
}, [tickNumber, scale, valueFormatter, tickInterval]);
|
|
58
65
|
}
|
|
59
66
|
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 {
|
|
39
|
-
|
|
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), {
|
|
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 {
|
|
53
|
-
stroke: theme.palette.text.primary,
|
|
22
|
+
}), _defineProperty(_ref2, "& .".concat(axisClasses.tick), {
|
|
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.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.palette.text.primary
|
|
79
|
-
});
|
|
25
|
+
}), _ref2;
|
|
80
26
|
});
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
2
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
|
+
var _excluded = ["x", "y", "style", "text", "ownerState"],
|
|
4
|
+
_excluded2 = ["angle", "textAnchor", "dominantBaseline"];
|
|
5
|
+
import * as React from 'react';
|
|
6
|
+
import { getStringSize } from '../domUtils';
|
|
7
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
+
export function getWordsByLines(_ref) {
|
|
9
|
+
var style = _ref.style,
|
|
10
|
+
needsComputation = _ref.needsComputation,
|
|
11
|
+
text = _ref.text;
|
|
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) {
|
|
22
|
+
var x = props.x,
|
|
23
|
+
y = props.y,
|
|
24
|
+
styleProps = props.style,
|
|
25
|
+
text = props.text,
|
|
26
|
+
ownerState = props.ownerState,
|
|
27
|
+
textProps = _objectWithoutProperties(props, _excluded);
|
|
28
|
+
var _ref2 = styleProps != null ? styleProps : {},
|
|
29
|
+
angle = _ref2.angle,
|
|
30
|
+
textAnchor = _ref2.textAnchor,
|
|
31
|
+
dominantBaseline = _ref2.dominantBaseline,
|
|
32
|
+
style = _objectWithoutProperties(_ref2, _excluded2);
|
|
33
|
+
var wordsByLines = React.useMemo(function () {
|
|
34
|
+
return getWordsByLines({
|
|
35
|
+
style: style,
|
|
36
|
+
needsComputation: text.includes('\n'),
|
|
37
|
+
text: text
|
|
38
|
+
});
|
|
39
|
+
}, [style, text]);
|
|
40
|
+
var startDy;
|
|
41
|
+
switch (dominantBaseline) {
|
|
42
|
+
case 'hanging':
|
|
43
|
+
startDy = 0;
|
|
44
|
+
break;
|
|
45
|
+
case 'central':
|
|
46
|
+
startDy = (wordsByLines.length - 1) / 2 * -wordsByLines[0].height;
|
|
47
|
+
break;
|
|
48
|
+
default:
|
|
49
|
+
startDy = (wordsByLines.length - 1) * -wordsByLines[0].height;
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
var transforms = [];
|
|
53
|
+
// if (scaleToFit) {
|
|
54
|
+
// const lineWidth = wordsByLines[0].width;
|
|
55
|
+
// transforms.push(`scale(${(isNumber(width as number) ? (width as number) / lineWidth : 1) / lineWidth})`);
|
|
56
|
+
// }
|
|
57
|
+
if (angle) {
|
|
58
|
+
transforms.push("rotate(".concat(angle, ", ").concat(x, ", ").concat(y, ")"));
|
|
59
|
+
}
|
|
60
|
+
if (transforms.length) {
|
|
61
|
+
textProps.transform = transforms.join(' ');
|
|
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
|
+
dominantBaseline: dominantBaseline // Propagated to fix Safari issue: https://github.com/mui/mui-x/issues/10808
|
|
74
|
+
,
|
|
75
|
+
children: line.text
|
|
76
|
+
}, index);
|
|
77
|
+
})
|
|
78
|
+
}));
|
|
79
|
+
}
|
|
@@ -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
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
var ANGLE_APPROX = 5; // Angle (in deg) for which we approximate the rectangle as perfectly horizontal/vertical
|
|
2
|
+
|
|
3
|
+
var warnedOnce = false;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Return the minimal translation along the x-axis to avoid overflow of a rectangle of a given width, height, and rotation.
|
|
7
|
+
* This assumes that all rectangles have the same height and angle between -90 and 90.
|
|
8
|
+
* Otherwise it would be problematic because you need the height/width of the next rectangle to do the correct computation.
|
|
9
|
+
* @param width the side along the x axis.
|
|
10
|
+
* @param height the side along the y axis.
|
|
11
|
+
* @param angle the rotation in degrees.
|
|
12
|
+
*/
|
|
13
|
+
export function getMinXTranslation(width, height) {
|
|
14
|
+
var angle = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
15
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
16
|
+
if (!warnedOnce && angle > 90 && angle < -90) {
|
|
17
|
+
warnedOnce = true;
|
|
18
|
+
console.warn(["MUI X: It seems you applied an angle larger than 90\xB0 or smaller than -90\xB0 to an axis text.", "This could cause some text overlapping.", "If you encounter a use case where it's needed, please open an issue."].join('\n'));
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
var standardAngle = Math.min(Math.abs(angle) % 180, Math.abs(Math.abs(angle) % 180 - 180) % 180); // Map from R to [0, 90]
|
|
22
|
+
|
|
23
|
+
if (standardAngle < ANGLE_APPROX) {
|
|
24
|
+
// It's nearly horizontal
|
|
25
|
+
return width;
|
|
26
|
+
}
|
|
27
|
+
if (standardAngle > 90 - ANGLE_APPROX) {
|
|
28
|
+
// It's nearly vertical
|
|
29
|
+
return height;
|
|
30
|
+
}
|
|
31
|
+
var radAngle = standardAngle * Math.PI / 180;
|
|
32
|
+
var angleSwich = Math.atan2(height, width);
|
|
33
|
+
if (radAngle < angleSwich) {
|
|
34
|
+
return width / Math.cos(radAngle);
|
|
35
|
+
}
|
|
36
|
+
return height / Math.sin(radAngle);
|
|
37
|
+
}
|