Committed by
Gerrit Code Review
Merge "GUI -- added removeHost code; augmented 'simple' scenario to include remo…
…veHost. - flattened lat/long in device props "bag" - example events."
Showing
6 changed files
with
58 additions
and
23 deletions
... | @@ -11,11 +11,8 @@ | ... | @@ -11,11 +11,8 @@ |
11 | null | 11 | null |
12 | ], | 12 | ], |
13 | "props": { | 13 | "props": { |
14 | - "location": { | 14 | + "latitude": 123.5, |
15 | - "type": "latlng", | 15 | + "longitude": 67.8, |
16 | - "lat": 123.5, | ||
17 | - "lng": 67.8 | ||
18 | - }, | ||
19 | "anotherProp": "foobar" | 16 | "anotherProp": "foobar" |
20 | } | 17 | } |
21 | } | 18 | } | ... | ... |
... | @@ -11,11 +11,8 @@ | ... | @@ -11,11 +11,8 @@ |
11 | null | 11 | null |
12 | ], | 12 | ], |
13 | "props": { | 13 | "props": { |
14 | - "location": { | 14 | + "latitude": 123.5, |
15 | - "type": "latlng", | 15 | + "longitude": 67.8, |
16 | - "lat": 123.5, | ||
17 | - "lng": 67.8 | ||
18 | - }, | ||
19 | "anotherProp": "foobar" | 16 | "anotherProp": "foobar" |
20 | }, | 17 | }, |
21 | "metaUi": { | 18 | "metaUi": { | ... | ... |
1 | +{ | ||
2 | + "event": "removeHost", | ||
3 | + "payload": { | ||
4 | + "id": "A6:96:E5:03:52:5F/-1", | ||
5 | + "ingress": "A6:96:E5:03:52:5F/-1/0-of:0000ffffffff0008/1", | ||
6 | + "egress": "of:0000ffffffff0008/1-A6:96:E5:03:52:5F/-1/0", | ||
7 | + "cp": { | ||
8 | + "device": "of:0000ffffffff0008", | ||
9 | + "port": 1 | ||
10 | + }, | ||
11 | + "labels": [ | ||
12 | + "10.0.0.17", | ||
13 | + "A6:96:E5:03:52:5F" | ||
14 | + ], | ||
15 | + "props": {} | ||
16 | + } | ||
17 | +} |
... | @@ -20,6 +20,6 @@ | ... | @@ -20,6 +20,6 @@ |
20 | "10. update link (increase width, update props)", | 20 | "10. update link (increase width, update props)", |
21 | "11. update link (reduce width, update props)", | 21 | "11. update link (reduce width, update props)", |
22 | "12. remove link", | 22 | "12. remove link", |
23 | - "" | 23 | + "13. remove host (10.0.0.17)" |
24 | ] | 24 | ] |
25 | } | 25 | } | ... | ... |
... | @@ -352,7 +352,7 @@ | ... | @@ -352,7 +352,7 @@ |
352 | updateHost: updateHost, | 352 | updateHost: updateHost, |
353 | removeDevice: stillToImplement, | 353 | removeDevice: stillToImplement, |
354 | removeLink: removeLink, | 354 | removeLink: removeLink, |
355 | - removeHost: stillToImplement, | 355 | + removeHost: removeHost, |
356 | showPath: showPath | 356 | showPath: showPath |
357 | }; | 357 | }; |
358 | 358 | ||
... | @@ -389,6 +389,7 @@ | ... | @@ -389,6 +389,7 @@ |
389 | 389 | ||
390 | lnk = createHostLink(host); | 390 | lnk = createHostLink(host); |
391 | if (lnk) { | 391 | if (lnk) { |
392 | + node.linkData = lnk; // cache ref on its host | ||
392 | network.links.push(lnk); | 393 | network.links.push(lnk); |
393 | network.lookup[host.ingress] = lnk; | 394 | network.lookup[host.ingress] = lnk; |
394 | network.lookup[host.egress] = lnk; | 395 | network.lookup[host.egress] = lnk; |
... | @@ -397,6 +398,7 @@ | ... | @@ -397,6 +398,7 @@ |
397 | network.force.start(); | 398 | network.force.start(); |
398 | } | 399 | } |
399 | 400 | ||
401 | + // TODO: fold updateX(...) methods into one base method; remove duplication | ||
400 | function updateDevice(data) { | 402 | function updateDevice(data) { |
401 | fnTrace('updateDevice', data.payload.id); | 403 | fnTrace('updateDevice', data.payload.id); |
402 | var device = data.payload, | 404 | var device = data.payload, |
... | @@ -436,6 +438,7 @@ | ... | @@ -436,6 +438,7 @@ |
436 | } | 438 | } |
437 | } | 439 | } |
438 | 440 | ||
441 | + // TODO: fold removeX(...) methods into base method - remove dup code | ||
439 | function removeLink(data) { | 442 | function removeLink(data) { |
440 | fnTrace('removeLink', data.payload.id); | 443 | fnTrace('removeLink', data.payload.id); |
441 | var link = data.payload, | 444 | var link = data.payload, |
... | @@ -448,6 +451,18 @@ | ... | @@ -448,6 +451,18 @@ |
448 | } | 451 | } |
449 | } | 452 | } |
450 | 453 | ||
454 | + function removeHost(data) { | ||
455 | + fnTrace('removeHost', data.payload.id); | ||
456 | + var host = data.payload, | ||
457 | + id = host.id, | ||
458 | + hostData = network.lookup[id]; | ||
459 | + if (hostData) { | ||
460 | + removeHostElement(hostData); | ||
461 | + } else { | ||
462 | + logicError('removeHost lookup fail. ID = "' + id + '"'); | ||
463 | + } | ||
464 | + } | ||
465 | + | ||
451 | function showPath(data) { | 466 | function showPath(data) { |
452 | fnTrace('showPath', data.payload.id); | 467 | fnTrace('showPath', data.payload.id); |
453 | var links = data.payload.links, | 468 | var links = data.payload.links, |
... | @@ -604,7 +619,6 @@ | ... | @@ -604,7 +619,6 @@ |
604 | //link .foo() .bar() ... | 619 | //link .foo() .bar() ... |
605 | 620 | ||
606 | // operate on exiting links: | 621 | // operate on exiting links: |
607 | - // TODO: better transition (longer as a dashed, grey line) | ||
608 | link.exit() | 622 | link.exit() |
609 | .attr({ | 623 | .attr({ |
610 | 'stroke-dasharray': '3, 3' | 624 | 'stroke-dasharray': '3, 3' |
... | @@ -873,11 +887,12 @@ | ... | @@ -873,11 +887,12 @@ |
873 | // TODO: figure out how to remove the node 'g' AND its children | 887 | // TODO: figure out how to remove the node 'g' AND its children |
874 | node.exit() | 888 | node.exit() |
875 | .transition() | 889 | .transition() |
876 | - .duration(750) | 890 | + .style('opacity', 0.4) |
891 | + .attr('fill', '#888') | ||
892 | + .transition() | ||
893 | + .duration(2000) | ||
877 | .attr({ | 894 | .attr({ |
878 | opacity: 0, | 895 | opacity: 0, |
879 | - cx: 0, | ||
880 | - cy: 0, | ||
881 | r: 0 | 896 | r: 0 |
882 | }) | 897 | }) |
883 | .remove(); | 898 | .remove(); |
... | @@ -897,12 +912,27 @@ | ... | @@ -897,12 +912,27 @@ |
897 | delete network.lookup[linkData.id]; | 912 | delete network.lookup[linkData.id]; |
898 | // remove from links array | 913 | // remove from links array |
899 | var idx = find(linkData.id, network.links); | 914 | var idx = find(linkData.id, network.links); |
900 | - | ||
901 | network.links.splice(idx, 1); | 915 | network.links.splice(idx, 1); |
902 | // remove from SVG | 916 | // remove from SVG |
903 | updateLinks(); | 917 | updateLinks(); |
918 | + network.force.resume(); | ||
904 | } | 919 | } |
905 | 920 | ||
921 | + function removeHostElement(hostData) { | ||
922 | + // first, remove associated hostLink... | ||
923 | + removeLinkElement(hostData.linkData); | ||
924 | + | ||
925 | + // remove from lookup cache | ||
926 | + delete network.lookup[hostData.id]; | ||
927 | + // remove from nodes array | ||
928 | + var idx = find(hostData.id, network.nodes); | ||
929 | + network.nodes.splice(idx, 1); | ||
930 | + // remove from SVG | ||
931 | + updateNodes(); | ||
932 | + network.force.resume(); | ||
933 | + } | ||
934 | + | ||
935 | + | ||
906 | function tick() { | 936 | function tick() { |
907 | node.attr({ | 937 | node.attr({ |
908 | transform: function (d) { return translate(d.x, d.y); } | 938 | transform: function (d) { return translate(d.x, d.y); } | ... | ... |
-
Please register or login to post a comment