fdc20dc4e1544fa5facd1493ab8080099399f3a4
2 * @fileoverview Tests synchronizer.
4 * @author nyx@nyx.cz (Marek Janda)
7 import Dygraph from
'../../src/dygraph';
8 import '../../src/extras/synchronizer'; // Sets Dygraph.synchronize
10 import DygraphOps from
'./DygraphOps';
12 describe("synchronize", function() {
14 var originalCallbackCalled
;
15 var data
= "X,a,b,c\n" +
21 var graph
= document
.getElementById('graph');
23 beforeEach(function() {
24 graph
.innerHTML
= "<div id='graph1'></div><div id='graph2'></div>";
25 originalCallbackCalled
= false;
26 h_row
= 0, h_pts
= [];
29 var highlightCallback
= function(e
, x
, pts
, row
) {
30 originalCallbackCalled
= true;
34 assert
.equal(gs
[0], this);
37 gs
.push(new Dygraph(document
.getElementById("graph1"), data
, {
40 visibility
: [false, true, true],
41 highlightCallback
: highlightCallback
43 gs
.push(new Dygraph(document
.getElementById("graph2"), data
, {
46 visibility
: [false, true, true],
50 afterEach(function() {
55 * This tests if original highlightCallback is called when synchronizer is attached
57 it('testOriginalHighlightCallbackStillWorks', function() {
58 var sync
= Dygraph
.synchronize(gs
);
60 DygraphOps
.dispatchMouseMove(gs
[1], 5, 5);
61 // check that chart2 doesn't trigger highlightCallback on chart1
62 assert
.equal(originalCallbackCalled
, false);
64 DygraphOps
.dispatchMouseMove(gs
[0], 13, 10);
65 // check that original highlightCallback was called
66 assert
.equal(originalCallbackCalled
, true);
72 * This tests if selection is propagated correctly between charts
74 it('testChartsAreSynchronized', function() {
75 DygraphOps
.dispatchMouseMove(gs
[0], 13, 10);
76 assert
.notEqual(gs
[0].getSelection(), gs
[1].getSelection());
77 DygraphOps
.dispatchMouseMove(gs
[0], 0, 0);
79 var sync
= Dygraph
.synchronize(gs
);
81 DygraphOps
.dispatchMouseMove(gs
[0], 13, 10);
83 //check correct row is highlighted on second chart
84 assert
.equal(3, h_row
);
85 //check there are only two points (because first series is hidden)
86 assert
.equal(2, h_pts
.length
);
87 //check that selection on both charts is the same
88 assert
.equal(gs
[0].getSelection(), gs
[1].getSelection());
94 * This tests if detach works
96 it('testSynchronizerDetach', function() {
97 var sync
= Dygraph
.synchronize(gs
);
98 DygraphOps
.dispatchMouseMove(gs
[1], 10, 10);
101 originalCallbackCalled
= false;
102 DygraphOps
.dispatchMouseMove(gs
[1], 0, 0);
104 //check that chart2 doesn't have highlightCallback
105 assert
.equal(originalCallbackCalled
, false);
107 DygraphOps
.dispatchMouseMove(gs
[0], 13, 10);
109 //check that original callback was re-attached
110 assert
.equal(originalCallbackCalled
, true);
112 //check that selection isn't synchronized anymore
113 assert
.equal(gs
[0].getSelection(), 3);
114 assert
.equal(gs
[1].getSelection(), 0);