2 * @fileoverview Tests for rolling averages.
4 * @author danvk@google.com (Dan Vanderkam)
6 var rollingAverageTestCase
= TestCase("rolling-average");
8 rollingAverageTestCase
.prototype.setUp
= function() {
9 document
.body
.innerHTML
= "<div id='graph'></div>";
12 rollingAverageTestCase
.prototype.tearDown
= function() {
15 rollingAverageTestCase
.prototype.getLegend
= function() {
16 return document
.getElementsByClassName("dygraph-legend")[0].textContent
;
19 rollingAverageTestCase
.prototype.testRollingAverage
= function() {
33 var graph
= document
.getElementById("graph");
34 var g
= new Dygraph(graph
, data
, opts
);
36 g
.setSelection(0); assertEquals("0: Y:0", this.getLegend());
37 g
.setSelection(1); assertEquals("1: Y:1", this.getLegend());
38 g
.setSelection(2); assertEquals("2: Y:2", this.getLegend());
39 g
.setSelection(3); assertEquals("3: Y:3", this.getLegend());
40 assertEquals(1, g
.rollPeriod());
42 g
.updateOptions({rollPeriod
: 2});
43 g
.setSelection(0); assertEquals("0: Y:0", this.getLegend());
44 g
.setSelection(1); assertEquals("1: Y:0.5", this.getLegend());
45 g
.setSelection(2); assertEquals("2: Y:1.5", this.getLegend());
46 g
.setSelection(3); assertEquals("3: Y:2.5", this.getLegend());
47 assertEquals(2, g
.rollPeriod());
49 g
.updateOptions({rollPeriod
: 3});
50 g
.setSelection(0); assertEquals("0: Y:0", this.getLegend());
51 g
.setSelection(1); assertEquals("1: Y:0.5", this.getLegend());
52 g
.setSelection(2); assertEquals("2: Y:1", this.getLegend());
53 g
.setSelection(3); assertEquals("3: Y:2", this.getLegend());
54 assertEquals(3, g
.rollPeriod());
56 g
.updateOptions({rollPeriod
: 4});
57 g
.setSelection(0); assertEquals("0: Y:0", this.getLegend());
58 g
.setSelection(1); assertEquals("1: Y:0.5", this.getLegend());
59 g
.setSelection(2); assertEquals("2: Y:1", this.getLegend());
60 g
.setSelection(3); assertEquals("3: Y:1.5", this.getLegend());
61 assertEquals(4, g
.rollPeriod());
64 rollingAverageTestCase
.prototype.testRollBoxDoesntDisapper
= function() {
75 var graph
= document
.getElementById("graph");
76 var g
= new Dygraph(graph
, data
, opts
);
78 var roll_box
= graph
.getElementsByTagName("input");
79 assertEquals(1, roll_box
.length
);
80 assertEquals("1", roll_box
[0].value
);
82 graph
.style
.width
= "500px";
84 assertEquals(1, roll_box
.length
);
85 assertEquals("1", roll_box
[0].value
);