Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 难以理解d3.range.js和d3.scale.linear_Javascript_Svg_D3.js_Range - Fatal编程技术网

Javascript 难以理解d3.range.js和d3.scale.linear

Javascript 难以理解d3.range.js和d3.scale.linear,javascript,svg,d3.js,range,Javascript,Svg,D3.js,Range,我知道如何使用,也知道领域和范围 但是当我阅读range.js和linear.js中的代码时,我非常困惑,为什么它看起来如此复杂和神秘: 例如linear.js中的代码: step = Math.pow(10, Math.floor(Math.log(span / m) / Math.LN10)), err = m / span * step; // Filter ticks to get closer to the desired count. if (err <= .15) step

我知道如何使用,也知道领域和范围

但是当我阅读range.js和linear.js中的代码时,我非常困惑,为什么它看起来如此复杂和神秘: 例如linear.js中的代码:

step = Math.pow(10, Math.floor(Math.log(span / m) / Math.LN10)),
err = m / span * step;
// Filter ticks to get closer to the desired count.
if (err <= .15) step *= 10;
else if (err <= .35) step *= 5;
else if (err <= .75) step *= 2;
step=Math.pow(10,Math.floor(Math.log(span/m)/Math.LN10)),
误差=m/span*步;
//过滤滴答声以接近所需的计数。

if(err上周我不得不为此算法编写单元测试。下面是我的解释:

// Approximate the step to the closest power of ten by transforming to the
// commom log scale, truncating the mantissa, and transforming back.
step = Math.pow(10, Math.floor(Math.log(span / m) / Math.LN10)),

// Calculate how closely the step covers the span of the domain.
err = (m * step) / span;

// Given the coverage of the current step against the domain span, multiply
// (if necessary) by a constant to get closer to the desired tick count.
if (err <= 0.15) step *= 10;
else if (err <= 0.35) step *= 5;
else if (err <= 0.75) step *= 2;
//通过转换为
//常用对数标度,截断尾数,并转换回。
step=Math.pow(10,Math.floor(Math.log(span/m)/Math.LN10)),
//计算步骤覆盖域范围的程度。
误差=(m*步)/span;
//给定当前步骤对域范围的覆盖率,乘以
//(如有必要)通过一个常数来接近所需的刻度计数。

如果(错误),你发布的简单代码会给你打勾,但不一定是好的。也就是说,如果你的域是0到2,比如3个勾,你会在0.66666和1.333333处打勾。D3会尝试打勾(即在“舍入”数字处),因此会有额外的代码。
// Approximate the step to the closest power of ten by transforming to the
// commom log scale, truncating the mantissa, and transforming back.
step = Math.pow(10, Math.floor(Math.log(span / m) / Math.LN10)),

// Calculate how closely the step covers the span of the domain.
err = (m * step) / span;

// Given the coverage of the current step against the domain span, multiply
// (if necessary) by a constant to get closer to the desired tick count.
if (err <= 0.15) step *= 10;
else if (err <= 0.35) step *= 5;
else if (err <= 0.75) step *= 2;