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

Fixes labelOffset not working for vertical axes #4249

Merged
merged 9 commits into from Jul 15, 2017

Conversation

suheb
Copy link
Contributor

@suheb suheb commented May 12, 2017

Signed-off-by: Suhaib Khan suheb.work@gmail.com

Fixes #3889
Example: https://codepen.io/anon/pen/EmEzKb

Signed-off-by: Suhaib Khan <suheb.work@gmail.com>
@etimberg
Copy link
Member

@suheb would it be possible to add some tests for this?

@etimberg etimberg added this to the Version 2.7 milestone May 21, 2017
@suheb
Copy link
Contributor Author

suheb commented May 23, 2017

@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.

@etimberg
Copy link
Member

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

@simonbrunel
Copy link
Member

Everything explained in #3988

Signed-off-by: Suhaib Khan <suheb.work@gmail.com>
@suheb
Copy link
Contributor Author

suheb commented May 24, 2017

@simonbrunel Thanks for the link, really helpful.
@etimberg I've added a basic test for this. Let me know if anything else is needed :)

@suheb
Copy link
Contributor Author

suheb commented May 26, 2017

@simonbrunel The test passes when I run the it using gulp unittest --watch --inputs=test/specs/{spec.name}.js. Not sure why it's failing in the travis build.

Copy link
Member

@simonbrunel simonbrunel left a 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:

image

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,
Copy link
Member

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

suheb added 3 commits May 26, 2017 22:44
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",
Copy link
Member

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.

Copy link
Member

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?

Copy link
Contributor Author

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".

Copy link
Member

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.

Copy link
Contributor Author

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. :/

suheb added 3 commits May 30, 2017 21:32
Signed-off-by: Suhaib Khan <suheb.work@gmail.com>
Signed-off-by: Suhaib Khan <suheb.work@gmail.com>
@etimberg
Copy link
Member

etimberg commented Jun 4, 2017

@simonbrunel is this good to merge?

@simonbrunel
Copy link
Member

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 helpers.aliasPixel, may be better to also remove the grid line at zero?

image

image

@suheb
Copy link
Contributor Author

suheb commented Jun 19, 2017

@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 :)

@suheb
Copy link
Contributor Author

suheb commented Jul 14, 2017

@simonbrunel @etimberg Is this ready to be merged? Let me know if any other changes are needed.

@simonbrunel
Copy link
Member

@suheb sorry for the delay, looks good to me, can you just remove: test/fixtures/core.scale/label-offset-vertical-axes.json~ (the one with the extra ~)?

Signed-off-by: Suhaib Khan <suheb.work@gmail.com>
@suheb
Copy link
Contributor Author

suheb commented Jul 14, 2017

@simonbrunel Ah! Not sure how that file got added. Just removed it :)

Copy link
Member

@simonbrunel simonbrunel left a comment

Choose a reason for hiding this comment

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

Thanks!

@simonbrunel simonbrunel merged commit b03ab1c into chartjs:master Jul 15, 2017
yofreke pushed a commit to yofreke/Chart.js that referenced this pull request Dec 30, 2017
exwm pushed a commit to exwm/Chart.js that referenced this pull request Apr 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants