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 4 commits
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
13 changes: 10 additions & 3 deletions src/core/core.ticks.js
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.toString().length - 2);
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(Math.round((niceMin + j * spacing) * precision) / precision);
}
ticks.push(generationOptions.max !== undefined ? generationOptions.max : niceMax);

Expand Down Expand Up @@ -121,6 +126,7 @@ module.exports = {
exp = Math.floor(helpers.log10(tickVal));
significand = Math.floor(tickVal / Math.pow(10, exp));
}
var precision = exp < 0 ? Math.pow(10, Math.abs(exp)) : 1;

do {
ticks.push(tickVal);
Expand All @@ -129,9 +135,10 @@ module.exports = {
if (significand === 10) {
significand = 1;
++exp;
precision = exp >= 0 ? 1 : precision;
}

tickVal = significand * Math.pow(10, exp);
tickVal = Math.round(significand * Math.pow(10, exp) * precision) / precision;
} while (exp < endExp || (exp === endExp && significand < endSignificand));

var lastTick = valueOrDefault(generationOptions.max, tickVal);
Expand Down