Simon Hunt

GUI - Fixed auto positioning of existing nodes (ONOS-299)

 - Added GEO lng/lat data to updateMeta event (ONOS-314)

Change-Id: I5f205a45efa94bef5b8df18f4f0739f84806311f
...@@ -680,10 +680,13 @@ ...@@ -680,10 +680,13 @@
680 evTrace(data); 680 evTrace(data);
681 var device = data.payload, 681 var device = data.payload,
682 id = device.id, 682 id = device.id,
683 - nodeData = network.lookup[id]; 683 + d = network.lookup[id];
684 - if (nodeData) { 684 + if (d) {
685 - $.extend(nodeData, device); 685 + $.extend(d, device);
686 - updateDeviceState(nodeData); 686 + if (positionNode(d, true)) {
687 + sendUpdateMeta(d);
688 + }
689 + updateNodes();
687 } else { 690 } else {
688 logicError('updateDevice lookup fail. ID = "' + id + '"'); 691 logicError('updateDevice lookup fail. ID = "' + id + '"');
689 } 692 }
...@@ -1460,7 +1463,7 @@ ...@@ -1460,7 +1463,7 @@
1460 return node; 1463 return node;
1461 } 1464 }
1462 1465
1463 - function positionNode(node) { 1466 + function positionNode(node, forUpdate) {
1464 var meta = node.metaUi, 1467 var meta = node.metaUi,
1465 x = meta && meta.x, 1468 x = meta && meta.x,
1466 y = meta && meta.y, 1469 y = meta && meta.y,
...@@ -1469,8 +1472,10 @@ ...@@ -1469,8 +1472,10 @@
1469 // If we have [x,y] already, use that... 1472 // If we have [x,y] already, use that...
1470 if (x && y) { 1473 if (x && y) {
1471 node.fixed = true; 1474 node.fixed = true;
1472 - node.x = x; 1475 + node.px = node.x = x;
1473 - node.y = y; 1476 + node.py = node.y = y;
1477 + //node.px = x;
1478 + //node.py = y;
1474 return; 1479 return;
1475 } 1480 }
1476 1481
...@@ -1478,8 +1483,15 @@ ...@@ -1478,8 +1483,15 @@
1478 if (location && location.type === 'latlng') { 1483 if (location && location.type === 'latlng') {
1479 var coord = geoMapProjection([location.lng, location.lat]); 1484 var coord = geoMapProjection([location.lng, location.lat]);
1480 node.fixed = true; 1485 node.fixed = true;
1481 - node.x = coord[0]; 1486 + node.px = node.x = coord[0];
1482 - node.y = coord[1]; 1487 + node.py = node.y = coord[1];
1488 + //node.x = coord[0];
1489 + //node.y = coord[1];
1490 + return true;
1491 + }
1492 +
1493 + // if this is a node update (not a node add).. skip randomizer
1494 + if (forUpdate) {
1483 return; 1495 return;
1484 } 1496 }
1485 1497
...@@ -1524,9 +1536,6 @@ ...@@ -1524,9 +1536,6 @@
1524 $.extend(node, xy); 1536 $.extend(node, xy);
1525 } 1537 }
1526 1538
1527 - function iconUrl(d) {
1528 - return 'img/' + d.type + '.png';
1529 - }
1530 1539
1531 function iconGlyphUrl(d) { 1540 function iconGlyphUrl(d) {
1532 var which = d.type || 'unknown'; 1541 var which = d.type || 'unknown';
...@@ -1621,16 +1630,9 @@ ...@@ -1621,16 +1630,9 @@
1621 host.select('text').text(label); 1630 host.select('text').text(label);
1622 } 1631 }
1623 1632
1624 - // TODO: should be using updateNodes() to do the upates! 1633 + // FIXME : fold this into updateNodes.
1625 - function updateDeviceState(nodeData) {
1626 - nodeData.el.classed('online', nodeData.online);
1627 - updateDeviceLabel(nodeData);
1628 - // TODO: review what else might need to be updated
1629 - }
1630 -
1631 function updateHostState(hostData) { 1634 function updateHostState(hostData) {
1632 updateHostLabel(hostData); 1635 updateHostLabel(hostData);
1633 - // TODO: review what else might need to be updated
1634 } 1636 }
1635 1637
1636 function nodeMouseOver(d) { 1638 function nodeMouseOver(d) {
...@@ -1660,9 +1662,20 @@ ...@@ -1660,9 +1662,20 @@
1660 node = nodeG.selectAll('.node') 1662 node = nodeG.selectAll('.node')
1661 .data(network.nodes, function (d) { return d.id; }); 1663 .data(network.nodes, function (d) { return d.id; });
1662 1664
1663 - // TODO: operate on existing nodes 1665 + // operate on existing nodes...
1664 - // update host labels 1666 + node.filter('.device').each(function (d) {
1665 - //node .foo() .bar() ... 1667 + //var node = d3.select(this);
1668 + var node = d.el;
1669 + node.classed('online', d.online);
1670 + updateDeviceLabel(d);
1671 + positionNode(d, true);
1672 + });
1673 +
1674 + node.filter('.host').each(function (d) {
1675 + //var node = d3.select(this);
1676 + var node = d.el;
1677 + // TODO: appropriate update of host visuals
1678 + });
1666 1679
1667 // operate on entering nodes: 1680 // operate on entering nodes:
1668 var entering = node.enter() 1681 var entering = node.enter()
...@@ -1689,16 +1702,8 @@ ...@@ -1689,16 +1702,8 @@
1689 // provide ref to element from backing data.... 1702 // provide ref to element from backing data....
1690 d.el = node; 1703 d.el = node;
1691 1704
1692 - node.append('rect') 1705 + node.append('rect').attr({ rx: 5, ry: 5 });
1693 - .attr({ 1706 + node.append('text').text(label).attr('dy', '1.1em');
1694 - rx: 5,
1695 - ry: 5
1696 - });
1697 -
1698 - node.append('text')
1699 - .text(label)
1700 - .attr('dy', '1.1em');
1701 -
1702 box = adjustRectToFitText(node); 1707 box = adjustRectToFitText(node);
1703 node.select('rect').attr(box); 1708 node.select('rect').attr(box);
1704 addDeviceIcon(node, box, noLabel, iconGlyphUrl(d)); 1709 addDeviceIcon(node, box, noLabel, iconGlyphUrl(d));
...@@ -1710,14 +1715,8 @@ ...@@ -1710,14 +1715,8 @@
1710 bgpSpeaker: 14, 1715 bgpSpeaker: 14,
1711 router: 14, 1716 router: 14,
1712 endstation: 14 1717 endstation: 14
1713 - },
1714 - hostGlyphId = {
1715 - bgpSpeaker: 'bgpSpeaker',
1716 - router: 'router',
1717 - endstation: 'endstation'
1718 }; 1718 };
1719 1719
1720 -
1721 // augment host nodes... 1720 // augment host nodes...
1722 entering.filter('.host').each(function (d) { 1721 entering.filter('.host').each(function (d) {
1723 var node = d3.select(this), 1722 var node = d3.select(this),
...@@ -1728,8 +1727,7 @@ ...@@ -1728,8 +1727,7 @@
1728 // provide ref to element from backing data.... 1727 // provide ref to element from backing data....
1729 d.el = node; 1728 d.el = node;
1730 1729
1731 - node.append('circle') 1730 + node.append('circle').attr('r', r);
1732 - .attr('r', r);
1733 1731
1734 if (iid) { 1732 if (iid) {
1735 addHostIcon(node, r, iid); 1733 addHostIcon(node, r, iid);
...@@ -1739,18 +1737,6 @@ ...@@ -1739,18 +1737,6 @@
1739 .text(hostLabel) 1737 .text(hostLabel)
1740 .attr('dy', textDy) 1738 .attr('dy', textDy)
1741 .attr('text-anchor', 'middle'); 1739 .attr('text-anchor', 'middle');
1742 -
1743 - // debug function to show the modelled x,y coordinates of nodes...
1744 - if (debug('showNodeXY')) {
1745 - node.select('circle').attr('fill-opacity', 0.5);
1746 - node.append('circle')
1747 - .attr({
1748 - class: 'debug',
1749 - cx: 0,
1750 - cy: 0,
1751 - r: '3px'
1752 - });
1753 - }
1754 }); 1740 });
1755 1741
1756 // operate on both existing and new nodes, if necessary 1742 // operate on both existing and new nodes, if necessary
...@@ -1787,7 +1773,9 @@ ...@@ -1787,7 +1773,9 @@
1787 1773
1788 }); 1774 });
1789 1775
1790 - // TODO: device node exits 1776 + // TODO: device node exit animation
1777 +
1778 + network.force.resume();
1791 } 1779 }
1792 1780
1793 function addDeviceIcon(node, box, noLabel, iid) { 1781 function addDeviceIcon(node, box, noLabel, iid) {
...@@ -2315,18 +2303,6 @@ ...@@ -2315,18 +2303,6 @@
2315 //showInstances = mkTogBtn('Show Instances', toggleInst); 2303 //showInstances = mkTogBtn('Show Instances', toggleInst);
2316 } 2304 }
2317 2305
2318 - //function instShown() {
2319 - // return showInstances.classed('active');
2320 - //}
2321 - //function toggleInst() {
2322 - // showInstances.classed('active', !instShown());
2323 - // if (instShown()) {
2324 - // oiBox.show();
2325 - // } else {
2326 - // oiBox.hide();
2327 - // }
2328 - //}
2329 -
2330 function panZoom() { 2306 function panZoom() {
2331 return false; 2307 return false;
2332 } 2308 }
...@@ -2338,6 +2314,22 @@ ...@@ -2338,6 +2314,22 @@
2338 gly.defBadges(defs); 2314 gly.defBadges(defs);
2339 } 2315 }
2340 2316
2317 + function sendUpdateMeta(d) {
2318 + var ll = geoMapProjection.invert([d.x, d.y]),
2319 + metaUi = {
2320 + x: d.x,
2321 + y: d.y,
2322 + lng: ll[0],
2323 + lat: ll[1]
2324 + };
2325 + d.metaUi = metaUi;
2326 + sendMessage('updateMeta', {
2327 + id: d.id,
2328 + 'class': d.class,
2329 + 'memento': metaUi
2330 + });
2331 + }
2332 +
2341 // ============================== 2333 // ==============================
2342 // View life-cycle callbacks 2334 // View life-cycle callbacks
2343 2335
...@@ -2402,17 +2394,6 @@ ...@@ -2402,17 +2394,6 @@
2402 } 2394 }
2403 } 2395 }
2404 2396
2405 - function sendUpdateMeta(d) {
2406 - sendMessage('updateMeta', {
2407 - id: d.id,
2408 - 'class': d.class,
2409 - 'memento': {
2410 - x: d.x,
2411 - y: d.y
2412 - }
2413 - });
2414 - }
2415 -
2416 // set up the force layout 2397 // set up the force layout
2417 network.force = d3.layout.force() 2398 network.force = d3.layout.force()
2418 .size(forceDim) 2399 .size(forceDim)
......