I'm playing with d3.js and I noticed a weird behavior with dragging. If I add a circle using data and scaleX/scaleY, when I drag it the d3.event.y value is relative to the xy coordinates inside the "data" array, instead of the top left corner...
Here is the code and a jsFiddle: if you open the console, if you drag the first circle the reference is the top left corner, if you drag the second circle the reference is something related to {x: 3, y: 2}
var circle2 = svgGraph
.selectAll('.circle2')
.data([{ x: 3, y: 2 }])
.enter()
.append('circle') // Uses the enter().append() method
.attr('cx', scaleX(100))
.attr('cy', scaleY(100))
.attr('r', 15)
.call(d3.drag()
.on('start', (d) => { })
.on('drag', onHandlerDrag())
.on('end', (d) => { }));
function onHandlerDrag() {
return (d) => {
console.log(d3.event.y);
}
}
Is the behavior intended? Do you have any reference about it?
Thanks