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 | 127d7fb | 2013-03-25 23:39:20 -0700 | [diff] [blame] | 18 | var svg, selectedFlowsView; |
Paul Greyson | 56378ed | 2013-03-26 23:17:36 -0700 | [diff] [blame] | 19 | var updateTopology; |
Paul Greyson | 127d7fb | 2013-03-25 23:39:20 -0700 | [diff] [blame] | 20 | |
Paul Greyson | d1a22d9 | 2013-03-19 12:15:19 -0700 | [diff] [blame] | 21 | var colors = [ |
Paul Greyson | 3e14216 | 2013-03-19 13:56:17 -0700 | [diff] [blame] | 22 | 'color1', |
| 23 | 'color2', |
| 24 | 'color3', |
| 25 | 'color4', |
| 26 | 'color5', |
| 27 | 'color6', |
| 28 | 'color7', |
| 29 | 'color8', |
| 30 | 'color9', |
| 31 | 'color10', |
| 32 | 'color11', |
Paul Greyson | 127d7fb | 2013-03-25 23:39:20 -0700 | [diff] [blame] | 33 | 'color12' |
| 34 | ]; |
Paul Greyson | 01a5dff | 2013-03-19 15:50:14 -0700 | [diff] [blame] | 35 | colors.reverse(); |
Paul Greyson | d1a22d9 | 2013-03-19 12:15:19 -0700 | [diff] [blame] | 36 | |
| 37 | var controllerColorMap = {}; |
| 38 | |
| 39 | |
| 40 | |
Paul Greyson | 740bdaf | 2013-03-18 16:10:48 -0700 | [diff] [blame] | 41 | function createTopologyView() { |
Paul Greyson | 56378ed | 2013-03-26 23:17:36 -0700 | [diff] [blame] | 42 | |
| 43 | window.addEventListener('resize', function () { |
| 44 | // this is too slow. instead detect first resize event and hide the paths that have explicit matrix applied |
| 45 | // either that or is it possible to position the paths so they get the automatic transform as well? |
| 46 | // updateTopology(svg, model); |
| 47 | }); |
| 48 | |
Paul Greyson | b367de2 | 2013-03-23 11:09:11 -0700 | [diff] [blame] | 49 | var svg = d3.select('#svg-container').append('svg:svg'); |
| 50 | |
| 51 | svg.append("svg:defs").append("svg:marker") |
| 52 | .attr("id", "arrow") |
| 53 | .attr("viewBox", "0 -5 10 10") |
| 54 | .attr("refX", -1) |
| 55 | .attr("markerWidth", 5) |
| 56 | .attr("markerHeight", 5) |
| 57 | .attr("orient", "auto") |
| 58 | .append("svg:path") |
Paul Greyson | 45303ac | 2013-03-23 16:44:01 -0700 | [diff] [blame] | 59 | .attr("d", "M0,-3L10,0L0,3"); |
Paul Greyson | b367de2 | 2013-03-23 11:09:11 -0700 | [diff] [blame] | 60 | |
| 61 | 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] | 62 | attr('id', 'viewbox').append('svg:g').attr('transform', 'translate(500 500)'); |
Paul Greyson | 740bdaf | 2013-03-18 16:10:48 -0700 | [diff] [blame] | 63 | } |
| 64 | |
Paul Greyson | 127d7fb | 2013-03-25 23:39:20 -0700 | [diff] [blame] | 65 | var selectedFlowsData = [ |
| 66 | {selected: false, flow: null}, |
| 67 | {selected: false, flow: null}, |
Paul Greyson | 127d7fb | 2013-03-25 23:39:20 -0700 | [diff] [blame] | 68 | {selected: false, flow: null} |
| 69 | ]; |
| 70 | |
| 71 | function drawFlows() { |
| 72 | // DRAW THE FLOWS |
| 73 | var flows = d3.select('svg').selectAll('.flow').data(selectedFlowsData, function (d) { |
| 74 | return d.flow ? d.flow.flowId.value : null; |
| 75 | }); |
| 76 | |
| 77 | flows.enter().append("svg:path") |
| 78 | .attr('class', 'flow') |
| 79 | .attr('d', function (d) { |
| 80 | if (!d.flow) { |
| 81 | return; |
| 82 | } |
| 83 | var pts = []; |
| 84 | d.flow.dataPath.flowEntries.forEach(function (flowEntry) { |
| 85 | var s = d3.select(document.getElementById(flowEntry.dpid.value)); |
| 86 | var pt = document.querySelector('svg').createSVGPoint(); |
| 87 | pt.x = s.attr('x'); |
| 88 | pt.y = s.attr('y'); |
| 89 | pt = pt.matrixTransform(s[0][0].getCTM()); |
| 90 | pts.push(pt); |
| 91 | }); |
| 92 | return line(pts); |
| 93 | }) |
Paul Greyson | acb5941 | 2013-03-25 23:48:06 -0700 | [diff] [blame] | 94 | .attr('stroke-dasharray', '3, 10') |
Paul Greyson | 127d7fb | 2013-03-25 23:39:20 -0700 | [diff] [blame] | 95 | .append('svg:animate') |
| 96 | .attr('attributeName', 'stroke-dashoffset') |
| 97 | .attr('attributeType', 'xml') |
| 98 | .attr('from', '500') |
| 99 | .attr('to', '-500') |
| 100 | .attr('dur', '20s') |
| 101 | .attr('repeatCount', 'indefinite'); |
| 102 | |
| 103 | flows.style('visibility', function (d) { |
| 104 | if (d) { |
| 105 | return d.selected ? '' : 'hidden'; |
| 106 | } |
| 107 | }) |
| 108 | |
Paul Greyson | 56378ed | 2013-03-26 23:17:36 -0700 | [diff] [blame] | 109 | // "marching ants" |
| 110 | // TODO: this will only be true if there's an iperf session running |
Paul Greyson | 127d7fb | 2013-03-25 23:39:20 -0700 | [diff] [blame] | 111 | flows.select('animate').attr('from', function (d) { |
| 112 | if (d.flow) { |
| 113 | if (d.selected) { |
| 114 | return '500'; |
| 115 | } else { |
| 116 | return '-500'; |
| 117 | } |
| 118 | } |
| 119 | }); |
| 120 | } |
| 121 | |
| 122 | function updateFlowView() { |
| 123 | selectedFlowsView.data(selectedFlowsData); |
| 124 | |
| 125 | selectedFlowsView.classed('selected', function (d) { |
| 126 | if (d.flow) { |
| 127 | return d.selected; |
| 128 | } |
| 129 | }); |
| 130 | |
| 131 | selectedFlowsView.select('.flowId') |
| 132 | .text(function (d) { |
| 133 | if (d.flow) { |
| 134 | return d.flow.flowId.value; |
| 135 | } |
| 136 | }); |
| 137 | |
| 138 | selectedFlowsView.select('.srcDPID') |
| 139 | .text(function (d) { |
| 140 | if (d.flow) { |
| 141 | return d.flow.dataPath.srcPort.dpid.value; |
| 142 | } |
| 143 | }); |
| 144 | |
| 145 | selectedFlowsView.select('.dstDPID') |
| 146 | .text(function (d) { |
| 147 | if (d.flow) { |
| 148 | return d.flow.dataPath.dstPort.dpid.value; |
| 149 | } |
| 150 | }); |
| 151 | } |
| 152 | |
| 153 | function createFlowView() { |
| 154 | function rowEnter(d, i) { |
| 155 | var row = d3.select(this); |
| 156 | |
| 157 | row.on('click', function () { |
| 158 | selectedFlowsData[i].selected = !selectedFlowsData[i].selected; |
| 159 | updateFlowView(); |
| 160 | drawFlows(); |
| 161 | }); |
| 162 | |
| 163 | row.append('div') |
| 164 | .classed('flowIndex', true) |
| 165 | .text(function () { |
| 166 | return i+1; |
| 167 | }); |
| 168 | |
| 169 | row.append('div') |
| 170 | .classed('flowId', true); |
| 171 | |
| 172 | row.append('div') |
| 173 | .classed('srcDPID', true); |
| 174 | |
| 175 | row.append('div') |
| 176 | .classed('dstDPID', true); |
| 177 | |
| 178 | row.append('div') |
| 179 | .classed('iperf', true); |
| 180 | } |
| 181 | |
| 182 | var flows = d3.select('#selectedFlows') |
| 183 | .selectAll('.selectedFlow') |
| 184 | .data(selectedFlowsData) |
| 185 | .enter() |
| 186 | .append('div') |
| 187 | .classed('selectedFlow', true) |
| 188 | .each(rowEnter); |
| 189 | |
| 190 | |
| 191 | return flows; |
| 192 | } |
| 193 | |
Paul Greyson | d1a22d9 | 2013-03-19 12:15:19 -0700 | [diff] [blame] | 194 | function updateHeader(model) { |
Paul Greyson | b48943b | 2013-03-19 13:27:57 -0700 | [diff] [blame] | 195 | d3.select('#lastUpdate').text(new Date()); |
Paul Greyson | 952ccb6 | 2013-03-18 22:22:08 -0700 | [diff] [blame] | 196 | d3.select('#activeSwitches').text(model.edgeSwitches.length + model.aggregationSwitches.length + model.coreSwitches.length); |
| 197 | d3.select('#activeFlows').text(model.flows.length); |
| 198 | } |
| 199 | |
| 200 | function toRadians (angle) { |
| 201 | return angle * (Math.PI / 180); |
Paul Greyson | 740bdaf | 2013-03-18 16:10:48 -0700 | [diff] [blame] | 202 | } |
| 203 | |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 204 | var widths = { |
| 205 | edge: 6, |
| 206 | aggregation: 12, |
| 207 | core: 18 |
| 208 | } |
| 209 | |
Paul Greyson | c17278a | 2013-03-23 10:17:12 -0700 | [diff] [blame] | 210 | function createRingsFromModel(model) { |
Paul Greyson | 740bdaf | 2013-03-18 16:10:48 -0700 | [diff] [blame] | 211 | var rings = [{ |
| 212 | radius: 3, |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 213 | width: widths.edge, |
Paul Greyson | 952ccb6 | 2013-03-18 22:22:08 -0700 | [diff] [blame] | 214 | switches: model.edgeSwitches, |
Paul Greyson | de7fad5 | 2013-03-19 12:47:32 -0700 | [diff] [blame] | 215 | className: 'edge', |
| 216 | angles: [] |
Paul Greyson | 740bdaf | 2013-03-18 16:10:48 -0700 | [diff] [blame] | 217 | }, { |
Paul Greyson | d1a22d9 | 2013-03-19 12:15:19 -0700 | [diff] [blame] | 218 | radius: 2.25, |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 219 | width: widths.aggregation, |
Paul Greyson | 952ccb6 | 2013-03-18 22:22:08 -0700 | [diff] [blame] | 220 | switches: model.aggregationSwitches, |
Paul Greyson | de7fad5 | 2013-03-19 12:47:32 -0700 | [diff] [blame] | 221 | className: 'aggregation', |
| 222 | angles: [] |
Paul Greyson | 740bdaf | 2013-03-18 16:10:48 -0700 | [diff] [blame] | 223 | }, { |
Paul Greyson | 127d7fb | 2013-03-25 23:39:20 -0700 | [diff] [blame] | 224 | radius: 0.75, |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 225 | width: widths.core, |
Paul Greyson | 952ccb6 | 2013-03-18 22:22:08 -0700 | [diff] [blame] | 226 | switches: model.coreSwitches, |
Paul Greyson | de7fad5 | 2013-03-19 12:47:32 -0700 | [diff] [blame] | 227 | className: 'core', |
| 228 | angles: [] |
Paul Greyson | 740bdaf | 2013-03-18 16:10:48 -0700 | [diff] [blame] | 229 | }]; |
| 230 | |
Paul Greyson | de7fad5 | 2013-03-19 12:47:32 -0700 | [diff] [blame] | 231 | |
| 232 | var aggRanges = {}; |
| 233 | |
| 234 | // arrange edge switches at equal increments |
| 235 | var k = 360 / rings[0].switches.length; |
| 236 | rings[0].switches.forEach(function (s, i) { |
| 237 | var angle = k * i; |
| 238 | |
| 239 | rings[0].angles[i] = angle; |
| 240 | |
| 241 | // record the angle for the agg switch layout |
| 242 | var dpid = s.dpid.split(':'); |
Paul Greyson | 832d220 | 2013-03-21 13:27:56 -0700 | [diff] [blame] | 243 | 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] | 244 | var aggdpid = dpid.join(':'); |
| 245 | var aggRange = aggRanges[aggdpid]; |
| 246 | if (!aggRange) { |
| 247 | aggRange = aggRanges[aggdpid] = {}; |
| 248 | aggRange.min = aggRange.max = angle; |
| 249 | } else { |
| 250 | aggRange.max = angle; |
| 251 | } |
Paul Greyson | de7fad5 | 2013-03-19 12:47:32 -0700 | [diff] [blame] | 252 | }); |
| 253 | |
| 254 | // arrange aggregation switches to "fan out" to edge switches |
| 255 | k = 360 / rings[1].switches.length; |
| 256 | rings[1].switches.forEach(function (s, i) { |
| 257 | // rings[1].angles[i] = k * i; |
| 258 | var range = aggRanges[s.dpid]; |
| 259 | |
Paul Greyson | 832d220 | 2013-03-21 13:27:56 -0700 | [diff] [blame] | 260 | rings[1].angles[i] = (range.min + range.max)/2; |
Paul Greyson | de7fad5 | 2013-03-19 12:47:32 -0700 | [diff] [blame] | 261 | }); |
| 262 | |
Paul Greyson | 3f890b6 | 2013-03-22 17:39:36 -0700 | [diff] [blame] | 263 | // find the association between core switches and aggregation switches |
| 264 | var aggregationSwitchMap = {}; |
| 265 | model.aggregationSwitches.forEach(function (s, i) { |
Paul Greyson | c17278a | 2013-03-23 10:17:12 -0700 | [diff] [blame] | 266 | aggregationSwitchMap[s.dpid] = i; |
Paul Greyson | 3f890b6 | 2013-03-22 17:39:36 -0700 | [diff] [blame] | 267 | }); |
| 268 | |
Paul Greyson | 3f890b6 | 2013-03-22 17:39:36 -0700 | [diff] [blame] | 269 | // put core switches next to linked aggregation switches |
Paul Greyson | de7fad5 | 2013-03-19 12:47:32 -0700 | [diff] [blame] | 270 | k = 360 / rings[2].switches.length; |
| 271 | rings[2].switches.forEach(function (s, i) { |
Paul Greyson | 3f890b6 | 2013-03-22 17:39:36 -0700 | [diff] [blame] | 272 | // rings[2].angles[i] = k * i; |
Paul Greyson | c17278a | 2013-03-23 10:17:12 -0700 | [diff] [blame] | 273 | var associatedAggregationSwitches = model.configuration.association[s.dpid]; |
| 274 | // TODO: go between if there are multiple |
| 275 | var index = aggregationSwitchMap[associatedAggregationSwitches[0]]; |
| 276 | |
| 277 | rings[2].angles[i] = rings[1].angles[index]; |
Paul Greyson | de7fad5 | 2013-03-19 12:47:32 -0700 | [diff] [blame] | 278 | }); |
| 279 | |
Paul Greyson | 644d92a | 2013-03-23 18:00:40 -0700 | [diff] [blame] | 280 | // TODO: construct this form initially rather than converting. it works better because |
| 281 | // it allows binding by dpid |
| 282 | var testRings = []; |
| 283 | rings.forEach(function (ring) { |
| 284 | var testRing = []; |
| 285 | ring.switches.forEach(function (s, i) { |
| 286 | var testSwitch = { |
| 287 | dpid: s.dpid, |
| 288 | state: s.state, |
| 289 | radius: ring.radius, |
| 290 | width: ring.width, |
| 291 | className: ring.className, |
| 292 | angle: ring.angles[i], |
| 293 | controller: s.controller |
Paul Greyson | 127d7fb | 2013-03-25 23:39:20 -0700 | [diff] [blame] | 294 | }; |
Paul Greyson | 644d92a | 2013-03-23 18:00:40 -0700 | [diff] [blame] | 295 | testRing.push(testSwitch); |
| 296 | }); |
Paul Greyson | 6d9ed86 | 2013-03-23 17:37:15 -0700 | [diff] [blame] | 297 | |
| 298 | |
Paul Greyson | 644d92a | 2013-03-23 18:00:40 -0700 | [diff] [blame] | 299 | testRings.push(testRing); |
| 300 | }); |
Paul Greyson | 6d9ed86 | 2013-03-23 17:37:15 -0700 | [diff] [blame] | 301 | |
| 302 | |
Paul Greyson | 644d92a | 2013-03-23 18:00:40 -0700 | [diff] [blame] | 303 | // return rings; |
| 304 | return testRings; |
Paul Greyson | c17278a | 2013-03-23 10:17:12 -0700 | [diff] [blame] | 305 | } |
| 306 | |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 307 | function createLinkMap(model) { |
| 308 | var linkMap = {}; |
| 309 | model.links.forEach(function (link) { |
| 310 | var srcDPID = link['src-switch']; |
| 311 | var dstDPID = link['dst-switch']; |
| 312 | |
| 313 | var srcMap = linkMap[srcDPID] || {}; |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 314 | |
Paul Greyson | 8d1c636 | 2013-03-27 13:05:24 -0700 | [diff] [blame^] | 315 | srcMap[dstDPID] = link; |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 316 | |
| 317 | linkMap[srcDPID] = srcMap; |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 318 | }); |
| 319 | return linkMap; |
| 320 | } |
| 321 | |
Paul Greyson | 56378ed | 2013-03-26 23:17:36 -0700 | [diff] [blame] | 322 | updateTopology = function(svg, model) { |
Paul Greyson | c17278a | 2013-03-23 10:17:12 -0700 | [diff] [blame] | 323 | |
| 324 | // DRAW THE SWITCHES |
| 325 | var rings = svg.selectAll('.ring').data(createRingsFromModel(model)); |
| 326 | |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 327 | var linkMap = createLinkMap(model); |
| 328 | // var flowMap = createFlowMap(model); |
| 329 | |
Paul Greyson | 8d1c636 | 2013-03-27 13:05:24 -0700 | [diff] [blame^] | 330 | function mouseOverSwitch(data) { |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 331 | if (data.highlighted) { |
| 332 | return; |
| 333 | } |
| 334 | |
| 335 | // only highlight valid link or flow destination by checking for class of existing highlighted circle |
| 336 | var highlighted = svg.selectAll('circle.highlight')[0]; |
| 337 | if (highlighted.length == 1) { |
| 338 | var s = d3.select(highlighted[0]); |
| 339 | // only allow links |
| 340 | // edge->edge (flow) |
| 341 | // aggregation->core |
| 342 | // core->core |
| 343 | if (data.className == 'edge' && !s.classed('edge') || |
| 344 | data.className == 'core' && !s.classed('core') && !s.classed('aggregation') || |
| 345 | data.className == 'aggregation' && !s.classed('core')) { |
| 346 | return; |
| 347 | } |
| 348 | |
| 349 | // don't highlight if there's already a link or flow |
| 350 | // var map = linkMap[data.dpid]; |
| 351 | // console.log(map); |
| 352 | // console.log(s.data()[0].dpid); |
| 353 | // console.log(map[s.data()[0].dpid]); |
| 354 | // if (map && map[s.data()[0].dpid]) { |
| 355 | // return; |
| 356 | // } |
| 357 | |
| 358 | // the second highlighted switch is the target for a link or flow |
| 359 | data.target = true; |
| 360 | } |
| 361 | |
| 362 | |
| 363 | d3.select(document.getElementById(data.dpid + '-label')).classed('nolabel', false); |
| 364 | var node = d3.select(document.getElementById(data.dpid)); |
| 365 | node.select('circle').classed('highlight', true).transition().duration(100).attr("r", widths.core); |
| 366 | data.highlighted = true; |
| 367 | node.moveToFront(); |
| 368 | } |
| 369 | |
Paul Greyson | 8d1c636 | 2013-03-27 13:05:24 -0700 | [diff] [blame^] | 370 | function mouseOutSwitch(data) { |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 371 | if (data.mouseDown) |
| 372 | return; |
| 373 | |
| 374 | d3.select(document.getElementById(data.dpid + '-label')).classed('nolabel', true); |
| 375 | var node = d3.select(document.getElementById(data.dpid)); |
| 376 | node.select('circle').classed('highlight', false).transition().duration(100).attr("r", widths[data.className]); |
| 377 | data.highlighted = false; |
| 378 | data.target = false; |
| 379 | } |
| 380 | |
Paul Greyson | 8d1c636 | 2013-03-27 13:05:24 -0700 | [diff] [blame^] | 381 | function mouseDownSwitch(data) { |
| 382 | mouseOverSwitch(data); |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 383 | data.mouseDown = true; |
| 384 | } |
| 385 | |
Paul Greyson | 8d1c636 | 2013-03-27 13:05:24 -0700 | [diff] [blame^] | 386 | function mouseUpSwitch(data) { |
| 387 | if (data.mouseDown) { |
| 388 | data.mouseDown = false; |
| 389 | d3.event.stopPropagation(); |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | function doubleClickSwitch(data) { |
| 394 | if (data.state == 'ACTIVE') { |
| 395 | var prompt = 'Deactivate ' + data.dpid + '?'; |
| 396 | if (confirm(prompt)) { |
| 397 | switchDown(data); |
| 398 | } |
| 399 | } else { |
| 400 | var prompt = 'Activate ' + data.dpid + '?'; |
| 401 | if (confirm(prompt)) { |
| 402 | switchUp(data); |
| 403 | } |
| 404 | } |
| 405 | } |
| 406 | |
Paul Greyson | 740bdaf | 2013-03-18 16:10:48 -0700 | [diff] [blame] | 407 | function ringEnter(data, i) { |
Paul Greyson | 644d92a | 2013-03-23 18:00:40 -0700 | [diff] [blame] | 408 | if (!data.length) { |
Paul Greyson | 740bdaf | 2013-03-18 16:10:48 -0700 | [diff] [blame] | 409 | return; |
| 410 | } |
| 411 | |
Paul Greyson | c17278a | 2013-03-23 10:17:12 -0700 | [diff] [blame] | 412 | // create the nodes |
Paul Greyson | f9edc1a | 2013-03-19 13:22:06 -0700 | [diff] [blame] | 413 | var nodes = d3.select(this).selectAll("g") |
Paul Greyson | 644d92a | 2013-03-23 18:00:40 -0700 | [diff] [blame] | 414 | .data(data, function (data) { |
| 415 | return data.dpid; |
| 416 | }) |
Paul Greyson | 740bdaf | 2013-03-18 16:10:48 -0700 | [diff] [blame] | 417 | .enter().append("svg:g") |
Paul Greyson | 644d92a | 2013-03-23 18:00:40 -0700 | [diff] [blame] | 418 | .attr("id", function (data, i) { |
| 419 | return data.dpid; |
Paul Greyson | 23b0cd3 | 2013-03-18 23:45:48 -0700 | [diff] [blame] | 420 | }) |
Paul Greyson | 644d92a | 2013-03-23 18:00:40 -0700 | [diff] [blame] | 421 | .attr("transform", function(data, i) { |
| 422 | return "rotate(" + data.angle+ ")translate(" + data.radius * 150 + ")rotate(" + (-data.angle) + ")"; |
Paul Greyson | f9edc1a | 2013-03-19 13:22:06 -0700 | [diff] [blame] | 423 | }); |
| 424 | |
Paul Greyson | c17278a | 2013-03-23 10:17:12 -0700 | [diff] [blame] | 425 | // add the cirles representing the switches |
Paul Greyson | f9edc1a | 2013-03-19 13:22:06 -0700 | [diff] [blame] | 426 | nodes.append("svg:circle") |
Paul Greyson | 644d92a | 2013-03-23 18:00:40 -0700 | [diff] [blame] | 427 | .attr("transform", function(data, i) { |
Paul Greyson | d1a22d9 | 2013-03-19 12:15:19 -0700 | [diff] [blame] | 428 | var m = document.querySelector('#viewbox').getTransformToElement().inverse(); |
Paul Greyson | f8f4317 | 2013-03-18 23:00:30 -0700 | [diff] [blame] | 429 | if (data.scale) { |
| 430 | m = m.scale(data.scale); |
| 431 | } |
| 432 | 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] | 433 | }) |
Paul Greyson | 644d92a | 2013-03-23 18:00:40 -0700 | [diff] [blame] | 434 | .attr("x", function (data) { |
| 435 | return -data.width / 2; |
| 436 | }) |
| 437 | .attr("y", function (data) { |
| 438 | return -data.width / 2; |
| 439 | }) |
| 440 | .attr("r", function (data) { |
| 441 | return data.width; |
Paul Greyson | 127d7fb | 2013-03-25 23:39:20 -0700 | [diff] [blame] | 442 | }); |
Paul Greyson | f9edc1a | 2013-03-19 13:22:06 -0700 | [diff] [blame] | 443 | |
Paul Greyson | c17278a | 2013-03-23 10:17:12 -0700 | [diff] [blame] | 444 | // setup the mouseover behaviors |
Paul Greyson | 8d1c636 | 2013-03-27 13:05:24 -0700 | [diff] [blame^] | 445 | nodes.on('mouseover', mouseOverSwitch); |
| 446 | nodes.on('mouseout', mouseOutSwitch); |
| 447 | nodes.on('mouseup', mouseUpSwitch); |
| 448 | nodes.on('mousedown', mouseDownSwitch); |
| 449 | |
| 450 | // only do switch up/down for core switches |
| 451 | if (i == 2) { |
| 452 | nodes.on('dblclick', doubleClickSwitch); |
| 453 | } |
Paul Greyson | 740bdaf | 2013-03-18 16:10:48 -0700 | [diff] [blame] | 454 | } |
| 455 | |
Paul Greyson | c17278a | 2013-03-23 10:17:12 -0700 | [diff] [blame] | 456 | // append switches |
| 457 | rings.enter().append("svg:g") |
Paul Greyson | 740bdaf | 2013-03-18 16:10:48 -0700 | [diff] [blame] | 458 | .attr("class", "ring") |
| 459 | .each(ringEnter); |
Paul Greyson | f8f4317 | 2013-03-18 23:00:30 -0700 | [diff] [blame] | 460 | |
Paul Greyson | f9edc1a | 2013-03-19 13:22:06 -0700 | [diff] [blame] | 461 | |
Paul Greyson | c17278a | 2013-03-23 10:17:12 -0700 | [diff] [blame] | 462 | function ringUpdate(data, i) { |
Paul Greyson | 127d7fb | 2013-03-25 23:39:20 -0700 | [diff] [blame] | 463 | var nodes = d3.select(this).selectAll("g") |
Paul Greyson | 644d92a | 2013-03-23 18:00:40 -0700 | [diff] [blame] | 464 | .data(data, function (data) { |
| 465 | return data.dpid; |
Paul Greyson | 127d7fb | 2013-03-25 23:39:20 -0700 | [diff] [blame] | 466 | }); |
Paul Greyson | 644d92a | 2013-03-23 18:00:40 -0700 | [diff] [blame] | 467 | nodes.select('circle').attr('class', function (data, i) { |
Paul Greyson | 8d1c636 | 2013-03-27 13:05:24 -0700 | [diff] [blame^] | 468 | if (data.state === 'ACTIVE' && data.controller) { |
Paul Greyson | 644d92a | 2013-03-23 18:00:40 -0700 | [diff] [blame] | 469 | return data.className + ' ' + controllerColorMap[data.controller]; |
Paul Greyson | c17278a | 2013-03-23 10:17:12 -0700 | [diff] [blame] | 470 | } else { |
| 471 | return data.className + ' ' + 'colorInactive'; |
| 472 | } |
Paul Greyson | 127d7fb | 2013-03-25 23:39:20 -0700 | [diff] [blame] | 473 | }); |
Paul Greyson | c17278a | 2013-03-23 10:17:12 -0700 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | // update switches |
| 477 | rings.each(ringUpdate); |
| 478 | |
Paul Greyson | 968d1b4 | 2013-03-23 16:58:41 -0700 | [diff] [blame] | 479 | |
| 480 | // Now setup the labels |
| 481 | // This is done separately because SVG draws in node order and we want the labels |
| 482 | // always on top |
| 483 | var labelRings = svg.selectAll('.labelRing').data(createRingsFromModel(model)); |
| 484 | |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 485 | d3.select(document.body).on('mouseup', function () { |
| 486 | function clearHighlight() { |
| 487 | svg.selectAll('circle').each(function (data) { |
| 488 | data.mouseDown = false; |
Paul Greyson | 8d1c636 | 2013-03-27 13:05:24 -0700 | [diff] [blame^] | 489 | mouseOutSwitch(data); |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 490 | }) |
| 491 | }; |
| 492 | |
| 493 | |
| 494 | var highlighted = svg.selectAll('circle.highlight')[0]; |
| 495 | if (highlighted.length == 2) { |
| 496 | var s1Data = d3.select(highlighted[0]).data()[0]; |
| 497 | var s2Data = d3.select(highlighted[1]).data()[0]; |
| 498 | |
| 499 | var srcData, dstData; |
| 500 | if (s1Data.target) { |
| 501 | dstData = s1Data; |
| 502 | srcData = s2Data; |
| 503 | } else { |
| 504 | dstData = s2Data; |
| 505 | srcData = s1Data; |
| 506 | } |
| 507 | |
| 508 | if (s1Data.className == 'edge' && s2Data.className == 'edge') { |
| 509 | var prompt = 'Create flow from ' + srcData.dpid + ' to ' + dstData.dpid + '?'; |
| 510 | if (confirm(prompt)) { |
| 511 | alert('do create flow'); |
| 512 | } else { |
| 513 | alert('do not create flow'); |
| 514 | } |
| 515 | } else { |
| 516 | var map = linkMap[srcData.dpid]; |
| 517 | if (map && map[dstData.dpid]) { |
| 518 | var prompt = 'Remove link between ' + srcData.dpid + ' and ' + dstData.dpid + '?'; |
| 519 | if (confirm(prompt)) { |
Paul Greyson | 8d1c636 | 2013-03-27 13:05:24 -0700 | [diff] [blame^] | 520 | linkDown(map[dstData.dpid]); |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 521 | } |
| 522 | } else { |
Paul Greyson | 8d1c636 | 2013-03-27 13:05:24 -0700 | [diff] [blame^] | 523 | map = linkMap[dstData.dpid]; |
| 524 | if (map && map[srcData.dpid]) { |
| 525 | var prompt = 'Remove link between ' + dstData.dpid + ' and ' + srcData.dpid + '?'; |
| 526 | if (confirm(prompt)) { |
| 527 | linkDown(map[srcData.dpid]); |
| 528 | } |
| 529 | } else { |
| 530 | var prompt = 'Create link between ' + srcData.dpid + ' and ' + dstData.dpid + '?'; |
| 531 | if (confirm(prompt)) { |
| 532 | linkUp(srcData, dstData); |
| 533 | } |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 534 | } |
| 535 | } |
| 536 | } |
| 537 | |
| 538 | clearHighlight(); |
| 539 | } else { |
| 540 | clearHighlight(); |
| 541 | } |
| 542 | |
| 543 | }); |
| 544 | |
Paul Greyson | 9066ab0 | 2013-03-23 18:15:41 -0700 | [diff] [blame] | 545 | function labelRingEnter(data) { |
Paul Greyson | 644d92a | 2013-03-23 18:00:40 -0700 | [diff] [blame] | 546 | if (!data.length) { |
Paul Greyson | 968d1b4 | 2013-03-23 16:58:41 -0700 | [diff] [blame] | 547 | return; |
| 548 | } |
| 549 | |
| 550 | // create the nodes |
| 551 | var nodes = d3.select(this).selectAll("g") |
Paul Greyson | 644d92a | 2013-03-23 18:00:40 -0700 | [diff] [blame] | 552 | .data(data, function (data) { |
| 553 | return data.dpid; |
| 554 | }) |
Paul Greyson | 968d1b4 | 2013-03-23 16:58:41 -0700 | [diff] [blame] | 555 | .enter().append("svg:g") |
| 556 | .classed('nolabel', true) |
Paul Greyson | 9066ab0 | 2013-03-23 18:15:41 -0700 | [diff] [blame] | 557 | .attr("id", function (data) { |
Paul Greyson | 644d92a | 2013-03-23 18:00:40 -0700 | [diff] [blame] | 558 | return data.dpid + '-label'; |
Paul Greyson | 968d1b4 | 2013-03-23 16:58:41 -0700 | [diff] [blame] | 559 | }) |
Paul Greyson | 644d92a | 2013-03-23 18:00:40 -0700 | [diff] [blame] | 560 | .attr("transform", function(data, i) { |
| 561 | return "rotate(" + data.angle+ ")translate(" + data.radius * 150 + ")rotate(" + (-data.angle) + ")"; |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 562 | }) |
Paul Greyson | 968d1b4 | 2013-03-23 16:58:41 -0700 | [diff] [blame] | 563 | |
| 564 | // add the text nodes which show on mouse over |
| 565 | nodes.append("svg:text") |
Paul Greyson | 127d7fb | 2013-03-25 23:39:20 -0700 | [diff] [blame] | 566 | .text(function (data) {return data.dpid;}) |
Paul Greyson | 9066ab0 | 2013-03-23 18:15:41 -0700 | [diff] [blame] | 567 | .attr("x", function (data) { |
| 568 | if (data.angle <= 90 || data.angle >= 270 && data.angle <= 360) { |
| 569 | if (data.className == 'edge') { |
Paul Greyson | 1eb2dd1 | 2013-03-23 18:22:00 -0700 | [diff] [blame] | 570 | return - data.width*3 - 4; |
Paul Greyson | 9066ab0 | 2013-03-23 18:15:41 -0700 | [diff] [blame] | 571 | } else { |
Paul Greyson | 1eb2dd1 | 2013-03-23 18:22:00 -0700 | [diff] [blame] | 572 | return - data.width - 4; |
Paul Greyson | 9066ab0 | 2013-03-23 18:15:41 -0700 | [diff] [blame] | 573 | } |
| 574 | } else { |
| 575 | if (data.className == 'edge') { |
| 576 | return data.width*3 + 4; |
| 577 | } else { |
| 578 | return data.width + 4; |
| 579 | } |
| 580 | } |
| 581 | }) |
| 582 | .attr("y", function (data) { |
| 583 | var y; |
| 584 | if (data.angle <= 90 || data.angle >= 270 && data.angle <= 360) { |
| 585 | if (data.className == 'edge') { |
| 586 | y = data.width*3/2 + 4; |
| 587 | } else { |
| 588 | y = data.width/2 + 4; |
| 589 | } |
| 590 | } else { |
| 591 | if (data.className == 'edge') { |
| 592 | y = data.width*3/2 + 4; |
| 593 | } else { |
| 594 | y = data.width/2 + 4; |
| 595 | } |
| 596 | } |
| 597 | return y - 6; |
| 598 | }) |
| 599 | .attr("text-anchor", function (data) { |
| 600 | if (data.angle <= 90 || data.angle >= 270 && data.angle <= 360) { |
| 601 | return "end"; |
| 602 | } else { |
| 603 | return "start"; |
| 604 | } |
| 605 | }) |
| 606 | .attr("transform", function(data) { |
Paul Greyson | 968d1b4 | 2013-03-23 16:58:41 -0700 | [diff] [blame] | 607 | var m = document.querySelector('#viewbox').getTransformToElement().inverse(); |
| 608 | if (data.scale) { |
| 609 | m = m.scale(data.scale); |
| 610 | } |
| 611 | return "matrix( " + m.a + " " + m.b + " " + m.c + " " + m.d + " " + m.e + " " + m.f + " )"; |
| 612 | }) |
| 613 | } |
| 614 | |
| 615 | labelRings.enter().append("svg:g") |
| 616 | .attr("class", "textRing") |
| 617 | .each(labelRingEnter); |
| 618 | |
Paul Greyson | c17278a | 2013-03-23 10:17:12 -0700 | [diff] [blame] | 619 | // switches should not change during operation of the ui so no |
| 620 | // rings.exit() |
| 621 | |
| 622 | |
Paul Greyson | d1a22d9 | 2013-03-19 12:15:19 -0700 | [diff] [blame] | 623 | // DRAW THE LINKS |
Paul Greyson | d1a22d9 | 2013-03-19 12:15:19 -0700 | [diff] [blame] | 624 | |
Paul Greyson | c17278a | 2013-03-23 10:17:12 -0700 | [diff] [blame] | 625 | // key on link dpids since these will come/go during demo |
Paul Greyson | b367de2 | 2013-03-23 11:09:11 -0700 | [diff] [blame] | 626 | var links = d3.select('svg').selectAll('.link').data(model.links, function (d) { |
Paul Greyson | c17278a | 2013-03-23 10:17:12 -0700 | [diff] [blame] | 627 | return d['src-switch']+'->'+d['dst-switch']; |
| 628 | }); |
| 629 | |
| 630 | // add new links |
Paul Greyson | b367de2 | 2013-03-23 11:09:11 -0700 | [diff] [blame] | 631 | links.enter().append("svg:path") |
Paul Greyson | 56378ed | 2013-03-26 23:17:36 -0700 | [diff] [blame] | 632 | .attr("class", "link"); |
| 633 | |
| 634 | links |
| 635 | .attr("d", function (d) { |
Paul Greyson | c17278a | 2013-03-23 10:17:12 -0700 | [diff] [blame] | 636 | |
Paul Greyson | d1a22d9 | 2013-03-19 12:15:19 -0700 | [diff] [blame] | 637 | var src = d3.select(document.getElementById(d['src-switch'])); |
| 638 | var dst = d3.select(document.getElementById(d['dst-switch'])); |
| 639 | |
| 640 | var srcPt = document.querySelector('svg').createSVGPoint(); |
| 641 | srcPt.x = src.attr('x'); |
Paul Greyson | b367de2 | 2013-03-23 11:09:11 -0700 | [diff] [blame] | 642 | srcPt.y = src.attr('y'); |
| 643 | srcPt = srcPt.matrixTransform(src[0][0].getCTM()); |
Paul Greyson | d1a22d9 | 2013-03-19 12:15:19 -0700 | [diff] [blame] | 644 | |
| 645 | var dstPt = document.querySelector('svg').createSVGPoint(); |
| 646 | dstPt.x = dst.attr('x'); |
Paul Greyson | b367de2 | 2013-03-23 11:09:11 -0700 | [diff] [blame] | 647 | dstPt.y = dst.attr('y'); // tmp: make up and down links distinguishable |
| 648 | dstPt = dstPt.matrixTransform(dst[0][0].getCTM()); |
Paul Greyson | d1a22d9 | 2013-03-19 12:15:19 -0700 | [diff] [blame] | 649 | |
Paul Greyson | b367de2 | 2013-03-23 11:09:11 -0700 | [diff] [blame] | 650 | var midPt = document.querySelector('svg').createSVGPoint(); |
| 651 | midPt.x = (srcPt.x + dstPt.x)/2; |
| 652 | midPt.y = (srcPt.y + dstPt.y)/2; |
| 653 | |
| 654 | return line([srcPt, midPt, dstPt]); |
| 655 | }) |
| 656 | .attr("marker-mid", function(d) { return "url(#arrow)"; }); |
Paul Greyson | c17278a | 2013-03-23 10:17:12 -0700 | [diff] [blame] | 657 | |
Paul Greyson | 56378ed | 2013-03-26 23:17:36 -0700 | [diff] [blame] | 658 | |
Paul Greyson | c17278a | 2013-03-23 10:17:12 -0700 | [diff] [blame] | 659 | // remove old links |
| 660 | links.exit().remove(); |
Paul Greyson | 644d92a | 2013-03-23 18:00:40 -0700 | [diff] [blame] | 661 | |
Paul Greyson | 127d7fb | 2013-03-25 23:39:20 -0700 | [diff] [blame] | 662 | |
| 663 | drawFlows(); |
Paul Greyson | d1a22d9 | 2013-03-19 12:15:19 -0700 | [diff] [blame] | 664 | } |
| 665 | |
| 666 | function updateControllers(model) { |
| 667 | var controllers = d3.select('#controllerList').selectAll('.controller').data(model.controllers); |
Paul Greyson | 3e14216 | 2013-03-19 13:56:17 -0700 | [diff] [blame] | 668 | controllers.enter().append('div') |
Paul Greyson | e262a29 | 2013-03-23 10:35:23 -0700 | [diff] [blame] | 669 | .each(function (c) { |
| 670 | controllerColorMap[c] = colors.pop(); |
| 671 | d3.select(document.body).classed(controllerColorMap[c] + '-selected', true); |
| 672 | }) |
| 673 | .text(function (d) { |
| 674 | return d; |
| 675 | }); |
Paul Greyson | bcd3c77 | 2013-03-21 13:16:44 -0700 | [diff] [blame] | 676 | |
Paul Greyson | e262a29 | 2013-03-23 10:35:23 -0700 | [diff] [blame] | 677 | controllers.attr('class', function (d) { |
Paul Greyson | eed3635 | 2013-03-23 11:19:11 -0700 | [diff] [blame] | 678 | var color = 'colorInactive'; |
Paul Greyson | bcd3c77 | 2013-03-21 13:16:44 -0700 | [diff] [blame] | 679 | if (model.activeControllers.indexOf(d) != -1) { |
| 680 | color = controllerColorMap[d]; |
Paul Greyson | d1a22d9 | 2013-03-19 12:15:19 -0700 | [diff] [blame] | 681 | } |
Paul Greyson | bcd3c77 | 2013-03-21 13:16:44 -0700 | [diff] [blame] | 682 | var className = 'controller ' + color; |
| 683 | return className; |
Paul Greyson | d1a22d9 | 2013-03-19 12:15:19 -0700 | [diff] [blame] | 684 | }); |
Paul Greyson | d1a22d9 | 2013-03-19 12:15:19 -0700 | [diff] [blame] | 685 | |
Paul Greyson | e262a29 | 2013-03-23 10:35:23 -0700 | [diff] [blame] | 686 | // this should never be needed |
| 687 | // controllers.exit().remove(); |
Paul Greyson | d1a22d9 | 2013-03-19 12:15:19 -0700 | [diff] [blame] | 688 | |
Paul Greyson | 8d1c636 | 2013-03-27 13:05:24 -0700 | [diff] [blame^] | 689 | controllers.on('click', function (c) { |
Paul Greyson | c3e21a0 | 2013-03-21 13:56:05 -0700 | [diff] [blame] | 690 | var allSelected = true; |
| 691 | for (var key in controllerColorMap) { |
| 692 | if (!d3.select(document.body).classed(controllerColorMap[key] + '-selected')) { |
| 693 | allSelected = false; |
| 694 | break; |
| 695 | } |
| 696 | } |
| 697 | if (allSelected) { |
| 698 | for (var key in controllerColorMap) { |
| 699 | d3.select(document.body).classed(controllerColorMap[key] + '-selected', key == c) |
| 700 | } |
| 701 | } else { |
| 702 | for (var key in controllerColorMap) { |
| 703 | d3.select(document.body).classed(controllerColorMap[key] + '-selected', true) |
| 704 | } |
| 705 | } |
| 706 | |
| 707 | // var selected = d3.select(document.body).classed(controllerColorMap[c] + '-selected'); |
| 708 | // d3.select(document.body).classed(controllerColorMap[c] + '-selected', !selected); |
Paul Greyson | d1a22d9 | 2013-03-19 12:15:19 -0700 | [diff] [blame] | 709 | }); |
Paul Greyson | 8d1c636 | 2013-03-27 13:05:24 -0700 | [diff] [blame^] | 710 | |
| 711 | |
Paul Greyson | 740bdaf | 2013-03-18 16:10:48 -0700 | [diff] [blame] | 712 | } |
| 713 | |
Paul Greyson | 127d7fb | 2013-03-25 23:39:20 -0700 | [diff] [blame] | 714 | function sync(svg, selectedFlowsView) { |
Paul Greyson | bcd3c77 | 2013-03-21 13:16:44 -0700 | [diff] [blame] | 715 | var d = Date.now(); |
Paul Greyson | b48943b | 2013-03-19 13:27:57 -0700 | [diff] [blame] | 716 | updateModel(function (newModel) { |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 717 | // console.log('Update time: ' + (Date.now() - d)/1000 + 's'); |
Paul Greyson | 740bdaf | 2013-03-18 16:10:48 -0700 | [diff] [blame] | 718 | |
Paul Greyson | 56378ed | 2013-03-26 23:17:36 -0700 | [diff] [blame] | 719 | if (!model || JSON.stringify(model) != JSON.stringify(newModel)) { |
Paul Greyson | b48943b | 2013-03-19 13:27:57 -0700 | [diff] [blame] | 720 | updateControllers(newModel); |
Paul Greyson | 127d7fb | 2013-03-25 23:39:20 -0700 | [diff] [blame] | 721 | |
| 722 | // fake flows right now |
| 723 | var i; |
Paul Greyson | 56378ed | 2013-03-26 23:17:36 -0700 | [diff] [blame] | 724 | for (i = 0; i < newModel.flows.length && i < selectedFlowsData.length; i+=1) { |
Paul Greyson | 127d7fb | 2013-03-25 23:39:20 -0700 | [diff] [blame] | 725 | var selected = selectedFlowsData[i] ? selectedFlowsData[i].selected : false; |
| 726 | selectedFlowsData[i].flow = newModel.flows[i]; |
| 727 | selectedFlowsData[i].selected = selected; |
| 728 | } |
| 729 | |
| 730 | updateFlowView(newModel); |
Paul Greyson | b48943b | 2013-03-19 13:27:57 -0700 | [diff] [blame] | 731 | updateTopology(svg, newModel); |
| 732 | } else { |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 733 | // console.log('no change'); |
Paul Greyson | b48943b | 2013-03-19 13:27:57 -0700 | [diff] [blame] | 734 | } |
| 735 | updateHeader(newModel); |
| 736 | |
Paul Greyson | 56378ed | 2013-03-26 23:17:36 -0700 | [diff] [blame] | 737 | model = newModel; |
Paul Greyson | 740bdaf | 2013-03-18 16:10:48 -0700 | [diff] [blame] | 738 | |
| 739 | // do it again in 1s |
| 740 | setTimeout(function () { |
Paul Greyson | a36a923 | 2013-03-22 22:41:27 -0700 | [diff] [blame] | 741 | sync(svg) |
Paul Greyson | d1a22d9 | 2013-03-19 12:15:19 -0700 | [diff] [blame] | 742 | }, 1000); |
Paul Greyson | 6f86d1e | 2013-03-18 14:40:39 -0700 | [diff] [blame] | 743 | }); |
| 744 | } |
Paul Greyson | 740bdaf | 2013-03-18 16:10:48 -0700 | [diff] [blame] | 745 | |
Paul Greyson | 38d8bde | 2013-03-22 22:07:35 -0700 | [diff] [blame] | 746 | svg = createTopologyView(); |
Paul Greyson | 127d7fb | 2013-03-25 23:39:20 -0700 | [diff] [blame] | 747 | selectedFlowsView = createFlowView(); |
Paul Greyson | 38d8bde | 2013-03-22 22:07:35 -0700 | [diff] [blame] | 748 | // workaround for Chrome v25 bug |
| 749 | // if executed immediately, the view box transform logic doesn't work properly |
| 750 | // fixed in Chrome v27 |
| 751 | setTimeout(function () { |
| 752 | // workaround for another Chrome v25 bug |
| 753 | // viewbox transform stuff doesn't work in combination with browser zoom |
Paul Greyson | c17278a | 2013-03-23 10:17:12 -0700 | [diff] [blame] | 754 | // also works in Chrome v27 |
Paul Greyson | 38d8bde | 2013-03-22 22:07:35 -0700 | [diff] [blame] | 755 | d3.select('#svg-container').style('zoom', window.document.body.clientWidth/window.document.width); |
Paul Greyson | 127d7fb | 2013-03-25 23:39:20 -0700 | [diff] [blame] | 756 | sync(svg, selectedFlowsView); |
Paul Greyson | 38d8bde | 2013-03-22 22:07:35 -0700 | [diff] [blame] | 757 | }, 100); |