blob: a2a69aef15b27871f6c3ea950d82d8f520d88314 [file] [log] [blame]
Paul Greyson7a300822013-04-09 12:57:49 -07001/***************************************************************************************************
2functions for creating and interacting with the topology view of the webui
3
4flow related topology is in flows.js
5***************************************************************************************************/
6
Paul Greysone15c4392013-04-09 15:05:31 -07007(function () {
Paul Greyson7a300822013-04-09 12:57:49 -07008
Paul Greyson30636252013-04-09 15:22:04 -07009function updateLinkLines() {
Paul Greyson7a300822013-04-09 12:57:49 -070010
11 // key on link dpids since these will come/go during demo
Paul Greysone15c4392013-04-09 15:05:31 -070012 var linkLines = d3.select('svg').selectAll('.link').data(links, function (d) {
Paul Greyson30636252013-04-09 15:22:04 -070013 return d['src-switch']+'->'+d['dst-switch'];
Paul Greyson7a300822013-04-09 12:57:49 -070014 });
15
16 // add new links
Paul Greyson30636252013-04-09 15:22:04 -070017 linkLines.enter().append("svg:path").attr("class", "link");
Paul Greyson7a300822013-04-09 12:57:49 -070018
Paul Greysone15c4392013-04-09 15:05:31 -070019 linkLines.attr('id', function (d) {
Paul Greyson7a300822013-04-09 12:57:49 -070020 return makeLinkKey(d);
Paul Greyson30636252013-04-09 15:22:04 -070021 }).attr("d", function (d) {
Paul Greyson7a300822013-04-09 12:57:49 -070022 var src = d3.select(document.getElementById(d['src-switch']));
23 var dst = d3.select(document.getElementById(d['dst-switch']));
24
25 var srcPt = document.querySelector('svg').createSVGPoint();
26 srcPt.x = src.attr('x');
27 srcPt.y = src.attr('y');
28 srcPt = srcPt.matrixTransform(src[0][0].getCTM());
29
30 var dstPt = document.querySelector('svg').createSVGPoint();
31 dstPt.x = dst.attr('x');
32 dstPt.y = dst.attr('y');
33 dstPt = dstPt.matrixTransform(dst[0][0].getCTM());
34
35 var midPt = document.querySelector('svg').createSVGPoint();
36 midPt.x = (srcPt.x + dstPt.x)/2;
37 midPt.y = (srcPt.y + dstPt.y)/2;
38
39 return line([srcPt, midPt, dstPt]);
40 })
41 .attr("marker-mid", function(d) { return "url(#arrow)"; })
42 .classed('pending', function (d) {
43 return d.pending;
44 });
45
Paul Greyson7a300822013-04-09 12:57:49 -070046 // remove old links
Paul Greysone15c4392013-04-09 15:05:31 -070047 linkLines.exit().remove();
48}
49
Paul Greyson30636252013-04-09 15:22:04 -070050updateTopology = function() {
51
52 /* currently rings.js and map.js can be included to define the topology display */
53
54 drawTopology();
55
56
57
58 /* the remainder should work regardless of the topology display */
59
60 updateLinkLines();
61
62 // setup the mouseover behaviors
63 var allSwitches = d3.selectAll('.edge, .core, .aggregation');
64
65 allSwitches.on('mouseover', mouseOverSwitch);
66 allSwitches.on('mouseout', mouseOutSwitch);
67 allSwitches.on('mouseup', mouseUpSwitch);
68 allSwitches.on('mousedown', mouseDownSwitch);
69
70 // only do switch up/down for core switches
71 d3.selectAll('.core').on('dblclick', doubleClickSwitch);
72}
73
Paul Greysone15c4392013-04-09 15:05:31 -070074})();