Simon Hunt

Pin nodes at end of mousedrag.

Allow nodes to be unpinned by hovering over and pressing 'U'.
...@@ -30,8 +30,8 @@ ...@@ -30,8 +30,8 @@
30 var config = { 30 var config = {
31 debugOn: false, 31 debugOn: false,
32 debug: { 32 debug: {
33 - showNodeXY: true, 33 + showNodeXY: false,
34 - showKeyHandler: false 34 + showKeyHandler: true
35 }, 35 },
36 options: { 36 options: {
37 layering: true, 37 layering: true,
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
50 note: 'node.class or link.class is used to differentiate', 50 note: 'node.class or link.class is used to differentiate',
51 linkDistance: { 51 linkDistance: {
52 infra: 200, 52 infra: 200,
53 - host: 20 53 + host: 40
54 }, 54 },
55 linkStrength: { 55 linkStrength: {
56 infra: 1.0, 56 infra: 1.0,
...@@ -58,7 +58,7 @@ ...@@ -58,7 +58,7 @@
58 }, 58 },
59 charge: { 59 charge: {
60 device: -800, 60 device: -800,
61 - host: -400 61 + host: -1000
62 }, 62 },
63 ticksWithoutCollisions: 50, 63 ticksWithoutCollisions: 50,
64 marginLR: 20, 64 marginLR: 20,
...@@ -84,7 +84,7 @@ ...@@ -84,7 +84,7 @@
84 }, 84 },
85 constraints: { 85 constraints: {
86 ypos: { 86 ypos: {
87 - host: 0.15, 87 + host: 0.05,
88 switch: 0.3, 88 switch: 0.3,
89 roadm: 0.7 89 roadm: 0.7
90 } 90 }
...@@ -99,6 +99,7 @@ ...@@ -99,6 +99,7 @@
99 network = {}, 99 network = {},
100 selected = {}, 100 selected = {},
101 highlighted = null, 101 highlighted = null,
102 + hovered = null,
102 viewMode = 'showAll'; 103 viewMode = 'showAll';
103 104
104 105
...@@ -179,15 +180,15 @@ ...@@ -179,15 +180,15 @@
179 }); 180 });
180 } 181 }
181 182
183 + function contextLabel() {
184 + return hovered === null ? "(nothing)" : hovered.id;
185 + }
186 +
182 function radioButton(group, id) { 187 function radioButton(group, id) {
183 d3.selectAll("#" + group + " .radio").classed("active", false); 188 d3.selectAll("#" + group + " .radio").classed("active", false);
184 d3.select("#" + group + " #" + id).classed("active", true); 189 d3.select("#" + group + " #" + id).classed("active", true);
185 } 190 }
186 191
187 - function contextLabel() {
188 - return highlighted === null ? "(nothing)" : highlighted.id;
189 - }
190 -
191 function processKeyEvent() { 192 function processKeyEvent() {
192 var code = d3.event.keyCode; 193 var code = d3.event.keyCode;
193 switch (code) { 194 switch (code) {
...@@ -196,16 +197,28 @@ ...@@ -196,16 +197,28 @@
196 break; 197 break;
197 case 80: // P 198 case 80: // P
198 togglePorts(); 199 togglePorts();
200 + break;
201 + case 85: // U
202 + unpin();
203 + break;
199 } 204 }
200 205
201 } 206 }
202 207
203 function cycleLabels() { 208 function cycleLabels() {
204 - alert('Cycle Labels - context = ' + contextLabel()); 209 + console.log('Cycle Labels - context = ' + contextLabel());
205 } 210 }
206 211
207 function togglePorts() { 212 function togglePorts() {
208 - alert('Toggle Ports - context = ' + contextLabel()); 213 + console.log('Toggle Ports - context = ' + contextLabel());
214 + }
215 +
216 + function unpin() {
217 + if (hovered) {
218 + hovered.fixed = false;
219 + network.force.resume();
220 + }
221 + console.log('Unpin - context = ' + contextLabel());
209 } 222 }
210 223
211 224
...@@ -217,7 +230,7 @@ ...@@ -217,7 +230,7 @@
217 prepareNodesAndLinks(); 230 prepareNodesAndLinks();
218 createLayout(); 231 createLayout();
219 console.log("\n\nHere is the augmented network object..."); 232 console.log("\n\nHere is the augmented network object...");
220 - console.warn(network); 233 + console.log(network);
221 } 234 }
222 235
223 function prepareNodesAndLinks() { 236 function prepareNodesAndLinks() {
...@@ -419,6 +432,12 @@ ...@@ -419,6 +432,12 @@
419 selectObject(d, this); 432 selectObject(d, this);
420 } 433 }
421 d.fixed &= ~6; 434 d.fixed &= ~6;
435 +
436 + // once we've finished moving, pin the node in position,
437 + // if it is a device
438 + if (d.class === 'device') {
439 + d.fixed = true;
440 + }
422 }); 441 });
423 442
424 $('#view').on('click', function(e) { 443 $('#view').on('click', function(e) {
...@@ -445,29 +464,21 @@ ...@@ -445,29 +464,21 @@
445 .call(network.drag) 464 .call(network.drag)
446 .on('mouseover', function(d) { 465 .on('mouseover', function(d) {
447 // TODO: show tooltip 466 // TODO: show tooltip
448 -/* 467 + if (network.mouseoutTimeout) {
449 - if (!selected.obj) { 468 + clearTimeout(network.mouseoutTimeout);
450 - if (network.mouseoutTimeout) { 469 + network.mouseoutTimeout = null;
451 - clearTimeout(network.mouseoutTimeout);
452 - network.mouseoutTimeout = null;
453 - }
454 - highlightObject(d);
455 } 470 }
456 -*/ 471 + hoverObject(d);
457 }) 472 })
458 .on('mouseout', function(d) { 473 .on('mouseout', function(d) {
459 // TODO: hide tooltip 474 // TODO: hide tooltip
460 -/* 475 + if (network.mouseoutTimeout) {
461 - if (!selected.obj) { 476 + clearTimeout(network.mouseoutTimeout);
462 - if (network.mouseoutTimeout) { 477 + network.mouseoutTimeout = null;
463 - clearTimeout(network.mouseoutTimeout);
464 - network.mouseoutTimeout = null;
465 - }
466 - network.mouseoutTimeout = setTimeout(function() {
467 - highlightObject(null);
468 - }, config.mouseOutTimerDelayMs);
469 } 478 }
470 -*/ 479 + network.mouseoutTimeout = setTimeout(function() {
480 + hoverObject(null);
481 + }, config.mouseOutTimerDelayMs);
471 }); 482 });
472 483
473 484
...@@ -596,15 +607,14 @@ ...@@ -596,15 +607,14 @@
596 box = text.node().getBBox(), 607 box = text.node().getBBox(),
597 lab = config.labels; 608 lab = config.labels;
598 609
610 + // not sure why n.data() returns an array of 1 element...
611 + var data = n.data()[0];
612 +
599 text.attr('text-anchor', 'middle') 613 text.attr('text-anchor', 'middle')
600 .attr('y', '-0.8em') 614 .attr('y', '-0.8em')
601 .attr('x', lab.imgPad/2) 615 .attr('x', lab.imgPad/2)
602 ; 616 ;
603 617
604 - // TODO: figure out how to access the data on selection
605 - console.log("\nadjust rect for " + n.data().id);
606 - console.log(box);
607 -
608 // translate the bbox so that it is centered on [x,y] 618 // translate the bbox so that it is centered on [x,y]
609 box.x = -box.width / 2; 619 box.x = -box.width / 2;
610 box.y = -box.height / 2; 620 box.y = -box.height / 2;
...@@ -813,7 +823,7 @@ ...@@ -813,7 +823,7 @@
813 el : el 823 el : el
814 }; 824 };
815 825
816 - highlightObject(obj); 826 +// highlightObject(obj);
817 827
818 node.classed('selected', true); 828 node.classed('selected', true);
819 829
...@@ -827,10 +837,11 @@ ...@@ -827,10 +837,11 @@
827 if (doResize || typeof doResize == 'undefined') { 837 if (doResize || typeof doResize == 'undefined') {
828 resize(false); 838 resize(false);
829 } 839 }
840 +
830 // deselect all nodes in the network... 841 // deselect all nodes in the network...
831 network.node.classed('selected', false); 842 network.node.classed('selected', false);
832 selected = {}; 843 selected = {};
833 - highlightObject(null); 844 +// highlightObject(null);
834 } 845 }
835 846
836 function highlightObject(obj) { 847 function highlightObject(obj) {
...@@ -859,6 +870,17 @@ ...@@ -859,6 +870,17 @@
859 } 870 }
860 } 871 }
861 872
873 + function hoverObject(obj) {
874 + if (obj) {
875 + hovered = obj;
876 + } else {
877 + if (hovered) {
878 + hovered = null;
879 + }
880 + }
881 + }
882 +
883 +
862 function resize(showDetails) { 884 function resize(showDetails) {
863 console.log("resize() called..."); 885 console.log("resize() called...");
864 886
......
...@@ -132,7 +132,8 @@ svg .node rect.debug { ...@@ -132,7 +132,8 @@ svg .node rect.debug {
132 } 132 }
133 133
134 134
135 -svg .node.selected rect { 135 +svg .node.selected rect,
136 +svg .node.selected circle {
136 filter: url(#blue-glow); 137 filter: url(#blue-glow);
137 } 138 }
138 139
......