Ive been trying to make persistent tooltip by drawing a layer over the graph and track the tooltip based on mouse position. Unfortunately I kept getting an error on line xScaleFunc.invert(d3.mouse(this)[0]). Then i came across this custom invert code for scaleband scales. From here : https://bl.ocks.org/shimizu/808e0f5cadb6a63f28bb00082dc8fe3f .
The question is i'm not understanding whats going on here.I'm kinda new to D3 , any help would be much appreciated.
xScaleFunc.invert = (function(){
var domain = xScaleFunc.domain()
var range = xScaleFunc.range()
var scale = d3.scaleQuantize().domain(range).range(domain)
return function(x){
return scale(x)
}
})()