More turbocharge for CanvasAssertions.
[dygraphs.git] / auto_tests / tests / missing_points.js
CommitLineData
cea0fb70
RK
1// Copyright (c) 2012 Google, Inc.
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy
4// of this software and associated documentation files (the "Software"), to deal
5// in the Software without restriction, including without limitation the rights
6// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7// copies of the Software, and to permit persons to whom the Software is
8// furnished to do so, subject to the following conditions:
9//
10// The above copyright notice and this permission notice shall be included in
11// all copies or substantial portions of the Software.
12//
13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19// THE SOFTWARE.
20
21/**
22 * @fileoverview Test cases for drawing lines with missing points.
23 *
24 * @author konigsberg@google.com (Robert Konigsberg)
25 */
26var ZERO_TO_FIFTY = [[ 10, 0 ] , [ 20, 50 ]];
27
28var MissingPointsTestCase = TestCase("missing-points");
29
30var _origFunc = Dygraph.getContext;
31MissingPointsTestCase.prototype.setUp = function() {
32 document.body.innerHTML = "<div id='graph'></div>";
33 Dygraph.getContext = function(canvas) {
34 return new Proxy(_origFunc(canvas));
35 }
36};
37
38MissingPointsTestCase.prototype.tearDown = function() {
39 Dygraph.getContext = _origFunc;
40};
41
42MissingPointsTestCase.prototype.testSeparatedPointsDontDraw = function() {
43 var graph = document.getElementById("graph");
44 var g = new Dygraph(
45 graph,
46 [[1, 10, 11],
47 [2, 11, null],
48 [3, 12, 13]],
49 { colors: ['red', 'blue']});
50 var htx = g.hidden_ctx_;
51 assertEquals(2, CanvasAssertions.numLinesDrawn(htx, '#ff0000'));
52 assertEquals(0, CanvasAssertions.numLinesDrawn(htx, '#0000ff'));
53}
54
55MissingPointsTestCase.prototype.testSeparatedPointsDontDraw_expanded = function() {
56 var graph = document.getElementById("graph");
57 var g = new Dygraph(
58 graph,
59 [[0, 10],
60 [1, 11],
61 [2, null],
62 [3, 13],
63 [4, 14]],
64 { colors: ['blue']});
65 var htx = g.hidden_ctx_;
66 /*
67 var num_lines = 0;
68 var lines = CanvasAssertions.getLinesDrawn(htx);
69 for (var idx = 0; idx < lines.length; idx++) {
70 var line = lines[idx];
71 var color = line[1].properties.strokeStyle;
72 if (color === "#ff0000" || color === "#0000ff") {
73 console.log(line[0].args, line[1].args, color);
74 }
75 }
76 */
77
78 assertEquals(2, CanvasAssertions.numLinesDrawn(htx, '#0000ff'));
79 CanvasAssertions.assertLineDrawn(htx, [56, 275], [161, 212],
80 { strokeStyle: '#0000ff', });
81 CanvasAssertions.assertLineDrawn(htx, [370, 87], [475, 25],
82 { strokeStyle: '#0000ff', });
83}
84
85MissingPointsTestCase.prototype.testSeparatedPointsDontDraw_expanded_connected = function() {
86 var graph = document.getElementById("graph");
87 var g = new Dygraph(
88 graph,
89 [[0, 10],
90 [1, 11],
91 [2, null],
92 [3, 13],
93 [4, 14]],
94 { colors: ['blue'], connectSeparatedPoints: true});
95 var htx = g.hidden_ctx_;
96 var num_lines = 0;
97 var lines = CanvasAssertions.getLinesDrawn(htx);
98 for (var idx = 0; idx < lines.length; idx++) {
99 var line = lines[idx];
100 var color = line[1].properties.strokeStyle;
101 if (color === "#ff0000" || color === "#0000ff") {
102 console.log(line[0].args, line[1].args, color);
103 }
104 }
105
106 assertEquals(3, CanvasAssertions.numLinesDrawn(htx, '#0000ff'));
107 CanvasAssertions.assertLineDrawn(htx, [56, 275], [161, 212],
108 { strokeStyle: '#0000ff', });
109 CanvasAssertions.assertLineDrawn(htx, [161, 212], [370, 87],
110 { strokeStyle: '#0000ff', });
111 CanvasAssertions.assertLineDrawn(htx, [370, 87], [475, 25],
112 { strokeStyle: '#0000ff', });
113}
0b9ce4de
RK
114
115/**
116 * At the time of writing this test, the blue series is only points, and not lines.
117 */
118MissingPointsTestCase.prototype.testConnectSeparatedPoints = function() {
119 var g = new Dygraph(
120 document.getElementById("graph"),
121 [
122 [1, null, 3],
123 [2, 2, null],
124 [3, null, 7],
125 [4, 5, null],
126 [5, null, 5],
127 [6, 3, null]
128 ],
129 {
130 connectSeparatedPoints: true,
131 drawPoints: true,
132 colors: ['red', 'blue']
133 }
134 );
135 fail("write assertions");
136}
137
138/**
139 * At the time of writing this test, the blue series is only points, and not lines.
140 */
141MissingPointsTestCase.prototype.testConnectSeparatedPointsWithNan = function() {
142 var g = new Dygraph(
143 document.getElementById("graph"),
144 "x,A,B \n" +
145 "1,,3 \n" +
146 "2,2, \n" +
147 "3,,5 \n" +
148 "4,4, \n" +
149 "5,,7 \n" +
150 "6,NaN, \n" +
151 "8,8, \n" +
152 "10,10, \n",
153 {
154 connectSeparatedPoints: true,
155 drawPoints: true,
156 colors: ['red', 'blue']
157 }
158 );
159 fail("write assertions");
160}