GUI -- Implemented node lock ('X' key) in preparation for oblique view.
Change-Id: I485ca7977d18fe50ca7e5c500b3fc616506f4543
Showing
2 changed files
with
41 additions
and
14 deletions
... | @@ -27,7 +27,9 @@ | ... | @@ -27,7 +27,9 @@ |
27 | return $.isFunction(f) ? f : null; | 27 | return $.isFunction(f) ? f : null; |
28 | } | 28 | } |
29 | 29 | ||
30 | - function createDragBehavior(force, selectCb, atDragEnd, enabled) { | 30 | + // TODO: sensible defaults |
31 | + function createDragBehavior(force, selectCb, atDragEnd, | ||
32 | + dragEnabled, clickEnabled) { | ||
31 | var draggedThreshold = d3.scale.linear() | 33 | var draggedThreshold = d3.scale.linear() |
32 | .domain([0, 0.1]) | 34 | .domain([0, 0.1]) |
33 | .range([5, 20]) | 35 | .range([5, 20]) |
... | @@ -35,7 +37,8 @@ | ... | @@ -35,7 +37,8 @@ |
35 | drag, | 37 | drag, |
36 | fSel = isF(selectCb), | 38 | fSel = isF(selectCb), |
37 | fEnd = isF(atDragEnd), | 39 | fEnd = isF(atDragEnd), |
38 | - fEnb = isF(enabled), | 40 | + fDEn = isF(dragEnabled), |
41 | + fCEn = isF(clickEnabled), | ||
39 | bad = []; | 42 | bad = []; |
40 | 43 | ||
41 | function naf(what) { | 44 | function naf(what) { |
... | @@ -48,8 +51,11 @@ | ... | @@ -48,8 +51,11 @@ |
48 | if (!fEnd) { | 51 | if (!fEnd) { |
49 | bad.push(naf('atDragEnd')); | 52 | bad.push(naf('atDragEnd')); |
50 | } | 53 | } |
51 | - if (!fEnb) { | 54 | + if (!fDEn) { |
52 | - bad.push(naf('enabled')); | 55 | + bad.push(naf('dragEnabled')); |
56 | + } | ||
57 | + if (!fCEn) { | ||
58 | + bad.push(naf('clickEnabled')); | ||
53 | } | 59 | } |
54 | 60 | ||
55 | if (bad.length) { | 61 | if (bad.length) { |
... | @@ -71,7 +77,7 @@ | ... | @@ -71,7 +77,7 @@ |
71 | drag = d3.behavior.drag() | 77 | drag = d3.behavior.drag() |
72 | .origin(function(d) { return d; }) | 78 | .origin(function(d) { return d; }) |
73 | .on('dragstart', function(d) { | 79 | .on('dragstart', function(d) { |
74 | - if (enabled()) { | 80 | + if (clickEnabled() || dragEnabled()) { |
75 | d3.event.sourceEvent.stopPropagation(); | 81 | d3.event.sourceEvent.stopPropagation(); |
76 | 82 | ||
77 | d.oldX = d.x; | 83 | d.oldX = d.x; |
... | @@ -82,7 +88,7 @@ | ... | @@ -82,7 +88,7 @@ |
82 | } | 88 | } |
83 | }) | 89 | }) |
84 | .on('drag', function(d) { | 90 | .on('drag', function(d) { |
85 | - if (enabled()) { | 91 | + if (dragEnabled()) { |
86 | d.px = d3.event.x; | 92 | d.px = d3.event.x; |
87 | d.py = d3.event.y; | 93 | d.py = d3.event.y; |
88 | if (dragged(d)) { | 94 | if (dragged(d)) { |
... | @@ -96,13 +102,18 @@ | ... | @@ -96,13 +102,18 @@ |
96 | if (d.dragStarted) { | 102 | if (d.dragStarted) { |
97 | d.dragStarted = false; | 103 | d.dragStarted = false; |
98 | if (!dragged(d)) { | 104 | if (!dragged(d)) { |
99 | - // consider this the same as a 'click' (selection of node) | 105 | + // consider this the same as a 'click' |
100 | - selectCb(d, this); // TODO: set 'this' context instead of param | 106 | + // (selection of a node) |
107 | + if (clickEnabled()) { | ||
108 | + selectCb(d, this); // TODO: set 'this' context instead of param | ||
109 | + } | ||
101 | } | 110 | } |
102 | d.fixed &= ~6; | 111 | d.fixed &= ~6; |
103 | 112 | ||
104 | // hook at the end of a drag gesture | 113 | // hook at the end of a drag gesture |
105 | - atDragEnd(d, this); // TODO: set 'this' context instead of param | 114 | + if (dragEnabled()) { |
115 | + atDragEnd(d, this); // TODO: set 'this' context instead of param | ||
116 | + } | ||
106 | } | 117 | } |
107 | }); | 118 | }); |
108 | 119 | ... | ... |
... | @@ -148,6 +148,8 @@ | ... | @@ -148,6 +148,8 @@ |
148 | V: [showTrafficAction, 'Show related traffic'], | 148 | V: [showTrafficAction, 'Show related traffic'], |
149 | A: [showAllTrafficAction, 'Show all traffic'], | 149 | A: [showAllTrafficAction, 'Show all traffic'], |
150 | F: [showDeviceLinkFlowsAction, 'Show device link flows'], | 150 | F: [showDeviceLinkFlowsAction, 'Show device link flows'], |
151 | + X: [toggleNodeLock, 'Lock / unlock node positions'], | ||
152 | + Z: [toggleOblique, 'Toggle oblique view'], | ||
151 | esc: handleEscape | 153 | esc: handleEscape |
152 | }; | 154 | }; |
153 | 155 | ||
... | @@ -203,7 +205,8 @@ | ... | @@ -203,7 +205,8 @@ |
203 | showOffline = true, | 205 | showOffline = true, |
204 | useDetails = true, | 206 | useDetails = true, |
205 | haveDetails = false, | 207 | haveDetails = false, |
206 | - dragAllowed = true; | 208 | + nodeLock = false, |
209 | + oblique = false; | ||
207 | 210 | ||
208 | // constants | 211 | // constants |
209 | var hoverModeAll = 1, | 212 | var hoverModeAll = 1, |
... | @@ -323,6 +326,16 @@ | ... | @@ -323,6 +326,16 @@ |
323 | bgImg.style('visibility', visVal(vis === 'hidden')); | 326 | bgImg.style('visibility', visVal(vis === 'hidden')); |
324 | } | 327 | } |
325 | 328 | ||
329 | + function toggleNodeLock() { | ||
330 | + nodeLock = !nodeLock; | ||
331 | + flash('Node positions ' + (nodeLock ? 'locked' : 'unlocked')) | ||
332 | + } | ||
333 | + | ||
334 | + function toggleOblique() { | ||
335 | + oblique = !oblique; | ||
336 | + // TODO: oblique transformation | ||
337 | + } | ||
338 | + | ||
326 | function toggleHosts() { | 339 | function toggleHosts() { |
327 | showHosts = !showHosts; | 340 | showHosts = !showHosts; |
328 | updateHostVisibility(); | 341 | updateHostVisibility(); |
... | @@ -2704,9 +2717,12 @@ | ... | @@ -2704,9 +2717,12 @@ |
2704 | // predicate that indicates when dragging is active | 2717 | // predicate that indicates when dragging is active |
2705 | function dragEnabled() { | 2718 | function dragEnabled() { |
2706 | // meta key pressed means we are zooming/panning (so disable drag) | 2719 | // meta key pressed means we are zooming/panning (so disable drag) |
2707 | - return dragAllowed && !d3.event.sourceEvent.metaKey; | 2720 | + return !nodeLock && !d3.event.sourceEvent.metaKey; |
2708 | - // dragAllowed will be set false when we are in oblique view | 2721 | + } |
2709 | - // or when we 'lock' node positions | 2722 | + |
2723 | + // predicate that indicates when clicking is active | ||
2724 | + function clickEnabled() { | ||
2725 | + return true; | ||
2710 | } | 2726 | } |
2711 | 2727 | ||
2712 | // set up the force layout | 2728 | // set up the force layout |
... | @@ -2722,7 +2738,7 @@ | ... | @@ -2722,7 +2738,7 @@ |
2722 | .on('tick', tick); | 2738 | .on('tick', tick); |
2723 | 2739 | ||
2724 | network.drag = d3u.createDragBehavior(network.force, | 2740 | network.drag = d3u.createDragBehavior(network.force, |
2725 | - selectCb, atDragEnd, dragEnabled); | 2741 | + selectCb, atDragEnd, dragEnabled, clickEnabled); |
2726 | 2742 | ||
2727 | 2743 | ||
2728 | // create mask layer for when we lose connection to server. | 2744 | // create mask layer for when we lose connection to server. | ... | ... |
-
Please register or login to post a comment