Is it possible to conditionally ignore the drag function from eating an event? I have a pan/zoom canvas (as seen here: www.proofapp.io/workspace) and I'm trying to implement a shift+drag multi-selection lasso. The svg object already has the zoom function registered so when I put a drag function above it the zoom never gets called. Since call only runs once at the beginning I'm not sure how I can make this work. Any suggestions?
const zoom = d3.zoom()
.scaleExtent([0.25 ,5])
.on("zoom", function() {
root.attr('transform', d3.event.transform);
});
// THIS DOESNT WORK BECAUSE IT ONLY RUNS ONCE AT THE BEGINNING
const lasso = function() {
if (d3.event.sourceEvent) {
if (d3.event.sourceEvent.shiftKey) {
d3.drag()
.dragDisable() // maybe the answer is with this?
.on("start", function() { console.log('lasso-start') })
.on("drag", function() { console.log('lasso-drag') })
.on("end", function() { console.log('lasso-end') });
}
}
}
var svg = d3.select("div#nodegraph")
.append("svg")
.attr("width", "100%")
.attr("height", "100%")
.on('click', Graph.setNodeInactive)
.call(lasso)
.call(zoom);
UPDATE
Trying to just use the mousedown.drag event instead so that I can control the event bubbling. Not quite there yet, but the behaviour is correct (only blocks zoom when shift is pressed).
const zoom = d3.zoom()
.scaleExtent([0.25 ,5])
.on("zoom", function() {
root.attr('transform', d3.event.transform);
});
function lasso() {
if (d3.event.shiftKey) {
// do stuff
d3.event.stopImmediatePropagation();
}
}
var svg = d3.select("div#nodegraph")
.append("svg")
.attr("width", "100%")
.attr("height", "100%")
.on('click', Graph.setNodeInactive)
.on('mousedown.drag', lasso)
.call(zoom);