Created
December 27, 2016 03:19
-
-
Save fiftin/b0a217b5e4e8e8d1018ac7175358262e to your computer and use it in GitHub Desktop.
Best ticks for Y axis
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function bestTick(largest, mostticks) { | |
var minimum = largest / mostticks; | |
var magnitude = Math.pow(10, Math.floor(Math.log(minimum) / Math.log(10))); | |
var residual = minimum / magnitude; | |
var tick; | |
if (residual > 5) { | |
tick = 10 * magnitude; | |
} else if (residual > 2) { | |
tick = 5 * magnitude; | |
} else if (residual > 1) { | |
tick = 2 * magnitude; | |
} else { | |
tick = magnitude; | |
} | |
return tick; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment