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
Changes from 1 commit
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
14 changes: 14 additions & 0 deletions packages/x-charts/src/internals/geometry.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const ANGLE_APPROX = 5; // Angle (in deg) for which we approximate the rectangle as perfectly horizontal/vertical

let warnedOnce = false;

/**
* Return the minimal translation along x-axis to avoid overflow of a rectangle of a given width, height, rotation.
alexfauquette marked this conversation as resolved.
Show resolved Hide resolved
* This assume that all rectangles have the same heightand angle are in -90, 90.
alexfauquette marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -9,6 +11,18 @@ const ANGLE_APPROX = 5; // Angle (in deg) for which we approximate the rectangle
* @param angle the rotation in degree.
LukasTy marked this conversation as resolved.
Show resolved Hide resolved
*/
export function getMinXTranslation(width: number, height: number, angle: number = 0) {
if (process.env.NODE_ENV !== 'production') {
if (!warnedOnce && angle > 90 && angle < -90) {
warnedOnce = true;
console.warn(
[
`MUI X: It seems you applied an angle larger that 90° to an axis text.`,
LukasTy marked this conversation as resolved.
Show resolved Hide resolved
`This could cause some text overlapping.`,
`If you encounter a uscase where it's needed, please open an issue.`,
alexfauquette marked this conversation as resolved.
Show resolved Hide resolved
].join('\n'),
);
}
}
const standardAngle = Math.min(
Math.abs(angle) % 180,
Math.abs((Math.abs(angle) % 180) - 180) % 180,
Expand Down
Loading