waitingkuo
waitingkuo

Reputation: 93754

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?

Upvotes: 4

Views: 2581

Answers (2)

waitingkuo
waitingkuo

Reputation: 93754

Finally, got the solution by tracing the source code:

d3.scale.linear().domain([1, 100, 1000]).range([1, 100,190]) //poly-linear

Upvotes: 4

EricG
EricG

Reputation: 3849

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.

Upvotes: 0

Related Questions