Paul Greyson | 7a30082 | 2013-04-09 12:57:49 -0700 | [diff] [blame] | 1 | /*************************************************************************************************** |
| 2 | functions for creating and interacting with the topology view of the webui |
| 3 | |
| 4 | flow related topology is in flows.js |
| 5 | ***************************************************************************************************/ |
| 6 | |
Paul Greyson | e15c439 | 2013-04-09 15:05:31 -0700 | [diff] [blame] | 7 | (function () { |
Paul Greyson | 7a30082 | 2013-04-09 12:57:49 -0700 | [diff] [blame] | 8 | |
Paul Greyson | 3063625 | 2013-04-09 15:22:04 -0700 | [diff] [blame^] | 9 | function updateLinkLines() { |
Paul Greyson | 7a30082 | 2013-04-09 12:57:49 -0700 | [diff] [blame] | 10 | |
| 11 | // key on link dpids since these will come/go during demo |
Paul Greyson | e15c439 | 2013-04-09 15:05:31 -0700 | [diff] [blame] | 12 | var linkLines = d3.select('svg').selectAll('.link').data(links, function (d) { |
Paul Greyson | 3063625 | 2013-04-09 15:22:04 -0700 | [diff] [blame^] | 13 | return d['src-switch']+'->'+d['dst-switch']; |
Paul Greyson | 7a30082 | 2013-04-09 12:57:49 -0700 | [diff] [blame] | 14 | }); |
| 15 | |
| 16 | // add new links |
Paul Greyson | 3063625 | 2013-04-09 15:22:04 -0700 | [diff] [blame^] | 17 | linkLines.enter().append("svg:path").attr("class", "link"); |
Paul Greyson | 7a30082 | 2013-04-09 12:57:49 -0700 | [diff] [blame] | 18 | |
Paul Greyson | e15c439 | 2013-04-09 15:05:31 -0700 | [diff] [blame] | 19 | linkLines.attr('id', function (d) { |
Paul Greyson | 7a30082 | 2013-04-09 12:57:49 -0700 | [diff] [blame] | 20 | return makeLinkKey(d); |
Paul Greyson | 3063625 | 2013-04-09 15:22:04 -0700 | [diff] [blame^] | 21 | }).attr("d", function (d) { |
Paul Greyson | 7a30082 | 2013-04-09 12:57:49 -0700 | [diff] [blame] | 22 | 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 Greyson | 7a30082 | 2013-04-09 12:57:49 -0700 | [diff] [blame] | 46 | // remove old links |
Paul Greyson | e15c439 | 2013-04-09 15:05:31 -0700 | [diff] [blame] | 47 | linkLines.exit().remove(); |
| 48 | } |
| 49 | |
Paul Greyson | 3063625 | 2013-04-09 15:22:04 -0700 | [diff] [blame^] | 50 | updateTopology = 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 Greyson | e15c439 | 2013-04-09 15:05:31 -0700 | [diff] [blame] | 74 | })(); |