b1c96de33f6d30c31f93dc2204c200bbba39b857
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)
8 import Dygraph from
'../../src/dygraph';
10 describe("css", function() {
14 var data
= "X,Y,Z\n1,2,3\n4,5,6\n";
18 beforeEach(function() {
19 styleSheet
= document
.createElement("style");
20 styleSheet
.type
= "text/css";
21 document
.getElementsByTagName("head")[0].appendChild(styleSheet
);
24 afterEach(function() {
25 styleSheet
.innerHTML
= '';
28 // Verifies that an unstyled, unsized dygraph gets a default size.
29 it('testDefaultSize', function() {
32 var graph
= document
.getElementById("graph");
33 var g
= new Dygraph(graph
, data
, opts
);
35 assert
.equal(480, graph
.offsetWidth
);
36 assert
.equal(320, graph
.offsetHeight
);
37 assert
.deepEqual({width
: 480, height
: 320}, g
.size());
40 // Verifies that the width/height parameters work
.
41 it('testExplicitParamSize', function() {
46 var graph
= document
.getElementById("graph");
47 var g
= new Dygraph(graph
, data
, opts
);
49 assert
.equal(640, graph
.offsetWidth
);
50 assert
.equal(480, graph
.offsetHeight
);
51 assert
.deepEqual({width
: 640, height
: 480}, g
.size());
54 // Verifies that setting a style on the div works.
55 it('testExplicitStyleSize', function() {
58 var graph
= document
.getElementById("graph");
59 graph
.style
.width
= '600px';
60 graph
.style
.height
= '400px';
62 var g
= new Dygraph(graph
, data
, opts
);
63 assert
.equal(600, graph
.offsetWidth
);
64 assert
.equal(400, graph
.offsetHeight
);
65 assert
.deepEqual({width
: 600, height
: 400}, g
.size());
68 // Verifies that CSS pixel styles on the div trump explicit parameters.
69 it('testPixelStyleWins', function() {
74 var graph
= document
.getElementById("graph");
75 graph
.style
.width
= '600px';
76 graph
.style
.height
= '400px';
78 var g
= new Dygraph(graph
, data
, opts
);
79 assert
.equal(600, graph
.offsetWidth
);
80 assert
.equal(400, graph
.offsetHeight
);
81 assert
.deepEqual({width
: 600, height
: 400}, g
.size());
84 // Verifies that a CSS percentage size works.
85 it('testPercentageSize', function() {
86 var testdiv
= document
.getElementById("graph");
88 '<div style="width: 600px; height: 400px;">' +
89 '<div id="inner-graph"></div></div>';
92 var graph
= document
.getElementById("inner-graph");
93 graph
.style
.width
= '50%';
94 graph
.style
.height
= '50%';
96 var g
= new Dygraph(graph
, data
, opts
);
97 assert
.equal(300, graph
.offsetWidth
);
98 assert
.equal(200, graph
.offsetHeight
);
99 assert
.deepEqual({width
: 300, height
: 200}, g
.size());
102 // Verifies that a CSS class size works.
103 it('testClassPixelSize', function() {
104 styleSheet
.innerHTML
= '.chart { width: 456px; height: 345px; }';
108 var graph
= document
.getElementById("graph");
109 graph
.className
= "chart";
110 var g
= new Dygraph(graph
, data
, opts
);
111 assert
.equal(456, graph
.offsetWidth
);
112 assert
.equal(345, graph
.offsetHeight
);
113 assert
.deepEqual({width
: 456, height
: 345}, g
.size());
116 // An invisible chart div shouldn't produce an error.
117 it('testInvisibleChart', function() {
119 '<div style="display:none;">' +
120 '<div id="inner-graph" style="width: 640px; height: 480px;"></div>' +
122 new Dygraph('inner-graph', data
, {});
125 // An invisible chart div shouldn't produce an error.
126 it('testInvisibleChartDate', function() {
128 '<div style="display:none;">' +
129 '<div id="inner-graph" style="width: 640px; height: 480px;"></div>' +
131 new Dygraph('inner-graph',
142 // An invisible chart div that becomes visible.
143 it('testInvisibleThenVisibleChart', function() {
144 var testdiv
= document
.getElementById("graph");
146 '<div id="x" style="display:none;">' +
147 '<div id="inner-graph" style="width: 640px; height: 480px;"></div>' +
149 var graph
= document
.getElementById("inner-graph");
150 var g
= new Dygraph(graph
,
160 // g.size() is undefined here (probably 0x0)
161 document
.getElementById("x").style
.display
= "";
163 // This resize() call is annoying but essential.
164 // There are no DOM events to inform the dygraph that its div has changed size
165 // or visibility so we need to let it know ourselves.
168 assert
.equal(640, graph
.offsetWidth
);
169 assert
.equal(480, graph
.offsetHeight
);
170 assert
.deepEqual({width
: 640, height
: 480}, g
.size());
173 // Verifies that a div resize gets picked up.
175 this one isn't quite ready yet.
176 it('testDivResize', function() {
179 var graph = document.getElementById("graph");
180 graph.style.width = '640px';
181 graph.style.height = '480px';
182 var g = new Dygraph(graph, data, opts);
184 assert.equal(640, graph.offsetWidth);
185 assert.equal(480, graph.offsetHeight);
186 assert.deepEqual({width: 640, height: 480}, g.size());
188 graph.style.width = '650px';
189 graph.style.height = '490px';
190 assert.equal(650, graph.offsetWidth);
191 assert.equal(490, graph.offsetHeight);
192 assert.deepEqual({width: 650, height: 490}, g.size());