javascript - Convert given range values to domain values in D3 -
javascript - Convert given range values to domain values in D3 -
i have linear scale:
var xrange.range([0, parentwidth]).domain([0, 100]);
now on mouseover xy coords of mouse cursor using d3.mouse(container)
. show floating tooltip. need set xy values calculated mouse position according xrange scale.
how do it? or have create scale swapped range , domain values?
no need scale. linear (numeric) input can utilize linear.invert()
, which:
returns value in input domain x corresponding value in output range y. represents inverse mapping range domain.
example:
var x = d3.scale.linear() .domain([0,50]) .range([0,100]); // domain range: x(25); // 50 // range domain: x.invert(50); // 25
javascript d3.js
Comments
Post a Comment