From 0dd82a21bbc4e1312f94ad1ed3444c480bebdb61 Mon Sep 17 00:00:00 2001 From: Dan Vanderkam Date: Sat, 29 Nov 2014 12:20:13 -0500 Subject: [PATCH] Update synchronize gallery demo --- gallery/index.html | 2 ++ gallery/synchronize.js | 58 +++++++++++++++++++++++++++++++------------------- tests/synchronize.html | 2 +- 3 files changed, 39 insertions(+), 23 deletions(-) diff --git a/gallery/index.html b/gallery/index.html index 9e661d4..9cf4791 100644 --- a/gallery/index.html +++ b/gallery/index.html @@ -8,6 +8,8 @@ + + diff --git a/gallery/synchronize.js b/gallery/synchronize.js index ae92efb..233da0c 100644 --- a/gallery/synchronize.js +++ b/gallery/synchronize.js @@ -8,14 +8,30 @@ Gallery.register( title: 'Multiple graphs in sync', setup: function(parent) { parent.innerHTML = [ - "

Zooming and panning on any of the charts will zoom and pan all the", - "others.

", - "

", - "", - "", - "", - "", - "
"].join("\n"); + '', + '

Zooming and panning on any of the charts will zoom and pan all the', + 'others. Selecting points on one will select points on the others.

', + '

To use this, source extras/synchronizer.js on your page.', + 'See the comments in that file for usage.

', + '
', + '
', + '
', + '
', + '
', + '
', + '

', + ' Synchronize what?', + ' ', + ' ', + '

' + ].join("\n"); }, run: function() { var gs = []; @@ -27,23 +43,21 @@ Gallery.register( NoisyData, { rollPeriod: 7, errorBars: true, - drawCallback: function(me, initial) { - if (blockRedraw || initial) return; - blockRedraw = true; - var range = me.xAxisRange(); - var yrange = me.yAxisRange(); - for (var j = 0; j < 4; j++) { - if (gs[j] == me) continue; - gs[j].updateOptions( { - dateWindow: range, - valueRange: yrange - } ); - } - blockRedraw = false; - } } ) ); } + var sync = Dygraph.synchronize(gs); + + function update() { + var zoom = document.getElementById('chk-zoom').checked; + var selection = document.getElementById('chk-selection').checked; + sync.detach(); + sync = Dygraph.synchronize(gs, { + zoom: zoom, + selection: selection + }); + } + $('#chk-zoom, #chk-selection').change(update); } }); diff --git a/tests/synchronize.html b/tests/synchronize.html index b93a219..92a4e4a 100644 --- a/tests/synchronize.html +++ b/tests/synchronize.html @@ -14,7 +14,7 @@ -