Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[charts] Use new text component to avoid tick label overflow on x-axis #10648

Merged
merged 25 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/data/charts/lines/CSSCustomization.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export default function CSSCustomization() {
id: 'Years',
data: years,
scaleType: 'time',
valueFormatter: (date) => date.getFullYear(),
valueFormatter: (date) => date.getFullYear().toString(),
},
]}
series={[
Expand Down
2 changes: 1 addition & 1 deletion docs/data/charts/lines/CSSCustomization.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export default function CSSCustomization() {
id: 'Years',
data: years,
scaleType: 'time',
valueFormatter: (date) => date.getFullYear(),
valueFormatter: (date) => date.getFullYear().toString(),
},
]}
series={[
Expand Down
2 changes: 1 addition & 1 deletion docs/data/charts/lines/StackedAreas.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export default function StackedAreas() {
id: 'Years',
data: years,
scaleType: 'time',
valueFormatter: (date) => date.getFullYear(),
valueFormatter: (date) => date.getFullYear().toString(),
},
]}
series={[
Expand Down
2 changes: 1 addition & 1 deletion docs/data/charts/lines/StackedAreas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export default function StackedAreas() {
id: 'Years',
data: years,
scaleType: 'time',
valueFormatter: (date) => date.getFullYear(),
valueFormatter: (date) => date.getFullYear().toString(),
},
]}
series={[
Expand Down
22 changes: 10 additions & 12 deletions docs/data/charts/stacking/StackOrderDemo.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import TextField from '@mui/material/TextField';
import MenuItem from '@mui/material/MenuItem';
import { BarChart } from '@mui/x-charts/BarChart';

import { axisClasses } from '@mui/x-charts/ChartsAxis';

// Data comming from https://www.insee.fr/fr/statistiques/5013868
const commonTransportation = [
6.5, 12.5, 17.2, 19.6, 20.1, 20.0, 19.5, 18.8, 18.2, 17.3, 16.4, 15.9, 15.2, 14.7,
Expand Down Expand Up @@ -110,22 +108,22 @@ export default function StackOrderDemo() {
<BarChart
width={700}
height={300}
xAxis={[xAxis]}
yAxis={[{ min: 0, max: 100 }]}
series={modifiedSeries}
margin={{ bottom: 70 }}
sx={{
[`.${axisClasses.bottom}`]: {
[`.${axisClasses.tickLabel}`]: {
transform: 'rotate(45deg)',
xAxis={[
{
...xAxis,
tickLabelStyle: {
angle: 45,
dominantBaseline: 'hanging',
textAnchor: 'start',
},
[`.${axisClasses.label}`]: {
labelStyle: {
transform: 'translateY(15px)',
},
},
}}
]}
yAxis={[{ min: 0, max: 100 }]}
series={modifiedSeries}
margin={{ bottom: 70 }}
/>
</Box>
</Box>
Expand Down
21 changes: 10 additions & 11 deletions docs/data/charts/stacking/StackOrderDemo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import TextField from '@mui/material/TextField';
import MenuItem from '@mui/material/MenuItem';
import { BarChart } from '@mui/x-charts/BarChart';
import { StackOrderType } from '@mui/x-charts/models';
import { axisClasses } from '@mui/x-charts/ChartsAxis';

// Data comming from https://www.insee.fr/fr/statistiques/5013868
const commonTransportation = [
Expand Down Expand Up @@ -105,22 +104,22 @@ export default function StackOrderDemo() {
<BarChart
width={700}
height={300}
xAxis={[xAxis]}
yAxis={[{ min: 0, max: 100 }]}
series={modifiedSeries}
margin={{ bottom: 70 }}
sx={{
[`.${axisClasses.bottom}`]: {
[`.${axisClasses.tickLabel}`]: {
transform: 'rotate(45deg)',
xAxis={[
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically here all the styling is moved in the axis properties

{
...xAxis,
tickLabelStyle: {
angle: 45,
dominantBaseline: 'hanging',
textAnchor: 'start',
},
[`.${axisClasses.label}`]: {
labelStyle: {
transform: 'translateY(15px)',
},
},
}}
]}
yAxis={[{ min: 0, max: 100 }]}
series={modifiedSeries}
margin={{ bottom: 70 }}
/>
</Box>
</Box>
Expand Down
8 changes: 4 additions & 4 deletions docs/pages/x/api/charts/bar-chart.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"bottomAxis": {
"type": {
"name": "union",
"description": "{ axisId: string, classes?: object, disableLine?: bool, disableTicks?: bool, fill?: string, label?: string, labelFontSize?: number, position?: 'bottom'<br>&#124;&nbsp;'top', slotProps?: object, slots?: object, stroke?: string, tickFontSize?: number, tickMaxStep?: number, tickMinStep?: number, tickNumber?: number, tickSize?: number }<br>&#124;&nbsp;string"
"description": "{ axisId: string, classes?: object, disableLine?: bool, disableTicks?: bool, fill?: string, label?: string, labelFontSize?: number, labelStyle?: object, position?: 'bottom'<br>&#124;&nbsp;'top', slotProps?: object, slots?: object, stroke?: string, tickFontSize?: number, tickInterval?: 'auto'<br>&#124;&nbsp;func, tickLabelInterval?: 'auto'<br>&#124;&nbsp;func, tickLabelStyle?: object, tickMaxStep?: number, tickMinStep?: number, tickNumber?: number, tickSize?: number }<br>&#124;&nbsp;string"
},
"default": "xAxisIds[0] The id of the first provided axis"
},
Expand All @@ -13,14 +13,14 @@
"leftAxis": {
"type": {
"name": "union",
"description": "{ axisId: string, classes?: object, disableLine?: bool, disableTicks?: bool, fill?: string, label?: string, labelFontSize?: number, position?: 'left'<br>&#124;&nbsp;'right', slotProps?: object, slots?: object, stroke?: string, tickFontSize?: number, tickMaxStep?: number, tickMinStep?: number, tickNumber?: number, tickSize?: number }<br>&#124;&nbsp;string"
"description": "{ axisId: string, classes?: object, disableLine?: bool, disableTicks?: bool, fill?: string, label?: string, labelFontSize?: number, labelStyle?: object, position?: 'left'<br>&#124;&nbsp;'right', slotProps?: object, slots?: object, stroke?: string, tickFontSize?: number, tickInterval?: 'auto'<br>&#124;&nbsp;func, tickLabelInterval?: 'auto'<br>&#124;&nbsp;func, tickLabelStyle?: object, tickMaxStep?: number, tickMinStep?: number, tickNumber?: number, tickSize?: number }<br>&#124;&nbsp;string"
},
"default": "yAxisIds[0] The id of the first provided axis"
},
"rightAxis": {
"type": {
"name": "union",
"description": "{ axisId: string, classes?: object, disableLine?: bool, disableTicks?: bool, fill?: string, label?: string, labelFontSize?: number, position?: 'left'<br>&#124;&nbsp;'right', slotProps?: object, slots?: object, stroke?: string, tickFontSize?: number, tickMaxStep?: number, tickMinStep?: number, tickNumber?: number, tickSize?: number }<br>&#124;&nbsp;string"
"description": "{ axisId: string, classes?: object, disableLine?: bool, disableTicks?: bool, fill?: string, label?: string, labelFontSize?: number, labelStyle?: object, position?: 'left'<br>&#124;&nbsp;'right', slotProps?: object, slots?: object, stroke?: string, tickFontSize?: number, tickInterval?: 'auto'<br>&#124;&nbsp;func, tickLabelInterval?: 'auto'<br>&#124;&nbsp;func, tickLabelStyle?: object, tickMaxStep?: number, tickMinStep?: number, tickNumber?: number, tickSize?: number }<br>&#124;&nbsp;string"
},
"default": "null"
},
Expand All @@ -29,7 +29,7 @@
"topAxis": {
"type": {
"name": "union",
"description": "{ axisId: string, classes?: object, disableLine?: bool, disableTicks?: bool, fill?: string, label?: string, labelFontSize?: number, position?: 'bottom'<br>&#124;&nbsp;'top', slotProps?: object, slots?: object, stroke?: string, tickFontSize?: number, tickMaxStep?: number, tickMinStep?: number, tickNumber?: number, tickSize?: number }<br>&#124;&nbsp;string"
"description": "{ axisId: string, classes?: object, disableLine?: bool, disableTicks?: bool, fill?: string, label?: string, labelFontSize?: number, labelStyle?: object, position?: 'bottom'<br>&#124;&nbsp;'top', slotProps?: object, slots?: object, stroke?: string, tickFontSize?: number, tickInterval?: 'auto'<br>&#124;&nbsp;func, tickLabelInterval?: 'auto'<br>&#124;&nbsp;func, tickLabelStyle?: object, tickMaxStep?: number, tickMinStep?: number, tickNumber?: number, tickSize?: number }<br>&#124;&nbsp;string"
},
"default": "null"
}
Expand Down
8 changes: 4 additions & 4 deletions docs/pages/x/api/charts/charts-axis.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
"bottomAxis": {
"type": {
"name": "union",
"description": "{ axisId: string, classes?: object, disableLine?: bool, disableTicks?: bool, fill?: string, label?: string, labelFontSize?: number, position?: 'bottom'<br>&#124;&nbsp;'top', slotProps?: object, slots?: object, stroke?: string, tickFontSize?: number, tickMaxStep?: number, tickMinStep?: number, tickNumber?: number, tickSize?: number }<br>&#124;&nbsp;string"
"description": "{ axisId: string, classes?: object, disableLine?: bool, disableTicks?: bool, fill?: string, label?: string, labelFontSize?: number, labelStyle?: object, position?: 'bottom'<br>&#124;&nbsp;'top', slotProps?: object, slots?: object, stroke?: string, tickFontSize?: number, tickInterval?: 'auto'<br>&#124;&nbsp;func, tickLabelInterval?: 'auto'<br>&#124;&nbsp;func, tickLabelStyle?: object, tickMaxStep?: number, tickMinStep?: number, tickNumber?: number, tickSize?: number }<br>&#124;&nbsp;string"
},
"default": "xAxisIds[0] The id of the first provided axis"
},
"leftAxis": {
"type": {
"name": "union",
"description": "{ axisId: string, classes?: object, disableLine?: bool, disableTicks?: bool, fill?: string, label?: string, labelFontSize?: number, position?: 'left'<br>&#124;&nbsp;'right', slotProps?: object, slots?: object, stroke?: string, tickFontSize?: number, tickMaxStep?: number, tickMinStep?: number, tickNumber?: number, tickSize?: number }<br>&#124;&nbsp;string"
"description": "{ axisId: string, classes?: object, disableLine?: bool, disableTicks?: bool, fill?: string, label?: string, labelFontSize?: number, labelStyle?: object, position?: 'left'<br>&#124;&nbsp;'right', slotProps?: object, slots?: object, stroke?: string, tickFontSize?: number, tickInterval?: 'auto'<br>&#124;&nbsp;func, tickLabelInterval?: 'auto'<br>&#124;&nbsp;func, tickLabelStyle?: object, tickMaxStep?: number, tickMinStep?: number, tickNumber?: number, tickSize?: number }<br>&#124;&nbsp;string"
},
"default": "yAxisIds[0] The id of the first provided axis"
},
"rightAxis": {
"type": {
"name": "union",
"description": "{ axisId: string, classes?: object, disableLine?: bool, disableTicks?: bool, fill?: string, label?: string, labelFontSize?: number, position?: 'left'<br>&#124;&nbsp;'right', slotProps?: object, slots?: object, stroke?: string, tickFontSize?: number, tickMaxStep?: number, tickMinStep?: number, tickNumber?: number, tickSize?: number }<br>&#124;&nbsp;string"
"description": "{ axisId: string, classes?: object, disableLine?: bool, disableTicks?: bool, fill?: string, label?: string, labelFontSize?: number, labelStyle?: object, position?: 'left'<br>&#124;&nbsp;'right', slotProps?: object, slots?: object, stroke?: string, tickFontSize?: number, tickInterval?: 'auto'<br>&#124;&nbsp;func, tickLabelInterval?: 'auto'<br>&#124;&nbsp;func, tickLabelStyle?: object, tickMaxStep?: number, tickMinStep?: number, tickNumber?: number, tickSize?: number }<br>&#124;&nbsp;string"
},
"default": "null"
},
Expand All @@ -26,7 +26,7 @@
"topAxis": {
"type": {
"name": "union",
"description": "{ axisId: string, classes?: object, disableLine?: bool, disableTicks?: bool, fill?: string, label?: string, labelFontSize?: number, position?: 'bottom'<br>&#124;&nbsp;'top', slotProps?: object, slots?: object, stroke?: string, tickFontSize?: number, tickMaxStep?: number, tickMinStep?: number, tickNumber?: number, tickSize?: number }<br>&#124;&nbsp;string"
"description": "{ axisId: string, classes?: object, disableLine?: bool, disableTicks?: bool, fill?: string, label?: string, labelFontSize?: number, labelStyle?: object, position?: 'bottom'<br>&#124;&nbsp;'top', slotProps?: object, slots?: object, stroke?: string, tickFontSize?: number, tickInterval?: 'auto'<br>&#124;&nbsp;func, tickLabelInterval?: 'auto'<br>&#124;&nbsp;func, tickLabelStyle?: object, tickMaxStep?: number, tickMinStep?: number, tickNumber?: number, tickSize?: number }<br>&#124;&nbsp;string"
},
"default": "null"
}
Expand Down
24 changes: 22 additions & 2 deletions docs/pages/x/api/charts/charts-x-axis.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,32 @@
"disableTicks": { "type": { "name": "bool" } },
"fill": { "type": { "name": "string" }, "default": "'currentColor'" },
"label": { "type": { "name": "string" } },
"labelFontSize": { "type": { "name": "number" }, "default": "14" },
"labelFontSize": {
"type": { "name": "number" },
"default": "14",
"deprecated": true,
"deprecationInfo": "You can us <code>labelStyle.fontSize</code> instead."
},
"labelStyle": { "type": { "name": "object" } },
"position": { "type": { "name": "enum", "description": "'bottom'<br>&#124;&nbsp;'top'" } },
"slotProps": { "type": { "name": "object" }, "default": "{}" },
"slots": { "type": { "name": "object" }, "default": "{}" },
"stroke": { "type": { "name": "string" }, "default": "'currentColor'" },
"tickFontSize": { "type": { "name": "number" }, "default": "12" },
"tickFontSize": {
"type": { "name": "number" },
"default": "12",
"deprecated": true,
"deprecationInfo": "You can us <code>tickLabelStyle.fontSize</code> instead."
},
"tickInterval": {
"type": { "name": "union", "description": "'auto'<br>&#124;&nbsp;func" },
"default": "'auto'"
},
"tickLabelInterval": {
"type": { "name": "union", "description": "'auto'<br>&#124;&nbsp;func" },
"default": "'auto'"
},
"tickLabelStyle": { "type": { "name": "object" } },
"tickMaxStep": { "type": { "name": "number" } },
"tickMinStep": { "type": { "name": "number" } },
"tickNumber": { "type": { "name": "number" } },
Expand Down
24 changes: 22 additions & 2 deletions docs/pages/x/api/charts/charts-y-axis.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,32 @@
"disableTicks": { "type": { "name": "bool" } },
"fill": { "type": { "name": "string" }, "default": "'currentColor'" },
"label": { "type": { "name": "string" } },
"labelFontSize": { "type": { "name": "number" }, "default": "14" },
"labelFontSize": {
"type": { "name": "number" },
"default": "14",
"deprecated": true,
"deprecationInfo": "You can us <code>labelStyle.fontSize</code> instead."
},
"labelStyle": { "type": { "name": "object" } },
"position": { "type": { "name": "enum", "description": "'left'<br>&#124;&nbsp;'right'" } },
"slotProps": { "type": { "name": "object" }, "default": "{}" },
"slots": { "type": { "name": "object" }, "default": "{}" },
"stroke": { "type": { "name": "string" }, "default": "'currentColor'" },
"tickFontSize": { "type": { "name": "number" }, "default": "12" },
"tickFontSize": {
"type": { "name": "number" },
"default": "12",
"deprecated": true,
"deprecationInfo": "You can us <code>tickLabelStyle.fontSize</code> instead."
},
"tickInterval": {
"type": { "name": "union", "description": "'auto'<br>&#124;&nbsp;func" },
"default": "'auto'"
},
"tickLabelInterval": {
"type": { "name": "union", "description": "'auto'<br>&#124;&nbsp;func" },
"default": "'auto'"
},
"tickLabelStyle": { "type": { "name": "object" } },
"tickMaxStep": { "type": { "name": "number" } },
"tickMinStep": { "type": { "name": "number" } },
"tickNumber": { "type": { "name": "number" } },
Expand Down
8 changes: 4 additions & 4 deletions docs/pages/x/api/charts/line-chart.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"bottomAxis": {
"type": {
"name": "union",
"description": "{ axisId: string, classes?: object, disableLine?: bool, disableTicks?: bool, fill?: string, label?: string, labelFontSize?: number, position?: 'bottom'<br>&#124;&nbsp;'top', slotProps?: object, slots?: object, stroke?: string, tickFontSize?: number, tickMaxStep?: number, tickMinStep?: number, tickNumber?: number, tickSize?: number }<br>&#124;&nbsp;string"
"description": "{ axisId: string, classes?: object, disableLine?: bool, disableTicks?: bool, fill?: string, label?: string, labelFontSize?: number, labelStyle?: object, position?: 'bottom'<br>&#124;&nbsp;'top', slotProps?: object, slots?: object, stroke?: string, tickFontSize?: number, tickInterval?: 'auto'<br>&#124;&nbsp;func, tickLabelInterval?: 'auto'<br>&#124;&nbsp;func, tickLabelStyle?: object, tickMaxStep?: number, tickMinStep?: number, tickNumber?: number, tickSize?: number }<br>&#124;&nbsp;string"
},
"default": "xAxisIds[0] The id of the first provided axis"
},
Expand All @@ -14,14 +14,14 @@
"leftAxis": {
"type": {
"name": "union",
"description": "{ axisId: string, classes?: object, disableLine?: bool, disableTicks?: bool, fill?: string, label?: string, labelFontSize?: number, position?: 'left'<br>&#124;&nbsp;'right', slotProps?: object, slots?: object, stroke?: string, tickFontSize?: number, tickMaxStep?: number, tickMinStep?: number, tickNumber?: number, tickSize?: number }<br>&#124;&nbsp;string"
"description": "{ axisId: string, classes?: object, disableLine?: bool, disableTicks?: bool, fill?: string, label?: string, labelFontSize?: number, labelStyle?: object, position?: 'left'<br>&#124;&nbsp;'right', slotProps?: object, slots?: object, stroke?: string, tickFontSize?: number, tickInterval?: 'auto'<br>&#124;&nbsp;func, tickLabelInterval?: 'auto'<br>&#124;&nbsp;func, tickLabelStyle?: object, tickMaxStep?: number, tickMinStep?: number, tickNumber?: number, tickSize?: number }<br>&#124;&nbsp;string"
},
"default": "yAxisIds[0] The id of the first provided axis"
},
"rightAxis": {
"type": {
"name": "union",
"description": "{ axisId: string, classes?: object, disableLine?: bool, disableTicks?: bool, fill?: string, label?: string, labelFontSize?: number, position?: 'left'<br>&#124;&nbsp;'right', slotProps?: object, slots?: object, stroke?: string, tickFontSize?: number, tickMaxStep?: number, tickMinStep?: number, tickNumber?: number, tickSize?: number }<br>&#124;&nbsp;string"
"description": "{ axisId: string, classes?: object, disableLine?: bool, disableTicks?: bool, fill?: string, label?: string, labelFontSize?: number, labelStyle?: object, position?: 'left'<br>&#124;&nbsp;'right', slotProps?: object, slots?: object, stroke?: string, tickFontSize?: number, tickInterval?: 'auto'<br>&#124;&nbsp;func, tickLabelInterval?: 'auto'<br>&#124;&nbsp;func, tickLabelStyle?: object, tickMaxStep?: number, tickMinStep?: number, tickNumber?: number, tickSize?: number }<br>&#124;&nbsp;string"
},
"default": "null"
},
Expand All @@ -30,7 +30,7 @@
"topAxis": {
"type": {
"name": "union",
"description": "{ axisId: string, classes?: object, disableLine?: bool, disableTicks?: bool, fill?: string, label?: string, labelFontSize?: number, position?: 'bottom'<br>&#124;&nbsp;'top', slotProps?: object, slots?: object, stroke?: string, tickFontSize?: number, tickMaxStep?: number, tickMinStep?: number, tickNumber?: number, tickSize?: number }<br>&#124;&nbsp;string"
"description": "{ axisId: string, classes?: object, disableLine?: bool, disableTicks?: bool, fill?: string, label?: string, labelFontSize?: number, labelStyle?: object, position?: 'bottom'<br>&#124;&nbsp;'top', slotProps?: object, slots?: object, stroke?: string, tickFontSize?: number, tickInterval?: 'auto'<br>&#124;&nbsp;func, tickLabelInterval?: 'auto'<br>&#124;&nbsp;func, tickLabelStyle?: object, tickMaxStep?: number, tickMinStep?: number, tickNumber?: number, tickSize?: number }<br>&#124;&nbsp;string"
},
"default": "null"
}
Expand Down
Loading
Loading