2 * @fileoverview Test cases for toDomCoords/toDataCoords
4 * @author danvk@google.com (Dan Vanderkam)
7 var ToDomCoordsTestCase
= TestCase("to-dom-coords");
9 var _origFunc
= Dygraph
.getContext
;
10 ToDomCoordsTestCase
.prototype.setUp
= function() {
11 document
.body
.innerHTML
= "<div id='graph'></div>";
12 Dygraph
.getContext
= function(canvas
) {
13 return new Proxy(_origFunc(canvas
));
17 ToDomCoordsTestCase
.prototype.tearDown
= function() {
18 Dygraph
.getContext
= _origFunc
;
21 // Checks that toDomCoords and toDataCoords are inverses of one another.
22 ToDomCoordsTestCase
.prototype.checkForInverses
= function(g
) {
23 var x_range
= g
.xAxisRange();
24 var y_range
= g
.yAxisRange();
25 for (var i
= 0; i
<= 10; i
++) {
26 var x
= x_range
[0] + i
/ 10.0 * (x_range
[1] - x_range
[0]);
27 for (var j
= 0; j
<= 10; j
++) {
28 var y
= y_range
[0] + j
/ 10.0 * (y_range
[1] - y_range
[0]);
29 assertEquals(x
, g
.toDataXCoord(g
.toDomXCoord(x
)));
30 assertEquals(y
, g
.toDataYCoord(g
.toDomYCoord(y
)));
35 ToDomCoordsTestCase
.prototype.testPlainChart
= function() {
49 var graph
= document
.getElementById("graph");
50 g
= new Dygraph(graph
, [ [0,0], [100,100] ], opts
);
52 assertEquals([0, 100], g
.toDataCoords(0, 0));
53 assertEquals([0, 0], g
.toDataCoords(0, 400));
54 assertEquals([100, 100], g
.toDataCoords(400, 0));
55 assertEquals([100, 0], g
.toDataCoords(400, 400));
57 this.checkForInverses(g
);
59 var htx
= g
.hidden_ctx_
;
60 assertEquals(1, CanvasAssertions
.numLinesDrawn(htx
, '#ff0000'));
63 ToDomCoordsTestCase
.prototype.testChartWithAxes
= function() {
80 var graph
= document
.getElementById("graph");
81 g
= new Dygraph(graph
, [ [0,0], [100,100] ], opts
);
83 assertEquals([0, 100], g
.toDataCoords(100, 0));
84 assertEquals([0, 0], g
.toDataCoords(100, 400));
85 assertEquals([100, 100], g
.toDataCoords(500, 0));
86 assertEquals([100, 0], g
.toDataCoords(500, 400));
88 this.checkForInverses(g
);
91 ToDomCoordsTestCase
.prototype.testChartWithAxesAndLabels
= function() {
101 valueRange
: [0, 100],
102 dateWindow
: [0, 100],
106 ylabel
: 'This is the y-axis',
107 xlabel
: 'This is the x-axis',
109 title
: 'This is the title of the chart',
113 var graph
= document
.getElementById("graph");
114 g
= new Dygraph(graph
, [ [0,0], [100,100] ], opts
);
116 assertEquals([0, 100], g
.toDataCoords(100, 25));
117 assertEquals([0, 0], g
.toDataCoords(100, 425));
118 assertEquals([100, 100], g
.toDataCoords(500, 25));
119 assertEquals([100, 0], g
.toDataCoords(500, 425));
121 this.checkForInverses(g
);