2 * @fileoverview Test cases for resizing.
4 * @author konigsberg@google.com (Robert Konigsberg)
6 var ResizeTestCase
= TestCase("resize");
17 ResizeTestCase
.prototype.setUp
= function() {
18 document
.body
.innerHTML
= "<div id='graph'></div>";
21 ResizeTestCase
.prototype.tearDown
= function() {
24 ResizeTestCase
.prototype.testResizeMaintainsMouseOperations
= function() {
25 document
.body
.innerHTML
=
26 '<div id="graph" style="width: 640px; height: 480px;"></div>' +
28 var graph
= document
.getElementById("graph");
30 var callbackCount
= 0;
31 var callback
= function() {
35 // Strum the mouse along the y-coordinate y, from 0 to x2. These are DOM values.
36 var strum
= function(g
, y
, x2
) {
37 DygraphOps
.dispatchMouseDown_Point(g
, 0, y
);
38 for (var x
= 0; x
< x2
; x
++) {
39 DygraphOps
.dispatchMouseMove_Point(g
, x
, y
);
41 DygraphOps
.dispatchMouseUp_Point(g
, x2
- 1, y
);
44 g
= new Dygraph(graph
, ResizeTestCase
.data
, {highlightCallback
: callback
});
47 assertEquals(6, callbackCount
);
49 document
.getElementById("graph").style
.width
= "500px";
54 assertEquals(6, callbackCount
);
58 * Tests that a graph created in a not-displayed div works as expected
59 * if the graph options include height and width. Resize not needed.
61 ResizeTestCase
.prototype.testHiddenDivWithSizedGraph
= function() {
62 var div
= document
.getElementById("graph");
64 div
.style
.display
= 'none';
65 var g
= new Dygraph(div
, ResizeTestCase
.data
, {width
: 400, height
: 300});
66 div
.style
.display
= '';
68 var area
= g
.getArea();
69 assertTrue(area
.w
> 0);
70 assertTrue(area
.h
> 0);
74 * Tests that a graph created in a not-displayed div with
75 * CSS-specified size but no graph height or width options works as
76 * expected. The user needs to call resize() on it after displaying
79 ResizeTestCase
.prototype.testHiddenDivWithResize
= function() {
80 var div
= document
.getElementById("graph");
82 div
.style
.display
= 'none';
83 div
.style
.width
= '400px';
84 div
.style
.height
= '300px';
86 // Setting strokeWidth 3 removes any ambiguitiy from the pixel sampling
88 var g
= new Dygraph(div
, ResizeTestCase
.data
, {strokeWidth
: 3});
89 div
.style
.display
= '';
93 assertTrue(area
.w
> 0);
94 assertTrue(area
.h
> 0);
96 // Regression test: check that graph remains visible after no-op resize.
98 var x
= Math
.floor(g
.toDomXCoord(2));
99 var y
= Math
.floor(g
.toDomYCoord(200));
100 assertEquals("Unexpected grid color found at pixel: x: " + x
+ " y: " + y
,
101 [0, 128, 128, 255], Util
.samplePixel(g
.hidden_
, x
, y
));