Merge branch 'master' of https://github.com/kberg/dygraphs into new-series-option
[dygraphs.git] / auto_tests / tests / per_series.js
1 /**
2 * @fileoverview Tests for per-series options.
3 *
4 * @author danvk@google.com (Dan Vanderkam)
5 */
6 var perSeriesTestCase = TestCase("per-series");
7
8 perSeriesTestCase.prototype.setUp = function() {
9 document.body.innerHTML = "<div id='graph'></div>";
10 };
11
12 perSeriesTestCase.prototype.tearDown = function() {
13 };
14
15
16 perSeriesTestCase.prototype.testPerSeriesFill = function() {
17 var opts = {
18 width: 480,
19 height: 320,
20 drawXGrid: false,
21 drawYGrid: false,
22 drawXAxis: false,
23 drawYAxis: false,
24 Y: { fillGraph: true },
25 colors: [ '#FF0000', '#0000FF' ],
26 fillAlpha: 0.15
27 };
28 var data = "X,Y,Z\n" +
29 "1,0,0\n" +
30 "2,0,1\n" +
31 "3,0,1\n" +
32 "4,0,0\n" +
33 "5,0,0\n" +
34 "6,1,0\n" +
35 "7,1,0\n" +
36 "8,0,0\n"
37 ;
38
39 var graph = document.getElementById("graph");
40 g = new Dygraph(graph, data, opts);
41
42 var sampler = new PixelSampler(g);
43
44 // Inside of the "Z" bump -- no fill.
45 assertEquals([0,0,0,0], sampler.colorAtCoordinate(2.5, 0.5));
46
47 // Inside of the "Y" bump -- filled in.
48 assertEquals([255,0,0,38], sampler.colorAtCoordinate(6.5, 0.5));
49 };
50
51 perSeriesTestCase.prototype.testOldStyleSeries = function() {
52 var opts = {
53 pointSize : 5,
54 Y: { pointSize : 4 },
55 };
56 var graph = document.getElementById("graph");
57 var data = "X,Y,Z\n1,0,0\n";
58 g = new Dygraph(graph, data, opts);
59
60 assertEquals(5, g.getOption("pointSize"));
61 assertEquals(4, g.getOption("pointSize", "Y"));
62 assertEquals(5, g.getOption("pointSize", "Z"));
63 };
64
65 perSeriesTestCase.prototype.testNewStyleSeries = function() {
66 var opts = {
67 pointSize : 5,
68 series : {
69 Y: { pointSize : 4 }
70 },
71 };
72 var graph = document.getElementById("graph");
73 var data = "X,Y,Z\n1,0,0\n";
74 g = new Dygraph(graph, data, opts);
75
76 assertEquals(5, g.getOption("pointSize"));
77 assertEquals(4, g.getOption("pointSize", "Y"));
78 assertEquals(5, g.getOption("pointSize", "Z"));
79 };
80
81 perSeriesTestCase.prototype.testNewStyleSeriesTrumpsOldStyle = function() {
82 var opts = {
83 pointSize : 5,
84 Z : { pointSize : 6 },
85 series : {
86 Y: { pointSize : 4 }
87 },
88 };
89 var graph = document.getElementById("graph");
90 var data = "X,Y,Z\n1,0,0\n";
91 g = new Dygraph(graph, data, opts);
92
93 assertEquals(5, g.getOption("pointSize"));
94 assertEquals(4, g.getOption("pointSize", "Y"));
95 assertEquals(5, g.getOption("pointSize", "Z"));
96
97 // Erase the series object, and Z will become visible again.
98 g.updateOptions({ series : undefined });
99 assertEquals(5, g.getOption("pointSize"));
100 assertEquals(6, g.getOption("pointSize", "Z"));
101 assertEquals(5, g.getOption("pointSize", "Y"));
102 };
103