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: v2.0.0~73^2 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=23e6849ffb9bf04f6bf3170e2da2fdef2d643557;p=dygraphs.git delay synchronizing until all the dygraphs are ready. --- diff --git a/extras/synchronizer.js b/extras/synchronizer.js index f39209b..12d8043 100644 --- a/extras/synchronizer.js +++ b/extras/synchronizer.js @@ -100,16 +100,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++) {