I'm trying to do some logic based on the coordinates of a rectangle, when dragged. I want to select all circles within the rectangle.
function dragmove(d) {
var barz = document.querySelector("#visual");
var point = d3.mouse(barz),
tempP = {
x: point[0],
y: point[1]
};
d3.event.sourceEvent.stopPropagation();
d3.select(this).style({
opacity: 0.05
})
console.log(selectionBox.x); //turns out undefined
console.log(d.x); //also undefined
console.log(d3.select(this)); //undefined
vis.selectAll("circle").filter(function (d, i) {
return (d.x > d3.select(this).x && d.x < (d3.select(this).x + d3.select(this).width))
}).style({
opacity: 0.1
});
If you didn't already notice, right now I only have it checking within the x coordinates, at least until I finish fixing this. Here's the fiddle.
Whenever I try to run it, it doesn't pull any errors, but it doesn't work as intended because the reference is undefined. Is there any reason why none of the references work at all?
To reproduce this you need to first drag on the canvas to draw a rectangle, and then drag that rectangle