From: Russ Nelson Date: Mon, 23 Feb 2015 22:00:24 +0000 (-0500) Subject: delay synchronizing until all the dygraphs are ready. X-Git-Tag: v1.1.1~8 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=1d00d341c8adc4d2c2afa49dbd94f542cfa4b563;p=dygraphs.git delay synchronizing until all the dygraphs are ready. --- diff --git a/extras/synchronizer.js b/extras/synchronizer.js index f2ba905..d2c5bbf 100644 --- a/extras/synchronizer.js +++ b/extras/synchronizer.js @@ -96,16 +96,24 @@ Dygraph.synchronize = function(/* dygraphs..., opts */) { throw 'Invalid invocation of Dygraph.synchronize(). ' + 'Need two or more dygraphs to synchronize.'; } + + var readycount = dygraphs.length; + for (var i = 0; i < dygraphs.length; i++) { + var g = dygraphs[i]; + g.ready( function() { + if (--readycount == 0) { + // Listen for draw, highlight, unhighlight callbacks. + if (opts.zoom) { + attachZoomHandlers(dygraphs, opts, prevCallbacks); + } - // Listen for draw, highlight, unhighlight callbacks. - if (opts.zoom) { - attachZoomHandlers(dygraphs, opts, prevCallbacks); - } - - if (opts.selection) { - attachSelectionHandlers(dygraphs, prevCallbacks); + if (opts.selection) { + attachSelectionHandlers(dygraphs, prevCallbacks); + } + } + }); } - + return { detach: function() { for (var i = 0; i < dygraphs.length; i++) {