Commit | Line | Data |
---|---|---|
e88a95b4 | 1 | /*global Gallery,Dygraph,data */ |
e1e80cce | 2 | /*jshint loopfunc:true */ |
e88a95b4 | 3 | /*global NoisyData */ |
e2a5e398 RK |
4 | Gallery.register( |
5 | 'synchronize', | |
6 | { | |
7 | name: 'Synchronization', | |
8 | title: 'Multiple graphs in sync', | |
9 | setup: function(parent) { | |
605b6119 | 10 | parent.innerHTML = [ |
0dd82a21 DV |
11 | '<style>', |
12 | ' .chart { width: 500px; height: 300px; }', | |
13 | ' .chart-container { overflow: hidden; }', | |
14 | ' #div1 { float: left; }', | |
15 | ' #div2 { float: left; }', | |
16 | ' #div3 { float: left; clear: left; }', | |
17 | ' #div4 { float: left; }', | |
18 | '</style>', | |
19 | '<p>Zooming and panning on any of the charts will zoom and pan all the', | |
20 | 'others. Selecting points on one will select points on the others.</p>', | |
9ee99eb1 | 21 | '<p>To use this, source <a href="https://github.com/danvk/dygraphs/blob/master/src/extras/synchronizer.js"><code>extras/synchronizer.js</code></a> on your page.', |
0dd82a21 DV |
22 | 'See the comments in that file for usage.</p>', |
23 | '<div class="chart-container">', | |
24 | ' <div id="div1" class="chart"></div>', | |
25 | ' <div id="div2" class="chart"></div>', | |
26 | ' <div id="div3" class="chart"></div>', | |
27 | ' <div id="div4" class="chart"></div>', | |
28 | '</div>', | |
29 | '<p>', | |
30 | ' Synchronize what?', | |
31 | ' <input type=checkbox id="chk-zoom" checked><label for="chk-zoom"> Zoom</label>', | |
32 | ' <input type=checkbox id="chk-selection" checked><label for="chk-selection"> Selection</label>', | |
33 | '</p>' | |
34 | ].join("\n"); | |
e2a5e398 RK |
35 | }, |
36 | run: function() { | |
e88a95b4 | 37 | var gs = []; |
e2a5e398 | 38 | var blockRedraw = false; |
e2a5e398 RK |
39 | for (var i = 1; i <= 4; i++) { |
40 | gs.push( | |
41 | new Dygraph( | |
42 | document.getElementById("div" + i), | |
43 | NoisyData, { | |
44 | rollPeriod: 7, | |
45 | errorBars: true, | |
e2a5e398 RK |
46 | } |
47 | ) | |
48 | ); | |
49 | } | |
0dd82a21 DV |
50 | var sync = Dygraph.synchronize(gs); |
51 | ||
52 | function update() { | |
53 | var zoom = document.getElementById('chk-zoom').checked; | |
54 | var selection = document.getElementById('chk-selection').checked; | |
55 | sync.detach(); | |
56 | sync = Dygraph.synchronize(gs, { | |
57 | zoom: zoom, | |
58 | selection: selection | |
59 | }); | |
60 | } | |
61 | $('#chk-zoom, #chk-selection').change(update); | |
e2a5e398 RK |
62 | } |
63 | }); |