From: Marcus Kempe Date: Sun, 14 Dec 2014 03:48:26 +0000 (+0100) Subject: Added opts flag for enabling/disabling synchronization of range. This is useful when... X-Git-Tag: v2.0.0~78 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=8fd112363c54ddef4bc31ce029b446508677da25;p=dygraphs.git Added opts flag for enabling/disabling synchronization of range. This is useful when looking at multiple graphs with same domain but different range. --- diff --git a/extras/synchronizer.js b/extras/synchronizer.js index 66dc2d8..228390e 100644 --- a/extras/synchronizer.js +++ b/extras/synchronizer.js @@ -37,10 +37,11 @@ Dygraph.synchronize = function(/* dygraphs..., opts */) { throw 'Invalid invocation of Dygraph.synchronize(). Need >= 1 argument.'; } - var OPTIONS = ['selection', 'zoom']; + var OPTIONS = ['selection', 'zoom', 'syncRange']; var opts = { selection: true, - zoom: true + zoom: true, + syncRange: true }; var dygraphs = []; @@ -93,7 +94,12 @@ Dygraph.synchronize = function(/* dygraphs..., opts */) { // Listen for draw, highlight, unhighlight callbacks. if (opts.zoom) { - attachZoomHandlers(dygraphs); + if (opts.syncRange) { + attachZoomHandlers(dygraphs,true); + } + else { + attachZoomHandlers(dygraphs,false); + } } if (opts.selection) { @@ -122,7 +128,7 @@ Dygraph.synchronize = function(/* dygraphs..., opts */) { }; // TODO: call any `drawCallback`s that were set before this. -function attachZoomHandlers(gs) { +function attachZoomHandlers(gs,syncRange) { var block = false; for (var i = 0; i < gs.length; i++) { var g = gs[i]; @@ -134,10 +140,17 @@ function attachZoomHandlers(gs) { var yrange = me.yAxisRange(); for (var j = 0; j < gs.length; j++) { if (gs[j] == me) continue; - gs[j].updateOptions( { - dateWindow: range, - valueRange: yrange - }); + if (syncRange) { + gs[j].updateOptions( { + dateWindow: range, + valueRange: yrange + }); + } + else { + gs[j].updateOptions( { + dateWindow: range + }); + } } block = false; }