From 1d00d341c8adc4d2c2afa49dbd94f542cfa4b563 Mon Sep 17 00:00:00 2001 From: Russ Nelson Date: Mon, 23 Feb 2015 17:00:24 -0500 Subject: [PATCH] delay synchronizing until all the dygraphs are ready. --- extras/synchronizer.js | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) 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++) { -- 2.7.4