1 // Copyright 2011 Google Inc. All Rights Reserved.
4 * @fileoverview Regression test based on some strange customBars data.
5 * @author danvk@google.com (Dan Vanderkam)
7 describe("css", function() {
9 var data
= "X,Y,Z\n1,2,3\n4,5,6\n";
13 beforeEach(function() {
14 document
.body
.innerHTML
= "<div id='graph'></div>";
15 styleSheet
= document
.createElement("style");
16 styleSheet
.type
= "text/css";
17 document
.getElementsByTagName("head")[0].appendChild(styleSheet
);
20 afterEach(function() {
23 // Verifies that an unstyled, unsized dygraph gets a default size.
24 it('testDefaultSize', function() {
27 var graph
= document
.getElementById("graph");
28 var g
= new Dygraph(graph
, data
, opts
);
30 assert
.equal(480, graph
.offsetWidth
);
31 assert
.equal(320, graph
.offsetHeight
);
32 assert
.deepEqual({width
: 480, height
: 320}, g
.size());
35 // Verifies that the width/height parameters work
.
36 it('testExplicitParamSize', function() {
41 var graph
= document
.getElementById("graph");
42 var g
= new Dygraph(graph
, data
, opts
);
44 assert
.equal(640, graph
.offsetWidth
);
45 assert
.equal(480, graph
.offsetHeight
);
46 assert
.deepEqual({width
: 640, height
: 480}, g
.size());
49 // Verifies that setting a style on the div works.
50 it('testExplicitStyleSize', function() {
53 var graph
= document
.getElementById("graph");
54 graph
.style
.width
= '600px';
55 graph
.style
.height
= '400px';
57 var g
= new Dygraph(graph
, data
, opts
);
58 assert
.equal(600, graph
.offsetWidth
);
59 assert
.equal(400, graph
.offsetHeight
);
60 assert
.deepEqual({width
: 600, height
: 400}, g
.size());
63 // Verifies that CSS pixel styles on the div trump explicit parameters.
64 it('testPixelStyleWins', function() {
69 var graph
= document
.getElementById("graph");
70 graph
.style
.width
= '600px';
71 graph
.style
.height
= '400px';
73 var g
= new Dygraph(graph
, data
, opts
);
74 assert
.equal(600, graph
.offsetWidth
);
75 assert
.equal(400, graph
.offsetHeight
);
76 assert
.deepEqual({width
: 600, height
: 400}, g
.size());
79 // Verifies that a CSS percentage size works.
80 it('testPercentageSize', function() {
81 document
.body
.innerHTML
=
82 '<div style="width: 600px; height: 400px;">' +
83 '<div id="graph"></div></div>';
86 var graph
= document
.getElementById("graph");
87 graph
.style
.width
= '50%';
88 graph
.style
.height
= '50%';
90 var g
= new Dygraph(graph
, data
, opts
);
91 assert
.equal(300, graph
.offsetWidth
);
92 assert
.equal(200, graph
.offsetHeight
);
93 assert
.deepEqual({width
: 300, height
: 200}, g
.size());
96 // Verifies that a CSS class size works.
97 it('testClassPixelSize', function() {
98 styleSheet
.innerHTML
= '.chart { width: 456px; height: 345px; }';
102 var graph
= document
.getElementById("graph");
103 graph
.className
= "chart";
104 var g
= new Dygraph(graph
, data
, opts
);
105 assert
.equal(456, graph
.offsetWidth
);
106 assert
.equal(345, graph
.offsetHeight
);
107 assert
.deepEqual({width
: 456, height
: 345}, g
.size());
110 // An invisible chart div shouldn't produce an error.
111 it('testInvisibleChart', function() {
112 document
.body
.innerHTML
=
113 '<div style="display:none;">' +
114 '<div id="graph" style="width: 640px; height: 480px;"></div>' +
116 var graph
= document
.getElementById("graph");
117 new Dygraph(graph
, data
, {});
120 // An invisible chart div shouldn't produce an error.
121 it('testInvisibleChartDate', function() {
122 document
.body
.innerHTML
=
123 '<div style="display:none;">' +
124 '<div id="graph" style="width: 640px; height: 480px;"></div>' +
126 var graph
= document
.getElementById("graph");
138 // An invisible chart div that becomes visible.
139 it('testInvisibleThenVisibleChart', function() {
140 document
.body
.innerHTML
=
141 '<div id="x" style="display:none;">' +
142 '<div id="graph" style="width: 640px; height: 480px;"></div>' +
144 var graph
= document
.getElementById("graph");
145 var g
= new Dygraph(graph
,
155 // g.size() is undefined here (probably 0x0)
156 document
.getElementById("x").style
.display
= "";
158 // This resize() call is annoying but essential.
159 // There are no DOM events to inform the dygraph that its div has changed size
160 // or visibility so we need to let it know ourselves.
163 assert
.equal(640, graph
.offsetWidth
);
164 assert
.equal(480, graph
.offsetHeight
);
165 assert
.deepEqual({width
: 640, height
: 480}, g
.size());
168 // Verifies that a div resize gets picked up.
170 this one isn't quite ready yet.
171 it('testDivResize', function() {
174 var graph = document.getElementById("graph");
175 graph.style.width = '640px';
176 graph.style.height = '480px';
177 var g = new Dygraph(graph, data, opts);
179 assert.equal(640, graph.offsetWidth);
180 assert.equal(480, graph.offsetHeight);
181 assert.deepEqual({width: 640, height: 480}, g.size());
183 graph.style.width = '650px';
184 graph.style.height = '490px';
185 assert.equal(650, graph.offsetWidth);
186 assert.equal(490, graph.offsetHeight);
187 assert.deepEqual({width: 650, height: 490}, g.size());