@mui/x-charts 8.3.0 → 8.3.1
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/CHANGELOG.md +96 -10
- package/ChartsGrid/ChartsHorizontalGrid.js +2 -1
- package/ChartsGrid/ChartsVerticalGrid.js +2 -1
- package/ChartsXAxis/ChartsXAxis.js +2 -1
- package/ChartsYAxis/ChartsYAxis.js +2 -1
- package/esm/ChartsGrid/ChartsHorizontalGrid.js +2 -1
- package/esm/ChartsGrid/ChartsVerticalGrid.js +2 -1
- package/esm/ChartsXAxis/ChartsXAxis.js +2 -1
- package/esm/ChartsYAxis/ChartsYAxis.js +2 -1
- package/esm/hooks/useTicks.d.ts +1 -4
- package/esm/hooks/useTicks.js +33 -28
- package/esm/index.js +1 -1
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/computeAxisValue.js +2 -2
- package/esm/internals/plugins/featurePlugins/useChartPolarAxis/computeAxisValue.js +2 -2
- package/esm/internals/ticks.d.ts +6 -0
- package/esm/internals/ticks.js +22 -0
- package/hooks/useTicks.d.ts +1 -4
- package/hooks/useTicks.js +33 -29
- package/index.js +1 -1
- package/internals/plugins/featurePlugins/useChartCartesianAxis/computeAxisValue.js +3 -3
- package/internals/plugins/featurePlugins/useChartPolarAxis/computeAxisValue.js +3 -3
- package/internals/ticks.d.ts +6 -0
- package/internals/ticks.js +29 -0
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,96 @@
|
|
|
5
5
|
All notable changes to this project will be documented in this file.
|
|
6
6
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
7
7
|
|
|
8
|
+
## 8.3.1
|
|
9
|
+
|
|
10
|
+
_May 14, 2025_
|
|
11
|
+
|
|
12
|
+
We'd like to offer a big thanks to the 12 contributors who made this release possible. Here are some highlights ✨:
|
|
13
|
+
|
|
14
|
+
- 🌍 Improve Norwegian Bokmål (nb-NO) locale on the Data Grid
|
|
15
|
+
- 🌍 Improve Korean (ko-KR) locale on the Data Grid and Pickers
|
|
16
|
+
- 📚 Documentation improvements
|
|
17
|
+
- 🐞 Bugfixes
|
|
18
|
+
|
|
19
|
+
Special thanks go out to the community members for their valuable contributions:
|
|
20
|
+
@100pearlcent, @htollefsen, @JanPretzel, @sai6855.
|
|
21
|
+
Following are all team members who have contributed to this release:
|
|
22
|
+
@bernardobelchior, @cherniavskii, @flaviendelangle, @Janpot, @JCQuintas, @MBilalShafi, @oliviertassinari, @prakhargupta1.
|
|
23
|
+
|
|
24
|
+
<!--/ HIGHLIGHT_ABOVE_SEPARATOR /-->
|
|
25
|
+
|
|
26
|
+
### Data Grid
|
|
27
|
+
|
|
28
|
+
#### `@mui/x-data-grid@8.3.1`
|
|
29
|
+
|
|
30
|
+
- [DataGrid] Add `reason` param for `onRowSelectionModelChange` callback (#17545) @sai6855
|
|
31
|
+
- [DataGrid] Fix `renderContext` calculation loop (#17779) @cherniavskii
|
|
32
|
+
- [DataGrid] Fix column spanning jump on scroll (#17759) @cherniavskii
|
|
33
|
+
- [DataGrid] Fix material augmentation not working (#17761) @cherniavskii
|
|
34
|
+
- [DataGrid] Use arguments selector for checkbox props (#17683) @MBilalShafi
|
|
35
|
+
- [l10n] Improve Norwegian Bokmål (nb-NO) locale (#17766) @htollefsen
|
|
36
|
+
- [l10n] Improve Korean (ko-KR) locale (#17484) @100pearlcent
|
|
37
|
+
|
|
38
|
+
#### `@mui/x-data-grid-pro@8.3.1` [](https://mui.com/r/x-pro-svg-link 'Pro plan')
|
|
39
|
+
|
|
40
|
+
Same changes as in `@mui/x-data-grid@8.3.1`.
|
|
41
|
+
|
|
42
|
+
#### `@mui/x-data-grid-premium@8.3.1` [](https://mui.com/r/x-premium-svg-link 'Premium plan')
|
|
43
|
+
|
|
44
|
+
Same changes as in `@mui/x-data-grid-pro@8.3.1`, plus:
|
|
45
|
+
|
|
46
|
+
- [DataGridPremium] Fix aggregation label not being used in pivot panel (#17760) @cherniavskii
|
|
47
|
+
|
|
48
|
+
### Date and Time Pickers
|
|
49
|
+
|
|
50
|
+
#### `@mui/x-date-pickers@8.3.1`
|
|
51
|
+
|
|
52
|
+
- [fields] Add notch to the field outlined when the label is manually shrank (#17620) @flaviendelangle
|
|
53
|
+
- [l10n] Improve Korean (ko-KR) locale (#17484) @100pearlcent
|
|
54
|
+
|
|
55
|
+
#### `@mui/x-date-pickers-pro@8.3.1` [](https://mui.com/r/x-pro-svg-link 'Pro plan')
|
|
56
|
+
|
|
57
|
+
Same changes as in `@mui/x-date-pickers@8.3.1`.
|
|
58
|
+
|
|
59
|
+
### Charts
|
|
60
|
+
|
|
61
|
+
#### `@mui/x-charts@8.3.1`
|
|
62
|
+
|
|
63
|
+
- [charts] Fix infinite tick number when zoom range is zero (#17750) @bernardobelchior
|
|
64
|
+
- [charts] Improve tick rendering performance (#17755) @bernardobelchior
|
|
65
|
+
|
|
66
|
+
#### `@mui/x-charts-pro@8.3.1` [](https://mui.com/r/x-pro-svg-link 'Pro plan')
|
|
67
|
+
|
|
68
|
+
Same changes as in `@mui/x-charts@8.3.1`, plus:
|
|
69
|
+
|
|
70
|
+
- [charts-pro] Fix ESM build issue with Vite (#17774) @bernardobelchior
|
|
71
|
+
- [charts-pro] Add benchmark for zoomed in scatter chart (#17756) @bernardobelchior
|
|
72
|
+
|
|
73
|
+
### Tree View
|
|
74
|
+
|
|
75
|
+
#### `@mui/x-tree-view@8.3.1`
|
|
76
|
+
|
|
77
|
+
Internal changes.
|
|
78
|
+
|
|
79
|
+
#### `@mui/x-tree-view-pro@8.3.1` [](https://mui.com/r/x-pro-svg-link 'Pro plan')
|
|
80
|
+
|
|
81
|
+
Same changes as in `@mui/x-tree-view@8.3.1`.
|
|
82
|
+
|
|
83
|
+
### Docs
|
|
84
|
+
|
|
85
|
+
- [docs] Fix 301 to Next.js docs for license @oliviertassinari
|
|
86
|
+
- [docs] Fix AI assistant API URL (#17745) @oliviertassinari
|
|
87
|
+
- [docs] Fix heading structure in README @oliviertassinari
|
|
88
|
+
- [docs] Fix translation keys documentation (#17811) @JanPretzel
|
|
89
|
+
- [docs] Improve CHANGELOG format @oliviertassinari
|
|
90
|
+
|
|
91
|
+
### Core
|
|
92
|
+
|
|
93
|
+
- [core] Apply YAML convention, blank line only at top level @oliviertassinari
|
|
94
|
+
- [code-infra] Fix dynamic import missing extensions (#17767) @Janpot
|
|
95
|
+
- [code-infra] Replace `mocha` with `vitest` for browser & jsdom tests (#14508) @JCQuintas
|
|
96
|
+
- [scheduler] Create the package and setup a private doc page (#17239) @flaviendelangle
|
|
97
|
+
|
|
8
98
|
## 8.3.0
|
|
9
99
|
|
|
10
100
|
_May 8, 2025_
|
|
@@ -15,10 +105,8 @@ We'd like to offer a big thanks to the 11 contributors who made this release pos
|
|
|
15
105
|
- 📚 Documentation improvements
|
|
16
106
|
- 🐞 Bugfixes
|
|
17
107
|
|
|
18
|
-
Special thanks go out to this community member for a valuable contribution:
|
|
19
|
-
@
|
|
20
|
-
Team members who have contributed to this release:
|
|
21
|
-
@alexfauquette, @arminmeh, @bernardobelchior, @flaviendelangle, @Janpot, @JCQuintas, @LukasTy, @MBilalShafi, @rita-codes, @romgrk.
|
|
108
|
+
Special thanks go out to this community member for a valuable contribution: @ptuukkan.
|
|
109
|
+
Team members who have contributed to this release: @alexfauquette, @arminmeh, @bernardobelchior, @flaviendelangle, @Janpot, @JCQuintas, @LukasTy, @MBilalShafi, @rita-codes, @romgrk.
|
|
22
110
|
|
|
23
111
|
### Data Grid
|
|
24
112
|
|
|
@@ -531,8 +619,7 @@ We'd like to offer a big thanks to the 12 contributors who made this release pos
|
|
|
531
619
|
- 📚 Documentation improvements
|
|
532
620
|
- 🐞 Bugfixes
|
|
533
621
|
|
|
534
|
-
Team members who have contributed to this release:
|
|
535
|
-
@bernardobelchior, @cherniavskii, @flaviendelangle, @JCQuintas, @KenanYusuf, @LukasTy, @MBilalShafi, @michelengelen, @oliviertassinari, @noraleonte, @romgrk, @alexfauquette.
|
|
622
|
+
Team members who have contributed to this release: @bernardobelchior, @cherniavskii, @flaviendelangle, @JCQuintas, @KenanYusuf, @LukasTy, @MBilalShafi, @michelengelen, @oliviertassinari, @noraleonte, @romgrk, @alexfauquette.
|
|
536
623
|
|
|
537
624
|
<!--/ HIGHLIGHT_ABOVE_SEPARATOR /-->
|
|
538
625
|
|
|
@@ -845,7 +932,7 @@ We'd like to offer a big thanks to the 21 contributors who made this release pos
|
|
|
845
932
|
- 🌍 Improve Chinese (zh-CN), (zh-HK), (zh-TW), Czech (cs-CZ), Korean (ko-KR) and Slovak (sk-Sk) locales on the Data Grid
|
|
846
933
|
- 🌍 Improve Chinese (zh-CN), (zh-HK) and (zh-TW) locales on the Pickers
|
|
847
934
|
|
|
848
|
-
|
|
935
|
+
### Breaking changes
|
|
849
936
|
|
|
850
937
|
- ℹ️ The peer dependency on `@mui/material` has been updated to accept only v7.
|
|
851
938
|
This has been done to increase the adoption rate of ESM.
|
|
@@ -858,7 +945,7 @@ Following are all team members who have contributed to this release:
|
|
|
858
945
|
|
|
859
946
|
<!--/ HIGHLIGHT_ABOVE_SEPARATOR /-->
|
|
860
947
|
|
|
861
|
-
|
|
948
|
+
### Alpha release highlights
|
|
862
949
|
|
|
863
950
|
Below are the highlights of the alpha releases leading up to this beta release:
|
|
864
951
|
|
|
@@ -3152,8 +3239,7 @@ We'd like to offer a big thanks to the 4 contributors who made this release poss
|
|
|
3152
3239
|
|
|
3153
3240
|
- 🐞 Bugfixes
|
|
3154
3241
|
|
|
3155
|
-
Team members who have contributed to this release:
|
|
3156
|
-
@arminmeh, @cherniavskii, @LukasTy, @michelengelen.
|
|
3242
|
+
Team members who have contributed to this release: @arminmeh, @cherniavskii, @LukasTy, @michelengelen.
|
|
3157
3243
|
|
|
3158
3244
|
<!--/ HIGHLIGHT_ABOVE_SEPARATOR /-->
|
|
3159
3245
|
|
|
@@ -257,7 +257,8 @@ function ChartsXAxis(inProps) {
|
|
|
257
257
|
valueFormatter,
|
|
258
258
|
tickInterval,
|
|
259
259
|
tickPlacement,
|
|
260
|
-
tickLabelPlacement
|
|
260
|
+
tickLabelPlacement,
|
|
261
|
+
direction: 'x'
|
|
261
262
|
});
|
|
262
263
|
const visibleLabels = getVisibleLabels(xTicks, {
|
|
263
264
|
tickLabelStyle: axisTickLabelProps.style,
|
|
@@ -163,7 +163,8 @@ function ChartsYAxis(inProps) {
|
|
|
163
163
|
valueFormatter,
|
|
164
164
|
tickPlacement,
|
|
165
165
|
tickLabelPlacement,
|
|
166
|
-
tickInterval
|
|
166
|
+
tickInterval,
|
|
167
|
+
direction: 'y'
|
|
167
168
|
});
|
|
168
169
|
const positionSign = position === 'right' ? 1 : -1;
|
|
169
170
|
const tickFontSize = typeof tickLabelStyle?.fontSize === 'number' ? tickLabelStyle.fontSize : 12;
|
|
@@ -250,7 +250,8 @@ function ChartsXAxis(inProps) {
|
|
|
250
250
|
valueFormatter,
|
|
251
251
|
tickInterval,
|
|
252
252
|
tickPlacement,
|
|
253
|
-
tickLabelPlacement
|
|
253
|
+
tickLabelPlacement,
|
|
254
|
+
direction: 'x'
|
|
254
255
|
});
|
|
255
256
|
const visibleLabels = getVisibleLabels(xTicks, {
|
|
256
257
|
tickLabelStyle: axisTickLabelProps.style,
|
|
@@ -156,7 +156,8 @@ function ChartsYAxis(inProps) {
|
|
|
156
156
|
valueFormatter,
|
|
157
157
|
tickPlacement,
|
|
158
158
|
tickLabelPlacement,
|
|
159
|
-
tickInterval
|
|
159
|
+
tickInterval,
|
|
160
|
+
direction: 'y'
|
|
160
161
|
});
|
|
161
162
|
const positionSign = position === 'right' ? 1 : -1;
|
|
162
163
|
const tickFontSize = typeof tickLabelStyle?.fontSize === 'number' ? tickLabelStyle.fontSize : 12;
|
package/esm/hooks/useTicks.d.ts
CHANGED
|
@@ -40,10 +40,6 @@ export interface TickParams {
|
|
|
40
40
|
*/
|
|
41
41
|
tickLabelPlacement?: 'middle' | 'tick';
|
|
42
42
|
}
|
|
43
|
-
export declare function getTickNumber(params: TickParams & {
|
|
44
|
-
range: number[];
|
|
45
|
-
domain: any[];
|
|
46
|
-
}): number;
|
|
47
43
|
export type TickItemType = {
|
|
48
44
|
/**
|
|
49
45
|
* This property is undefined only if it's the tick closing the last band
|
|
@@ -56,4 +52,5 @@ export type TickItemType = {
|
|
|
56
52
|
export declare function useTicks(options: {
|
|
57
53
|
scale: D3Scale;
|
|
58
54
|
valueFormatter?: AxisConfig['valueFormatter'];
|
|
55
|
+
direction: 'x' | 'y';
|
|
59
56
|
} & Pick<TickParams, 'tickNumber' | 'tickInterval' | 'tickPlacement' | 'tickLabelPlacement'>): TickItemType[];
|
package/esm/hooks/useTicks.js
CHANGED
|
@@ -1,21 +1,9 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import * as React from 'react';
|
|
4
|
+
import { useChartContext } from "../context/ChartProvider/index.js";
|
|
4
5
|
import { isBandScale } from "../internals/isBandScale.js";
|
|
5
6
|
import { isInfinity } from "../internals/isInfinity.js";
|
|
6
|
-
export function getTickNumber(params) {
|
|
7
|
-
const {
|
|
8
|
-
tickMaxStep,
|
|
9
|
-
tickMinStep,
|
|
10
|
-
tickNumber,
|
|
11
|
-
range,
|
|
12
|
-
domain
|
|
13
|
-
} = params;
|
|
14
|
-
const maxTicks = tickMinStep === undefined ? 999 : Math.floor(Math.abs(domain[1] - domain[0]) / tickMinStep);
|
|
15
|
-
const minTicks = tickMaxStep === undefined ? 2 : Math.ceil(Math.abs(domain[1] - domain[0]) / tickMaxStep);
|
|
16
|
-
const defaultizedTickNumber = tickNumber ?? Math.floor(Math.abs(range[1] - range[0]) / 50);
|
|
17
|
-
return Math.min(maxTicks, Math.max(minTicks, defaultizedTickNumber));
|
|
18
|
-
}
|
|
19
7
|
const offsetRatio = {
|
|
20
8
|
start: 0,
|
|
21
9
|
extremities: 0,
|
|
@@ -29,8 +17,12 @@ export function useTicks(options) {
|
|
|
29
17
|
valueFormatter,
|
|
30
18
|
tickInterval,
|
|
31
19
|
tickPlacement = 'extremities',
|
|
32
|
-
tickLabelPlacement: tickLabelPlacementProp
|
|
20
|
+
tickLabelPlacement: tickLabelPlacementProp,
|
|
21
|
+
direction
|
|
33
22
|
} = options;
|
|
23
|
+
const {
|
|
24
|
+
instance
|
|
25
|
+
} = useChartContext();
|
|
34
26
|
return React.useMemo(() => {
|
|
35
27
|
// band scale
|
|
36
28
|
if (isBandScale(scale)) {
|
|
@@ -74,18 +66,31 @@ export function useTicks(options) {
|
|
|
74
66
|
}
|
|
75
67
|
const tickLabelPlacement = tickLabelPlacementProp;
|
|
76
68
|
const ticks = typeof tickInterval === 'object' ? tickInterval : scale.ticks(tickNumber);
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
|
|
69
|
+
|
|
70
|
+
// Ticks inside the drawing area
|
|
71
|
+
const visibleTicks = [];
|
|
72
|
+
for (let i = 0; i < ticks.length; i += 1) {
|
|
73
|
+
const value = ticks[i];
|
|
74
|
+
const offset = scale(value);
|
|
75
|
+
if (instance.isPointInside({
|
|
76
|
+
x: offset,
|
|
77
|
+
y: offset
|
|
78
|
+
}, {
|
|
79
|
+
direction
|
|
80
|
+
})) {
|
|
81
|
+
visibleTicks.push({
|
|
82
|
+
value,
|
|
83
|
+
formattedValue: valueFormatter?.(value, {
|
|
84
|
+
location: 'tick',
|
|
85
|
+
scale
|
|
86
|
+
}) ?? scale.tickFormat(tickNumber)(value),
|
|
87
|
+
offset,
|
|
88
|
+
// Allowing the label to be placed in the middle of a continuous scale is weird.
|
|
89
|
+
// But it is useful in some cases, like funnel categories with a linear scale.
|
|
90
|
+
labelOffset: tickLabelPlacement === 'middle' ? scale(ticks[i - 1] ?? 0) - (offset + scale(ticks[i - 1] ?? 0)) / 2 : 0
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return visibleTicks;
|
|
95
|
+
}, [scale, tickLabelPlacementProp, tickInterval, tickNumber, tickPlacement, valueFormatter, direction, instance]);
|
|
91
96
|
}
|
package/esm/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import _extends from "@babel/runtime/helpers/esm/extends";
|
|
|
2
2
|
import { scaleBand, scalePoint, scaleTime } from '@mui/x-charts-vendor/d3-scale';
|
|
3
3
|
import { isBandScaleConfig, isPointScaleConfig } from "../../../../models/axis.js";
|
|
4
4
|
import { getColorScale, getOrdinalColorScale } from "../../../colorScale.js";
|
|
5
|
-
import { getTickNumber } from "
|
|
5
|
+
import { getTickNumber, scaleTickNumberByRange } from "../../../ticks.js";
|
|
6
6
|
import { getScale } from "../../../getScale.js";
|
|
7
7
|
import { zoomScaleRange } from "./zoom.js";
|
|
8
8
|
import { getAxisExtremum } from "./getAxisExtremum.js";
|
|
@@ -114,7 +114,7 @@ export function computeAxisValue({
|
|
|
114
114
|
range,
|
|
115
115
|
domain: axisExtremums
|
|
116
116
|
}));
|
|
117
|
-
const tickNumber = rawTickNumber
|
|
117
|
+
const tickNumber = scaleTickNumberByRange(rawTickNumber, zoomRange);
|
|
118
118
|
const zoomedRange = zoomScaleRange(range, zoomRange);
|
|
119
119
|
const scale = getScale(scaleType, axisExtremums, zoomedRange);
|
|
120
120
|
const finalScale = domainLimit === 'nice' ? scale.nice(rawTickNumber) : scale;
|
|
@@ -2,7 +2,7 @@ import _extends from "@babel/runtime/helpers/esm/extends";
|
|
|
2
2
|
import { scaleBand, scalePoint, scaleTime } from '@mui/x-charts-vendor/d3-scale';
|
|
3
3
|
import { isBandScaleConfig, isPointScaleConfig } from "../../../../models/axis.js";
|
|
4
4
|
import { getColorScale, getOrdinalColorScale } from "../../../colorScale.js";
|
|
5
|
-
import { getTickNumber } from "
|
|
5
|
+
import { getTickNumber, scaleTickNumberByRange } from "../../../ticks.js";
|
|
6
6
|
import { getScale } from "../../../getScale.js";
|
|
7
7
|
import { getAxisExtremum } from "./getAxisExtremum.js";
|
|
8
8
|
import { deg2rad } from "../../../angleConversion.js";
|
|
@@ -109,7 +109,7 @@ export function computeAxisValue({
|
|
|
109
109
|
range,
|
|
110
110
|
domain: axisExtremums
|
|
111
111
|
}));
|
|
112
|
-
const tickNumber = rawTickNumber
|
|
112
|
+
const tickNumber = scaleTickNumberByRange(rawTickNumber, range);
|
|
113
113
|
const scale = getScale(scaleType, axisExtremums, range);
|
|
114
114
|
const finalScale = domainLimit === 'nice' ? scale.nice(rawTickNumber) : scale;
|
|
115
115
|
const [minDomain, maxDomain] = finalScale.domain();
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export function getTickNumber(params) {
|
|
2
|
+
const {
|
|
3
|
+
tickMaxStep,
|
|
4
|
+
tickMinStep,
|
|
5
|
+
tickNumber,
|
|
6
|
+
range,
|
|
7
|
+
domain
|
|
8
|
+
} = params;
|
|
9
|
+
const maxTicks = tickMinStep === undefined ? 999 : Math.floor(Math.abs(domain[1] - domain[0]) / tickMinStep);
|
|
10
|
+
const minTicks = tickMaxStep === undefined ? 2 : Math.ceil(Math.abs(domain[1] - domain[0]) / tickMaxStep);
|
|
11
|
+
const defaultizedTickNumber = tickNumber ?? Math.floor(Math.abs(range[1] - range[0]) / 50);
|
|
12
|
+
return Math.min(maxTicks, Math.max(minTicks, defaultizedTickNumber));
|
|
13
|
+
}
|
|
14
|
+
export function scaleTickNumberByRange(tickNumber, range) {
|
|
15
|
+
const rangeGap = range[1] - range[0];
|
|
16
|
+
|
|
17
|
+
/* If the range start and end are the same, `tickNumber` will become infinity, so we default to 1. */
|
|
18
|
+
if (rangeGap === 0) {
|
|
19
|
+
return 1;
|
|
20
|
+
}
|
|
21
|
+
return tickNumber / ((range[1] - range[0]) / 100);
|
|
22
|
+
}
|
package/hooks/useTicks.d.ts
CHANGED
|
@@ -40,10 +40,6 @@ export interface TickParams {
|
|
|
40
40
|
*/
|
|
41
41
|
tickLabelPlacement?: 'middle' | 'tick';
|
|
42
42
|
}
|
|
43
|
-
export declare function getTickNumber(params: TickParams & {
|
|
44
|
-
range: number[];
|
|
45
|
-
domain: any[];
|
|
46
|
-
}): number;
|
|
47
43
|
export type TickItemType = {
|
|
48
44
|
/**
|
|
49
45
|
* This property is undefined only if it's the tick closing the last band
|
|
@@ -56,4 +52,5 @@ export type TickItemType = {
|
|
|
56
52
|
export declare function useTicks(options: {
|
|
57
53
|
scale: D3Scale;
|
|
58
54
|
valueFormatter?: AxisConfig['valueFormatter'];
|
|
55
|
+
direction: 'x' | 'y';
|
|
59
56
|
} & Pick<TickParams, 'tickNumber' | 'tickInterval' | 'tickPlacement' | 'tickLabelPlacement'>): TickItemType[];
|
package/hooks/useTicks.js
CHANGED
|
@@ -5,24 +5,11 @@ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWild
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.getTickNumber = getTickNumber;
|
|
9
8
|
exports.useTicks = useTicks;
|
|
10
9
|
var React = _interopRequireWildcard(require("react"));
|
|
10
|
+
var _ChartProvider = require("../context/ChartProvider");
|
|
11
11
|
var _isBandScale = require("../internals/isBandScale");
|
|
12
12
|
var _isInfinity = require("../internals/isInfinity");
|
|
13
|
-
function getTickNumber(params) {
|
|
14
|
-
const {
|
|
15
|
-
tickMaxStep,
|
|
16
|
-
tickMinStep,
|
|
17
|
-
tickNumber,
|
|
18
|
-
range,
|
|
19
|
-
domain
|
|
20
|
-
} = params;
|
|
21
|
-
const maxTicks = tickMinStep === undefined ? 999 : Math.floor(Math.abs(domain[1] - domain[0]) / tickMinStep);
|
|
22
|
-
const minTicks = tickMaxStep === undefined ? 2 : Math.ceil(Math.abs(domain[1] - domain[0]) / tickMaxStep);
|
|
23
|
-
const defaultizedTickNumber = tickNumber ?? Math.floor(Math.abs(range[1] - range[0]) / 50);
|
|
24
|
-
return Math.min(maxTicks, Math.max(minTicks, defaultizedTickNumber));
|
|
25
|
-
}
|
|
26
13
|
const offsetRatio = {
|
|
27
14
|
start: 0,
|
|
28
15
|
extremities: 0,
|
|
@@ -36,8 +23,12 @@ function useTicks(options) {
|
|
|
36
23
|
valueFormatter,
|
|
37
24
|
tickInterval,
|
|
38
25
|
tickPlacement = 'extremities',
|
|
39
|
-
tickLabelPlacement: tickLabelPlacementProp
|
|
26
|
+
tickLabelPlacement: tickLabelPlacementProp,
|
|
27
|
+
direction
|
|
40
28
|
} = options;
|
|
29
|
+
const {
|
|
30
|
+
instance
|
|
31
|
+
} = (0, _ChartProvider.useChartContext)();
|
|
41
32
|
return React.useMemo(() => {
|
|
42
33
|
// band scale
|
|
43
34
|
if ((0, _isBandScale.isBandScale)(scale)) {
|
|
@@ -81,18 +72,31 @@ function useTicks(options) {
|
|
|
81
72
|
}
|
|
82
73
|
const tickLabelPlacement = tickLabelPlacementProp;
|
|
83
74
|
const ticks = typeof tickInterval === 'object' ? tickInterval : scale.ticks(tickNumber);
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
|
|
75
|
+
|
|
76
|
+
// Ticks inside the drawing area
|
|
77
|
+
const visibleTicks = [];
|
|
78
|
+
for (let i = 0; i < ticks.length; i += 1) {
|
|
79
|
+
const value = ticks[i];
|
|
80
|
+
const offset = scale(value);
|
|
81
|
+
if (instance.isPointInside({
|
|
82
|
+
x: offset,
|
|
83
|
+
y: offset
|
|
84
|
+
}, {
|
|
85
|
+
direction
|
|
86
|
+
})) {
|
|
87
|
+
visibleTicks.push({
|
|
88
|
+
value,
|
|
89
|
+
formattedValue: valueFormatter?.(value, {
|
|
90
|
+
location: 'tick',
|
|
91
|
+
scale
|
|
92
|
+
}) ?? scale.tickFormat(tickNumber)(value),
|
|
93
|
+
offset,
|
|
94
|
+
// Allowing the label to be placed in the middle of a continuous scale is weird.
|
|
95
|
+
// But it is useful in some cases, like funnel categories with a linear scale.
|
|
96
|
+
labelOffset: tickLabelPlacement === 'middle' ? scale(ticks[i - 1] ?? 0) - (offset + scale(ticks[i - 1] ?? 0)) / 2 : 0
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return visibleTicks;
|
|
101
|
+
}, [scale, tickLabelPlacementProp, tickInterval, tickNumber, tickPlacement, valueFormatter, direction, instance]);
|
|
98
102
|
}
|
package/index.js
CHANGED
|
@@ -9,7 +9,7 @@ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")
|
|
|
9
9
|
var _d3Scale = require("@mui/x-charts-vendor/d3-scale");
|
|
10
10
|
var _axis = require("../../../../models/axis");
|
|
11
11
|
var _colorScale = require("../../../colorScale");
|
|
12
|
-
var
|
|
12
|
+
var _ticks = require("../../../ticks");
|
|
13
13
|
var _getScale = require("../../../getScale");
|
|
14
14
|
var _zoom = require("./zoom");
|
|
15
15
|
var _getAxisExtremum = require("./getAxisExtremum");
|
|
@@ -117,11 +117,11 @@ function computeAxisValue({
|
|
|
117
117
|
axisExtremums[0] = min;
|
|
118
118
|
axisExtremums[1] = max;
|
|
119
119
|
}
|
|
120
|
-
const rawTickNumber = (0,
|
|
120
|
+
const rawTickNumber = (0, _ticks.getTickNumber)((0, _extends2.default)({}, axis, {
|
|
121
121
|
range,
|
|
122
122
|
domain: axisExtremums
|
|
123
123
|
}));
|
|
124
|
-
const tickNumber =
|
|
124
|
+
const tickNumber = (0, _ticks.scaleTickNumberByRange)(rawTickNumber, zoomRange);
|
|
125
125
|
const zoomedRange = (0, _zoom.zoomScaleRange)(range, zoomRange);
|
|
126
126
|
const scale = (0, _getScale.getScale)(scaleType, axisExtremums, zoomedRange);
|
|
127
127
|
const finalScale = domainLimit === 'nice' ? scale.nice(rawTickNumber) : scale;
|
|
@@ -9,7 +9,7 @@ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")
|
|
|
9
9
|
var _d3Scale = require("@mui/x-charts-vendor/d3-scale");
|
|
10
10
|
var _axis = require("../../../../models/axis");
|
|
11
11
|
var _colorScale = require("../../../colorScale");
|
|
12
|
-
var
|
|
12
|
+
var _ticks = require("../../../ticks");
|
|
13
13
|
var _getScale = require("../../../getScale");
|
|
14
14
|
var _getAxisExtremum = require("./getAxisExtremum");
|
|
15
15
|
var _angleConversion = require("../../../angleConversion");
|
|
@@ -112,11 +112,11 @@ function computeAxisValue({
|
|
|
112
112
|
axisExtremums[0] = min;
|
|
113
113
|
axisExtremums[1] = max;
|
|
114
114
|
}
|
|
115
|
-
const rawTickNumber = (0,
|
|
115
|
+
const rawTickNumber = (0, _ticks.getTickNumber)((0, _extends2.default)({}, axis, {
|
|
116
116
|
range,
|
|
117
117
|
domain: axisExtremums
|
|
118
118
|
}));
|
|
119
|
-
const tickNumber =
|
|
119
|
+
const tickNumber = (0, _ticks.scaleTickNumberByRange)(rawTickNumber, range);
|
|
120
120
|
const scale = (0, _getScale.getScale)(scaleType, axisExtremums, range);
|
|
121
121
|
const finalScale = domainLimit === 'nice' ? scale.nice(rawTickNumber) : scale;
|
|
122
122
|
const [minDomain, maxDomain] = finalScale.domain();
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getTickNumber = getTickNumber;
|
|
7
|
+
exports.scaleTickNumberByRange = scaleTickNumberByRange;
|
|
8
|
+
function getTickNumber(params) {
|
|
9
|
+
const {
|
|
10
|
+
tickMaxStep,
|
|
11
|
+
tickMinStep,
|
|
12
|
+
tickNumber,
|
|
13
|
+
range,
|
|
14
|
+
domain
|
|
15
|
+
} = params;
|
|
16
|
+
const maxTicks = tickMinStep === undefined ? 999 : Math.floor(Math.abs(domain[1] - domain[0]) / tickMinStep);
|
|
17
|
+
const minTicks = tickMaxStep === undefined ? 2 : Math.ceil(Math.abs(domain[1] - domain[0]) / tickMaxStep);
|
|
18
|
+
const defaultizedTickNumber = tickNumber ?? Math.floor(Math.abs(range[1] - range[0]) / 50);
|
|
19
|
+
return Math.min(maxTicks, Math.max(minTicks, defaultizedTickNumber));
|
|
20
|
+
}
|
|
21
|
+
function scaleTickNumberByRange(tickNumber, range) {
|
|
22
|
+
const rangeGap = range[1] - range[0];
|
|
23
|
+
|
|
24
|
+
/* If the range start and end are the same, `tickNumber` will become infinity, so we default to 1. */
|
|
25
|
+
if (rangeGap === 0) {
|
|
26
|
+
return 1;
|
|
27
|
+
}
|
|
28
|
+
return tickNumber / ((range[1] - range[0]) / 100);
|
|
29
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/x-charts",
|
|
3
|
-
"version": "8.3.
|
|
3
|
+
"version": "8.3.1",
|
|
4
4
|
"author": "MUI Team",
|
|
5
5
|
"description": "The community edition of MUI X Charts components.",
|
|
6
6
|
"main": "./index.js",
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
"prop-types": "^15.8.1",
|
|
37
37
|
"reselect": "^5.1.1",
|
|
38
38
|
"use-sync-external-store": "^1.5.0",
|
|
39
|
-
"@mui/x-
|
|
40
|
-
"@mui/x-
|
|
39
|
+
"@mui/x-internals": "8.3.1",
|
|
40
|
+
"@mui/x-charts-vendor": "8.3.1"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
43
|
"@emotion/react": "^11.9.0",
|