当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - Custom the scale function in d3.js

问题描述:

I would like to map 1-1000 to 1-190, my map function is:

f(x) = { x if 1<=x and x<=100,

100 + (x-100)/10 if 100 < x <= 1000 }

How should I do?

网友答案:

Finally, got the solution by tracing the source code:

d3.scale.linear().domain([1, 100, 1000]).range([1, 100,190]) //poly-linear
网友答案:

I'm not familiar with 3d.js, but this is how I would do it in regular JS

function toNewScale( x ) {

    return Math.round( x / 1000 * 190 );
}

if this is what you were asking.

分享给朋友:
您可能感兴趣的文章:
随机阅读: