@mui/x-charts 6.0.0-alpha.15 → 6.0.0-alpha.16
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 +13 -2
- package/BarChart/BarChart.js +45 -3
- package/BarChart/BarElement.d.ts +1318 -3
- package/BarChart/BarElement.js +10 -8
- package/BarChart/BarPlot.d.ts +17 -1
- package/BarChart/BarPlot.js +152 -66
- package/CHANGELOG.md +65 -0
- package/ChartContainer/index.js +5 -2
- package/ChartsAxis/ChartsAxis.js +18 -2
- package/ChartsAxis/axisClasses.d.ts +1 -1
- package/ChartsAxisHighlight/ChartsAxisHighlight.js +2 -2
- package/ChartsClipPath/ChartsClipPath.js +2 -2
- package/ChartsLegend/ChartsLegend.d.ts +2 -1
- package/ChartsLegend/ChartsLegend.js +12 -8
- package/ChartsSurface.js +2 -2
- package/ChartsTooltip/ChartsAxisTooltipContent.js +2 -2
- package/ChartsTooltip/ChartsItemTooltipContent.js +2 -2
- package/ChartsTooltip/ChartsTooltip.js +2 -2
- package/ChartsTooltip/utils.js +2 -2
- package/ChartsXAxis/ChartsXAxis.js +123 -35
- package/ChartsYAxis/ChartsYAxis.js +38 -16
- package/LineChart/AreaElement.d.ts +10 -0
- package/LineChart/AreaElement.js +12 -2
- package/LineChart/AreaPlot.d.ts +11 -0
- package/LineChart/AreaPlot.js +13 -2
- package/LineChart/LineChart.d.ts +10 -0
- package/LineChart/LineChart.js +36 -2
- package/LineChart/LineElement.d.ts +10 -0
- package/LineChart/LineElement.js +12 -2
- package/LineChart/LineHighlightElement.d.ts +10 -0
- package/LineChart/LineHighlightElement.js +12 -2
- package/LineChart/LineHighlightPlot.d.ts +10 -0
- package/LineChart/LineHighlightPlot.js +12 -2
- package/LineChart/LinePlot.d.ts +10 -0
- package/LineChart/LinePlot.js +12 -2
- package/LineChart/MarkElement.d.ts +10 -0
- package/LineChart/MarkElement.js +12 -2
- package/LineChart/MarkPlot.d.ts +10 -0
- package/LineChart/MarkPlot.js +12 -2
- package/PieChart/PieArc.js +2 -2
- package/PieChart/PieArcLabel.js +2 -2
- package/PieChart/PieChart.d.ts +10 -0
- package/PieChart/PieChart.js +37 -2
- package/PieChart/PiePlot.d.ts +10 -0
- package/PieChart/PiePlot.js +12 -2
- package/ResponsiveChartContainer/index.js +4 -4
- package/ScatterChart/Scatter.d.ts +10 -0
- package/ScatterChart/Scatter.js +12 -2
- package/ScatterChart/ScatterChart.d.ts +10 -0
- package/ScatterChart/ScatterChart.js +36 -2
- package/ScatterChart/ScatterPlot.d.ts +10 -0
- package/ScatterChart/ScatterPlot.js +12 -2
- package/SparkLineChart/SparkLineChart.d.ts +9 -0
- package/SparkLineChart/SparkLineChart.js +16 -2
- package/context/CartesianContextProvider.js +10 -2
- package/context/DrawingProvider.js +2 -2
- package/context/HighlightProvider.js +2 -2
- package/context/InteractionProvider.js +2 -2
- package/context/SeriesContextProvider.js +2 -2
- package/esm/BarChart/BarChart.js +43 -1
- package/esm/BarChart/BarElement.js +7 -4
- package/esm/BarChart/BarPlot.js +152 -67
- package/esm/ChartContainer/index.js +3 -0
- package/esm/ChartsAxis/ChartsAxis.js +16 -0
- package/esm/ChartsLegend/ChartsLegend.js +10 -6
- package/esm/ChartsXAxis/ChartsXAxis.js +122 -34
- package/esm/ChartsYAxis/ChartsYAxis.js +36 -14
- package/esm/LineChart/AreaElement.js +10 -0
- package/esm/LineChart/AreaPlot.js +11 -0
- package/esm/LineChart/LineChart.js +34 -0
- package/esm/LineChart/LineElement.js +10 -0
- package/esm/LineChart/LineHighlightElement.js +10 -0
- package/esm/LineChart/LineHighlightPlot.js +10 -0
- package/esm/LineChart/LinePlot.js +10 -0
- package/esm/LineChart/MarkElement.js +10 -0
- package/esm/LineChart/MarkPlot.js +10 -0
- package/esm/PieChart/PieChart.js +35 -0
- package/esm/PieChart/PiePlot.js +10 -0
- package/esm/ResponsiveChartContainer/index.js +2 -2
- package/esm/ScatterChart/Scatter.js +10 -0
- package/esm/ScatterChart/ScatterChart.js +34 -0
- package/esm/ScatterChart/ScatterPlot.js +10 -0
- package/esm/SparkLineChart/SparkLineChart.js +14 -0
- package/esm/context/CartesianContextProvider.js +8 -0
- package/esm/hooks/useMounted.js +16 -0
- package/esm/hooks/useReducedMotion.js +27 -0
- package/esm/hooks/useTicks.js +12 -6
- package/esm/internals/components/ChartsText.js +17 -13
- package/esm/internals/geometry.js +36 -0
- package/hooks/useAxisEvents.js +2 -2
- package/hooks/useChartDimensions.js +2 -2
- 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 +18 -9
- package/hooks/useTicks.js +14 -8
- package/index.js +1 -1
- package/internals/components/ChartsText.d.ts +11 -8
- package/internals/components/ChartsText.js +19 -15
- package/internals/defaultizeColor.d.ts +1 -1
- package/internals/domUtils.d.ts +0 -1
- package/internals/geometry.d.ts +9 -0
- package/internals/geometry.js +42 -0
- package/legacy/BarChart/BarChart.js +43 -1
- package/legacy/BarChart/BarElement.js +6 -3
- package/legacy/BarChart/BarPlot.js +151 -63
- package/legacy/ChartContainer/index.js +3 -0
- package/legacy/ChartsAxis/ChartsAxis.js +16 -0
- package/legacy/ChartsLegend/ChartsLegend.js +14 -7
- package/legacy/ChartsXAxis/ChartsXAxis.js +126 -36
- package/legacy/ChartsYAxis/ChartsYAxis.js +36 -14
- package/legacy/LineChart/AreaElement.js +10 -0
- package/legacy/LineChart/AreaPlot.js +11 -0
- package/legacy/LineChart/LineChart.js +34 -0
- package/legacy/LineChart/LineElement.js +10 -0
- package/legacy/LineChart/LineHighlightElement.js +10 -0
- package/legacy/LineChart/LineHighlightPlot.js +10 -0
- package/legacy/LineChart/LinePlot.js +10 -0
- package/legacy/LineChart/MarkElement.js +10 -0
- package/legacy/LineChart/MarkPlot.js +10 -0
- package/legacy/PieChart/PieChart.js +35 -0
- package/legacy/PieChart/PiePlot.js +10 -0
- package/legacy/ResponsiveChartContainer/index.js +2 -2
- package/legacy/ScatterChart/Scatter.js +10 -0
- package/legacy/ScatterChart/ScatterChart.js +34 -0
- package/legacy/ScatterChart/ScatterPlot.js +10 -0
- package/legacy/SparkLineChart/SparkLineChart.js +14 -0
- package/legacy/context/CartesianContextProvider.js +8 -0
- package/legacy/hooks/useMounted.js +21 -0
- package/legacy/hooks/useReducedMotion.js +27 -0
- package/legacy/hooks/useTicks.js +13 -6
- package/legacy/index.js +1 -1
- package/legacy/internals/components/ChartsText.js +15 -15
- package/legacy/internals/geometry.js +37 -0
- package/models/axis.d.ts +19 -2
- package/models/seriesType/line.d.ts +2 -2
- package/modern/BarChart/BarChart.js +43 -1
- package/modern/BarChart/BarElement.js +7 -4
- package/modern/BarChart/BarPlot.js +149 -65
- package/modern/ChartContainer/index.js +3 -0
- package/modern/ChartsAxis/ChartsAxis.js +16 -0
- package/modern/ChartsLegend/ChartsLegend.js +10 -6
- package/modern/ChartsXAxis/ChartsXAxis.js +122 -34
- package/modern/ChartsYAxis/ChartsYAxis.js +36 -14
- package/modern/LineChart/AreaElement.js +10 -0
- package/modern/LineChart/AreaPlot.js +11 -0
- package/modern/LineChart/LineChart.js +34 -0
- package/modern/LineChart/LineElement.js +10 -0
- package/modern/LineChart/LineHighlightElement.js +10 -0
- package/modern/LineChart/LineHighlightPlot.js +10 -0
- package/modern/LineChart/LinePlot.js +10 -0
- package/modern/LineChart/MarkElement.js +10 -0
- package/modern/LineChart/MarkPlot.js +10 -0
- package/modern/PieChart/PieChart.js +35 -0
- package/modern/PieChart/PiePlot.js +10 -0
- package/modern/ResponsiveChartContainer/index.js +2 -2
- package/modern/ScatterChart/Scatter.js +10 -0
- package/modern/ScatterChart/ScatterChart.js +34 -0
- package/modern/ScatterChart/ScatterPlot.js +10 -0
- package/modern/SparkLineChart/SparkLineChart.js +14 -0
- package/modern/context/CartesianContextProvider.js +8 -0
- package/modern/hooks/useMounted.js +16 -0
- package/modern/hooks/useReducedMotion.js +27 -0
- package/modern/hooks/useTicks.js +12 -6
- package/modern/index.js +1 -1
- package/modern/internals/components/ChartsText.js +17 -13
- package/modern/internals/geometry.js +36 -0
- package/package.json +5 -3
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.useMounted = useMounted;
|
|
8
|
+
var React = _interopRequireWildcard(require("react"));
|
|
9
|
+
var _useEnhancedEffect = _interopRequireDefault(require("@mui/utils/useEnhancedEffect"));
|
|
10
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
11
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
12
|
+
function useMounted(defer = false) {
|
|
13
|
+
const [mountedState, setMountedState] = React.useState(false);
|
|
14
|
+
(0, _useEnhancedEffect.default)(() => {
|
|
15
|
+
if (!defer) {
|
|
16
|
+
setMountedState(true);
|
|
17
|
+
}
|
|
18
|
+
}, [defer]);
|
|
19
|
+
React.useEffect(() => {
|
|
20
|
+
if (defer) {
|
|
21
|
+
setMountedState(true);
|
|
22
|
+
}
|
|
23
|
+
}, [defer]);
|
|
24
|
+
return mountedState;
|
|
25
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns `boolean` or `null`, used to automatically
|
|
3
|
+
* set skipAnimations to the value of the user's
|
|
4
|
+
* `prefers-reduced-motion` query.
|
|
5
|
+
*
|
|
6
|
+
* The return value, post-effect, is the value of their prefered setting
|
|
7
|
+
*/
|
|
8
|
+
export declare const useReducedMotion: () => void;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useReducedMotion = void 0;
|
|
7
|
+
var _web = require("@react-spring/web");
|
|
8
|
+
/**
|
|
9
|
+
* Returns `boolean` or `null`, used to automatically
|
|
10
|
+
* set skipAnimations to the value of the user's
|
|
11
|
+
* `prefers-reduced-motion` query.
|
|
12
|
+
*
|
|
13
|
+
* The return value, post-effect, is the value of their prefered setting
|
|
14
|
+
*/
|
|
15
|
+
const useReducedMotion = () => {
|
|
16
|
+
// Taken from: https://github.com/pmndrs/react-spring/blob/02ec877bbfab0df46da0e4a47d5f68d3e731206a/packages/shared/src/hooks/useReducedMotion.ts#L13
|
|
17
|
+
|
|
18
|
+
(0, _web.useIsomorphicLayoutEffect)(() => {
|
|
19
|
+
const mql = window.matchMedia('(prefers-reduced-motion)');
|
|
20
|
+
const handleMediaChange = e => {
|
|
21
|
+
_web.Globals.assign({
|
|
22
|
+
// Modification such the react-spring implementation such that this hook can remove animation but never activate animation.
|
|
23
|
+
skipAnimation: e.matches || undefined
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
handleMediaChange(mql);
|
|
27
|
+
mql.addEventListener('change', handleMediaChange);
|
|
28
|
+
return () => {
|
|
29
|
+
mql.removeEventListener('change', handleMediaChange);
|
|
30
|
+
};
|
|
31
|
+
}, []);
|
|
32
|
+
};
|
|
33
|
+
exports.useReducedMotion = useReducedMotion;
|
package/hooks/useScale.d.ts
CHANGED
|
@@ -6,5 +6,5 @@ import { D3Scale } from '../models/axis';
|
|
|
6
6
|
* @returns (value: any) => number
|
|
7
7
|
*/
|
|
8
8
|
export declare function getValueToPositionMapper(scale: D3Scale): (value: any) => number;
|
|
9
|
-
export declare function useXScale(identifier?: number | string): import("d3-scale").ScaleBand<any> | import("d3-scale").ScalePoint<any> | import("d3-scale").
|
|
10
|
-
export declare function useYScale(identifier?: number | string): import("d3-scale").ScaleBand<any> | import("d3-scale").ScalePoint<any> | import("d3-scale").
|
|
9
|
+
export declare function useXScale(identifier?: number | string): import("d3-scale").ScaleBand<any> | import("d3-scale").ScalePoint<any> | import("d3-scale").ScaleLinear<any, any, never> | import("d3-scale").ScaleTime<any, any, never> | import("d3-scale").ScaleLogarithmic<any, any, never> | import("d3-scale").ScalePower<any, any, never>;
|
|
10
|
+
export declare function useYScale(identifier?: number | string): import("d3-scale").ScaleBand<any> | import("d3-scale").ScalePoint<any> | import("d3-scale").ScaleLinear<any, any, never> | import("d3-scale").ScaleTime<any, any, never> | import("d3-scale").ScaleLogarithmic<any, any, never> | import("d3-scale").ScalePower<any, any, never>;
|
package/hooks/useScale.js
CHANGED
|
@@ -9,8 +9,8 @@ exports.useYScale = useYScale;
|
|
|
9
9
|
var React = _interopRequireWildcard(require("react"));
|
|
10
10
|
var _CartesianContextProvider = require("../context/CartesianContextProvider");
|
|
11
11
|
var _isBandScale = require("../internals/isBandScale");
|
|
12
|
-
function _getRequireWildcardCache(
|
|
13
|
-
function _interopRequireWildcard(
|
|
12
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
13
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
14
14
|
/**
|
|
15
15
|
* For a given scale return a function that map value to their position.
|
|
16
16
|
* Usefull when dealing with specific scale such as band.
|
package/hooks/useTicks.d.ts
CHANGED
|
@@ -17,21 +17,30 @@ export interface TickParams {
|
|
|
17
17
|
* Not supported by categorical axis (band, points).
|
|
18
18
|
*/
|
|
19
19
|
tickNumber?: number;
|
|
20
|
+
/**
|
|
21
|
+
* Defines which ticks are displayed. Its value can be:
|
|
22
|
+
* - 'auto' In such case the ticks are computed based on axis scale and other parameters.
|
|
23
|
+
* - a filtering function of the form `(value, index) => boolean` which is available only if the axis has a data property.
|
|
24
|
+
* - an array containing the values where ticks should be displayed.
|
|
25
|
+
* @default 'auto'
|
|
26
|
+
*/
|
|
27
|
+
tickInterval?: 'auto' | ((value: any, index: number) => boolean) | any[];
|
|
20
28
|
}
|
|
21
29
|
export declare function getTickNumber(params: TickParams & {
|
|
22
30
|
range: any[];
|
|
23
31
|
domain: any[];
|
|
24
32
|
}): number;
|
|
33
|
+
export type TickItemType = {
|
|
34
|
+
/**
|
|
35
|
+
* This property is undefined only if it's the tick closing the last band
|
|
36
|
+
*/
|
|
37
|
+
value?: any;
|
|
38
|
+
formattedValue?: string;
|
|
39
|
+
offset: number;
|
|
40
|
+
labelOffset: number;
|
|
41
|
+
};
|
|
25
42
|
declare function useTicks(options: {
|
|
26
43
|
scale: D3Scale;
|
|
27
44
|
valueFormatter?: (value: any) => string;
|
|
28
|
-
} & Pick<TickParams, 'tickNumber'>):
|
|
29
|
-
formattedValue: any;
|
|
30
|
-
offset: number;
|
|
31
|
-
labelOffset: number;
|
|
32
|
-
}[] | {
|
|
33
|
-
formattedValue: string;
|
|
34
|
-
offset: any;
|
|
35
|
-
labelOffset: number;
|
|
36
|
-
}[];
|
|
45
|
+
} & Pick<TickParams, 'tickNumber' | 'tickInterval'>): TickItemType[];
|
|
37
46
|
export default useTicks;
|
package/hooks/useTicks.js
CHANGED
|
@@ -7,8 +7,8 @@ exports.default = void 0;
|
|
|
7
7
|
exports.getTickNumber = getTickNumber;
|
|
8
8
|
var React = _interopRequireWildcard(require("react"));
|
|
9
9
|
var _isBandScale = require("../internals/isBandScale");
|
|
10
|
-
function _getRequireWildcardCache(
|
|
11
|
-
function _interopRequireWildcard(
|
|
10
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
11
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
12
12
|
function getTickNumber(params) {
|
|
13
13
|
const {
|
|
14
14
|
tickMaxStep,
|
|
@@ -26,7 +26,8 @@ function useTicks(options) {
|
|
|
26
26
|
const {
|
|
27
27
|
scale,
|
|
28
28
|
tickNumber,
|
|
29
|
-
valueFormatter
|
|
29
|
+
valueFormatter,
|
|
30
|
+
tickInterval
|
|
30
31
|
} = options;
|
|
31
32
|
return React.useMemo(() => {
|
|
32
33
|
// band scale
|
|
@@ -35,7 +36,8 @@ function useTicks(options) {
|
|
|
35
36
|
if (scale.bandwidth() > 0) {
|
|
36
37
|
// scale type = 'band'
|
|
37
38
|
return [...domain.map(value => ({
|
|
38
|
-
|
|
39
|
+
value,
|
|
40
|
+
formattedValue: valueFormatter?.(value) ?? `${value}`,
|
|
39
41
|
offset: scale(value) - (scale.step() - scale.bandwidth()) / 2,
|
|
40
42
|
labelOffset: scale.step() / 2
|
|
41
43
|
})), {
|
|
@@ -46,17 +48,21 @@ function useTicks(options) {
|
|
|
46
48
|
}
|
|
47
49
|
|
|
48
50
|
// scale type = 'point'
|
|
49
|
-
|
|
50
|
-
|
|
51
|
+
const filteredDomain = typeof tickInterval === 'function' && domain.filter(tickInterval) || typeof tickInterval === 'object' && tickInterval || domain;
|
|
52
|
+
return filteredDomain.map(value => ({
|
|
53
|
+
value,
|
|
54
|
+
formattedValue: valueFormatter?.(value) ?? `${value}`,
|
|
51
55
|
offset: scale(value),
|
|
52
56
|
labelOffset: 0
|
|
53
57
|
}));
|
|
54
58
|
}
|
|
55
|
-
|
|
59
|
+
const ticks = typeof tickInterval === 'object' ? tickInterval : scale.ticks(tickNumber);
|
|
60
|
+
return ticks.map(value => ({
|
|
61
|
+
value,
|
|
56
62
|
formattedValue: valueFormatter?.(value) ?? scale.tickFormat(tickNumber)(value),
|
|
57
63
|
offset: scale(value),
|
|
58
64
|
labelOffset: 0
|
|
59
65
|
}));
|
|
60
|
-
}, [tickNumber, scale, valueFormatter]);
|
|
66
|
+
}, [tickNumber, scale, valueFormatter, tickInterval]);
|
|
61
67
|
}
|
|
62
68
|
var _default = exports.default = useTicks;
|
package/index.js
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
+
export type ChartsTextBaseline = 'hanging' | 'central' | 'auto';
|
|
3
|
+
export interface ChartsTextStyle extends React.CSSProperties {
|
|
4
|
+
angle?: number;
|
|
5
|
+
/**
|
|
6
|
+
* The text baseline
|
|
7
|
+
* @default 'central'
|
|
8
|
+
*/
|
|
9
|
+
dominantBaseline?: ChartsTextBaseline;
|
|
10
|
+
}
|
|
2
11
|
interface GetWordsByLinesParams {
|
|
3
12
|
/**
|
|
4
13
|
* Text displayed.
|
|
@@ -7,24 +16,18 @@ interface GetWordsByLinesParams {
|
|
|
7
16
|
/**
|
|
8
17
|
* Style applied to text elements.
|
|
9
18
|
*/
|
|
10
|
-
style?:
|
|
19
|
+
style?: ChartsTextStyle;
|
|
11
20
|
/**
|
|
12
21
|
* If true, the line width is computed.
|
|
13
22
|
* @default false
|
|
14
23
|
*/
|
|
15
24
|
needsComputation?: boolean;
|
|
16
25
|
}
|
|
17
|
-
export
|
|
18
|
-
export interface ChartsTextProps extends Omit<React.SVGTextElementAttributes<SVGTextElement>, 'width' | 'ref'>, GetWordsByLinesParams {
|
|
26
|
+
export interface ChartsTextProps extends Omit<React.SVGTextElementAttributes<SVGTextElement>, 'width' | 'ref' | 'style' | 'dominantBaseline'>, GetWordsByLinesParams {
|
|
19
27
|
/**
|
|
20
28
|
* Height of a text line (in `em`).
|
|
21
29
|
*/
|
|
22
30
|
lineHeight?: number;
|
|
23
|
-
/**
|
|
24
|
-
* The text baseline
|
|
25
|
-
* @default 'central'
|
|
26
|
-
*/
|
|
27
|
-
dominantBaseline?: ChartsTextBaseline;
|
|
28
31
|
ownerState?: any;
|
|
29
32
|
}
|
|
30
33
|
export declare function getWordsByLines({ style, needsComputation, text }: GetWordsByLinesParams): any[];
|
|
@@ -11,9 +11,10 @@ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")
|
|
|
11
11
|
var React = _interopRequireWildcard(require("react"));
|
|
12
12
|
var _domUtils = require("../domUtils");
|
|
13
13
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
14
|
-
const _excluded = ["x", "y", "
|
|
15
|
-
|
|
16
|
-
function
|
|
14
|
+
const _excluded = ["x", "y", "style", "text", "ownerState"],
|
|
15
|
+
_excluded2 = ["angle", "textAnchor", "dominantBaseline"];
|
|
16
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
17
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
17
18
|
function getWordsByLines({
|
|
18
19
|
style,
|
|
19
20
|
needsComputation,
|
|
@@ -30,12 +31,17 @@ function ChartsText(props) {
|
|
|
30
31
|
const {
|
|
31
32
|
x,
|
|
32
33
|
y,
|
|
33
|
-
|
|
34
|
-
dominantBaseline = 'central',
|
|
35
|
-
style,
|
|
34
|
+
style: styleProps,
|
|
36
35
|
text
|
|
37
36
|
} = props,
|
|
38
37
|
textProps = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
|
|
38
|
+
const _ref = styleProps ?? {},
|
|
39
|
+
{
|
|
40
|
+
angle,
|
|
41
|
+
textAnchor,
|
|
42
|
+
dominantBaseline
|
|
43
|
+
} = _ref,
|
|
44
|
+
style = (0, _objectWithoutPropertiesLoose2.default)(_ref, _excluded2);
|
|
39
45
|
const wordsByLines = React.useMemo(() => getWordsByLines({
|
|
40
46
|
style,
|
|
41
47
|
needsComputation: text.includes('\n'),
|
|
@@ -53,19 +59,17 @@ function ChartsText(props) {
|
|
|
53
59
|
startDy = (wordsByLines.length - 1) * -wordsByLines[0].height;
|
|
54
60
|
break;
|
|
55
61
|
}
|
|
56
|
-
|
|
57
|
-
// const transforms = [];
|
|
62
|
+
const transforms = [];
|
|
58
63
|
// if (scaleToFit) {
|
|
59
64
|
// const lineWidth = wordsByLines[0].width;
|
|
60
65
|
// transforms.push(`scale(${(isNumber(width as number) ? (width as number) / lineWidth : 1) / lineWidth})`);
|
|
61
66
|
// }
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
if (angle) {
|
|
68
|
+
transforms.push(`rotate(${angle}, ${x}, ${y})`);
|
|
69
|
+
}
|
|
70
|
+
if (transforms.length) {
|
|
71
|
+
textProps.transform = transforms.join(' ');
|
|
72
|
+
}
|
|
69
73
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)("text", (0, _extends2.default)({}, textProps, {
|
|
70
74
|
x: x,
|
|
71
75
|
y: y,
|
|
@@ -57,7 +57,7 @@ export declare function defaultizeColor(series: AllSeriesType, seriesIndex: numb
|
|
|
57
57
|
area?: boolean | undefined;
|
|
58
58
|
label?: string | undefined;
|
|
59
59
|
curve?: import("../models/seriesType").CurveType | undefined;
|
|
60
|
-
showMark?: boolean | ((params: import("../models/seriesType").ShowMarkParams) => boolean) | undefined;
|
|
60
|
+
showMark?: boolean | ((params: import("../models/seriesType").ShowMarkParams<number | Date>) => boolean) | undefined;
|
|
61
61
|
disableHighlight?: boolean | undefined;
|
|
62
62
|
id?: string | undefined;
|
|
63
63
|
color: string;
|
package/internals/domUtils.d.ts
CHANGED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Return the minimal translation along the x-axis to avoid overflow of a rectangle of a given width, height, and rotation.
|
|
3
|
+
* This assumes that all rectangles have the same height and angle between -90 and 90.
|
|
4
|
+
* Otherwise it would be problematic because you need the height/width of the next rectangle to do the correct computation.
|
|
5
|
+
* @param width the side along the x axis.
|
|
6
|
+
* @param height the side along the y axis.
|
|
7
|
+
* @param angle the rotation in degrees.
|
|
8
|
+
*/
|
|
9
|
+
export declare function getMinXTranslation(width: number, height: number, angle?: number): number;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getMinXTranslation = getMinXTranslation;
|
|
7
|
+
const ANGLE_APPROX = 5; // Angle (in deg) for which we approximate the rectangle as perfectly horizontal/vertical
|
|
8
|
+
|
|
9
|
+
let warnedOnce = false;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Return the minimal translation along the x-axis to avoid overflow of a rectangle of a given width, height, and rotation.
|
|
13
|
+
* This assumes that all rectangles have the same height and angle between -90 and 90.
|
|
14
|
+
* Otherwise it would be problematic because you need the height/width of the next rectangle to do the correct computation.
|
|
15
|
+
* @param width the side along the x axis.
|
|
16
|
+
* @param height the side along the y axis.
|
|
17
|
+
* @param angle the rotation in degrees.
|
|
18
|
+
*/
|
|
19
|
+
function getMinXTranslation(width, height, angle = 0) {
|
|
20
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
21
|
+
if (!warnedOnce && angle > 90 && angle < -90) {
|
|
22
|
+
warnedOnce = true;
|
|
23
|
+
console.warn([`MUI X: It seems you applied an angle larger than 90° or smaller than -90° 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'));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const standardAngle = Math.min(Math.abs(angle) % 180, Math.abs(Math.abs(angle) % 180 - 180) % 180); // Map from R to [0, 90]
|
|
27
|
+
|
|
28
|
+
if (standardAngle < ANGLE_APPROX) {
|
|
29
|
+
// It's nearly horizontal
|
|
30
|
+
return width;
|
|
31
|
+
}
|
|
32
|
+
if (standardAngle > 90 - ANGLE_APPROX) {
|
|
33
|
+
// It's nearly vertical
|
|
34
|
+
return height;
|
|
35
|
+
}
|
|
36
|
+
const radAngle = standardAngle * Math.PI / 180;
|
|
37
|
+
const angleSwich = Math.atan2(height, width);
|
|
38
|
+
if (radAngle < angleSwich) {
|
|
39
|
+
return width / Math.cos(radAngle);
|
|
40
|
+
}
|
|
41
|
+
return height / Math.sin(radAngle);
|
|
42
|
+
}
|
|
@@ -13,6 +13,17 @@ import { ChartsAxisHighlight } from '../ChartsAxisHighlight';
|
|
|
13
13
|
import { ChartsClipPath } from '../ChartsClipPath';
|
|
14
14
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
15
15
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
16
|
+
/**
|
|
17
|
+
* Demos:
|
|
18
|
+
*
|
|
19
|
+
* - [Bars](https://mui.com/x/react-charts/bars/)
|
|
20
|
+
* - [Bar demonstration](https://mui.com/x/react-charts/bar-demo/)
|
|
21
|
+
* - [Stacking](https://mui.com/x/react-charts/stacking/)
|
|
22
|
+
*
|
|
23
|
+
* API:
|
|
24
|
+
*
|
|
25
|
+
* - [BarChart API](https://mui.com/x/api/charts/bar-chart/)
|
|
26
|
+
*/
|
|
16
27
|
var BarChart = /*#__PURE__*/React.forwardRef(function BarChart(props, ref) {
|
|
17
28
|
var xAxis = props.xAxis,
|
|
18
29
|
yAxis = props.yAxis,
|
|
@@ -31,6 +42,7 @@ var BarChart = /*#__PURE__*/React.forwardRef(function BarChart(props, ref) {
|
|
|
31
42
|
leftAxis = props.leftAxis,
|
|
32
43
|
rightAxis = props.rightAxis,
|
|
33
44
|
bottomAxis = props.bottomAxis,
|
|
45
|
+
skipAnimation = props.skipAnimation,
|
|
34
46
|
children = props.children,
|
|
35
47
|
slots = props.slots,
|
|
36
48
|
slotProps = props.slotProps;
|
|
@@ -81,7 +93,8 @@ var BarChart = /*#__PURE__*/React.forwardRef(function BarChart(props, ref) {
|
|
|
81
93
|
clipPath: "url(#".concat(clipPathId, ")"),
|
|
82
94
|
children: /*#__PURE__*/_jsx(BarPlot, {
|
|
83
95
|
slots: slots,
|
|
84
|
-
slotProps: slotProps
|
|
96
|
+
slotProps: slotProps,
|
|
97
|
+
skipAnimation: skipAnimation
|
|
85
98
|
})
|
|
86
99
|
}), /*#__PURE__*/_jsx(ChartsAxis, {
|
|
87
100
|
topAxis: topAxis,
|
|
@@ -123,11 +136,15 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
123
136
|
fill: PropTypes.string,
|
|
124
137
|
label: PropTypes.string,
|
|
125
138
|
labelFontSize: PropTypes.number,
|
|
139
|
+
labelStyle: PropTypes.object,
|
|
126
140
|
position: PropTypes.oneOf(['bottom', 'top']),
|
|
127
141
|
slotProps: PropTypes.object,
|
|
128
142
|
slots: PropTypes.object,
|
|
129
143
|
stroke: PropTypes.string,
|
|
130
144
|
tickFontSize: PropTypes.number,
|
|
145
|
+
tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
|
|
146
|
+
tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
|
|
147
|
+
tickLabelStyle: PropTypes.object,
|
|
131
148
|
tickMaxStep: PropTypes.number,
|
|
132
149
|
tickMinStep: PropTypes.number,
|
|
133
150
|
tickNumber: PropTypes.number,
|
|
@@ -157,11 +174,15 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
157
174
|
fill: PropTypes.string,
|
|
158
175
|
label: PropTypes.string,
|
|
159
176
|
labelFontSize: PropTypes.number,
|
|
177
|
+
labelStyle: PropTypes.object,
|
|
160
178
|
position: PropTypes.oneOf(['left', 'right']),
|
|
161
179
|
slotProps: PropTypes.object,
|
|
162
180
|
slots: PropTypes.object,
|
|
163
181
|
stroke: PropTypes.string,
|
|
164
182
|
tickFontSize: PropTypes.number,
|
|
183
|
+
tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
|
|
184
|
+
tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
|
|
185
|
+
tickLabelStyle: PropTypes.object,
|
|
165
186
|
tickMaxStep: PropTypes.number,
|
|
166
187
|
tickMinStep: PropTypes.number,
|
|
167
188
|
tickNumber: PropTypes.number,
|
|
@@ -200,11 +221,15 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
200
221
|
fill: PropTypes.string,
|
|
201
222
|
label: PropTypes.string,
|
|
202
223
|
labelFontSize: PropTypes.number,
|
|
224
|
+
labelStyle: PropTypes.object,
|
|
203
225
|
position: PropTypes.oneOf(['left', 'right']),
|
|
204
226
|
slotProps: PropTypes.object,
|
|
205
227
|
slots: PropTypes.object,
|
|
206
228
|
stroke: PropTypes.string,
|
|
207
229
|
tickFontSize: PropTypes.number,
|
|
230
|
+
tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
|
|
231
|
+
tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
|
|
232
|
+
tickLabelStyle: PropTypes.object,
|
|
208
233
|
tickMaxStep: PropTypes.number,
|
|
209
234
|
tickMinStep: PropTypes.number,
|
|
210
235
|
tickNumber: PropTypes.number,
|
|
@@ -229,6 +254,11 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
229
254
|
xAxisKey: PropTypes.string,
|
|
230
255
|
yAxisKey: PropTypes.string
|
|
231
256
|
})).isRequired,
|
|
257
|
+
/**
|
|
258
|
+
* If `true`, animations are skiped.
|
|
259
|
+
* @default false
|
|
260
|
+
*/
|
|
261
|
+
skipAnimation: PropTypes.bool,
|
|
232
262
|
/**
|
|
233
263
|
* The props used for each component slot.
|
|
234
264
|
* @default {}
|
|
@@ -262,11 +292,15 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
262
292
|
fill: PropTypes.string,
|
|
263
293
|
label: PropTypes.string,
|
|
264
294
|
labelFontSize: PropTypes.number,
|
|
295
|
+
labelStyle: PropTypes.object,
|
|
265
296
|
position: PropTypes.oneOf(['bottom', 'top']),
|
|
266
297
|
slotProps: PropTypes.object,
|
|
267
298
|
slots: PropTypes.object,
|
|
268
299
|
stroke: PropTypes.string,
|
|
269
300
|
tickFontSize: PropTypes.number,
|
|
301
|
+
tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
|
|
302
|
+
tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
|
|
303
|
+
tickLabelStyle: PropTypes.object,
|
|
270
304
|
tickMaxStep: PropTypes.number,
|
|
271
305
|
tickMinStep: PropTypes.number,
|
|
272
306
|
tickNumber: PropTypes.number,
|
|
@@ -291,6 +325,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
291
325
|
id: PropTypes.string,
|
|
292
326
|
label: PropTypes.string,
|
|
293
327
|
labelFontSize: PropTypes.number,
|
|
328
|
+
labelStyle: PropTypes.object,
|
|
294
329
|
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
295
330
|
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
296
331
|
position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
|
|
@@ -299,6 +334,9 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
299
334
|
slots: PropTypes.object,
|
|
300
335
|
stroke: PropTypes.string,
|
|
301
336
|
tickFontSize: PropTypes.number,
|
|
337
|
+
tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
|
|
338
|
+
tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
|
|
339
|
+
tickLabelStyle: PropTypes.object,
|
|
302
340
|
tickMaxStep: PropTypes.number,
|
|
303
341
|
tickMinStep: PropTypes.number,
|
|
304
342
|
tickNumber: PropTypes.number,
|
|
@@ -317,6 +355,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
317
355
|
id: PropTypes.string,
|
|
318
356
|
label: PropTypes.string,
|
|
319
357
|
labelFontSize: PropTypes.number,
|
|
358
|
+
labelStyle: PropTypes.object,
|
|
320
359
|
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
321
360
|
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
322
361
|
position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
|
|
@@ -325,6 +364,9 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
325
364
|
slots: PropTypes.object,
|
|
326
365
|
stroke: PropTypes.string,
|
|
327
366
|
tickFontSize: PropTypes.number,
|
|
367
|
+
tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
|
|
368
|
+
tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
|
|
369
|
+
tickLabelStyle: PropTypes.object,
|
|
328
370
|
tickMaxStep: PropTypes.number,
|
|
329
371
|
tickMinStep: PropTypes.number,
|
|
330
372
|
tickNumber: PropTypes.number,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
3
|
-
var _excluded = ["id", "dataIndex", "classes", "color", "highlightScope", "slots", "slotProps"];
|
|
3
|
+
var _excluded = ["id", "dataIndex", "classes", "color", "highlightScope", "slots", "slotProps", "style"];
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import composeClasses from '@mui/utils/composeClasses';
|
|
6
6
|
import { useSlotProps } from '@mui/base/utils';
|
|
@@ -8,13 +8,14 @@ import generateUtilityClass from '@mui/utils/generateUtilityClass';
|
|
|
8
8
|
import { styled } from '@mui/material/styles';
|
|
9
9
|
import { color as d3Color } from 'd3-color';
|
|
10
10
|
import generateUtilityClasses from '@mui/utils/generateUtilityClasses';
|
|
11
|
+
import { animated } from '@react-spring/web';
|
|
11
12
|
import { getIsFaded, getIsHighlighted, useInteractionItemProps } from '../hooks/useInteractionItemProps';
|
|
12
13
|
import { InteractionContext } from '../context/InteractionProvider';
|
|
13
14
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
15
|
export function getBarElementUtilityClass(slot) {
|
|
15
16
|
return generateUtilityClass('MuiBarElement', slot);
|
|
16
17
|
}
|
|
17
|
-
export var
|
|
18
|
+
export var barElementClasses = generateUtilityClasses('MuiBarElement', ['root']);
|
|
18
19
|
var useUtilityClasses = function useUtilityClasses(ownerState) {
|
|
19
20
|
var classes = ownerState.classes,
|
|
20
21
|
id = ownerState.id;
|
|
@@ -23,7 +24,7 @@ var useUtilityClasses = function useUtilityClasses(ownerState) {
|
|
|
23
24
|
};
|
|
24
25
|
return composeClasses(slots, getBarElementUtilityClass, classes);
|
|
25
26
|
};
|
|
26
|
-
export var BarElementPath = styled(
|
|
27
|
+
export var BarElementPath = styled(animated.rect, {
|
|
27
28
|
name: 'MuiBarElement',
|
|
28
29
|
slot: 'Root',
|
|
29
30
|
overridesResolver: function overridesResolver(_, styles) {
|
|
@@ -48,6 +49,7 @@ export function BarElement(props) {
|
|
|
48
49
|
highlightScope = props.highlightScope,
|
|
49
50
|
slots = props.slots,
|
|
50
51
|
slotProps = props.slotProps,
|
|
52
|
+
style = props.style,
|
|
51
53
|
other = _objectWithoutProperties(props, _excluded);
|
|
52
54
|
var getInteractionItemProps = useInteractionItemProps(highlightScope);
|
|
53
55
|
var _React$useContext = React.useContext(InteractionContext),
|
|
@@ -80,6 +82,7 @@ export function BarElement(props) {
|
|
|
80
82
|
seriesId: id,
|
|
81
83
|
dataIndex: dataIndex
|
|
82
84
|
}), {
|
|
85
|
+
style: style,
|
|
83
86
|
className: classes.root
|
|
84
87
|
}),
|
|
85
88
|
ownerState: ownerState
|