forcegraph: keyboard zoom using + -

This commit is contained in:
Nils Schneider 2015-07-07 10:19:38 +02:00
parent 144dba319e
commit 160100e6df

View file

@ -469,6 +469,21 @@ define(["d3"], function (d3) {
} }
} }
function keyboardZoom(z) {
return function () {
var e = d3.event
if (e.altKey || e.ctrlKey || e.metaKey)
return
if (e.keyCode === 43)
animatePanzoom(z.translate(), z.scale() * 1.41)
if (e.keyCode === 45)
animatePanzoom(z.translate(), z.scale() / 1.41)
}
}
el = document.createElement("div") el = document.createElement("div")
el.classList.add("graph") el.classList.add("graph")
self.div = el self.div = el
@ -479,10 +494,11 @@ define(["d3"], function (d3) {
.translate([sidebar.getWidth(), 0]) .translate([sidebar.getWidth(), 0])
canvas = d3.select(el) canvas = d3.select(el)
.call(zoomBehavior)
.append("canvas") .append("canvas")
.attr("pointer-events", "all") .attr("tabindex", 1)
.on("click", onClick) .on("click", onClick)
.on("keypress", keyboardZoom(zoomBehavior))
.call(zoomBehavior)
.call(draggableNode) .call(draggableNode)
.node() .node()