fcda671b19829656f191e8ab42267b1f4868d0e1
[dygraphs.git] / auto_tests / tests / numeric_ticker.js
1 /**
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.
5 *
6 * @author danvdk@gmail.com (Dan Vanderkam)
7 */
8
9 var NumericTickerTestCase = TestCase("numeric-ticker-tests");
10
11 NumericTickerTestCase.prototype.setUp = function() {
12 document.body.innerHTML = "<div id='graph'></div>";
13 };
14
15 NumericTickerTestCase.prototype.createOptionsViewForAxis = function(axis, dict) {
16 return function (x) {
17 if (dict && dict.hasOwnProperty(x)) {
18 return dict[x];
19 }
20 if (Dygraph.DEFAULT_ATTRS.axes[axis].hasOwnProperty(x)) {
21 return Dygraph.DEFAULT_ATTRS.axes[axis][x];
22 }
23 if (Dygraph.DEFAULT_ATTRS.hasOwnProperty(x)) {
24 return Dygraph.DEFAULT_ATTRS[x];
25 }
26 if (x == 'axisLabelFormatter') return null;
27 throw "mysterious " + axis + "-axis option: " + x;
28 };
29 };
30
31 NumericTickerTestCase.prototype.testBasicNumericTicker = function() {
32 var opts = {"logscale":null,"labelsKMG2":false,"labelsKMB":false};
33 var options = this.createOptionsViewForAxis('y', opts);
34
35 var ticks = Dygraph.numericTicks(-0.4, 4.4, 320, options);
36 var expected_ticks = [
37 {"v":-0.5,"label":"-0.5"},
38 {"v":0,"label":"0"},
39 {"v":0.5,"label":"0.5"},
40 {"v":1,"label":"1"},
41 {"v":1.5,"label":"1.5"},
42 {"v":2,"label":"2"},
43 {"v":2.5,"label":"2.5"},
44 {"v":3,"label":"3"},
45 {"v":3.5,"label":"3.5"},
46 {"v":4,"label":"4"},
47 {"v":4.5,"label":"4.5"}];
48 assertEquals(expected_ticks, ticks);
49
50 ticks = Dygraph.numericTicks(1, 84, 540, options);
51 var expected_ticks = [
52 {"v":0,"label":"0"},
53 {"v":5,"label":"5"},
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"},
69 {"v":85,"label":"85"}
70 ];
71 assertEquals(expected_ticks, ticks);
72 };