基于d3.js 不清楚也没关系
function calc(max, min, countHint){
span = max-min;
step = Math.pow(10, Math.floor(Math.log(span / countHint) / Math.LN10));
err = countHint / span * step;
// Filter ticks to get closer to the desired count.
if err <= .15 then step *= 10
else if err <= .35 then step *= 5
else if err <= .75 then step *= 2
return step;
}
calc(300,100,6);
有没有人看懂啊?为什么 求 step 这么复杂,到底在算什么?
Math.log(num) / Math.LN10
这个函数其他地方也出现过,是为了干嘛的?
数学问题。
关键在于Math.floor,可以将这个值变大一点。