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

Set maxWidth during title draw to avoid overflow #3358

Merged
merged 2 commits into from
Sep 24, 2016
Merged

Set maxWidth during title draw to avoid overflow #3358

merged 2 commits into from
Sep 24, 2016

Conversation

dylan-kerr
Copy link
Contributor

CanvasRenderingContext2D.fillText() accepts a fourth parameter called maxWidth that sets the maximum width of the drawn text, enforced by scaling the entire line.

This commit uses the title element's layout dimensions to set maxWidth and avoid overflow outside of the canvas.

Example before and after screenshots:
image
image

I expect the same logic could be applied to axis labels, but it's not a problem I've run into.

CanvasRenderingContext2D.fillText() accepts a fourth parameter called maxWidth that sets the maximum width of the drawn text, enforced by scaling the entire line.

This commit uses the title element's layout dimensions to set maxWidth and avoid overflow outside of the canvas.
Copy link
Member

@etimberg etimberg left a comment

Choose a reason for hiding this comment

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

Looks good to me

@etimberg etimberg merged commit edc22ca into chartjs:master Sep 24, 2016
@dylan-kerr dylan-kerr deleted the fix/limit-title-length branch September 24, 2016 08:07
@simonbrunel simonbrunel added this to the Version 2.4 milestone Sep 24, 2016
exwm pushed a commit to exwm/Chart.js that referenced this pull request Apr 30, 2021
Set maxWidth during title draw to avoid overflow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants