2 * @fileoverview Tests for window.devicePixelRatio > 1.
4 * @author danvdk@gmail.com (Dan Vanderkam)
7 import Dygraph from
'../../src/dygraph';
9 describe("hidpi", function() {
14 beforeEach(function() {
15 savePixelRatio
= window
.devicePixelRatio
;
16 window
.devicePixelRatio
= 2;
19 afterEach(function() {
20 window
.devicePixelRatio
= savePixelRatio
;
23 it('testDoesntCreateScrollbars', function() {
24 var sw
= document
.body
.scrollWidth
;
25 var cw
= document
.body
.clientWidth
;
27 var graph
= document
.getElementById("graph");
28 graph
.style
.width
= "70%"; // more than half.
29 graph
.style
.height
= "200px";
39 var g
= new Dygraph(graph
, data
, opts
);
41 // Adding the graph shouldn't cause the width of the page to change.
42 // (essentially, we're checking that we don't end up with a scrollbar)
43 // See http://stackoverflow.com/a/2146905/388951
44 assert
.equal(cw
, document
.body
.clientWidth
);
45 assert
.equal(sw
, document
.body
.scrollWidth
);
48 it('should be influenced by options.pixelRatio', function () {
49 var graph
= document
.getElementById("graph");
51 // make sure devicePixelRatio is still setup to not 1.
52 assert(devicePixelRatio
> 1.5, 'devicePixelRatio is not much greater than 1.');
60 // first try a default one
61 var g1
= new Dygraph(graph
, data
, {});
62 var area1
= g1
.getArea();
64 var g2
= new Dygraph(graph
, data
, { pixelRatio
: 1 });
65 var area2
= g2
.getArea();
67 var g3
= new Dygraph(graph
, data
, { pixelRatio
: 3 });
68 var area3
= g3
.getArea();
70 assert
.deepEqual(area1
, area2
, 'areas 1 and 2 are not the same');
71 assert
.deepEqual(area2
, area3
, 'areas 2 and 3 are not the same');
73 assert
.notEqual(g1
.canvas_
.width
, g2
.canvas_
.width
,
74 'Expected, for devicePixelRatio != 1, '
75 + 'that setting options.pixelRatio would change the canvas width');
76 assert
.equal(g2
.canvas_
.width
* 3, g3
.canvas_
.width
,
77 'Expected that pixelRatio of 3 vs 1 would triple the canvas width.');