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

fix #4216 when dataset empty, set scale min max to default if null #4258

Closed
wants to merge 1 commit into from

Conversation

xg-wang
Copy link
Contributor

@xg-wang xg-wang commented May 13, 2017

Currently, when dataset empty, we do not check whether min, max is null.
https://github.com/chartjs/Chart.js/blob/master/src/scales/scale.linear.js#L102-L128

Set it to default if null could prevent axis's ticks array being [0, NaN], which led to the issue #4216

@xg-wang
Copy link
Contributor Author

xg-wang commented May 13, 2017

Have no idea why

  • "Linear Scale Should ensure that the scale has a max and min that are not equal"
  • "Linear Scale Should get the correct pixel value for a point"
    failed.

me.min = isFinite(me.min) ? me.min : DEFAULT_MIN;
me.max = isFinite(me.max) ? me.max : DEFAULT_MAX;
me.min = (me.min && isFinite(me.min)) ? me.min : DEFAULT_MIN;
me.max = (me.max && isFinite(me.max)) ? me.max : DEFAULT_MAX;
Copy link
Member

Choose a reason for hiding this comment

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

Is it intentional to use DEFAULT_MAX if max === 0 (same for min)?

Copy link
Contributor Author

@xg-wang xg-wang May 14, 2017

Choose a reason for hiding this comment

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

Sorry, meant to be not null. Have modified the commit.

@@ -47,10 +47,10 @@ module.exports = function(Chart) {
}
}

if (me.min === me.max) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The previous commit is not enough. Say when we set min: 10 (whatever larger than default max), will result in me.min > me.max here but not processed correctly.
I changed this to be based on the opts' min setting if exists.

@xg-wang
Copy link
Contributor Author

xg-wang commented May 14, 2017

Just checked the two new failed tests, I guess they are set wrong. When I change the DEFAULT_MIN to be -1, the two tests will pass, but another test will fail.
Seems someone misunderstood what should be the default value (0 or -1).

Should I create another test here for the case when tick.min is set, max value should be larger than the config min value?

@simonbrunel simonbrunel added this to the Version 2.7 milestone May 14, 2017
@simonbrunel simonbrunel requested a review from etimberg May 14, 2017 09:04
@etimberg
Copy link
Member

etimberg commented Jul 1, 2017

Looks good to me. Just needs a rebase and we can merge

@xg-wang
Copy link
Contributor Author

xg-wang commented Jul 1, 2017

squashed into 1 commit

@benmccann
Copy link
Contributor

Looks like this got fixed in #4425

@etimberg
Copy link
Member

Closing per @benmccann's comment

@etimberg etimberg closed this Aug 10, 2017
@xg-wang xg-wang deleted the fix/horizontal_bar_label branch August 10, 2017 03:04
@simonbrunel simonbrunel removed this from the Version 2.7 milestone Aug 28, 2017
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

4 participants