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 issue #4928: linear tick generator doesn't round values to needed precision. #4943

Merged
merged 5 commits into from
Dec 2, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/core/core.ticks.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,15 @@ module.exports = {
numSpaces = Math.ceil(numSpaces);
}

// Put the values into the ticks array
var precision = 1;
if (spacing < 1) {
precision = Math.pow(10, spacing.toPrecision().length - 2);
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be equivalent to replace .toPrecision() with .toString()? I think that would make it clearer

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this case I think they both return equal results. Since the code is trying to find the number of significant digits after the decimal point.

niceMin = Math.round(niceMin * precision) / precision;
niceMax = Math.round(niceMax * precision) / precision;
}
ticks.push(generationOptions.min !== undefined ? generationOptions.min : niceMin);
for (var j = 1; j < numSpaces; ++j) {
ticks.push(niceMin + (j * spacing));
ticks.push(niceMin + Math.round(j * spacing * precision) / precision);
}
ticks.push(generationOptions.max !== undefined ? generationOptions.max : niceMax);

Expand Down