Use tick step to calculate a smarter _getFormat when values are small.

Thanks to flot library for algorithm (https://github.com/flot/flot/blob/master/jquery.flot.js#L1696)

Closes #124.
master
Scott Stafford 2014-11-03 12:54:24 -05:00
parent ecadee96df
commit a89d33176e
2 changed files with 3 additions and 1 deletions

View File

@ -40,7 +40,7 @@
return (n === 0 ? 0 : d3.format(",." + dp + "f")(n / Math.pow(1000, chunks)) + suffix);
};
} else {
dp = (len <= 1 ? 1 : 0);
dp = -Math.floor(Math.log(this._tick_step) / Math.LN10);
returnFormat = d3.format(",." + dp + "f");
}
} else {

View File

@ -218,6 +218,8 @@
step = ticks[1] - ticks[0];
// Get the remainder
remainder = ((this._max - this._min) % step).toFixed(0);
// Store the tick step if needed to calculate _getFormat.
this._tick_step = step;
// If the remainder is not zero
if (remainder !== 0) {