1 // Copyright 2011 Google Inc. All Rights Reserved.
4 * @fileoverview Tests for the updateOptions function.
5 * @author antrob@google.com (Anthony Robledo)
7 var UpdateOptionsTestCase
= TestCase("update-options");
9 UpdateOptionsTestCase
.prototype.opts
= {
14 UpdateOptionsTestCase
.prototype.data
= "X,Y1,Y2\n" +
21 UpdateOptionsTestCase
.prototype.setUp
= function() {
22 document
.body
.innerHTML
= "<div id='graph'></div><div id='labels'></div>";
25 UpdateOptionsTestCase
.prototype.tearDown
= function() {
28 UpdateOptionsTestCase
.prototype.wrap
= function(g
) {
29 g
._testDrawCalled
= false;
30 var oldDrawGraph
= Dygraph
.prototype.drawGraph_
;
31 Dygraph
.prototype.drawGraph_
= function() {
32 g
._testDrawCalled
= true;
39 UpdateOptionsTestCase
.prototype.unWrap
= function(oldDrawGraph
) {
40 Dygraph
.prototype.drawGraph_
= oldDrawGraph
;
43 UpdateOptionsTestCase
.prototype.testStrokeAll
= function() {
44 var graphDiv
= document
.getElementById("graph");
45 var graph
= new Dygraph(graphDiv
, this.data
, this.opts
);
46 var updatedOptions
= { };
48 updatedOptions
['strokeWidth'] = 3;
50 // These options will allow us to jump to renderGraph_()
51 // drawGraph_() will be skipped.
52 var oldDrawGraph
= this.wrap(graph
);
53 graph
.updateOptions(updatedOptions
);
54 this.unWrap(oldDrawGraph
);
55 assertFalse(graph
._testDrawCalled
);
58 UpdateOptionsTestCase
.prototype.testStrokeSingleSeries
= function() {
59 var graphDiv
= document
.getElementById("graph");
60 var graph
= new Dygraph(graphDiv
, this.data
, this.opts
);
61 var updatedOptions
= { };
62 var optionsForY1
= { };
64 optionsForY1
['strokeWidth'] = 3;
65 updatedOptions
['Y1'] = optionsForY1
;
67 // These options will allow us to jump to renderGraph_()
68 // drawGraph_() will be skipped.
69 var oldDrawGraph
= this.wrap(graph
);
70 graph
.updateOptions(updatedOptions
);
71 this.unWrap(oldDrawGraph
);
72 assertFalse(graph
._testDrawCalled
);
75 UpdateOptionsTestCase
.prototype.testSingleSeriesRequiresNewPoints
= function() {
76 var graphDiv
= document
.getElementById("graph");
77 var graph
= new Dygraph(graphDiv
, this.data
, this.opts
);
78 var updatedOptions
= { };
79 var optionsForY1
= { };
80 var optionsForY2
= { };
82 // This will not require new points.
83 optionsForY1
['strokeWidth'] = 2;
84 updatedOptions
['Y1'] = optionsForY1
;
86 // This will require new points.
87 optionsForY2
['stepPlot'] = true;
88 updatedOptions
['Y2'] = optionsForY2
;
90 // These options will not allow us to jump to renderGraph_()
91 // drawGraph_() must be called
92 var oldDrawGraph
= this.wrap(graph
);
93 graph
.updateOptions(updatedOptions
);
94 this.unWrap(oldDrawGraph
);
95 assertTrue(graph
._testDrawCalled
);
98 UpdateOptionsTestCase
.prototype.testWidthChangeNeedsNewPoints
= function() {
99 var graphDiv
= document
.getElementById("graph");
100 var graph
= new Dygraph(graphDiv
, this.data
, this.opts
);
101 var updatedOptions
= { };
103 // This will require new points.
104 updatedOptions
['width'] = 600;
106 // These options will not allow us to jump to renderGraph_()
107 // drawGraph_() must be called
108 var oldDrawGraph
= this.wrap(graph
);
109 graph
.updateOptions(updatedOptions
);
110 this.unWrap(oldDrawGraph
);
111 assertTrue(graph
._testDrawCalled
);
114 // Test https://github.com/danvk/dygraphs/issues/87
115 UpdateOptionsTestCase
.prototype.testUpdateLabelsDivDoesntInfiniteLoop
= function() {
116 var graphDiv
= document
.getElementById("graph");
117 var labelsDiv
= document
.getElementById("labels");
118 var graph
= new Dygraph(graphDiv
, this.data
, this.opts
);
119 graph
.updateOptions({labelsDiv
: labelsDiv
});