fcda671b19829656f191e8ab42267b1f4868d0e1
2 * @fileoverview Test cases for the numeric tick-generating functions.
3 * These were generated by adding logging code to the old ticker functions. The
4 * tests serve to track existing behavior should it change in the future.
6 * @author danvdk@gmail.com (Dan Vanderkam)
9 var NumericTickerTestCase
= TestCase("numeric-ticker-tests");
11 NumericTickerTestCase
.prototype.setUp
= function() {
12 document
.body
.innerHTML
= "<div id='graph'></div>";
15 NumericTickerTestCase
.prototype.createOptionsViewForAxis
= function(axis
, dict
) {
17 if (dict
&& dict
.hasOwnProperty(x
)) {
20 if (Dygraph
.DEFAULT_ATTRS
.axes
[axis
].hasOwnProperty(x
)) {
21 return Dygraph
.DEFAULT_ATTRS
.axes
[axis
][x
];
23 if (Dygraph
.DEFAULT_ATTRS
.hasOwnProperty(x
)) {
24 return Dygraph
.DEFAULT_ATTRS
[x
];
26 if (x
== 'axisLabelFormatter') return null;
27 throw "mysterious " + axis
+ "-axis option: " + x
;
31 NumericTickerTestCase
.prototype.testBasicNumericTicker
= function() {
32 var opts
= {"logscale":null,"labelsKMG2":false,"labelsKMB":false};
33 var options
= this.createOptionsViewForAxis('y', opts
);
35 var ticks
= Dygraph
.numericTicks(-0.4, 4.4, 320, options
);
36 var expected_ticks
= [
37 {"v":-0.5,"label":"-0.5"},
39 {"v":0.5,"label":"0.5"},
41 {"v":1.5,"label":"1.5"},
43 {"v":2.5,"label":"2.5"},
45 {"v":3.5,"label":"3.5"},
47 {"v":4.5,"label":"4.5"}];
48 assertEquals(expected_ticks
, ticks
);
50 ticks
= Dygraph
.numericTicks(1, 84, 540, options
);
51 var expected_ticks
= [
54 {"v":10,"label":"10"},
55 {"v":15,"label":"15"},
56 {"v":20,"label":"20"},
57 {"v":25,"label":"25"},
58 {"v":30,"label":"30"},
59 {"v":35,"label":"35"},
60 {"v":40,"label":"40"},
61 {"v":45,"label":"45"},
62 {"v":50,"label":"50"},
63 {"v":55,"label":"55"},
64 {"v":60,"label":"60"},
65 {"v":65,"label":"65"},
66 {"v":70,"label":"70"},
67 {"v":75,"label":"75"},
68 {"v":80,"label":"80"},
71 assertEquals(expected_ticks
, ticks
);