Skip to content

Commit

Permalink
Better solution
Browse files Browse the repository at this point in the history
  • Loading branch information
etimberg committed Jul 1, 2021
1 parent c30ddcc commit 46e32cd
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/helpers/helpers.math.js
Expand Up @@ -22,8 +22,10 @@ export const sign = Math.sign;
* @return {number}
*/
export function niceNum(range) {
const roundedRange = Math.round(range);
range = almostEquals(range, roundedRange, range / 1000) ? roundedRange : range;
const niceRange = Math.pow(10, Math.floor(log10(range)));
const fraction = range / niceRange - 0.000001;
const fraction = range / niceRange;
const niceFraction = fraction <= 1 ? 1 : fraction <= 2 ? 2 : fraction <= 5 ? 5 : 10;
return niceFraction * niceRange;
}
Expand Down

0 comments on commit 46e32cd

Please sign in to comment.