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

Incorrect conversion of number to boolean #5209

Merged
merged 7 commits into from Jul 29, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/scales/scale.linearbase.js
Expand Up @@ -25,7 +25,7 @@ function generateTicks(generationOptions, dataRange) {
var niceMax = Math.ceil(dataRange.max / spacing) * spacing;

// If min, max and stepSize is set and they make an evenly spaced scale use it.
if (generationOptions.min && generationOptions.max && generationOptions.stepSize) {
if (generationOptions.min !== undefined && generationOptions.max !== undefined && generationOptions.stepSize !== undefined) {
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 wise to also check for NaN, infinite values, or values of other types. Perhaps if (!isNaN(generationOptions.min) && isFinite(generationOptions.min) ... )

Copy link
Contributor

Choose a reason for hiding this comment

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

I feel that if we were going to check for those values we should probably log an error or throw an exception or somehow tell the user they've passed in invalid values rather than just silently ignoring the parameters. And maybe we should have a single method to validate user options called in the constructor or something rather than placing that code here

But in any case I feel it's quite unlikely for a user to set their options to Infinity, so I'm not sure I would require it before merging this PR. It would be a nice thing to do and I wouldn't object to validating user options, but this seems like a positive change even without that further improvement, so I don't want to block this PR on it necessarily

Copy link
Member

Choose a reason for hiding this comment

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

At least we could check for undefined and null since setting null is quite common to ignore an option:

if (!helpers.isNullOrUndef(generationOptions.min) &&
    !helpers.isNullOrUndef(generationOptions.max) &&
    !helpers.isNullOrUndef(generationOptions.stepSize)  {
    // ...
}

// If very close to our whole number, use it.
if (helpers.almostWhole((generationOptions.max - generationOptions.min) / generationOptions.stepSize, spacing / 1000)) {
niceMin = generationOptions.min;
Expand Down