drag = {
function isInBothCircles(x, y) {
const distFromCircleA =
Math.sqrt(Math.pow((x - d3.select("#circle0").attr("cx")),2) + Math.pow((y - d3.select("#circle0").attr("cy")),2));
const distFromCircleB =
Math.sqrt(Math.pow((x - d3.select("#circle1").attr("cx")),2) + Math.pow((y - d3.select("#circle1").attr("cy")),2));
return distFromCircleA <= d3.select("#circle0").attr("r") && distFromCircleB <= d3.select("#circle1").attr("r")
}
function dragstarted(event, d) {
d3.select(this).raise().attr("stroke", "black");
}
function dragged(event, d) {
d3.select(this).attr("cx", d.x = event.x).attr("cy", d.y = event.y);
}
function dragended(event, d) {
d3.select(this).attr("stroke", null);
d3.selectAll(".bobaShop").attr("fill", d => isInBothCircles(path.centroid(d)[0], path.centroid(d)[1]) ? "green" : "gray")
d3.selectAll(".bobaShop").attr("opacity", d => isInBothCircles(path.centroid(d)[0], path.centroid(d)[1]) ? 1 : .5)
}
return d3.drag()
.on("start", dragstarted)
.on("drag", dragged)
.on("end", dragended)
}