blob: c6438fafc6fd965f4cd3681d9d4f166fa695df81 [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();
Paul Greysone15c4392013-04-09 15:05:31 -070024 reconcilePendingLinks(model);
25 updateLinkMap(links);
Paul Greysone5991b52013-04-04 01:34:04 -070026 updateTopology();
27 }
Paul Greyson5cc35f02013-03-28 10:07:36 -070028
Paul Greysone5991b52013-04-04 01:34:04 -070029 updateHeader(newModel);
Paul Greyson7a300822013-04-09 12:57:49 -070030
31 d3.select('#contents').style('visibility', 'visible');
Paul Greysone5991b52013-04-04 01:34:04 -070032 }
Paul Greyson740bdaf2013-03-18 16:10:48 -070033
34 // do it again in 1s
35 setTimeout(function () {
Paul Greysonc090d142013-04-09 16:59:03 -070036 sync()
Paul Greysond1a22d92013-03-19 12:15:19 -070037 }, 1000);
Paul Greyson6f86d1e2013-03-18 14:40:39 -070038 });
39}
Paul Greyson740bdaf2013-03-18 16:10:48 -070040
Paul Greysonc090d142013-04-09 16:59:03 -070041appInit(function () {
42 // workaround for Chrome v25 bug
43 // if executed immediately, the view box transform logic doesn't work properly
44 // fixed in Chrome v27
45 setTimeout(function () {
Paul Greyson72f18852013-03-27 15:56:11 -070046
Paul Greysonc090d142013-04-09 16:59:03 -070047 // workaround for another Chrome v25 bug
48 // viewbox transform stuff doesn't work in combination with browser zoom
49 // also works in Chrome v27
50 d3.select('#svg-container').style('zoom', window.document.body.clientWidth/window.document.width);
51
52 sync();
53 }, 100);
54});
55
56