summaryrefslogtreecommitdiff
path: root/src/client/view/graph_view.js
diff options
context:
space:
mode:
authorAlon Levy <alon@pobox.com>2015-03-10 13:02:07 +0200
committerAlon Levy <alon@pobox.com>2015-03-10 13:02:31 +0200
commit353c6b50db1a80b67c4b0511bc4171944a56b226 (patch)
treec4d194f606df3719f187c04c462eee0499ecf5ca /src/client/view/graph_view.js
parent3ebb8554564760482eeabb079813db589e734a51 (diff)
client: graph_view: handle keyboard events when svg nodes are focused
enter to open edit, space and shift-space to select/append.
Diffstat (limited to 'src/client/view/graph_view.js')
-rw-r--r--src/client/view/graph_view.js32
1 files changed, 30 insertions, 2 deletions
diff --git a/src/client/view/graph_view.js b/src/client/view/graph_view.js
index 68891e5c..0016acda 100644
--- a/src/client/view/graph_view.js
+++ b/src/client/view/graph_view.js
@@ -25,9 +25,10 @@
* which resulted in overly complex (read: undefined/buggy) code.
*/
-define(['d3', 'Bacon_wrapper', 'util', 'view/selection', 'view/helpers', 'model/diff', 'view/view', 'view/bubble', 'model/types'],
-function(d3 , Bacon , util , selection , view_helpers, model_diff , view, view_bubble, model_types) {
+define(['d3', 'Bacon_wrapper', 'consts', 'util', 'view/selection', 'view/helpers', 'model/diff', 'view/view', 'view/bubble', 'model/types'],
+function(d3 , Bacon , consts, util , selection , view_helpers, model_diff , view, view_bubble, model_types) {
+// aliases
var obj_take = util.obj_take;
/* debugging helper */
@@ -791,6 +792,32 @@ function GraphView(spec) {
y: zcy + new_r * Math.sin(a)};
}
+ function handle_space(e, node) {
+ (e.shiftKey? selection.invert : selection.update)([node]);
+ }
+
+ function handle_enter(e, node) {
+ showNodeInfo(node);
+ }
+
+ var keyboard_handlers = _.object([
+ [consts.VK_SPACE, handle_space],
+ [consts.VK_ENTER, handle_enter],
+ ]);
+
+ function keyboard_handler(e) {
+ var target_node = graph.find_node__by_id(e.target.id);
+
+ if (null === target_node ||
+ undefined === keyboard_handlers[e.keyCode]) {
+ return;
+ }
+ keyboard_handlers[e.keyCode](e, target_node);
+ e.preventDefault();
+ e.stopPropagation();
+ }
+ gv.keyboard_handler = keyboard_handler;
+
/**
* Recomputes all link and node locations according to force layout and
* bubble animation.
@@ -875,6 +902,7 @@ function GraphView(spec) {
vis.attr("id", graph_name);
vis.append("g").attr("id", "link-group");
vis.append("g").attr("id", "selected-link-group");
+ gv.root_element = vis[0][0];
drag = d3.behavior.drag()
.origin(function(d) { return d; })