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
Fixes Label Array Tick alignment and Centering #5248
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -857,6 +857,11 @@ module.exports = function(Chart) { | |
|
||
var label = itemToDraw.label; | ||
if (helpers.isArray(label)) { | ||
if (label.length % 2 === 0) { | ||
context.translate(0, (-tickFont.size * (label.length / 2)) / 2); | ||
} else { | ||
context.translate(0, -tickFont.size * (label.length / 2)); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to use the line height (not only the font size) and it would be easier and faster to translate
|
||
for (var i = 0, y = 0; i < label.length; ++i) { | ||
// We just make sure the multiline element is a string here.. | ||
context.fillText('' + label[i], 0, y); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the reason for this if? If I understand correctly,
-tickFont.size * label.length 2
is half the height of the label so we should just move up by that amount. I think this is working around simply setting a different text baseline that would make the code cleanerThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason for that if is to check if there is an even amount of labels. If so then the labels get centered evenly since it would be a different calculation when compared to an odd amount of labels. I think you are meaning
-tickFont.size * label.length / 2
? I'm fairly new to the project but I think setting a different baseline could work as well like you said. Thank you for the review.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also don't understand why we need to handle odd/even amount of lines differently and based on your screenshot, it doesn't seem correct when there is 2 lines (I would expect the text centered on the bar):