Bug 1024633 - Add a way of specifying a fixed width or height for canvas graphs, r=pbrosset

This commit is contained in:
Victor Porof 2014-06-16 08:59:36 -04:00
Родитель 497e088be5
Коммит 1a04655381
3 изменённых файлов: 57 добавлений и 0 удалений

Просмотреть файл

@ -24,6 +24,7 @@ support-files =
[browser_graphs-10.js]
[browser_graphs-11.js]
[browser_graphs-12.js]
[browser_graphs-13.js]
[browser_layoutHelpers.js]
[browser_layoutHelpers-getBoxQuads.js]
[browser_observableobject.js]

Просмотреть файл

@ -0,0 +1,45 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
// Tests that graph widgets may have a fixed width or height.
let {LineGraphWidget} = Cu.import("resource:///modules/devtools/Graphs.jsm", {});
let {DOMHelpers} = Cu.import("resource:///modules/devtools/DOMHelpers.jsm", {});
let {Promise} = devtools.require("resource://gre/modules/Promise.jsm");
let {Hosts} = devtools.require("devtools/framework/toolbox-hosts");
let test = Task.async(function*() {
yield promiseTab("about:blank");
yield performTest();
gBrowser.removeCurrentTab();
finish();
});
function* performTest() {
let [host, win, doc] = yield createHost();
doc.body.setAttribute("style", "position: fixed; width: 100%; height: 100%; margin: 0;");
let graph = new LineGraphWidget(doc.body, "fps");
graph.fixedWidth = 200;
graph.fixedHeight = 100;
yield graph.ready();
testGraph(host, graph);
graph.destroy();
host.destroy();
}
function testGraph(host, graph) {
let bounds = host.frame.getBoundingClientRect();
isnot(graph.width, bounds.width * window.devicePixelRatio,
"The graph should not span all the parent node's width.");
isnot(graph.height, bounds.height * window.devicePixelRatio,
"The graph should not span all the parent node's height.");
is(graph.width, graph.fixedWidth * window.devicePixelRatio,
"The graph has the correct width.");
is(graph.height, graph.fixedHeight * window.devicePixelRatio,
"The graph has the correct height.");
}

Просмотреть файл

@ -153,6 +153,8 @@ this.AbstractCanvasGraph = function(parent, name, sharpness) {
canvas.className = name + "-widget-canvas graph-widget-canvas";
let bounds = parent.getBoundingClientRect();
bounds.width = this.fixedWidth || bounds.width;
bounds.height = this.fixedHeight || bounds.height;
iframe.setAttribute("width", bounds.width);
iframe.setAttribute("height", bounds.height);
@ -245,6 +247,13 @@ AbstractCanvasGraph.prototype = {
regionBackgroundColor: "transparent",
regionStripesColor: "transparent",
/**
* Makes sure the canvas graph is of the specified width or height, and
* doesn't flex to fit all the available space.
*/
fixedWidth: null,
fixedHeight: null,
/**
* Builds and caches a graph image, based on the data source supplied
* in `setData`. The graph image is not rebuilt on each frame, but
@ -493,6 +502,8 @@ AbstractCanvasGraph.prototype = {
*/
refresh: function() {
let bounds = this._parent.getBoundingClientRect();
bounds.width = this.fixedWidth || bounds.width;
bounds.height = this.fixedHeight || bounds.height;
this._iframe.setAttribute("width", bounds.width);
this._iframe.setAttribute("height", bounds.height);
this._width = this._canvas.width = bounds.width * this._pixelRatio;