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 | 740bdaf | 2013-03-18 16:10:48 -0700 | [diff] [blame] | 3 | |
Pavlin Radoslavov | c5165f4 | 2013-11-26 18:46:59 -0800 | [diff] [blame] | 4 | function updateFlow(model) { |
| 5 | model.flows.forEach(function (flow) { |
| 6 | flow.flowId = flow.flowId.value; |
| 7 | flow.installerId = flow.installerId.value; |
| 8 | flow.dstDpid = flow.dataPath.dstPort.dpid.value; |
| 9 | flow.srcDpid = flow.dataPath.srcPort.dpid.value; |
| 10 | flow.dstPort = flow.dataPath.dstPort.port.value; |
| 11 | flow.srcPort = flow.dataPath.srcPort.port.value; |
| 12 | }); |
| 13 | } |
| 14 | |
Paul Greyson | c090d14 | 2013-04-09 16:59:03 -0700 | [diff] [blame] | 15 | function sync() { |
Paul Greyson | bcd3c77 | 2013-03-21 13:16:44 -0700 | [diff] [blame] | 16 | var d = Date.now(); |
Paul Greyson | 7a30082 | 2013-04-09 12:57:49 -0700 | [diff] [blame] | 17 | |
Paul Greyson | b48943b | 2013-03-19 13:27:57 -0700 | [diff] [blame] | 18 | updateModel(function (newModel) { |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 19 | // console.log('Update time: ' + (Date.now() - d)/1000 + 's'); |
Paul Greyson | 740bdaf | 2013-03-18 16:10:48 -0700 | [diff] [blame] | 20 | |
Paul Greyson | e5991b5 | 2013-04-04 01:34:04 -0700 | [diff] [blame] | 21 | if (newModel) { |
Pavlin Radoslavov | c5165f4 | 2013-11-26 18:46:59 -0800 | [diff] [blame] | 22 | updateFlow(newModel); |
Paul Greyson | e5991b5 | 2013-04-04 01:34:04 -0700 | [diff] [blame] | 23 | var modelChanged = false; |
Paul Greyson | 2c35f57 | 2013-04-04 16:23:48 -0700 | [diff] [blame] | 24 | var newModelString = JSON.stringify(newModel); |
| 25 | if (!modelString || newModelString != modelString) { |
Paul Greyson | e5991b5 | 2013-04-04 01:34:04 -0700 | [diff] [blame] | 26 | modelChanged = true; |
| 27 | model = newModel; |
Paul Greyson | 2c35f57 | 2013-04-04 16:23:48 -0700 | [diff] [blame] | 28 | modelString = newModelString; |
Paul Greyson | e5991b5 | 2013-04-04 01:34:04 -0700 | [diff] [blame] | 29 | } else { |
| 30 | // console.log('no change'); |
| 31 | } |
Paul Greyson | b48943b | 2013-03-19 13:27:57 -0700 | [diff] [blame] | 32 | |
Paul Greyson | e5991b5 | 2013-04-04 01:34:04 -0700 | [diff] [blame] | 33 | if (modelChanged) { |
| 34 | updateControllers(); |
| 35 | updateSelectedFlows(); |
| 36 | updateTopology(); |
| 37 | } |
Paul Greyson | 5cc35f0 | 2013-03-28 10:07:36 -0700 | [diff] [blame] | 38 | |
Paul Greyson | e5991b5 | 2013-04-04 01:34:04 -0700 | [diff] [blame] | 39 | updateHeader(newModel); |
Paul Greyson | 7a30082 | 2013-04-09 12:57:49 -0700 | [diff] [blame] | 40 | |
| 41 | d3.select('#contents').style('visibility', 'visible'); |
Paul Greyson | e5991b5 | 2013-04-04 01:34:04 -0700 | [diff] [blame] | 42 | } |
Paul Greyson | 740bdaf | 2013-03-18 16:10:48 -0700 | [diff] [blame] | 43 | |
| 44 | // do it again in 1s |
| 45 | setTimeout(function () { |
Paul Greyson | c090d14 | 2013-04-09 16:59:03 -0700 | [diff] [blame] | 46 | sync() |
Paul Greyson | d1a22d9 | 2013-03-19 12:15:19 -0700 | [diff] [blame] | 47 | }, 1000); |
Paul Greyson | 6f86d1e | 2013-03-18 14:40:39 -0700 | [diff] [blame] | 48 | }); |
| 49 | } |
Paul Greyson | 740bdaf | 2013-03-18 16:10:48 -0700 | [diff] [blame] | 50 | |
Paul Greyson | 7be47a7 | 2013-04-11 10:01:19 -0700 | [diff] [blame] | 51 | // workaround for another Chrome v25 bug |
| 52 | // viewbox transform stuff doesn't work in combination with browser zoom |
| 53 | // also works in Chrome v27 |
| 54 | function zoomWorkaround() { |
| 55 | var zoom = window.document.body.clientWidth/window.document.width; |
Paul Greyson | 7be47a7 | 2013-04-11 10:01:19 -0700 | [diff] [blame] | 56 | // workaround does not seem to be effective for transforming mouse coordinates |
| 57 | // map display does not use the transform stuff, so commenting out |
| 58 | // d3.select('#svg-container').style('zoom', zoom); |
| 59 | } |
| 60 | |
| 61 | d3.select(window).on('resize', zoomWorkaround); |
| 62 | |
Paul Greyson | c090d14 | 2013-04-09 16:59:03 -0700 | [diff] [blame] | 63 | appInit(function () { |
| 64 | // workaround for Chrome v25 bug |
| 65 | // if executed immediately, the view box transform logic doesn't work properly |
| 66 | // fixed in Chrome v27 |
| 67 | setTimeout(function () { |
Paul Greyson | 7be47a7 | 2013-04-11 10:01:19 -0700 | [diff] [blame] | 68 | zoomWorkaround(); |
Paul Greyson | c090d14 | 2013-04-09 16:59:03 -0700 | [diff] [blame] | 69 | sync(); |
| 70 | }, 100); |
| 71 | }); |
| 72 | |
| 73 | |