2 * @fileoverview Test cases for how axis labels are chosen and formatted.
4 * @author dan@dygraphs.com (Dan Vanderkam)
6 var AxisLabelsTestCase
= TestCase("axis-labels");
8 AxisLabelsTestCase
.prototype.setUp
= function() {
9 document
.body
.innerHTML
= "<div id='graph'></div>";
12 AxisLabelsTestCase
.prototype.tearDown
= function() {
15 function getYLabels() {
16 var y_labels
= document
.getElementsByClassName("dygraph-axis-label-y");
18 for (var i
= 0; i
< y_labels
.length
; i
++) {
19 ary
.push(y_labels
[i
].innerHTML
);
24 AxisLabelsTestCase
.prototype.testMinusOneToOne
= function() {
36 var graph
= document
.getElementById("graph");
37 var g
= new Dygraph(graph
, data
, opts
);
39 // TODO(danvk): would ['-1.0','-0.5','0.0','0.5','1.0'] be better?
40 assertEquals(['-1','-0.5','0','0.5','1'], getYLabels());
44 g
.updateOptions({file
: data
});
45 assertEquals(['-1','-0.5','0','0.5','1','1.5','2'], getYLabels());
49 g
.updateOptions({file
: data
});
50 assertEquals(['-2','0','2','4','6','8','10'], getYLabels());
54 g
.updateOptions({file
: data
});
55 assertEquals(['0','20','40','60','80','100'], getYLabels());
58 AxisLabelsTestCase
.prototype.testSmallRangeNearZero
= function() {
69 opts
.valueRange
= [-0.1, 0.1];
71 var graph
= document
.getElementById("graph");
72 var g
= new Dygraph(graph
, data
, opts
);
73 assertEquals(["-0.1","-0.08","-0.06","-0.04","-0.02","0","0.02","0.04","0.06","0.08"], getYLabels());
75 opts
.valueRange
= [-0.05, 0.05];
76 g
.updateOptions(opts
);
77 // TODO(danvk): why '1.00e-2' and not '0.01'?
78 assertEquals(["-0.05","-0.04","-0.03","-0.02","-0.01","0","1.00e-2","0.02","0.03","0.04"], getYLabels());
80 opts
.valueRange
= [-0.01, 0.01];
81 g
.updateOptions(opts
);
82 assertEquals(["-0.01","-8.00e-3","-6.00e-3","-4.00e-3","-2.00e-3","0","2.00e-3","4.00e-3","6.00e-3","8.00e-3"], getYLabels());
85 AxisLabelsTestCase
.prototype.testSmallRangeAwayFromZero
= function() {
96 var graph
= document
.getElementById("graph");
98 opts
.valueRange
= [9.9, 10.1];
99 var g
= new Dygraph(graph
, data
, opts
);
100 assertEquals(["9.9","9.92","9.94","9.96","9.98","10","10.02","10.04","10.06","10.08"], getYLabels());
102 opts
.valueRange
= [9.99, 10.01];
103 g
.updateOptions(opts
);
104 // TODO(danvk): this is bad
105 assertEquals(["9.99","9.99","9.99","10","10","10","10","10","10.01","10.01"], getYLabels());
107 opts
.valueRange
= [9.999, 10.001];
108 g
.updateOptions(opts
);
109 // TODO(danvk): this is even worse!
110 assertEquals(["10","10","10","10","10","10","10","10","10","10"], getYLabels());