Paul Greyson | 127d7fb | 2013-03-25 23:39:20 -0700 | [diff] [blame] | 1 | /*global d3, document∆*/ |
Paul Greyson | 740bdaf | 2013-03-18 16:10:48 -0700 | [diff] [blame] | 2 | |
Paul Greyson | 6d9ed86 | 2013-03-23 17:37:15 -0700 | [diff] [blame] | 3 | d3.selection.prototype.moveToFront = function() { |
| 4 | return this.each(function(){ |
| 5 | this.parentNode.appendChild(this); |
| 6 | }); |
| 7 | }; |
Paul Greyson | d1a22d9 | 2013-03-19 12:15:19 -0700 | [diff] [blame] | 8 | |
Paul Greyson | 127d7fb | 2013-03-25 23:39:20 -0700 | [diff] [blame] | 9 | var line = d3.svg.line() |
| 10 | .x(function(d) { |
| 11 | return d.x; |
| 12 | }) |
| 13 | .y(function(d) { |
| 14 | return d.y; |
| 15 | }); |
| 16 | |
Paul Greyson | 56378ed | 2013-03-26 23:17:36 -0700 | [diff] [blame] | 17 | var model; |
Paul Greyson | 29aa98d | 2013-03-28 00:09:31 -0700 | [diff] [blame] | 18 | var svg; |
Paul Greyson | 56378ed | 2013-03-26 23:17:36 -0700 | [diff] [blame] | 19 | var updateTopology; |
Paul Greyson | 40c8a59 | 2013-03-27 14:10:33 -0700 | [diff] [blame] | 20 | var pendingLinks = {}; |
Paul Greyson | 13f02b9 | 2013-03-28 11:29:35 -0700 | [diff] [blame^] | 21 | var pendingFlows = {}; |
Paul Greyson | 127d7fb | 2013-03-25 23:39:20 -0700 | [diff] [blame] | 22 | |
Paul Greyson | d1a22d9 | 2013-03-19 12:15:19 -0700 | [diff] [blame] | 23 | var colors = [ |
Paul Greyson | 3e14216 | 2013-03-19 13:56:17 -0700 | [diff] [blame] | 24 | 'color1', |
| 25 | 'color2', |
| 26 | 'color3', |
| 27 | 'color4', |
Paul Greyson | 3e14216 | 2013-03-19 13:56:17 -0700 | [diff] [blame] | 28 | 'color7', |
| 29 | 'color8', |
| 30 | 'color9', |
Paul Greyson | 5cc35f0 | 2013-03-28 10:07:36 -0700 | [diff] [blame] | 31 | // 'color11', |
Paul Greyson | 127d7fb | 2013-03-25 23:39:20 -0700 | [diff] [blame] | 32 | 'color12' |
| 33 | ]; |
Paul Greyson | 01a5dff | 2013-03-19 15:50:14 -0700 | [diff] [blame] | 34 | colors.reverse(); |
Paul Greyson | d1a22d9 | 2013-03-19 12:15:19 -0700 | [diff] [blame] | 35 | |
| 36 | var controllerColorMap = {}; |
| 37 | |
Paul Greyson | 084779b | 2013-03-27 13:55:49 -0700 | [diff] [blame] | 38 | function setPending(selection) { |
| 39 | selection.classed('pending', false); |
| 40 | setTimeout(function () { |
| 41 | selection.classed('pending', true); |
| 42 | }) |
| 43 | } |
Paul Greyson | d1a22d9 | 2013-03-19 12:15:19 -0700 | [diff] [blame] | 44 | |
Paul Greyson | 740bdaf | 2013-03-18 16:10:48 -0700 | [diff] [blame] | 45 | function createTopologyView() { |
Paul Greyson | 56378ed | 2013-03-26 23:17:36 -0700 | [diff] [blame] | 46 | |
| 47 | window.addEventListener('resize', function () { |
| 48 | // this is too slow. instead detect first resize event and hide the paths that have explicit matrix applied |
| 49 | // either that or is it possible to position the paths so they get the automatic transform as well? |
Paul Greyson | 5cc35f0 | 2013-03-28 10:07:36 -0700 | [diff] [blame] | 50 | // updateTopology(); |
Paul Greyson | 56378ed | 2013-03-26 23:17:36 -0700 | [diff] [blame] | 51 | }); |
| 52 | |
Paul Greyson | b367de2 | 2013-03-23 11:09:11 -0700 | [diff] [blame] | 53 | var svg = d3.select('#svg-container').append('svg:svg'); |
| 54 | |
| 55 | svg.append("svg:defs").append("svg:marker") |
| 56 | .attr("id", "arrow") |
| 57 | .attr("viewBox", "0 -5 10 10") |
| 58 | .attr("refX", -1) |
| 59 | .attr("markerWidth", 5) |
| 60 | .attr("markerHeight", 5) |
| 61 | .attr("orient", "auto") |
| 62 | .append("svg:path") |
Paul Greyson | 45303ac | 2013-03-23 16:44:01 -0700 | [diff] [blame] | 63 | .attr("d", "M0,-3L10,0L0,3"); |
Paul Greyson | b367de2 | 2013-03-23 11:09:11 -0700 | [diff] [blame] | 64 | |
| 65 | return svg.append('svg:svg').attr('id', 'viewBox').attr('viewBox', '0 0 1000 1000').attr('preserveAspectRatio', 'none'). |
Paul Greyson | 952ccb6 | 2013-03-18 22:22:08 -0700 | [diff] [blame] | 66 | attr('id', 'viewbox').append('svg:g').attr('transform', 'translate(500 500)'); |
Paul Greyson | 740bdaf | 2013-03-18 16:10:48 -0700 | [diff] [blame] | 67 | } |
| 68 | |
Paul Greyson | 29aa98d | 2013-03-28 00:09:31 -0700 | [diff] [blame] | 69 | var selectedFlows = [null, null, null]; |
Paul Greyson | 127d7fb | 2013-03-25 23:39:20 -0700 | [diff] [blame] | 70 | |
Paul Greyson | 13f02b9 | 2013-03-28 11:29:35 -0700 | [diff] [blame^] | 71 | function updateSelectedFlowsTopology() { |
Paul Greyson | 127d7fb | 2013-03-25 23:39:20 -0700 | [diff] [blame] | 72 | // DRAW THE FLOWS |
Paul Greyson | 13f02b9 | 2013-03-28 11:29:35 -0700 | [diff] [blame^] | 73 | var flows = d3.select('svg').selectAll('.flow').data(selectedFlows); |
Paul Greyson | 127d7fb | 2013-03-25 23:39:20 -0700 | [diff] [blame] | 74 | |
Paul Greyson | 29aa98d | 2013-03-28 00:09:31 -0700 | [diff] [blame] | 75 | flows.enter().append("svg:path").attr('class', 'flow') |
| 76 | .attr('stroke-dasharray', '4, 10') |
| 77 | .append('svg:animate') |
| 78 | .attr('attributeName', 'stroke-dashoffset') |
| 79 | .attr('attributeType', 'xml') |
| 80 | .attr('from', '500') |
| 81 | .attr('to', '-500') |
| 82 | .attr('dur', '20s') |
| 83 | .attr('repeatCount', 'indefinite'); |
| 84 | |
| 85 | |
| 86 | flows.attr('d', function (d) { |
Paul Greyson | 13f02b9 | 2013-03-28 11:29:35 -0700 | [diff] [blame^] | 87 | if (!d) { |
| 88 | return; |
| 89 | } |
| 90 | var pts = []; |
| 91 | if (d.pending) { |
| 92 | // create a temporary vector to indicate the pending flow |
| 93 | var s1 = d3.select(document.getElementById(d.dataPath.srcPort.dpid.value)); |
| 94 | var s2 = d3.select(document.getElementById(d.dataPath.dstPort.dpid.value)); |
| 95 | |
| 96 | var pt1 = document.querySelector('svg').createSVGPoint(); |
| 97 | pt1.x = s1.attr('x'); |
| 98 | pt1.y = s1.attr('y'); |
| 99 | pt1 = pt1.matrixTransform(s1[0][0].getCTM()); |
| 100 | pts.push(pt1); |
| 101 | |
| 102 | var pt2 = document.querySelector('svg').createSVGPoint(); |
| 103 | pt2.x = s2.attr('x'); |
| 104 | pt2.y = s2.attr('y'); |
| 105 | pt2 = pt2.matrixTransform(s2[0][0].getCTM()); |
| 106 | pts.push(pt2); |
| 107 | |
| 108 | } else { |
| 109 | d.dataPath.flowEntries.forEach(function (flowEntry) { |
| 110 | var s = d3.select(document.getElementById(flowEntry.dpid.value)); |
| 111 | // s[0] is null if the flow entry refers to a non-existent switch |
| 112 | if (s[0][0]) { |
| 113 | var pt = document.querySelector('svg').createSVGPoint(); |
| 114 | pt.x = s.attr('x'); |
| 115 | pt.y = s.attr('y'); |
| 116 | pt = pt.matrixTransform(s[0][0].getCTM()); |
| 117 | pts.push(pt); |
| 118 | } else { |
| 119 | console.log('flow refers to non-existent switch: ' + flowEntry.dpid.value); |
| 120 | } |
| 121 | }); |
| 122 | } |
| 123 | return line(pts); |
| 124 | }) |
| 125 | .classed('pending', function (d) { |
| 126 | return d && d.pending |
Paul Greyson | 127d7fb | 2013-03-25 23:39:20 -0700 | [diff] [blame] | 127 | }); |
Paul Greyson | 127d7fb | 2013-03-25 23:39:20 -0700 | [diff] [blame] | 128 | |
Paul Greyson | 56378ed | 2013-03-26 23:17:36 -0700 | [diff] [blame] | 129 | // "marching ants" |
Paul Greyson | 29aa98d | 2013-03-28 00:09:31 -0700 | [diff] [blame] | 130 | flows.select('animate').attr('from', 500); |
| 131 | |
Paul Greyson | 13f02b9 | 2013-03-28 11:29:35 -0700 | [diff] [blame^] | 132 | } |
| 133 | |
| 134 | function updateSelectedFlowsTable() { |
| 135 | function rowEnter(d) { |
| 136 | var row = d3.select(this); |
| 137 | row.append('div').classed('flowId', true); |
| 138 | row.append('div').classed('srcDPID', true); |
| 139 | row.append('div').classed('dstDPID', true); |
| 140 | row.append('div').classed('iperf', true); |
| 141 | } |
| 142 | |
| 143 | function rowUpdate(d) { |
| 144 | var row = d3.select(this); |
| 145 | row.select('.flowId') |
| 146 | .text(function (d) { |
| 147 | if (d) { |
| 148 | if (d.flowId) { |
| 149 | return d.flowId.value; |
| 150 | } else { |
| 151 | return '0x--'; |
| 152 | } |
| 153 | } |
| 154 | }) |
| 155 | .classed('pending', d && d.pending); |
| 156 | |
| 157 | row.select('.srcDPID') |
| 158 | .text(function (d) { |
| 159 | if (d) { |
| 160 | return d.dataPath.srcPort.dpid.value; |
| 161 | } |
| 162 | }); |
| 163 | |
| 164 | row.select('.dstDPID') |
| 165 | .text(function (d) { |
| 166 | if (d) { |
| 167 | return d.dataPath.dstPort.dpid.value; |
| 168 | } |
| 169 | }); |
| 170 | } |
| 171 | |
| 172 | var flows = d3.select('#selectedFlows') |
| 173 | .selectAll('.selectedFlow') |
| 174 | .data(selectedFlows); |
| 175 | |
| 176 | flows.enter() |
| 177 | .append('div') |
| 178 | .classed('selectedFlow', true) |
| 179 | .each(rowEnter); |
| 180 | |
| 181 | flows.each(rowUpdate); |
| 182 | |
Paul Greyson | 29aa98d | 2013-03-28 00:09:31 -0700 | [diff] [blame] | 183 | flows.exit().remove(); |
Paul Greyson | 127d7fb | 2013-03-25 23:39:20 -0700 | [diff] [blame] | 184 | } |
| 185 | |
Paul Greyson | 13f02b9 | 2013-03-28 11:29:35 -0700 | [diff] [blame^] | 186 | function updateSelectedFlows() { |
| 187 | // make sure that all of the selected flows are either |
| 188 | // 1) valid (meaning they are in the latest list of flows) |
| 189 | // 2) pending |
| 190 | if (model) { |
| 191 | var flowMap = {}; |
| 192 | model.flows.forEach(function (flow) { |
| 193 | flowMap[makeFlowKey(flow)] = flow; |
| 194 | }); |
| 195 | |
| 196 | var newSelectedFlows = []; |
| 197 | selectedFlows.forEach(function (flow) { |
| 198 | if (flow) { |
| 199 | if (flow.pending) { |
| 200 | newSelectedFlows.push(flow); |
| 201 | } else { |
| 202 | var liveFlow = flowMap[makeFlowKey(flow)]; |
| 203 | if (liveFlow) { |
| 204 | newSelectedFlows.push(liveFlow); |
| 205 | } |
| 206 | } |
| 207 | } else { |
| 208 | newSelectedFlows.push(null); |
| 209 | } |
| 210 | }); |
| 211 | selectedFlows = newSelectedFlows; |
| 212 | } |
| 213 | |
| 214 | updateSelectedFlowsTable(); |
| 215 | updateSelectedFlowsTopology(); |
| 216 | } |
| 217 | |
| 218 | function selectFlow(flow) { |
| 219 | selectedFlows.unshift(flow); |
| 220 | selectedFlows = selectedFlows.slice(0, 3); |
| 221 | updateSelectedFlows(); |
| 222 | } |
| 223 | |
| 224 | function deselectFlow(flow) { |
| 225 | var flowKey = makeFlowKey(flow); |
| 226 | var newSelectedFlows = []; |
| 227 | selectedFlows.forEach(function (flow) { |
| 228 | if (!flow || flowKey !== makeFlowKey(flow)) { |
| 229 | newSelectedFlows.push(flow); |
| 230 | } |
| 231 | }); |
| 232 | selectedFlows = newSelectedFlows; |
| 233 | while (selectedFlows.length < 3) { |
| 234 | selectedFlows.push(null); |
| 235 | } |
| 236 | |
| 237 | updateSelectedFlows(); |
| 238 | } |
| 239 | |
Paul Greyson | 29aa98d | 2013-03-28 00:09:31 -0700 | [diff] [blame] | 240 | function showFlowChooser() { |
| 241 | function rowEnter(d) { |
Paul Greyson | 127d7fb | 2013-03-25 23:39:20 -0700 | [diff] [blame] | 242 | var row = d3.select(this); |
| 243 | |
Paul Greyson | 127d7fb | 2013-03-25 23:39:20 -0700 | [diff] [blame] | 244 | row.append('div') |
Paul Greyson | 8247c3f | 2013-03-28 00:24:02 -0700 | [diff] [blame] | 245 | .classed('black-eye', true). |
Paul Greyson | 29aa98d | 2013-03-28 00:09:31 -0700 | [diff] [blame] | 246 | on('click', function () { |
Paul Greyson | 13f02b9 | 2013-03-28 11:29:35 -0700 | [diff] [blame^] | 247 | selectFlow(d); |
Paul Greyson | 127d7fb | 2013-03-25 23:39:20 -0700 | [diff] [blame] | 248 | }); |
| 249 | |
| 250 | row.append('div') |
Paul Greyson | 29aa98d | 2013-03-28 00:09:31 -0700 | [diff] [blame] | 251 | .classed('flowId', true) |
| 252 | .text(function (d) { |
| 253 | return d.flowId.value; |
| 254 | }); |
Paul Greyson | 127d7fb | 2013-03-25 23:39:20 -0700 | [diff] [blame] | 255 | |
| 256 | row.append('div') |
Paul Greyson | 29aa98d | 2013-03-28 00:09:31 -0700 | [diff] [blame] | 257 | .classed('srcDPID', true) |
| 258 | .text(function (d) { |
| 259 | return d.dataPath.srcPort.dpid.value; |
| 260 | }); |
| 261 | |
Paul Greyson | 127d7fb | 2013-03-25 23:39:20 -0700 | [diff] [blame] | 262 | |
| 263 | row.append('div') |
Paul Greyson | 29aa98d | 2013-03-28 00:09:31 -0700 | [diff] [blame] | 264 | .classed('dstDPID', true) |
| 265 | .text(function (d) { |
| 266 | return d.dataPath.dstPort.dpid.value; |
| 267 | }); |
Paul Greyson | 127d7fb | 2013-03-25 23:39:20 -0700 | [diff] [blame] | 268 | |
Paul Greyson | 127d7fb | 2013-03-25 23:39:20 -0700 | [diff] [blame] | 269 | } |
| 270 | |
Paul Greyson | 29aa98d | 2013-03-28 00:09:31 -0700 | [diff] [blame] | 271 | var flows = d3.select('#flowChooser') |
| 272 | .append('div') |
| 273 | .style('pointer-events', 'auto') |
Paul Greyson | 127d7fb | 2013-03-25 23:39:20 -0700 | [diff] [blame] | 274 | .selectAll('.selectedFlow') |
Paul Greyson | 29aa98d | 2013-03-28 00:09:31 -0700 | [diff] [blame] | 275 | .data(model.flows) |
Paul Greyson | 127d7fb | 2013-03-25 23:39:20 -0700 | [diff] [blame] | 276 | .enter() |
| 277 | .append('div') |
| 278 | .classed('selectedFlow', true) |
| 279 | .each(rowEnter); |
| 280 | |
Paul Greyson | 29aa98d | 2013-03-28 00:09:31 -0700 | [diff] [blame] | 281 | setTimeout(function () { |
| 282 | d3.select(document.body).on('click', function () { |
| 283 | d3.select('#flowChooser').html(''); |
| 284 | d3.select(document.body).on('click', null); |
| 285 | }); |
| 286 | }, 0); |
| 287 | } |
| 288 | |
Paul Greyson | 29aa98d | 2013-03-28 00:09:31 -0700 | [diff] [blame] | 289 | |
Paul Greyson | 127d7fb | 2013-03-25 23:39:20 -0700 | [diff] [blame] | 290 | |
Paul Greyson | d1a22d9 | 2013-03-19 12:15:19 -0700 | [diff] [blame] | 291 | function updateHeader(model) { |
Paul Greyson | b48943b | 2013-03-19 13:27:57 -0700 | [diff] [blame] | 292 | d3.select('#lastUpdate').text(new Date()); |
Paul Greyson | 952ccb6 | 2013-03-18 22:22:08 -0700 | [diff] [blame] | 293 | d3.select('#activeSwitches').text(model.edgeSwitches.length + model.aggregationSwitches.length + model.coreSwitches.length); |
| 294 | d3.select('#activeFlows').text(model.flows.length); |
| 295 | } |
| 296 | |
| 297 | function toRadians (angle) { |
| 298 | return angle * (Math.PI / 180); |
Paul Greyson | 740bdaf | 2013-03-18 16:10:48 -0700 | [diff] [blame] | 299 | } |
| 300 | |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 301 | var widths = { |
| 302 | edge: 6, |
| 303 | aggregation: 12, |
| 304 | core: 18 |
| 305 | } |
| 306 | |
Paul Greyson | c17278a | 2013-03-23 10:17:12 -0700 | [diff] [blame] | 307 | function createRingsFromModel(model) { |
Paul Greyson | 740bdaf | 2013-03-18 16:10:48 -0700 | [diff] [blame] | 308 | var rings = [{ |
| 309 | radius: 3, |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 310 | width: widths.edge, |
Paul Greyson | 952ccb6 | 2013-03-18 22:22:08 -0700 | [diff] [blame] | 311 | switches: model.edgeSwitches, |
Paul Greyson | de7fad5 | 2013-03-19 12:47:32 -0700 | [diff] [blame] | 312 | className: 'edge', |
| 313 | angles: [] |
Paul Greyson | 740bdaf | 2013-03-18 16:10:48 -0700 | [diff] [blame] | 314 | }, { |
Paul Greyson | d1a22d9 | 2013-03-19 12:15:19 -0700 | [diff] [blame] | 315 | radius: 2.25, |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 316 | width: widths.aggregation, |
Paul Greyson | 952ccb6 | 2013-03-18 22:22:08 -0700 | [diff] [blame] | 317 | switches: model.aggregationSwitches, |
Paul Greyson | de7fad5 | 2013-03-19 12:47:32 -0700 | [diff] [blame] | 318 | className: 'aggregation', |
| 319 | angles: [] |
Paul Greyson | 740bdaf | 2013-03-18 16:10:48 -0700 | [diff] [blame] | 320 | }, { |
Paul Greyson | 127d7fb | 2013-03-25 23:39:20 -0700 | [diff] [blame] | 321 | radius: 0.75, |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 322 | width: widths.core, |
Paul Greyson | 952ccb6 | 2013-03-18 22:22:08 -0700 | [diff] [blame] | 323 | switches: model.coreSwitches, |
Paul Greyson | de7fad5 | 2013-03-19 12:47:32 -0700 | [diff] [blame] | 324 | className: 'core', |
| 325 | angles: [] |
Paul Greyson | 740bdaf | 2013-03-18 16:10:48 -0700 | [diff] [blame] | 326 | }]; |
| 327 | |
Paul Greyson | de7fad5 | 2013-03-19 12:47:32 -0700 | [diff] [blame] | 328 | |
| 329 | var aggRanges = {}; |
| 330 | |
| 331 | // arrange edge switches at equal increments |
| 332 | var k = 360 / rings[0].switches.length; |
| 333 | rings[0].switches.forEach(function (s, i) { |
| 334 | var angle = k * i; |
| 335 | |
| 336 | rings[0].angles[i] = angle; |
| 337 | |
| 338 | // record the angle for the agg switch layout |
| 339 | var dpid = s.dpid.split(':'); |
Paul Greyson | 832d220 | 2013-03-21 13:27:56 -0700 | [diff] [blame] | 340 | dpid[7] = '01'; // the last component of the agg switch is always '01' |
Paul Greyson | de7fad5 | 2013-03-19 12:47:32 -0700 | [diff] [blame] | 341 | var aggdpid = dpid.join(':'); |
| 342 | var aggRange = aggRanges[aggdpid]; |
| 343 | if (!aggRange) { |
| 344 | aggRange = aggRanges[aggdpid] = {}; |
| 345 | aggRange.min = aggRange.max = angle; |
| 346 | } else { |
| 347 | aggRange.max = angle; |
| 348 | } |
Paul Greyson | de7fad5 | 2013-03-19 12:47:32 -0700 | [diff] [blame] | 349 | }); |
| 350 | |
| 351 | // arrange aggregation switches to "fan out" to edge switches |
| 352 | k = 360 / rings[1].switches.length; |
| 353 | rings[1].switches.forEach(function (s, i) { |
| 354 | // rings[1].angles[i] = k * i; |
| 355 | var range = aggRanges[s.dpid]; |
| 356 | |
Paul Greyson | 832d220 | 2013-03-21 13:27:56 -0700 | [diff] [blame] | 357 | rings[1].angles[i] = (range.min + range.max)/2; |
Paul Greyson | de7fad5 | 2013-03-19 12:47:32 -0700 | [diff] [blame] | 358 | }); |
| 359 | |
Paul Greyson | 3f890b6 | 2013-03-22 17:39:36 -0700 | [diff] [blame] | 360 | // find the association between core switches and aggregation switches |
| 361 | var aggregationSwitchMap = {}; |
| 362 | model.aggregationSwitches.forEach(function (s, i) { |
Paul Greyson | c17278a | 2013-03-23 10:17:12 -0700 | [diff] [blame] | 363 | aggregationSwitchMap[s.dpid] = i; |
Paul Greyson | 3f890b6 | 2013-03-22 17:39:36 -0700 | [diff] [blame] | 364 | }); |
| 365 | |
Paul Greyson | 3f890b6 | 2013-03-22 17:39:36 -0700 | [diff] [blame] | 366 | // put core switches next to linked aggregation switches |
Paul Greyson | de7fad5 | 2013-03-19 12:47:32 -0700 | [diff] [blame] | 367 | k = 360 / rings[2].switches.length; |
| 368 | rings[2].switches.forEach(function (s, i) { |
Paul Greyson | 3f890b6 | 2013-03-22 17:39:36 -0700 | [diff] [blame] | 369 | // rings[2].angles[i] = k * i; |
Paul Greyson | c17278a | 2013-03-23 10:17:12 -0700 | [diff] [blame] | 370 | var associatedAggregationSwitches = model.configuration.association[s.dpid]; |
| 371 | // TODO: go between if there are multiple |
| 372 | var index = aggregationSwitchMap[associatedAggregationSwitches[0]]; |
| 373 | |
| 374 | rings[2].angles[i] = rings[1].angles[index]; |
Paul Greyson | de7fad5 | 2013-03-19 12:47:32 -0700 | [diff] [blame] | 375 | }); |
| 376 | |
Paul Greyson | 644d92a | 2013-03-23 18:00:40 -0700 | [diff] [blame] | 377 | // TODO: construct this form initially rather than converting. it works better because |
| 378 | // it allows binding by dpid |
| 379 | var testRings = []; |
| 380 | rings.forEach(function (ring) { |
| 381 | var testRing = []; |
| 382 | ring.switches.forEach(function (s, i) { |
| 383 | var testSwitch = { |
| 384 | dpid: s.dpid, |
| 385 | state: s.state, |
| 386 | radius: ring.radius, |
| 387 | width: ring.width, |
| 388 | className: ring.className, |
| 389 | angle: ring.angles[i], |
| 390 | controller: s.controller |
Paul Greyson | 127d7fb | 2013-03-25 23:39:20 -0700 | [diff] [blame] | 391 | }; |
Paul Greyson | 644d92a | 2013-03-23 18:00:40 -0700 | [diff] [blame] | 392 | testRing.push(testSwitch); |
| 393 | }); |
Paul Greyson | 6d9ed86 | 2013-03-23 17:37:15 -0700 | [diff] [blame] | 394 | |
| 395 | |
Paul Greyson | 644d92a | 2013-03-23 18:00:40 -0700 | [diff] [blame] | 396 | testRings.push(testRing); |
| 397 | }); |
Paul Greyson | 6d9ed86 | 2013-03-23 17:37:15 -0700 | [diff] [blame] | 398 | |
| 399 | |
Paul Greyson | 644d92a | 2013-03-23 18:00:40 -0700 | [diff] [blame] | 400 | // return rings; |
| 401 | return testRings; |
Paul Greyson | c17278a | 2013-03-23 10:17:12 -0700 | [diff] [blame] | 402 | } |
| 403 | |
Paul Greyson | 40c8a59 | 2013-03-27 14:10:33 -0700 | [diff] [blame] | 404 | function makeLinkKey(link) { |
| 405 | return link['src-switch'] + '=>' + link['dst-switch']; |
| 406 | } |
| 407 | |
Paul Greyson | 13f02b9 | 2013-03-28 11:29:35 -0700 | [diff] [blame^] | 408 | function makeFlowKey(flow) { |
| 409 | return flow.dataPath.srcPort.dpid.value + '=>' + flow.dataPath.dstPort.dpid.value; |
| 410 | } |
| 411 | |
Paul Greyson | 40c8a59 | 2013-03-27 14:10:33 -0700 | [diff] [blame] | 412 | function createLinkMap(links) { |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 413 | var linkMap = {}; |
Paul Greyson | 40c8a59 | 2013-03-27 14:10:33 -0700 | [diff] [blame] | 414 | links.forEach(function (link) { |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 415 | var srcDPID = link['src-switch']; |
| 416 | var dstDPID = link['dst-switch']; |
| 417 | |
| 418 | var srcMap = linkMap[srcDPID] || {}; |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 419 | |
Paul Greyson | 8d1c636 | 2013-03-27 13:05:24 -0700 | [diff] [blame] | 420 | srcMap[dstDPID] = link; |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 421 | |
| 422 | linkMap[srcDPID] = srcMap; |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 423 | }); |
| 424 | return linkMap; |
| 425 | } |
| 426 | |
Paul Greyson | 5cc35f0 | 2013-03-28 10:07:36 -0700 | [diff] [blame] | 427 | // removes links from the pending list that are now in the model |
| 428 | function reconcilePendingLinks(model) { |
Paul Greyson | 40c8a59 | 2013-03-27 14:10:33 -0700 | [diff] [blame] | 429 | var links = []; |
| 430 | model.links.forEach(function (link) { |
| 431 | links.push(link); |
| 432 | delete pendingLinks[makeLinkKey(link)] |
| 433 | }) |
| 434 | var linkId; |
| 435 | for (linkId in pendingLinks) { |
| 436 | links.push(pendingLinks[linkId]); |
| 437 | } |
Paul Greyson | 5cc35f0 | 2013-03-28 10:07:36 -0700 | [diff] [blame] | 438 | return links |
| 439 | } |
Paul Greyson | 40c8a59 | 2013-03-27 14:10:33 -0700 | [diff] [blame] | 440 | |
Paul Greyson | 5cc35f0 | 2013-03-28 10:07:36 -0700 | [diff] [blame] | 441 | updateTopology = function() { |
| 442 | |
| 443 | // DRAW THE SWITCHES |
| 444 | var rings = svg.selectAll('.ring').data(createRingsFromModel(model)); |
| 445 | |
| 446 | var links = reconcilePendingLinks(model); |
Paul Greyson | 40c8a59 | 2013-03-27 14:10:33 -0700 | [diff] [blame] | 447 | var linkMap = createLinkMap(links); |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 448 | |
Paul Greyson | 8d1c636 | 2013-03-27 13:05:24 -0700 | [diff] [blame] | 449 | function mouseOverSwitch(data) { |
Paul Greyson | 72f1885 | 2013-03-27 15:56:11 -0700 | [diff] [blame] | 450 | |
| 451 | d3.event.preventDefault(); |
| 452 | |
Paul Greyson | 5cc35f0 | 2013-03-28 10:07:36 -0700 | [diff] [blame] | 453 | d3.select(document.getElementById(data.dpid + '-label')).classed('nolabel', false); |
| 454 | |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 455 | if (data.highlighted) { |
| 456 | return; |
| 457 | } |
| 458 | |
| 459 | // only highlight valid link or flow destination by checking for class of existing highlighted circle |
Paul Greyson | 421bfcd | 2013-03-27 22:22:09 -0700 | [diff] [blame] | 460 | var highlighted = svg.selectAll('.highlight')[0]; |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 461 | if (highlighted.length == 1) { |
Paul Greyson | 421bfcd | 2013-03-27 22:22:09 -0700 | [diff] [blame] | 462 | var s = d3.select(highlighted[0]).select('circle'); |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 463 | // only allow links |
| 464 | // edge->edge (flow) |
| 465 | // aggregation->core |
| 466 | // core->core |
| 467 | if (data.className == 'edge' && !s.classed('edge') || |
| 468 | data.className == 'core' && !s.classed('core') && !s.classed('aggregation') || |
| 469 | data.className == 'aggregation' && !s.classed('core')) { |
| 470 | return; |
| 471 | } |
| 472 | |
| 473 | // don't highlight if there's already a link or flow |
| 474 | // var map = linkMap[data.dpid]; |
| 475 | // console.log(map); |
| 476 | // console.log(s.data()[0].dpid); |
| 477 | // console.log(map[s.data()[0].dpid]); |
| 478 | // if (map && map[s.data()[0].dpid]) { |
| 479 | // return; |
| 480 | // } |
| 481 | |
| 482 | // the second highlighted switch is the target for a link or flow |
| 483 | data.target = true; |
| 484 | } |
| 485 | |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 486 | var node = d3.select(document.getElementById(data.dpid)); |
Paul Greyson | 421bfcd | 2013-03-27 22:22:09 -0700 | [diff] [blame] | 487 | node.classed('highlight', true).select('circle').transition().duration(100).attr("r", widths.core); |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 488 | data.highlighted = true; |
| 489 | node.moveToFront(); |
| 490 | } |
| 491 | |
Paul Greyson | 8d1c636 | 2013-03-27 13:05:24 -0700 | [diff] [blame] | 492 | function mouseOutSwitch(data) { |
Paul Greyson | 5cc35f0 | 2013-03-28 10:07:36 -0700 | [diff] [blame] | 493 | d3.select(document.getElementById(data.dpid + '-label')).classed('nolabel', true); |
| 494 | |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 495 | if (data.mouseDown) |
| 496 | return; |
| 497 | |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 498 | var node = d3.select(document.getElementById(data.dpid)); |
Paul Greyson | 421bfcd | 2013-03-27 22:22:09 -0700 | [diff] [blame] | 499 | node.classed('highlight', false).select('circle').transition().duration(100).attr("r", widths[data.className]); |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 500 | data.highlighted = false; |
| 501 | data.target = false; |
| 502 | } |
| 503 | |
Paul Greyson | 8d1c636 | 2013-03-27 13:05:24 -0700 | [diff] [blame] | 504 | function mouseDownSwitch(data) { |
| 505 | mouseOverSwitch(data); |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 506 | data.mouseDown = true; |
Paul Greyson | 72f1885 | 2013-03-27 15:56:11 -0700 | [diff] [blame] | 507 | d3.select('#topology').classed('linking', true); |
| 508 | |
Paul Greyson | 421bfcd | 2013-03-27 22:22:09 -0700 | [diff] [blame] | 509 | d3.select('svg') |
| 510 | .append('svg:path') |
| 511 | .attr('id', 'linkVector') |
| 512 | .attr('d', function () { |
| 513 | var s = d3.select(document.getElementById(data.dpid)); |
| 514 | |
| 515 | var pt = document.querySelector('svg').createSVGPoint(); |
| 516 | pt.x = s.attr('x'); |
| 517 | pt.y = s.attr('y'); |
| 518 | pt = pt.matrixTransform(s[0][0].getCTM()); |
| 519 | |
| 520 | return line([pt, pt]); |
| 521 | }); |
| 522 | |
| 523 | |
Paul Greyson | 72f1885 | 2013-03-27 15:56:11 -0700 | [diff] [blame] | 524 | if (data.className === 'core') { |
| 525 | d3.selectAll('.edge').classed('nodrop', true); |
| 526 | } |
| 527 | if (data.className === 'edge') { |
| 528 | d3.selectAll('.core').classed('nodrop', true); |
| 529 | d3.selectAll('.aggregation').classed('nodrop', true); |
| 530 | } |
| 531 | if (data.className === 'aggregation') { |
| 532 | d3.selectAll('.edge').classed('nodrop', true); |
| 533 | d3.selectAll('.aggregation').classed('nodrop', true); |
| 534 | } |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 535 | } |
| 536 | |
Paul Greyson | 8d1c636 | 2013-03-27 13:05:24 -0700 | [diff] [blame] | 537 | function mouseUpSwitch(data) { |
| 538 | if (data.mouseDown) { |
| 539 | data.mouseDown = false; |
Paul Greyson | 72f1885 | 2013-03-27 15:56:11 -0700 | [diff] [blame] | 540 | d3.select('#topology').classed('linking', false); |
Paul Greyson | 8d1c636 | 2013-03-27 13:05:24 -0700 | [diff] [blame] | 541 | d3.event.stopPropagation(); |
Paul Greyson | 72f1885 | 2013-03-27 15:56:11 -0700 | [diff] [blame] | 542 | d3.selectAll('.nodrop').classed('nodrop', false); |
Paul Greyson | 8d1c636 | 2013-03-27 13:05:24 -0700 | [diff] [blame] | 543 | } |
| 544 | } |
| 545 | |
| 546 | function doubleClickSwitch(data) { |
Paul Greyson | 084779b | 2013-03-27 13:55:49 -0700 | [diff] [blame] | 547 | var circle = d3.select(document.getElementById(data.dpid)).select('circle'); |
Paul Greyson | 8d1c636 | 2013-03-27 13:05:24 -0700 | [diff] [blame] | 548 | if (data.state == 'ACTIVE') { |
| 549 | var prompt = 'Deactivate ' + data.dpid + '?'; |
| 550 | if (confirm(prompt)) { |
| 551 | switchDown(data); |
Paul Greyson | 084779b | 2013-03-27 13:55:49 -0700 | [diff] [blame] | 552 | setPending(circle); |
Paul Greyson | 8d1c636 | 2013-03-27 13:05:24 -0700 | [diff] [blame] | 553 | } |
| 554 | } else { |
| 555 | var prompt = 'Activate ' + data.dpid + '?'; |
| 556 | if (confirm(prompt)) { |
| 557 | switchUp(data); |
Paul Greyson | 084779b | 2013-03-27 13:55:49 -0700 | [diff] [blame] | 558 | setPending(circle); |
Paul Greyson | 8d1c636 | 2013-03-27 13:05:24 -0700 | [diff] [blame] | 559 | } |
| 560 | } |
| 561 | } |
| 562 | |
Paul Greyson | 740bdaf | 2013-03-18 16:10:48 -0700 | [diff] [blame] | 563 | function ringEnter(data, i) { |
Paul Greyson | 644d92a | 2013-03-23 18:00:40 -0700 | [diff] [blame] | 564 | if (!data.length) { |
Paul Greyson | 740bdaf | 2013-03-18 16:10:48 -0700 | [diff] [blame] | 565 | return; |
| 566 | } |
| 567 | |
Paul Greyson | c17278a | 2013-03-23 10:17:12 -0700 | [diff] [blame] | 568 | // create the nodes |
Paul Greyson | f9edc1a | 2013-03-19 13:22:06 -0700 | [diff] [blame] | 569 | var nodes = d3.select(this).selectAll("g") |
Paul Greyson | 644d92a | 2013-03-23 18:00:40 -0700 | [diff] [blame] | 570 | .data(data, function (data) { |
| 571 | return data.dpid; |
| 572 | }) |
Paul Greyson | 740bdaf | 2013-03-18 16:10:48 -0700 | [diff] [blame] | 573 | .enter().append("svg:g") |
Paul Greyson | 644d92a | 2013-03-23 18:00:40 -0700 | [diff] [blame] | 574 | .attr("id", function (data, i) { |
| 575 | return data.dpid; |
Paul Greyson | 23b0cd3 | 2013-03-18 23:45:48 -0700 | [diff] [blame] | 576 | }) |
Paul Greyson | 644d92a | 2013-03-23 18:00:40 -0700 | [diff] [blame] | 577 | .attr("transform", function(data, i) { |
| 578 | return "rotate(" + data.angle+ ")translate(" + data.radius * 150 + ")rotate(" + (-data.angle) + ")"; |
Paul Greyson | f9edc1a | 2013-03-19 13:22:06 -0700 | [diff] [blame] | 579 | }); |
| 580 | |
Paul Greyson | c17278a | 2013-03-23 10:17:12 -0700 | [diff] [blame] | 581 | // add the cirles representing the switches |
Paul Greyson | f9edc1a | 2013-03-19 13:22:06 -0700 | [diff] [blame] | 582 | nodes.append("svg:circle") |
Paul Greyson | 644d92a | 2013-03-23 18:00:40 -0700 | [diff] [blame] | 583 | .attr("transform", function(data, i) { |
Paul Greyson | d1a22d9 | 2013-03-19 12:15:19 -0700 | [diff] [blame] | 584 | var m = document.querySelector('#viewbox').getTransformToElement().inverse(); |
Paul Greyson | f8f4317 | 2013-03-18 23:00:30 -0700 | [diff] [blame] | 585 | if (data.scale) { |
| 586 | m = m.scale(data.scale); |
| 587 | } |
| 588 | return "matrix( " + m.a + " " + m.b + " " + m.c + " " + m.d + " " + m.e + " " + m.f + " )"; |
Paul Greyson | 952ccb6 | 2013-03-18 22:22:08 -0700 | [diff] [blame] | 589 | }) |
Paul Greyson | 644d92a | 2013-03-23 18:00:40 -0700 | [diff] [blame] | 590 | .attr("x", function (data) { |
| 591 | return -data.width / 2; |
| 592 | }) |
| 593 | .attr("y", function (data) { |
| 594 | return -data.width / 2; |
| 595 | }) |
| 596 | .attr("r", function (data) { |
| 597 | return data.width; |
Paul Greyson | 127d7fb | 2013-03-25 23:39:20 -0700 | [diff] [blame] | 598 | }); |
Paul Greyson | f9edc1a | 2013-03-19 13:22:06 -0700 | [diff] [blame] | 599 | |
Paul Greyson | c17278a | 2013-03-23 10:17:12 -0700 | [diff] [blame] | 600 | // setup the mouseover behaviors |
Paul Greyson | 8d1c636 | 2013-03-27 13:05:24 -0700 | [diff] [blame] | 601 | nodes.on('mouseover', mouseOverSwitch); |
| 602 | nodes.on('mouseout', mouseOutSwitch); |
| 603 | nodes.on('mouseup', mouseUpSwitch); |
| 604 | nodes.on('mousedown', mouseDownSwitch); |
| 605 | |
| 606 | // only do switch up/down for core switches |
| 607 | if (i == 2) { |
| 608 | nodes.on('dblclick', doubleClickSwitch); |
| 609 | } |
Paul Greyson | 740bdaf | 2013-03-18 16:10:48 -0700 | [diff] [blame] | 610 | } |
| 611 | |
Paul Greyson | c17278a | 2013-03-23 10:17:12 -0700 | [diff] [blame] | 612 | // append switches |
| 613 | rings.enter().append("svg:g") |
Paul Greyson | 740bdaf | 2013-03-18 16:10:48 -0700 | [diff] [blame] | 614 | .attr("class", "ring") |
| 615 | .each(ringEnter); |
Paul Greyson | f8f4317 | 2013-03-18 23:00:30 -0700 | [diff] [blame] | 616 | |
Paul Greyson | f9edc1a | 2013-03-19 13:22:06 -0700 | [diff] [blame] | 617 | |
Paul Greyson | c17278a | 2013-03-23 10:17:12 -0700 | [diff] [blame] | 618 | function ringUpdate(data, i) { |
Paul Greyson | 127d7fb | 2013-03-25 23:39:20 -0700 | [diff] [blame] | 619 | var nodes = d3.select(this).selectAll("g") |
Paul Greyson | 644d92a | 2013-03-23 18:00:40 -0700 | [diff] [blame] | 620 | .data(data, function (data) { |
| 621 | return data.dpid; |
Paul Greyson | 127d7fb | 2013-03-25 23:39:20 -0700 | [diff] [blame] | 622 | }); |
Paul Greyson | 347fb74 | 2013-03-27 13:40:29 -0700 | [diff] [blame] | 623 | nodes.select('circle') |
| 624 | .each(function (data) { |
| 625 | // if there's a pending state changed and then the state changes, clear the pending class |
| 626 | var circle = d3.select(this); |
| 627 | if (data.state === 'ACTIVE' && circle.classed('inactive') || |
| 628 | data.state === 'INACTIVE' && circle.classed('active')) { |
| 629 | circle.classed('pending', false); |
| 630 | } |
| 631 | }) |
| 632 | .attr('class', function (data) { |
Paul Greyson | 8d1c636 | 2013-03-27 13:05:24 -0700 | [diff] [blame] | 633 | if (data.state === 'ACTIVE' && data.controller) { |
Paul Greyson | 347fb74 | 2013-03-27 13:40:29 -0700 | [diff] [blame] | 634 | return data.className + ' active ' + controllerColorMap[data.controller]; |
Paul Greyson | c17278a | 2013-03-23 10:17:12 -0700 | [diff] [blame] | 635 | } else { |
Paul Greyson | 347fb74 | 2013-03-27 13:40:29 -0700 | [diff] [blame] | 636 | return data.className + ' inactive ' + 'colorInactive'; |
Paul Greyson | c17278a | 2013-03-23 10:17:12 -0700 | [diff] [blame] | 637 | } |
Paul Greyson | 127d7fb | 2013-03-25 23:39:20 -0700 | [diff] [blame] | 638 | }); |
Paul Greyson | c17278a | 2013-03-23 10:17:12 -0700 | [diff] [blame] | 639 | } |
| 640 | |
| 641 | // update switches |
| 642 | rings.each(ringUpdate); |
| 643 | |
Paul Greyson | 968d1b4 | 2013-03-23 16:58:41 -0700 | [diff] [blame] | 644 | |
| 645 | // Now setup the labels |
| 646 | // This is done separately because SVG draws in node order and we want the labels |
| 647 | // always on top |
| 648 | var labelRings = svg.selectAll('.labelRing').data(createRingsFromModel(model)); |
| 649 | |
Paul Greyson | 421bfcd | 2013-03-27 22:22:09 -0700 | [diff] [blame] | 650 | d3.select(document.body).on('mousemove', function () { |
| 651 | if (!d3.select('#topology').classed('linking')) { |
| 652 | return; |
| 653 | } |
| 654 | var linkVector = document.getElementById('linkVector'); |
| 655 | if (!linkVector) { |
| 656 | return; |
| 657 | } |
| 658 | linkVector = d3.select(linkVector); |
| 659 | |
| 660 | var highlighted = svg.selectAll('.highlight')[0]; |
| 661 | var s1 = null, s2 = null; |
| 662 | if (highlighted.length > 1) { |
| 663 | var s1 = d3.select(highlighted[0]); |
| 664 | var s2 = d3.select(highlighted[1]); |
| 665 | |
| 666 | } else if (highlighted.length > 0) { |
| 667 | var s1 = d3.select(highlighted[0]); |
| 668 | } |
| 669 | var src = s1; |
| 670 | if (s2 && !s2.data()[0].target) { |
| 671 | src = s2; |
| 672 | } |
| 673 | if (src) { |
| 674 | linkVector.attr('d', function () { |
| 675 | var srcPt = document.querySelector('svg').createSVGPoint(); |
| 676 | srcPt.x = src.attr('x'); |
| 677 | srcPt.y = src.attr('y'); |
| 678 | srcPt = srcPt.matrixTransform(src[0][0].getCTM()); |
| 679 | |
| 680 | var svg = document.getElementById('topology'); |
| 681 | var mouse = d3.mouse(viewbox); |
| 682 | var dstPt = document.querySelector('svg').createSVGPoint(); |
| 683 | dstPt.x = mouse[0]; |
| 684 | dstPt.y = mouse[1]; |
| 685 | dstPt = dstPt.matrixTransform(viewbox.getCTM()); |
| 686 | |
| 687 | return line([srcPt, dstPt]); |
| 688 | }); |
| 689 | } |
| 690 | }); |
| 691 | |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 692 | d3.select(document.body).on('mouseup', function () { |
| 693 | function clearHighlight() { |
| 694 | svg.selectAll('circle').each(function (data) { |
| 695 | data.mouseDown = false; |
Paul Greyson | 72f1885 | 2013-03-27 15:56:11 -0700 | [diff] [blame] | 696 | d3.select('#topology').classed('linking', false); |
Paul Greyson | 8d1c636 | 2013-03-27 13:05:24 -0700 | [diff] [blame] | 697 | mouseOutSwitch(data); |
Paul Greyson | 421bfcd | 2013-03-27 22:22:09 -0700 | [diff] [blame] | 698 | }); |
| 699 | d3.select('#linkVector').remove(); |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 700 | }; |
| 701 | |
Paul Greyson | 72f1885 | 2013-03-27 15:56:11 -0700 | [diff] [blame] | 702 | d3.selectAll('.nodrop').classed('nodrop', false); |
| 703 | |
Paul Greyson | 084779b | 2013-03-27 13:55:49 -0700 | [diff] [blame] | 704 | function removeLink(link) { |
| 705 | var path1 = document.getElementById(link['src-switch'] + '=>' + link['dst-switch']); |
| 706 | var path2 = document.getElementById(link['dst-switch'] + '=>' + link['src-switch']); |
| 707 | |
| 708 | if (path1) { |
| 709 | setPending(d3.select(path1)); |
| 710 | } |
| 711 | if (path2) { |
| 712 | setPending(d3.select(path2)); |
| 713 | } |
| 714 | |
| 715 | linkDown(link); |
| 716 | } |
| 717 | |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 718 | |
Paul Greyson | 421bfcd | 2013-03-27 22:22:09 -0700 | [diff] [blame] | 719 | var highlighted = svg.selectAll('.highlight')[0]; |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 720 | if (highlighted.length == 2) { |
Paul Greyson | 421bfcd | 2013-03-27 22:22:09 -0700 | [diff] [blame] | 721 | var s1Data = highlighted[0].__data__; |
| 722 | var s2Data = highlighted[1].__data__; |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 723 | |
| 724 | var srcData, dstData; |
| 725 | if (s1Data.target) { |
| 726 | dstData = s1Data; |
| 727 | srcData = s2Data; |
| 728 | } else { |
| 729 | dstData = s2Data; |
| 730 | srcData = s1Data; |
| 731 | } |
| 732 | |
| 733 | if (s1Data.className == 'edge' && s2Data.className == 'edge') { |
| 734 | var prompt = 'Create flow from ' + srcData.dpid + ' to ' + dstData.dpid + '?'; |
| 735 | if (confirm(prompt)) { |
Paul Greyson | 13f02b9 | 2013-03-28 11:29:35 -0700 | [diff] [blame^] | 736 | addFlow(srcData, dstData); |
| 737 | |
| 738 | var flow = { |
| 739 | dataPath: { |
| 740 | srcPort: { |
| 741 | dpid: { |
| 742 | value: srcData.dpid |
| 743 | } |
| 744 | }, |
| 745 | dstPort: { |
| 746 | dpid: { |
| 747 | value: dstData.dpid |
| 748 | } |
| 749 | } |
| 750 | }, |
| 751 | pending: true |
| 752 | }; |
| 753 | |
| 754 | selectFlow(flow); |
| 755 | |
| 756 | setTimeout(function () { |
| 757 | deselectFlow(flow); |
| 758 | }, 10000); |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 759 | } |
| 760 | } else { |
| 761 | var map = linkMap[srcData.dpid]; |
| 762 | if (map && map[dstData.dpid]) { |
| 763 | var prompt = 'Remove link between ' + srcData.dpid + ' and ' + dstData.dpid + '?'; |
| 764 | if (confirm(prompt)) { |
Paul Greyson | 084779b | 2013-03-27 13:55:49 -0700 | [diff] [blame] | 765 | removeLink(map[dstData.dpid]); |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 766 | } |
| 767 | } else { |
Paul Greyson | 8d1c636 | 2013-03-27 13:05:24 -0700 | [diff] [blame] | 768 | map = linkMap[dstData.dpid]; |
| 769 | if (map && map[srcData.dpid]) { |
| 770 | var prompt = 'Remove link between ' + dstData.dpid + ' and ' + srcData.dpid + '?'; |
| 771 | if (confirm(prompt)) { |
Paul Greyson | 084779b | 2013-03-27 13:55:49 -0700 | [diff] [blame] | 772 | removeLink(map[srcData.dpid]); |
Paul Greyson | 8d1c636 | 2013-03-27 13:05:24 -0700 | [diff] [blame] | 773 | } |
| 774 | } else { |
| 775 | var prompt = 'Create link between ' + srcData.dpid + ' and ' + dstData.dpid + '?'; |
| 776 | if (confirm(prompt)) { |
Paul Greyson | 40c8a59 | 2013-03-27 14:10:33 -0700 | [diff] [blame] | 777 | var link1 = { |
| 778 | 'src-switch': srcData.dpid, |
Paul Greyson | 2913af8 | 2013-03-27 14:53:17 -0700 | [diff] [blame] | 779 | 'src-port': 1, |
Paul Greyson | 40c8a59 | 2013-03-27 14:10:33 -0700 | [diff] [blame] | 780 | 'dst-switch': dstData.dpid, |
Paul Greyson | 2913af8 | 2013-03-27 14:53:17 -0700 | [diff] [blame] | 781 | 'dst-port': 1, |
Paul Greyson | 40c8a59 | 2013-03-27 14:10:33 -0700 | [diff] [blame] | 782 | pending: true |
| 783 | }; |
| 784 | pendingLinks[makeLinkKey(link1)] = link1; |
| 785 | var link2 = { |
| 786 | 'src-switch': dstData.dpid, |
Paul Greyson | 2913af8 | 2013-03-27 14:53:17 -0700 | [diff] [blame] | 787 | 'src-port': 1, |
Paul Greyson | 40c8a59 | 2013-03-27 14:10:33 -0700 | [diff] [blame] | 788 | 'dst-switch': srcData.dpid, |
Paul Greyson | 2913af8 | 2013-03-27 14:53:17 -0700 | [diff] [blame] | 789 | 'dst-port': 1, |
Paul Greyson | 40c8a59 | 2013-03-27 14:10:33 -0700 | [diff] [blame] | 790 | pending: true |
| 791 | }; |
| 792 | pendingLinks[makeLinkKey(link2)] = link2; |
Paul Greyson | 5cc35f0 | 2013-03-28 10:07:36 -0700 | [diff] [blame] | 793 | updateTopology(); |
Paul Greyson | 40c8a59 | 2013-03-27 14:10:33 -0700 | [diff] [blame] | 794 | |
Paul Greyson | 2913af8 | 2013-03-27 14:53:17 -0700 | [diff] [blame] | 795 | linkUp(link1); |
Paul Greyson | 40c8a59 | 2013-03-27 14:10:33 -0700 | [diff] [blame] | 796 | |
Paul Greyson | 5cc35f0 | 2013-03-28 10:07:36 -0700 | [diff] [blame] | 797 | // remove the pending links after 10s |
Paul Greyson | 40c8a59 | 2013-03-27 14:10:33 -0700 | [diff] [blame] | 798 | setTimeout(function () { |
| 799 | delete pendingLinks[makeLinkKey(link1)]; |
| 800 | delete pendingLinks[makeLinkKey(link2)]; |
| 801 | |
Paul Greyson | 5cc35f0 | 2013-03-28 10:07:36 -0700 | [diff] [blame] | 802 | updateTopology(); |
Paul Greyson | 40c8a59 | 2013-03-27 14:10:33 -0700 | [diff] [blame] | 803 | }, 10000); |
Paul Greyson | 8d1c636 | 2013-03-27 13:05:24 -0700 | [diff] [blame] | 804 | } |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 805 | } |
| 806 | } |
| 807 | } |
| 808 | |
| 809 | clearHighlight(); |
| 810 | } else { |
| 811 | clearHighlight(); |
| 812 | } |
| 813 | |
| 814 | }); |
| 815 | |
Paul Greyson | 9066ab0 | 2013-03-23 18:15:41 -0700 | [diff] [blame] | 816 | function labelRingEnter(data) { |
Paul Greyson | 644d92a | 2013-03-23 18:00:40 -0700 | [diff] [blame] | 817 | if (!data.length) { |
Paul Greyson | 968d1b4 | 2013-03-23 16:58:41 -0700 | [diff] [blame] | 818 | return; |
| 819 | } |
| 820 | |
| 821 | // create the nodes |
| 822 | var nodes = d3.select(this).selectAll("g") |
Paul Greyson | 644d92a | 2013-03-23 18:00:40 -0700 | [diff] [blame] | 823 | .data(data, function (data) { |
| 824 | return data.dpid; |
| 825 | }) |
Paul Greyson | 968d1b4 | 2013-03-23 16:58:41 -0700 | [diff] [blame] | 826 | .enter().append("svg:g") |
| 827 | .classed('nolabel', true) |
Paul Greyson | 9066ab0 | 2013-03-23 18:15:41 -0700 | [diff] [blame] | 828 | .attr("id", function (data) { |
Paul Greyson | 644d92a | 2013-03-23 18:00:40 -0700 | [diff] [blame] | 829 | return data.dpid + '-label'; |
Paul Greyson | 968d1b4 | 2013-03-23 16:58:41 -0700 | [diff] [blame] | 830 | }) |
Paul Greyson | 644d92a | 2013-03-23 18:00:40 -0700 | [diff] [blame] | 831 | .attr("transform", function(data, i) { |
| 832 | return "rotate(" + data.angle+ ")translate(" + data.radius * 150 + ")rotate(" + (-data.angle) + ")"; |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 833 | }) |
Paul Greyson | 968d1b4 | 2013-03-23 16:58:41 -0700 | [diff] [blame] | 834 | |
| 835 | // add the text nodes which show on mouse over |
| 836 | nodes.append("svg:text") |
Paul Greyson | 127d7fb | 2013-03-25 23:39:20 -0700 | [diff] [blame] | 837 | .text(function (data) {return data.dpid;}) |
Paul Greyson | 9066ab0 | 2013-03-23 18:15:41 -0700 | [diff] [blame] | 838 | .attr("x", function (data) { |
| 839 | if (data.angle <= 90 || data.angle >= 270 && data.angle <= 360) { |
| 840 | if (data.className == 'edge') { |
Paul Greyson | 1eb2dd1 | 2013-03-23 18:22:00 -0700 | [diff] [blame] | 841 | return - data.width*3 - 4; |
Paul Greyson | 9066ab0 | 2013-03-23 18:15:41 -0700 | [diff] [blame] | 842 | } else { |
Paul Greyson | 1eb2dd1 | 2013-03-23 18:22:00 -0700 | [diff] [blame] | 843 | return - data.width - 4; |
Paul Greyson | 9066ab0 | 2013-03-23 18:15:41 -0700 | [diff] [blame] | 844 | } |
| 845 | } else { |
| 846 | if (data.className == 'edge') { |
| 847 | return data.width*3 + 4; |
| 848 | } else { |
| 849 | return data.width + 4; |
| 850 | } |
| 851 | } |
| 852 | }) |
| 853 | .attr("y", function (data) { |
| 854 | var y; |
| 855 | if (data.angle <= 90 || data.angle >= 270 && data.angle <= 360) { |
| 856 | if (data.className == 'edge') { |
| 857 | y = data.width*3/2 + 4; |
| 858 | } else { |
| 859 | y = data.width/2 + 4; |
| 860 | } |
| 861 | } else { |
| 862 | if (data.className == 'edge') { |
| 863 | y = data.width*3/2 + 4; |
| 864 | } else { |
| 865 | y = data.width/2 + 4; |
| 866 | } |
| 867 | } |
| 868 | return y - 6; |
| 869 | }) |
| 870 | .attr("text-anchor", function (data) { |
| 871 | if (data.angle <= 90 || data.angle >= 270 && data.angle <= 360) { |
| 872 | return "end"; |
| 873 | } else { |
| 874 | return "start"; |
| 875 | } |
| 876 | }) |
| 877 | .attr("transform", function(data) { |
Paul Greyson | 968d1b4 | 2013-03-23 16:58:41 -0700 | [diff] [blame] | 878 | var m = document.querySelector('#viewbox').getTransformToElement().inverse(); |
| 879 | if (data.scale) { |
| 880 | m = m.scale(data.scale); |
| 881 | } |
| 882 | return "matrix( " + m.a + " " + m.b + " " + m.c + " " + m.d + " " + m.e + " " + m.f + " )"; |
| 883 | }) |
| 884 | } |
| 885 | |
| 886 | labelRings.enter().append("svg:g") |
| 887 | .attr("class", "textRing") |
| 888 | .each(labelRingEnter); |
| 889 | |
Paul Greyson | c17278a | 2013-03-23 10:17:12 -0700 | [diff] [blame] | 890 | // switches should not change during operation of the ui so no |
| 891 | // rings.exit() |
| 892 | |
| 893 | |
Paul Greyson | d1a22d9 | 2013-03-19 12:15:19 -0700 | [diff] [blame] | 894 | // DRAW THE LINKS |
Paul Greyson | d1a22d9 | 2013-03-19 12:15:19 -0700 | [diff] [blame] | 895 | |
Paul Greyson | c17278a | 2013-03-23 10:17:12 -0700 | [diff] [blame] | 896 | // key on link dpids since these will come/go during demo |
Paul Greyson | 40c8a59 | 2013-03-27 14:10:33 -0700 | [diff] [blame] | 897 | var links = d3.select('svg').selectAll('.link').data(links, function (d) { |
Paul Greyson | c17278a | 2013-03-23 10:17:12 -0700 | [diff] [blame] | 898 | return d['src-switch']+'->'+d['dst-switch']; |
| 899 | }); |
| 900 | |
| 901 | // add new links |
Paul Greyson | b367de2 | 2013-03-23 11:09:11 -0700 | [diff] [blame] | 902 | links.enter().append("svg:path") |
Paul Greyson | 56378ed | 2013-03-26 23:17:36 -0700 | [diff] [blame] | 903 | .attr("class", "link"); |
| 904 | |
Paul Greyson | 084779b | 2013-03-27 13:55:49 -0700 | [diff] [blame] | 905 | links.attr('id', function (d) { |
Paul Greyson | 40c8a59 | 2013-03-27 14:10:33 -0700 | [diff] [blame] | 906 | return makeLinkKey(d); |
Paul Greyson | 084779b | 2013-03-27 13:55:49 -0700 | [diff] [blame] | 907 | }) |
Paul Greyson | 56378ed | 2013-03-26 23:17:36 -0700 | [diff] [blame] | 908 | .attr("d", function (d) { |
Paul Greyson | 084779b | 2013-03-27 13:55:49 -0700 | [diff] [blame] | 909 | var src = d3.select(document.getElementById(d['src-switch'])); |
| 910 | var dst = d3.select(document.getElementById(d['dst-switch'])); |
Paul Greyson | c17278a | 2013-03-23 10:17:12 -0700 | [diff] [blame] | 911 | |
Paul Greyson | 084779b | 2013-03-27 13:55:49 -0700 | [diff] [blame] | 912 | var srcPt = document.querySelector('svg').createSVGPoint(); |
| 913 | srcPt.x = src.attr('x'); |
| 914 | srcPt.y = src.attr('y'); |
| 915 | srcPt = srcPt.matrixTransform(src[0][0].getCTM()); |
Paul Greyson | d1a22d9 | 2013-03-19 12:15:19 -0700 | [diff] [blame] | 916 | |
Paul Greyson | 084779b | 2013-03-27 13:55:49 -0700 | [diff] [blame] | 917 | var dstPt = document.querySelector('svg').createSVGPoint(); |
| 918 | dstPt.x = dst.attr('x'); |
Paul Greyson | 421bfcd | 2013-03-27 22:22:09 -0700 | [diff] [blame] | 919 | dstPt.y = dst.attr('y'); |
Paul Greyson | 084779b | 2013-03-27 13:55:49 -0700 | [diff] [blame] | 920 | dstPt = dstPt.matrixTransform(dst[0][0].getCTM()); |
Paul Greyson | d1a22d9 | 2013-03-19 12:15:19 -0700 | [diff] [blame] | 921 | |
Paul Greyson | 084779b | 2013-03-27 13:55:49 -0700 | [diff] [blame] | 922 | var midPt = document.querySelector('svg').createSVGPoint(); |
| 923 | midPt.x = (srcPt.x + dstPt.x)/2; |
| 924 | midPt.y = (srcPt.y + dstPt.y)/2; |
Paul Greyson | d1a22d9 | 2013-03-19 12:15:19 -0700 | [diff] [blame] | 925 | |
Paul Greyson | 084779b | 2013-03-27 13:55:49 -0700 | [diff] [blame] | 926 | return line([srcPt, midPt, dstPt]); |
| 927 | }) |
Paul Greyson | 40c8a59 | 2013-03-27 14:10:33 -0700 | [diff] [blame] | 928 | .attr("marker-mid", function(d) { return "url(#arrow)"; }) |
| 929 | .classed('pending', function (d) { |
| 930 | return d.pending; |
| 931 | }); |
Paul Greyson | c17278a | 2013-03-23 10:17:12 -0700 | [diff] [blame] | 932 | |
Paul Greyson | 56378ed | 2013-03-26 23:17:36 -0700 | [diff] [blame] | 933 | |
Paul Greyson | c17278a | 2013-03-23 10:17:12 -0700 | [diff] [blame] | 934 | // remove old links |
| 935 | links.exit().remove(); |
Paul Greyson | d1a22d9 | 2013-03-19 12:15:19 -0700 | [diff] [blame] | 936 | } |
| 937 | |
Paul Greyson | 5cc35f0 | 2013-03-28 10:07:36 -0700 | [diff] [blame] | 938 | function updateControllers() { |
Paul Greyson | d1a22d9 | 2013-03-19 12:15:19 -0700 | [diff] [blame] | 939 | var controllers = d3.select('#controllerList').selectAll('.controller').data(model.controllers); |
Paul Greyson | 3e14216 | 2013-03-19 13:56:17 -0700 | [diff] [blame] | 940 | controllers.enter().append('div') |
Paul Greyson | e262a29 | 2013-03-23 10:35:23 -0700 | [diff] [blame] | 941 | .each(function (c) { |
| 942 | controllerColorMap[c] = colors.pop(); |
| 943 | d3.select(document.body).classed(controllerColorMap[c] + '-selected', true); |
| 944 | }) |
| 945 | .text(function (d) { |
| 946 | return d; |
Paul Greyson | 2913af8 | 2013-03-27 14:53:17 -0700 | [diff] [blame] | 947 | }) |
| 948 | .append('div') |
Paul Greyson | 8247c3f | 2013-03-28 00:24:02 -0700 | [diff] [blame] | 949 | .attr('class', 'black-eye'); |
Paul Greyson | bcd3c77 | 2013-03-21 13:16:44 -0700 | [diff] [blame] | 950 | |
Paul Greyson | e262a29 | 2013-03-23 10:35:23 -0700 | [diff] [blame] | 951 | controllers.attr('class', function (d) { |
Paul Greyson | eed3635 | 2013-03-23 11:19:11 -0700 | [diff] [blame] | 952 | var color = 'colorInactive'; |
Paul Greyson | bcd3c77 | 2013-03-21 13:16:44 -0700 | [diff] [blame] | 953 | if (model.activeControllers.indexOf(d) != -1) { |
| 954 | color = controllerColorMap[d]; |
Paul Greyson | d1a22d9 | 2013-03-19 12:15:19 -0700 | [diff] [blame] | 955 | } |
Paul Greyson | bcd3c77 | 2013-03-21 13:16:44 -0700 | [diff] [blame] | 956 | var className = 'controller ' + color; |
| 957 | return className; |
Paul Greyson | d1a22d9 | 2013-03-19 12:15:19 -0700 | [diff] [blame] | 958 | }); |
Paul Greyson | d1a22d9 | 2013-03-19 12:15:19 -0700 | [diff] [blame] | 959 | |
Paul Greyson | e262a29 | 2013-03-23 10:35:23 -0700 | [diff] [blame] | 960 | // this should never be needed |
| 961 | // controllers.exit().remove(); |
Paul Greyson | d1a22d9 | 2013-03-19 12:15:19 -0700 | [diff] [blame] | 962 | |
Paul Greyson | 2913af8 | 2013-03-27 14:53:17 -0700 | [diff] [blame] | 963 | controllers.on('dblclick', function (c) { |
| 964 | if (model.activeControllers.indexOf(c) != -1) { |
| 965 | var prompt = 'Dectivate ' + c + '?'; |
| 966 | if (confirm(prompt)) { |
| 967 | controllerDown(c); |
| 968 | setPending(d3.select(this)); |
| 969 | }; |
| 970 | } else { |
| 971 | var prompt = 'Activate ' + c + '?'; |
| 972 | if (confirm(prompt)) { |
| 973 | controllerUp(c); |
| 974 | setPending(d3.select(this)); |
| 975 | }; |
| 976 | } |
| 977 | }); |
| 978 | |
Paul Greyson | 8247c3f | 2013-03-28 00:24:02 -0700 | [diff] [blame] | 979 | controllers.select('.black-eye').on('click', function (c) { |
Paul Greyson | c3e21a0 | 2013-03-21 13:56:05 -0700 | [diff] [blame] | 980 | var allSelected = true; |
| 981 | for (var key in controllerColorMap) { |
| 982 | if (!d3.select(document.body).classed(controllerColorMap[key] + '-selected')) { |
| 983 | allSelected = false; |
| 984 | break; |
| 985 | } |
| 986 | } |
| 987 | if (allSelected) { |
| 988 | for (var key in controllerColorMap) { |
| 989 | d3.select(document.body).classed(controllerColorMap[key] + '-selected', key == c) |
| 990 | } |
| 991 | } else { |
| 992 | for (var key in controllerColorMap) { |
| 993 | d3.select(document.body).classed(controllerColorMap[key] + '-selected', true) |
| 994 | } |
| 995 | } |
| 996 | |
| 997 | // var selected = d3.select(document.body).classed(controllerColorMap[c] + '-selected'); |
| 998 | // d3.select(document.body).classed(controllerColorMap[c] + '-selected', !selected); |
Paul Greyson | d1a22d9 | 2013-03-19 12:15:19 -0700 | [diff] [blame] | 999 | }); |
Paul Greyson | 8d1c636 | 2013-03-27 13:05:24 -0700 | [diff] [blame] | 1000 | |
| 1001 | |
Paul Greyson | 740bdaf | 2013-03-18 16:10:48 -0700 | [diff] [blame] | 1002 | } |
| 1003 | |
Paul Greyson | 29aa98d | 2013-03-28 00:09:31 -0700 | [diff] [blame] | 1004 | function sync(svg) { |
Paul Greyson | bcd3c77 | 2013-03-21 13:16:44 -0700 | [diff] [blame] | 1005 | var d = Date.now(); |
Paul Greyson | b48943b | 2013-03-19 13:27:57 -0700 | [diff] [blame] | 1006 | updateModel(function (newModel) { |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 1007 | // console.log('Update time: ' + (Date.now() - d)/1000 + 's'); |
Paul Greyson | 740bdaf | 2013-03-18 16:10:48 -0700 | [diff] [blame] | 1008 | |
Paul Greyson | 5cc35f0 | 2013-03-28 10:07:36 -0700 | [diff] [blame] | 1009 | var modelChanged = false; |
Paul Greyson | 56378ed | 2013-03-26 23:17:36 -0700 | [diff] [blame] | 1010 | if (!model || JSON.stringify(model) != JSON.stringify(newModel)) { |
Paul Greyson | 5cc35f0 | 2013-03-28 10:07:36 -0700 | [diff] [blame] | 1011 | modelChanged = true; |
| 1012 | model = newModel; |
Paul Greyson | b48943b | 2013-03-19 13:27:57 -0700 | [diff] [blame] | 1013 | } else { |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 1014 | // console.log('no change'); |
Paul Greyson | b48943b | 2013-03-19 13:27:57 -0700 | [diff] [blame] | 1015 | } |
Paul Greyson | b48943b | 2013-03-19 13:27:57 -0700 | [diff] [blame] | 1016 | |
Paul Greyson | 5cc35f0 | 2013-03-28 10:07:36 -0700 | [diff] [blame] | 1017 | if (modelChanged) { |
| 1018 | updateControllers(); |
| 1019 | updateSelectedFlows(); |
| 1020 | updateTopology(); |
| 1021 | } |
| 1022 | |
| 1023 | updateHeader(newModel); |
Paul Greyson | 740bdaf | 2013-03-18 16:10:48 -0700 | [diff] [blame] | 1024 | |
| 1025 | // do it again in 1s |
| 1026 | setTimeout(function () { |
Paul Greyson | a36a923 | 2013-03-22 22:41:27 -0700 | [diff] [blame] | 1027 | sync(svg) |
Paul Greyson | d1a22d9 | 2013-03-19 12:15:19 -0700 | [diff] [blame] | 1028 | }, 1000); |
Paul Greyson | 6f86d1e | 2013-03-18 14:40:39 -0700 | [diff] [blame] | 1029 | }); |
| 1030 | } |
Paul Greyson | 740bdaf | 2013-03-18 16:10:48 -0700 | [diff] [blame] | 1031 | |
Paul Greyson | 38d8bde | 2013-03-22 22:07:35 -0700 | [diff] [blame] | 1032 | svg = createTopologyView(); |
Paul Greyson | 29aa98d | 2013-03-28 00:09:31 -0700 | [diff] [blame] | 1033 | updateSelectedFlows(); |
| 1034 | |
| 1035 | d3.select('#showFlowChooser').on('click', function () { |
| 1036 | showFlowChooser(); |
| 1037 | }); |
| 1038 | |
Paul Greyson | 72f1885 | 2013-03-27 15:56:11 -0700 | [diff] [blame] | 1039 | |
Paul Greyson | 38d8bde | 2013-03-22 22:07:35 -0700 | [diff] [blame] | 1040 | // workaround for Chrome v25 bug |
| 1041 | // if executed immediately, the view box transform logic doesn't work properly |
| 1042 | // fixed in Chrome v27 |
| 1043 | setTimeout(function () { |
| 1044 | // workaround for another Chrome v25 bug |
| 1045 | // viewbox transform stuff doesn't work in combination with browser zoom |
Paul Greyson | c17278a | 2013-03-23 10:17:12 -0700 | [diff] [blame] | 1046 | // also works in Chrome v27 |
Paul Greyson | 38d8bde | 2013-03-22 22:07:35 -0700 | [diff] [blame] | 1047 | d3.select('#svg-container').style('zoom', window.document.body.clientWidth/window.document.width); |
Paul Greyson | 29aa98d | 2013-03-28 00:09:31 -0700 | [diff] [blame] | 1048 | sync(svg); |
Paul Greyson | 38d8bde | 2013-03-22 22:07:35 -0700 | [diff] [blame] | 1049 | }, 100); |