-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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 labelOffset not working for vertical axes #4249
Conversation
Signed-off-by: Suhaib Khan <suheb.work@gmail.com>
@suheb would it be possible to add some tests for this? |
@etimberg Not sure how to test this as it effects the position where labels are drawn on chart. Are there any existing tests which check something similar to this? Maybe that'll me on this. |
there are some tests in https://github.com/chartjs/Chart.js/blob/master/test/specs/plugin.filler.tests.js that compare images generated from the canvas. This would be a good place to use that kind of tests. The baseline images are stored in https://github.com/chartjs/Chart.js/tree/master/test/fixtures/plugin.filler |
Everything explained in #3988 |
Signed-off-by: Suhaib Khan <suheb.work@gmail.com>
@simonbrunel Thanks for the link, really helpful. |
@simonbrunel The test passes when I run the it using |
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.
@suheb it fails for me locally:
Most of the time it's because of the font rendering that differs between platform/browser.
Setting tolerance
to 0.004 in label-offset-vertical-axes.json
works for me:
{
"tolerance": "0.004",
"config": {
// ...
}
}, | ||
"options": { | ||
"responsive": false, | ||
"spanGaps": true, |
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 would remove that options because it's not used by this test
Signed-off-by: Suhaib Khan <suheb.work@gmail.com>
Signed-off-by: Suhaib Khan <suheb.work@gmail.com>
Signed-off-by: Suhaib Khan <suheb.work@gmail.com>
@@ -0,0 +1,40 @@ | |||
{ | |||
"tolerance": "0.008", |
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.
0.008
might be too high, did you verify locally that the test fails if you temporary change "labelOffset": 25
to 20
? Maybe it worths a try to 0.005
, the lower the better :)
@etimberg I'm curious to know if there is a font that can be consistently rendered on all platforms/browsers that we could use for our unit tests.
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.
@simonbrunel not sure about a specific font. Maybe something monospace?
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.
@simonbrunel 0.008
is indeed too high. But the test does not fail (which it should) even at 0.004
if I change "labelOffset"
from 25
to 20
for short labels like "1", "2", "3", "4"
.
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.
Not sure what to do then :\ Unit tests must fail if labels are not correctly positioned, if it doesn't fail with short labels, simply use long labels to make the test relevant. Ideally, tolerance should be 0
(default is 0.001
), so pick the lowest value (with long labels) that passes on Travis but that easily fail if labelOffset
changes.
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.
@simonbrunel I tried using long labels but then the test was failing even at high tolerance due to different font rendering on browsers/platform. So I tried replacing text with unicode shapes instead and it's working fine for me locally on firefox and chrome (macOS 10.2.3) but still failing on travis. Moreover, I can't see the build log for the latest commit. :/
Signed-off-by: Suhaib Khan <suheb.work@gmail.com>
Signed-off-by: Suhaib Khan <suheb.work@gmail.com>
@simonbrunel is this good to merge? |
It fails locally and it seems because of the aliasing of the grid lines. @suheb that's weird you don't get the same result. I suspect the calls to |
@simonbrunel That's weird, seems to work fine on my local system. Anyway, I've removed the grid lines at zero to make it better. I hope this works fine now :) |
@simonbrunel @etimberg Is this ready to be merged? Let me know if any other changes are needed. |
@suheb sorry for the delay, looks good to me, can you just remove: |
Signed-off-by: Suhaib Khan <suheb.work@gmail.com>
@simonbrunel Ah! Not sure how that file got added. Just removed it :) |
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.
Thanks!
Signed-off-by: Suhaib Khan suheb.work@gmail.com
Fixes #3889
Example: https://codepen.io/anon/pen/EmEzKb