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 | |
Paul Greyson | c090d14 | 2013-04-09 16:59:03 -0700 | [diff] [blame] | 4 | function sync() { |
Paul Greyson | bcd3c77 | 2013-03-21 13:16:44 -0700 | [diff] [blame] | 5 | var d = Date.now(); |
Paul Greyson | 7a30082 | 2013-04-09 12:57:49 -0700 | [diff] [blame] | 6 | |
Paul Greyson | b48943b | 2013-03-19 13:27:57 -0700 | [diff] [blame] | 7 | updateModel(function (newModel) { |
Paul Greyson | 4e6dc3a | 2013-03-27 11:37:14 -0700 | [diff] [blame] | 8 | // console.log('Update time: ' + (Date.now() - d)/1000 + 's'); |
Paul Greyson | 740bdaf | 2013-03-18 16:10:48 -0700 | [diff] [blame] | 9 | |
Paul Greyson | e5991b5 | 2013-04-04 01:34:04 -0700 | [diff] [blame] | 10 | if (newModel) { |
| 11 | var modelChanged = false; |
Paul Greyson | 2c35f57 | 2013-04-04 16:23:48 -0700 | [diff] [blame] | 12 | var newModelString = JSON.stringify(newModel); |
| 13 | if (!modelString || newModelString != modelString) { |
Paul Greyson | e5991b5 | 2013-04-04 01:34:04 -0700 | [diff] [blame] | 14 | modelChanged = true; |
| 15 | model = newModel; |
Paul Greyson | 2c35f57 | 2013-04-04 16:23:48 -0700 | [diff] [blame] | 16 | modelString = newModelString; |
Paul Greyson | e5991b5 | 2013-04-04 01:34:04 -0700 | [diff] [blame] | 17 | } else { |
| 18 | // console.log('no change'); |
| 19 | } |
Paul Greyson | b48943b | 2013-03-19 13:27:57 -0700 | [diff] [blame] | 20 | |
Paul Greyson | e5991b5 | 2013-04-04 01:34:04 -0700 | [diff] [blame] | 21 | if (modelChanged) { |
| 22 | updateControllers(); |
| 23 | updateSelectedFlows(); |
| 24 | updateTopology(); |
| 25 | } |
Paul Greyson | 5cc35f0 | 2013-03-28 10:07:36 -0700 | [diff] [blame] | 26 | |
Paul Greyson | e5991b5 | 2013-04-04 01:34:04 -0700 | [diff] [blame] | 27 | updateHeader(newModel); |
Paul Greyson | 7a30082 | 2013-04-09 12:57:49 -0700 | [diff] [blame] | 28 | |
| 29 | d3.select('#contents').style('visibility', 'visible'); |
Paul Greyson | e5991b5 | 2013-04-04 01:34:04 -0700 | [diff] [blame] | 30 | } |
Paul Greyson | 740bdaf | 2013-03-18 16:10:48 -0700 | [diff] [blame] | 31 | |
| 32 | // do it again in 1s |
| 33 | setTimeout(function () { |
Paul Greyson | c090d14 | 2013-04-09 16:59:03 -0700 | [diff] [blame] | 34 | sync() |
Paul Greyson | d1a22d9 | 2013-03-19 12:15:19 -0700 | [diff] [blame] | 35 | }, 1000); |
Paul Greyson | 6f86d1e | 2013-03-18 14:40:39 -0700 | [diff] [blame] | 36 | }); |
| 37 | } |
Paul Greyson | 740bdaf | 2013-03-18 16:10:48 -0700 | [diff] [blame] | 38 | |
Paul Greyson | 7be47a7 | 2013-04-11 10:01:19 -0700 | [diff] [blame] | 39 | // workaround for another Chrome v25 bug |
| 40 | // viewbox transform stuff doesn't work in combination with browser zoom |
| 41 | // also works in Chrome v27 |
| 42 | function zoomWorkaround() { |
| 43 | var zoom = window.document.body.clientWidth/window.document.width; |
Paul Greyson | 7be47a7 | 2013-04-11 10:01:19 -0700 | [diff] [blame] | 44 | // 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 | |
| 49 | d3.select(window).on('resize', zoomWorkaround); |
| 50 | |
Paul Greyson | c090d14 | 2013-04-09 16:59:03 -0700 | [diff] [blame] | 51 | appInit(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 Greyson | 7be47a7 | 2013-04-11 10:01:19 -0700 | [diff] [blame] | 56 | zoomWorkaround(); |
Paul Greyson | c090d14 | 2013-04-09 16:59:03 -0700 | [diff] [blame] | 57 | sync(); |
| 58 | }, 100); |
| 59 | }); |
| 60 | |
| 61 | |