blob: 94c41e24edccb3adb9e13f6630f3957bd1a40a72 [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
Paul Greysonc090d142013-04-09 16:59:03 -07004function sync() {
Paul Greysonbcd3c772013-03-21 13:16:44 -07005 var d = Date.now();
Paul Greyson7a300822013-04-09 12:57:49 -07006
Paul Greysonb48943b2013-03-19 13:27:57 -07007 updateModel(function (newModel) {
Paul Greyson4e6dc3a2013-03-27 11:37:14 -07008// console.log('Update time: ' + (Date.now() - d)/1000 + 's');
Paul Greyson740bdaf2013-03-18 16:10:48 -07009
Paul Greysone5991b52013-04-04 01:34:04 -070010 if (newModel) {
11 var modelChanged = false;
Paul Greyson2c35f572013-04-04 16:23:48 -070012 var newModelString = JSON.stringify(newModel);
13 if (!modelString || newModelString != modelString) {
Paul Greysone5991b52013-04-04 01:34:04 -070014 modelChanged = true;
15 model = newModel;
Paul Greyson2c35f572013-04-04 16:23:48 -070016 modelString = newModelString;
Paul Greysone5991b52013-04-04 01:34:04 -070017 } else {
18 // console.log('no change');
19 }
Paul Greysonb48943b2013-03-19 13:27:57 -070020
Paul Greysone5991b52013-04-04 01:34:04 -070021 if (modelChanged) {
22 updateControllers();
23 updateSelectedFlows();
24 updateTopology();
25 }
Paul Greyson5cc35f02013-03-28 10:07:36 -070026
Paul Greysone5991b52013-04-04 01:34:04 -070027 updateHeader(newModel);
Paul Greyson7a300822013-04-09 12:57:49 -070028
29 d3.select('#contents').style('visibility', 'visible');
Paul Greysone5991b52013-04-04 01:34:04 -070030 }
Paul Greyson740bdaf2013-03-18 16:10:48 -070031
32 // do it again in 1s
33 setTimeout(function () {
Paul Greysonc090d142013-04-09 16:59:03 -070034 sync()
Paul Greysond1a22d92013-03-19 12:15:19 -070035 }, 1000);
Paul Greyson6f86d1e2013-03-18 14:40:39 -070036 });
37}
Paul Greyson740bdaf2013-03-18 16:10:48 -070038
Paul Greyson7be47a72013-04-11 10:01:19 -070039// workaround for another Chrome v25 bug
40// viewbox transform stuff doesn't work in combination with browser zoom
41// also works in Chrome v27
42function zoomWorkaround() {
43 var zoom = window.document.body.clientWidth/window.document.width;
Paul Greyson7be47a72013-04-11 10:01:19 -070044 // workaround does not seem to be effective for transforming mouse coordinates
45 // map display does not use the transform stuff, so commenting out
46// d3.select('#svg-container').style('zoom', zoom);
47}
48
49d3.select(window).on('resize', zoomWorkaround);
50
Paul Greysonc090d142013-04-09 16:59:03 -070051appInit(function () {
52 // workaround for Chrome v25 bug
53 // if executed immediately, the view box transform logic doesn't work properly
54 // fixed in Chrome v27
55 setTimeout(function () {
Paul Greyson7be47a72013-04-11 10:01:19 -070056 zoomWorkaround();
Paul Greysonc090d142013-04-09 16:59:03 -070057 sync();
58 }, 100);
59});
60
61