Paul Greyson | 740bdaf | 2013-03-18 16:10:48 -0700 | [diff] [blame] | 1 | /*global d3*/ |
| 2 | |
Paul Greyson | d1a22d9 | 2013-03-19 12:15:19 -0700 | [diff] [blame] | 3 | |
| 4 | var colors = [ |
Paul Greyson | 3e14216 | 2013-03-19 13:56:17 -0700 | [diff] [blame] | 5 | 'color1', |
| 6 | 'color2', |
| 7 | 'color3', |
| 8 | 'color4', |
| 9 | 'color5', |
| 10 | 'color6', |
| 11 | 'color7', |
| 12 | 'color8', |
| 13 | 'color9', |
| 14 | 'color10', |
| 15 | 'color11', |
| 16 | 'color12', |
Paul Greyson | d1a22d9 | 2013-03-19 12:15:19 -0700 | [diff] [blame] | 17 | ] |
Paul Greyson | 01a5dff | 2013-03-19 15:50:14 -0700 | [diff] [blame] | 18 | colors.reverse(); |
Paul Greyson | d1a22d9 | 2013-03-19 12:15:19 -0700 | [diff] [blame] | 19 | |
| 20 | var controllerColorMap = {}; |
| 21 | |
| 22 | |
| 23 | |
Paul Greyson | 740bdaf | 2013-03-18 16:10:48 -0700 | [diff] [blame] | 24 | function createTopologyView() { |
Paul Greyson | d1a22d9 | 2013-03-19 12:15:19 -0700 | [diff] [blame] | 25 | return d3.select('#svg-container').append('svg: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] | 26 | attr('id', 'viewbox').append('svg:g').attr('transform', 'translate(500 500)'); |
Paul Greyson | 740bdaf | 2013-03-18 16:10:48 -0700 | [diff] [blame] | 27 | } |
| 28 | |
Paul Greyson | d1a22d9 | 2013-03-19 12:15:19 -0700 | [diff] [blame] | 29 | function updateHeader(model) { |
Paul Greyson | b48943b | 2013-03-19 13:27:57 -0700 | [diff] [blame] | 30 | d3.select('#lastUpdate').text(new Date()); |
Paul Greyson | 952ccb6 | 2013-03-18 22:22:08 -0700 | [diff] [blame] | 31 | d3.select('#activeSwitches').text(model.edgeSwitches.length + model.aggregationSwitches.length + model.coreSwitches.length); |
| 32 | d3.select('#activeFlows').text(model.flows.length); |
| 33 | } |
| 34 | |
| 35 | function toRadians (angle) { |
| 36 | return angle * (Math.PI / 180); |
Paul Greyson | 740bdaf | 2013-03-18 16:10:48 -0700 | [diff] [blame] | 37 | } |
| 38 | |
Paul Greyson | c17278a | 2013-03-23 10:17:12 -0700 | [diff] [blame^] | 39 | function createRingsFromModel(model) { |
Paul Greyson | 740bdaf | 2013-03-18 16:10:48 -0700 | [diff] [blame] | 40 | var rings = [{ |
| 41 | radius: 3, |
Paul Greyson | de7fad5 | 2013-03-19 12:47:32 -0700 | [diff] [blame] | 42 | width: 6, |
Paul Greyson | 952ccb6 | 2013-03-18 22:22:08 -0700 | [diff] [blame] | 43 | switches: model.edgeSwitches, |
Paul Greyson | de7fad5 | 2013-03-19 12:47:32 -0700 | [diff] [blame] | 44 | className: 'edge', |
| 45 | angles: [] |
Paul Greyson | 740bdaf | 2013-03-18 16:10:48 -0700 | [diff] [blame] | 46 | }, { |
Paul Greyson | d1a22d9 | 2013-03-19 12:15:19 -0700 | [diff] [blame] | 47 | radius: 2.25, |
Paul Greyson | de7fad5 | 2013-03-19 12:47:32 -0700 | [diff] [blame] | 48 | width: 12, |
Paul Greyson | 952ccb6 | 2013-03-18 22:22:08 -0700 | [diff] [blame] | 49 | switches: model.aggregationSwitches, |
Paul Greyson | de7fad5 | 2013-03-19 12:47:32 -0700 | [diff] [blame] | 50 | className: 'aggregation', |
| 51 | angles: [] |
Paul Greyson | 740bdaf | 2013-03-18 16:10:48 -0700 | [diff] [blame] | 52 | }, { |
Paul Greyson | d1a22d9 | 2013-03-19 12:15:19 -0700 | [diff] [blame] | 53 | radius: .75, |
Paul Greyson | de7fad5 | 2013-03-19 12:47:32 -0700 | [diff] [blame] | 54 | width: 18, |
Paul Greyson | 952ccb6 | 2013-03-18 22:22:08 -0700 | [diff] [blame] | 55 | switches: model.coreSwitches, |
Paul Greyson | de7fad5 | 2013-03-19 12:47:32 -0700 | [diff] [blame] | 56 | className: 'core', |
| 57 | angles: [] |
Paul Greyson | 740bdaf | 2013-03-18 16:10:48 -0700 | [diff] [blame] | 58 | }]; |
| 59 | |
Paul Greyson | de7fad5 | 2013-03-19 12:47:32 -0700 | [diff] [blame] | 60 | |
| 61 | var aggRanges = {}; |
| 62 | |
| 63 | // arrange edge switches at equal increments |
| 64 | var k = 360 / rings[0].switches.length; |
| 65 | rings[0].switches.forEach(function (s, i) { |
| 66 | var angle = k * i; |
| 67 | |
| 68 | rings[0].angles[i] = angle; |
| 69 | |
| 70 | // record the angle for the agg switch layout |
| 71 | var dpid = s.dpid.split(':'); |
Paul Greyson | 832d220 | 2013-03-21 13:27:56 -0700 | [diff] [blame] | 72 | 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] | 73 | var aggdpid = dpid.join(':'); |
| 74 | var aggRange = aggRanges[aggdpid]; |
| 75 | if (!aggRange) { |
| 76 | aggRange = aggRanges[aggdpid] = {}; |
| 77 | aggRange.min = aggRange.max = angle; |
| 78 | } else { |
| 79 | aggRange.max = angle; |
| 80 | } |
Paul Greyson | de7fad5 | 2013-03-19 12:47:32 -0700 | [diff] [blame] | 81 | }); |
| 82 | |
| 83 | // arrange aggregation switches to "fan out" to edge switches |
| 84 | k = 360 / rings[1].switches.length; |
| 85 | rings[1].switches.forEach(function (s, i) { |
| 86 | // rings[1].angles[i] = k * i; |
| 87 | var range = aggRanges[s.dpid]; |
| 88 | |
Paul Greyson | 832d220 | 2013-03-21 13:27:56 -0700 | [diff] [blame] | 89 | rings[1].angles[i] = (range.min + range.max)/2; |
Paul Greyson | de7fad5 | 2013-03-19 12:47:32 -0700 | [diff] [blame] | 90 | }); |
| 91 | |
Paul Greyson | 3f890b6 | 2013-03-22 17:39:36 -0700 | [diff] [blame] | 92 | // find the association between core switches and aggregation switches |
| 93 | var aggregationSwitchMap = {}; |
| 94 | model.aggregationSwitches.forEach(function (s, i) { |
Paul Greyson | c17278a | 2013-03-23 10:17:12 -0700 | [diff] [blame^] | 95 | aggregationSwitchMap[s.dpid] = i; |
Paul Greyson | 3f890b6 | 2013-03-22 17:39:36 -0700 | [diff] [blame] | 96 | }); |
| 97 | |
Paul Greyson | 3f890b6 | 2013-03-22 17:39:36 -0700 | [diff] [blame] | 98 | // put core switches next to linked aggregation switches |
Paul Greyson | de7fad5 | 2013-03-19 12:47:32 -0700 | [diff] [blame] | 99 | k = 360 / rings[2].switches.length; |
| 100 | rings[2].switches.forEach(function (s, i) { |
Paul Greyson | 3f890b6 | 2013-03-22 17:39:36 -0700 | [diff] [blame] | 101 | // rings[2].angles[i] = k * i; |
Paul Greyson | c17278a | 2013-03-23 10:17:12 -0700 | [diff] [blame^] | 102 | var associatedAggregationSwitches = model.configuration.association[s.dpid]; |
| 103 | // TODO: go between if there are multiple |
| 104 | var index = aggregationSwitchMap[associatedAggregationSwitches[0]]; |
| 105 | |
| 106 | rings[2].angles[i] = rings[1].angles[index]; |
Paul Greyson | de7fad5 | 2013-03-19 12:47:32 -0700 | [diff] [blame] | 107 | }); |
| 108 | |
Paul Greyson | c17278a | 2013-03-23 10:17:12 -0700 | [diff] [blame^] | 109 | return rings; |
| 110 | } |
| 111 | |
| 112 | function updateTopology(svg, model) { |
| 113 | |
| 114 | // DRAW THE SWITCHES |
| 115 | var rings = svg.selectAll('.ring').data(createRingsFromModel(model)); |
| 116 | |
Paul Greyson | 740bdaf | 2013-03-18 16:10:48 -0700 | [diff] [blame] | 117 | function ringEnter(data, i) { |
| 118 | if (!data.switches.length) { |
| 119 | return; |
| 120 | } |
| 121 | |
Paul Greyson | c17278a | 2013-03-23 10:17:12 -0700 | [diff] [blame^] | 122 | // create the nodes |
| 123 | // TODO: do this in two layers so that the text can always be on top |
Paul Greyson | f9edc1a | 2013-03-19 13:22:06 -0700 | [diff] [blame] | 124 | var nodes = d3.select(this).selectAll("g") |
Paul Greyson | 740bdaf | 2013-03-18 16:10:48 -0700 | [diff] [blame] | 125 | .data(d3.range(data.switches.length).map(function() { |
Paul Greyson | f9edc1a | 2013-03-19 13:22:06 -0700 | [diff] [blame] | 126 | return data; |
| 127 | })) |
Paul Greyson | 740bdaf | 2013-03-18 16:10:48 -0700 | [diff] [blame] | 128 | .enter().append("svg:g") |
Paul Greyson | f9edc1a | 2013-03-19 13:22:06 -0700 | [diff] [blame] | 129 | .classed('nolabel', true) |
Paul Greyson | 23b0cd3 | 2013-03-18 23:45:48 -0700 | [diff] [blame] | 130 | .attr("id", function (_, i) { |
Paul Greyson | d1a22d9 | 2013-03-19 12:15:19 -0700 | [diff] [blame] | 131 | return data.switches[i].dpid; |
Paul Greyson | 23b0cd3 | 2013-03-18 23:45:48 -0700 | [diff] [blame] | 132 | }) |
Paul Greyson | 740bdaf | 2013-03-18 16:10:48 -0700 | [diff] [blame] | 133 | .attr("transform", function(_, i) { |
Paul Greyson | de7fad5 | 2013-03-19 12:47:32 -0700 | [diff] [blame] | 134 | return "rotate(" + data.angles[i]+ ")translate(" + data.radius * 150 + ")rotate(" + (-data.angles[i]) + ")"; |
Paul Greyson | f9edc1a | 2013-03-19 13:22:06 -0700 | [diff] [blame] | 135 | }); |
| 136 | |
Paul Greyson | c17278a | 2013-03-23 10:17:12 -0700 | [diff] [blame^] | 137 | // add the cirles representing the switches |
Paul Greyson | f9edc1a | 2013-03-19 13:22:06 -0700 | [diff] [blame] | 138 | nodes.append("svg:circle") |
Paul Greyson | 952ccb6 | 2013-03-18 22:22:08 -0700 | [diff] [blame] | 139 | .attr("transform", function(_, i) { |
Paul Greyson | d1a22d9 | 2013-03-19 12:15:19 -0700 | [diff] [blame] | 140 | var m = document.querySelector('#viewbox').getTransformToElement().inverse(); |
Paul Greyson | f8f4317 | 2013-03-18 23:00:30 -0700 | [diff] [blame] | 141 | if (data.scale) { |
| 142 | m = m.scale(data.scale); |
| 143 | } |
| 144 | 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] | 145 | }) |
Paul Greyson | 740bdaf | 2013-03-18 16:10:48 -0700 | [diff] [blame] | 146 | .attr("x", -data.width / 2) |
| 147 | .attr("y", -data.width / 2) |
Paul Greyson | d1a22d9 | 2013-03-19 12:15:19 -0700 | [diff] [blame] | 148 | .attr("r", data.width) |
Paul Greyson | f9edc1a | 2013-03-19 13:22:06 -0700 | [diff] [blame] | 149 | |
Paul Greyson | c17278a | 2013-03-23 10:17:12 -0700 | [diff] [blame^] | 150 | // add the text nodes which show on mouse over |
Paul Greyson | f9edc1a | 2013-03-19 13:22:06 -0700 | [diff] [blame] | 151 | nodes.append("svg:text") |
| 152 | .text(function (d, i) {return d.switches[i].dpid}) |
| 153 | .attr("x", 0) |
| 154 | .attr("y", 0) |
| 155 | .attr("transform", function(_, i) { |
| 156 | var m = document.querySelector('#viewbox').getTransformToElement().inverse(); |
| 157 | if (data.scale) { |
| 158 | m = m.scale(data.scale); |
| 159 | } |
| 160 | return "matrix( " + m.a + " " + m.b + " " + m.c + " " + m.d + " " + m.e + " " + m.f + " )"; |
| 161 | }) |
| 162 | |
Paul Greyson | c17278a | 2013-03-23 10:17:12 -0700 | [diff] [blame^] | 163 | // setup the mouseover behaviors |
Paul Greyson | f9edc1a | 2013-03-19 13:22:06 -0700 | [diff] [blame] | 164 | function showLabel(data, index) { |
| 165 | d3.select(document.getElementById(data.switches[index].dpid)).classed('nolabel', false); |
| 166 | } |
| 167 | |
| 168 | function hideLabel(data, index) { |
| 169 | d3.select(document.getElementById(data.switches[index].dpid)).classed('nolabel', true); |
| 170 | } |
| 171 | |
| 172 | nodes.on('mouseover', showLabel); |
| 173 | nodes.on('mouseout', hideLabel); |
Paul Greyson | 740bdaf | 2013-03-18 16:10:48 -0700 | [diff] [blame] | 174 | } |
| 175 | |
Paul Greyson | c17278a | 2013-03-23 10:17:12 -0700 | [diff] [blame^] | 176 | // append switches |
| 177 | rings.enter().append("svg:g") |
Paul Greyson | 740bdaf | 2013-03-18 16:10:48 -0700 | [diff] [blame] | 178 | .attr("class", "ring") |
| 179 | .each(ringEnter); |
Paul Greyson | f8f4317 | 2013-03-18 23:00:30 -0700 | [diff] [blame] | 180 | |
Paul Greyson | f9edc1a | 2013-03-19 13:22:06 -0700 | [diff] [blame] | 181 | |
Paul Greyson | c17278a | 2013-03-23 10:17:12 -0700 | [diff] [blame^] | 182 | function ringUpdate(data, i) { |
| 183 | nodes = d3.select(this).selectAll("circle"); |
| 184 | nodes.attr('class', function (_, i) { |
| 185 | if (data.switches[i].state == 'ACTIVE') { |
| 186 | return data.className + ' ' + controllerColorMap[data.switches[i].controller]; |
| 187 | } else { |
| 188 | return data.className + ' ' + 'colorInactive'; |
| 189 | } |
| 190 | }) |
| 191 | } |
| 192 | |
| 193 | // update switches |
| 194 | rings.each(ringUpdate); |
| 195 | |
| 196 | // switches should not change during operation of the ui so no |
| 197 | // rings.exit() |
| 198 | |
| 199 | |
Paul Greyson | f9edc1a | 2013-03-19 13:22:06 -0700 | [diff] [blame] | 200 | // do mouseover zoom on edge nodes |
Paul Greyson | c17278a | 2013-03-23 10:17:12 -0700 | [diff] [blame^] | 201 | // function zoom(data, index) { |
| 202 | // var g = d3.select(document.getElementById(data.switches[index].dpid)).select('circle'); |
| 203 | // g.transition().duration(100).attr("r", rings[0].width*3); |
| 204 | // } |
Paul Greyson | f8f4317 | 2013-03-18 23:00:30 -0700 | [diff] [blame] | 205 | |
Paul Greyson | c17278a | 2013-03-23 10:17:12 -0700 | [diff] [blame^] | 206 | // svg.selectAll('.edge').on('mouseover', zoom); |
| 207 | // svg.selectAll('.edge').on('mousedown', zoom); |
Paul Greyson | d1a22d9 | 2013-03-19 12:15:19 -0700 | [diff] [blame] | 208 | |
Paul Greyson | c17278a | 2013-03-23 10:17:12 -0700 | [diff] [blame^] | 209 | // function unzoom(data, index) { |
| 210 | // var g = d3.select(document.getElementById(data.switches[index].dpid)).select('circle'); |
| 211 | // g.transition().duration(100).attr("r", rings[0].width); |
| 212 | // } |
| 213 | // svg.selectAll('.edge').on('mouseout', unzoom); |
Paul Greyson | f9edc1a | 2013-03-19 13:22:06 -0700 | [diff] [blame] | 214 | |
| 215 | |
Paul Greyson | d1a22d9 | 2013-03-19 12:15:19 -0700 | [diff] [blame] | 216 | // DRAW THE LINKS |
| 217 | var line = d3.svg.line() |
| 218 | .x(function(d) { |
| 219 | return d.x; |
| 220 | }) |
| 221 | .y(function(d) { |
| 222 | return d.y; |
| 223 | }) |
| 224 | .interpolate("basis"); |
| 225 | |
Paul Greyson | c17278a | 2013-03-23 10:17:12 -0700 | [diff] [blame^] | 226 | // key on link dpids since these will come/go during demo |
| 227 | var links = d3.select('svg').selectAll('path').data(model.links, function (d) { |
| 228 | return d['src-switch']+'->'+d['dst-switch']; |
| 229 | }); |
| 230 | |
| 231 | // add new links |
| 232 | links.enter().append("svg:path").attr("d", function (d) { |
| 233 | |
Paul Greyson | d1a22d9 | 2013-03-19 12:15:19 -0700 | [diff] [blame] | 234 | var src = d3.select(document.getElementById(d['src-switch'])); |
| 235 | var dst = d3.select(document.getElementById(d['dst-switch'])); |
| 236 | |
| 237 | var srcPt = document.querySelector('svg').createSVGPoint(); |
| 238 | srcPt.x = src.attr('x'); |
Paul Greyson | c17278a | 2013-03-23 10:17:12 -0700 | [diff] [blame^] | 239 | srcPt.y = src.attr('y') + 10; // tmp: make up and down links distinguishable |
Paul Greyson | d1a22d9 | 2013-03-19 12:15:19 -0700 | [diff] [blame] | 240 | |
| 241 | var dstPt = document.querySelector('svg').createSVGPoint(); |
| 242 | dstPt.x = dst.attr('x'); |
Paul Greyson | c17278a | 2013-03-23 10:17:12 -0700 | [diff] [blame^] | 243 | dstPt.y = dst.attr('y') - 10; // tmp: make up and down links distinguishable |
Paul Greyson | d1a22d9 | 2013-03-19 12:15:19 -0700 | [diff] [blame] | 244 | |
| 245 | return line([srcPt.matrixTransform(src[0][0].getCTM()), dstPt.matrixTransform(dst[0][0].getCTM())]); |
| 246 | }); |
Paul Greyson | c17278a | 2013-03-23 10:17:12 -0700 | [diff] [blame^] | 247 | |
| 248 | // remove old links |
| 249 | links.exit().remove(); |
Paul Greyson | d1a22d9 | 2013-03-19 12:15:19 -0700 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | function updateControllers(model) { |
| 253 | var controllers = d3.select('#controllerList').selectAll('.controller').data(model.controllers); |
Paul Greyson | 3e14216 | 2013-03-19 13:56:17 -0700 | [diff] [blame] | 254 | controllers.enter().append('div') |
| 255 | .attr('class', function (d) { |
Paul Greyson | bcd3c77 | 2013-03-21 13:16:44 -0700 | [diff] [blame] | 256 | |
| 257 | var color = 'color0'; |
| 258 | if (model.activeControllers.indexOf(d) != -1) { |
| 259 | color = controllerColorMap[d]; |
| 260 | if (!color) { |
| 261 | color = controllerColorMap[d] = colors.pop(); |
| 262 | } |
| 263 | } else { |
| 264 | controllerColorMap[d] = color; |
Paul Greyson | d1a22d9 | 2013-03-19 12:15:19 -0700 | [diff] [blame] | 265 | } |
Paul Greyson | bcd3c77 | 2013-03-21 13:16:44 -0700 | [diff] [blame] | 266 | var className = 'controller ' + color; |
| 267 | return className; |
Paul Greyson | d1a22d9 | 2013-03-19 12:15:19 -0700 | [diff] [blame] | 268 | }); |
| 269 | controllers.text(function (d) { |
| 270 | return d; |
| 271 | }); |
| 272 | controllers.exit().remove(); |
| 273 | |
Paul Greyson | 3e14216 | 2013-03-19 13:56:17 -0700 | [diff] [blame] | 274 | model.controllers.forEach(function (c) { |
| 275 | d3.select(document.body).classed(controllerColorMap[c] + '-selected', true); |
| 276 | }); |
Paul Greyson | d1a22d9 | 2013-03-19 12:15:19 -0700 | [diff] [blame] | 277 | |
Paul Greyson | 3e14216 | 2013-03-19 13:56:17 -0700 | [diff] [blame] | 278 | controllers.on('click', function (c, index) { |
Paul Greyson | c3e21a0 | 2013-03-21 13:56:05 -0700 | [diff] [blame] | 279 | var allSelected = true; |
| 280 | for (var key in controllerColorMap) { |
| 281 | if (!d3.select(document.body).classed(controllerColorMap[key] + '-selected')) { |
| 282 | allSelected = false; |
| 283 | break; |
| 284 | } |
| 285 | } |
| 286 | if (allSelected) { |
| 287 | for (var key in controllerColorMap) { |
| 288 | d3.select(document.body).classed(controllerColorMap[key] + '-selected', key == c) |
| 289 | } |
| 290 | } else { |
| 291 | for (var key in controllerColorMap) { |
| 292 | d3.select(document.body).classed(controllerColorMap[key] + '-selected', true) |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | // var selected = d3.select(document.body).classed(controllerColorMap[c] + '-selected'); |
| 297 | // d3.select(document.body).classed(controllerColorMap[c] + '-selected', !selected); |
Paul Greyson | d1a22d9 | 2013-03-19 12:15:19 -0700 | [diff] [blame] | 298 | }); |
Paul Greyson | 740bdaf | 2013-03-18 16:10:48 -0700 | [diff] [blame] | 299 | } |
| 300 | |
Paul Greyson | b48943b | 2013-03-19 13:27:57 -0700 | [diff] [blame] | 301 | var oldModel; |
Paul Greyson | 740bdaf | 2013-03-18 16:10:48 -0700 | [diff] [blame] | 302 | function sync(svg) { |
Paul Greyson | bcd3c77 | 2013-03-21 13:16:44 -0700 | [diff] [blame] | 303 | var d = Date.now(); |
Paul Greyson | b48943b | 2013-03-19 13:27:57 -0700 | [diff] [blame] | 304 | updateModel(function (newModel) { |
Paul Greyson | bcd3c77 | 2013-03-21 13:16:44 -0700 | [diff] [blame] | 305 | console.log('Update time: ' + (Date.now() - d)/1000 + 's'); |
Paul Greyson | 740bdaf | 2013-03-18 16:10:48 -0700 | [diff] [blame] | 306 | |
Paul Greyson | c17278a | 2013-03-23 10:17:12 -0700 | [diff] [blame^] | 307 | if (true || !oldModel && JSON.stringify(oldModel) != JSON.stringify(newModel)) { |
Paul Greyson | b48943b | 2013-03-19 13:27:57 -0700 | [diff] [blame] | 308 | updateControllers(newModel); |
| 309 | updateTopology(svg, newModel); |
| 310 | } else { |
| 311 | console.log('no change'); |
| 312 | } |
| 313 | updateHeader(newModel); |
| 314 | |
| 315 | oldModel = newModel; |
Paul Greyson | 740bdaf | 2013-03-18 16:10:48 -0700 | [diff] [blame] | 316 | |
| 317 | // do it again in 1s |
| 318 | setTimeout(function () { |
Paul Greyson | a36a923 | 2013-03-22 22:41:27 -0700 | [diff] [blame] | 319 | sync(svg) |
Paul Greyson | d1a22d9 | 2013-03-19 12:15:19 -0700 | [diff] [blame] | 320 | }, 1000); |
Paul Greyson | 6f86d1e | 2013-03-18 14:40:39 -0700 | [diff] [blame] | 321 | }); |
| 322 | } |
Paul Greyson | 740bdaf | 2013-03-18 16:10:48 -0700 | [diff] [blame] | 323 | |
Paul Greyson | 38d8bde | 2013-03-22 22:07:35 -0700 | [diff] [blame] | 324 | svg = createTopologyView(); |
| 325 | // workaround for Chrome v25 bug |
| 326 | // if executed immediately, the view box transform logic doesn't work properly |
| 327 | // fixed in Chrome v27 |
| 328 | setTimeout(function () { |
| 329 | // workaround for another Chrome v25 bug |
| 330 | // viewbox transform stuff doesn't work in combination with browser zoom |
Paul Greyson | c17278a | 2013-03-23 10:17:12 -0700 | [diff] [blame^] | 331 | // also works in Chrome v27 |
Paul Greyson | 38d8bde | 2013-03-22 22:07:35 -0700 | [diff] [blame] | 332 | d3.select('#svg-container').style('zoom', window.document.body.clientWidth/window.document.width); |
| 333 | sync(svg); |
| 334 | }, 100); |