blob: d869de79bf5f7aa6cc15f72f1884e2fe6d5ecc6c [file] [log] [blame]
Paul Greyson127d7fb2013-03-25 23:39:20 -07001/*global d3, document∆*/
Paul Greyson740bdaf2013-03-18 16:10:48 -07002
Paul Greyson740bdaf2013-03-18 16:10:48 -07003
Pavlin Radoslavovc5165f42013-11-26 18:46:59 -08004function 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 Greysonc090d142013-04-09 16:59:03 -070015function sync() {
Paul Greysonbcd3c772013-03-21 13:16:44 -070016 var d = Date.now();
Paul Greyson7a300822013-04-09 12:57:49 -070017
Paul Greysonb48943b2013-03-19 13:27:57 -070018 updateModel(function (newModel) {
Paul Greyson4e6dc3a2013-03-27 11:37:14 -070019// console.log('Update time: ' + (Date.now() - d)/1000 + 's');
Paul Greyson740bdaf2013-03-18 16:10:48 -070020
Paul Greysone5991b52013-04-04 01:34:04 -070021 if (newModel) {
Pavlin Radoslavovc5165f42013-11-26 18:46:59 -080022 updateFlow(newModel);
Paul Greysone5991b52013-04-04 01:34:04 -070023 var modelChanged = false;
Paul Greyson2c35f572013-04-04 16:23:48 -070024 var newModelString = JSON.stringify(newModel);
25 if (!modelString || newModelString != modelString) {
Paul Greysone5991b52013-04-04 01:34:04 -070026 modelChanged = true;
27 model = newModel;
Paul Greyson2c35f572013-04-04 16:23:48 -070028 modelString = newModelString;
Paul Greysone5991b52013-04-04 01:34:04 -070029 } else {
30 // console.log('no change');
31 }
Paul Greysonb48943b2013-03-19 13:27:57 -070032
Paul Greysone5991b52013-04-04 01:34:04 -070033 if (modelChanged) {
34 updateControllers();
35 updateSelectedFlows();
36 updateTopology();
37 }
Paul Greyson5cc35f02013-03-28 10:07:36 -070038
Paul Greysone5991b52013-04-04 01:34:04 -070039 updateHeader(newModel);
Paul Greyson7a300822013-04-09 12:57:49 -070040
41 d3.select('#contents').style('visibility', 'visible');
Paul Greysone5991b52013-04-04 01:34:04 -070042 }
Paul Greyson740bdaf2013-03-18 16:10:48 -070043
44 // do it again in 1s
45 setTimeout(function () {
Paul Greysonc090d142013-04-09 16:59:03 -070046 sync()
Paul Greysond1a22d92013-03-19 12:15:19 -070047 }, 1000);
Paul Greyson6f86d1e2013-03-18 14:40:39 -070048 });
49}
Paul Greyson740bdaf2013-03-18 16:10:48 -070050
Paul Greyson7be47a72013-04-11 10:01:19 -070051// workaround for another Chrome v25 bug
52// viewbox transform stuff doesn't work in combination with browser zoom
53// also works in Chrome v27
54function zoomWorkaround() {
55 var zoom = window.document.body.clientWidth/window.document.width;
Paul Greyson7be47a72013-04-11 10:01:19 -070056 // 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
61d3.select(window).on('resize', zoomWorkaround);
62
Paul Greysonc090d142013-04-09 16:59:03 -070063appInit(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 Greyson7be47a72013-04-11 10:01:19 -070068 zoomWorkaround();
Paul Greysonc090d142013-04-09 16:59:03 -070069 sync();
70 }, 100);
71});
72
73