Skip to content

Commit

Permalink
requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
kurkle committed Jan 6, 2019
1 parent 9b69423 commit 7242e74
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/scales/scale.linearbase.js
Expand Up @@ -3,6 +3,8 @@
var helpers = require('../helpers/index');
var Scale = require('../core/core.scale');

var isNullOrUndef = helpers.isNullOrUndef;

/**
* Generate a set of linear ticks
* @param generationOptions the options used to generate the ticks
Expand All @@ -15,25 +17,20 @@ function generateTicks(generationOptions, dataRange) {
// "nice number" algorithm. See https://stackoverflow.com/questions/8506881/nice-label-algorithm-for-charts-with-minimum-ticks
// for details.

// Minimum spacing between ticks
var MIN_SPACING = 1e-14;
var stepSize = generationOptions.stepSize;
var unit = stepSize || 1;
var maxNumSpaces = generationOptions.maxTicks - 1;
var min = generationOptions.min;
var max = generationOptions.max;
var precision = generationOptions.precision;
var spacing, factor, niceMin, niceMax, numSpaces;

var rmin = dataRange.min;
var rmax = dataRange.max;
var isNullOrUndef = helpers.isNullOrUndef;

// spacing is set to a nice number of the dataRange divided by maxNumSpaces.
// stepSize is used as a minimum unit if it is specified.
spacing = helpers.niceNum((rmax - rmin) / maxNumSpaces / unit) * unit;
var spacing = helpers.niceNum((rmax - rmin) / maxNumSpaces / unit) * unit;
var factor, niceMin, niceMax, numSpaces;

// In case of really small numbers and min / max are undefined, default to rmin / rmax
// Beyond MIN_SPACING floating point numbers being to lose precision
// such that we can't do the math necessary to generate ticks
if (spacing < MIN_SPACING && isNullOrUndef(min) && isNullOrUndef(max)) {
return [rmin, rmax];
}
Expand Down

0 comments on commit 7242e74

Please sign in to comment.