0
我想用缩放/平移实现树节点选择。 考虑到缩放/平移将与使用鼠标(拖动)选择节点发生冲突,我将其作为两个独立的侦听器实现,我可以在其间使用CTRL 键盘按钮进行切换。就像这样:D3组合选择与缩放/平移
function toggleSelectZoom() {
if (useZoom) {
useZoom = false;
zoomListener.on("zoom", null);
container.classed("select", true)
.on("mousedown.select", startNodeSelection)
.on("mousemove.select", nodeSelection)
.on("mouseup.select", endNodeSelection);
} else {
useZoom = true;
container.classed("select", false)
.on("mousedown.select", null)
.on("mousemove.select", null)
.on("mouseup.select", null);
zoomListener.on("zoom", zoom);
}
}
document.onkeydown = function(e) { if (e.ctrlKey) { toggleSelectZoom(); }};
但有一个问题:切换到放大/平移模式 后绘制在选择模式选择框时,树(开始平移时),跳转到一个位置,在其 会在缩放/平移模式下进行相同的操作后。 这里是一个小提琴http://jsfiddle.net/PSVW6/2/
如何重置缩放行为的内部状态而不改变当前的翻译/缩放属性?第二个选项不适合我的需要,因为我需要能够拖动节点。 – SpiegS
你将不得不设置'zoom.translate()'和'zoom.scale()'。 –
谢谢!这没有窍门:) – SpiegS