Skip to content

Commit

Permalink
get rid of the loop
Browse files Browse the repository at this point in the history
  • Loading branch information
kurkle committed Jan 3, 2019
1 parent 3f22d35 commit 0a68915
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/scales/scale.linearbase.js
Expand Up @@ -22,7 +22,6 @@ function generateTicks(generationOptions, dataRange) {
var max = generationOptions.max;
var precision = generationOptions.precision;
var spacing, factor, niceMin, niceMax, numSpaces;
var i = 0;

// spacing is set to a nice number of the dataRange divided by maxNumSpaces.
// stepSize is used as a minimum unit if it is specified.
Expand All @@ -42,15 +41,15 @@ function generateTicks(generationOptions, dataRange) {
spacing = Math.ceil(spacing * factor) / factor;
}

// Loop here is for the case when min / spacing === max / spacing
// This happens due to float inccuracy when min and max are really close to each other
// One case: min = 1.8548483304974972 and max = 1.8548483304974974
do {
niceMin = Math.floor(dataRange.min / spacing) * spacing;
niceMax = Math.ceil(dataRange.max / spacing) * spacing;
spacing *= 2;
} while (niceMin === niceMax && ++i < 8);
spacing /= 2;
niceMin = Math.floor(dataRange.min / spacing) * spacing;
niceMax = Math.ceil(dataRange.max / spacing) * spacing;

if (niceMin === niceMax) {
// This happens due to float inccuracy when min and max are really close to each other
// One case: min = 1.8548483304974972 and max = 1.8548483304974974
ticks.push(niceMin - helpers.EPSILON, niceMax, niceMax + helpers.EPSILON);
return ticks;
}

// If min, max and stepSize is set and they make an evenly spaced scale use it.
if (stepSize) {
Expand All @@ -73,6 +72,7 @@ function generateTicks(generationOptions, dataRange) {

niceMin = Math.round(niceMin * factor) / factor;
niceMax = Math.round(niceMax * factor) / factor;

ticks.push(helpers.isNullOrUndef(min) ? niceMin : min);
for (var j = 1; j < numSpaces; ++j) {
ticks.push(Math.round((niceMin + j * spacing) * factor) / factor);
Expand Down

0 comments on commit 0a68915

Please sign in to comment.