Invert scale function

后端 未结 1 532
暗喜
暗喜 2021-02-02 05:50

This is interesting to me. Look at the following D3 code:

var scale = d3.scale.linear()
    .domain([100, 500])
    .range([10, 350]);

scale(100);  //Returns 10         


        
1条回答
  •  不思量自难忘°
    2021-02-02 06:33

    Yes, there is, and it's aptly named invert.

    console.log(scale.invert(10));   //Returns 100
    console.log(scale.invert(180));  //Returns 300
    console.log(scale.invert(350));  //Returns 500
    

    0 讨论(0)
提交回复
热议问题