/**
* Sets some PlotKit.CanvasRenderer options
* @param {Object} element The canvas to attach to
+ * @param {Object} elementContext The 2d context of the canvas (injected so it
+ * can be mocked for testing.)
* @param {Layout} layout The DygraphLayout object for this graph.
* @param {Object} options Options to pass on to CanvasRenderer
*/
-DygraphCanvasRenderer = function(dygraph, element, layout, options) {
+DygraphCanvasRenderer = function(dygraph, element, elementContext, layout,
+ options) {
// TODO(danvk): remove options, just use dygraph.attr_.
this.dygraph_ = dygraph;
this.layout = layout;
this.element = element;
+ this.elementContext = elementContext;
this.container = this.element.parentNode;
this.height = this.element.height;
// Set up a clipping area for the canvas (and the interaction canvas).
// This ensures that we don't overdraw.
- var ctx = this.dygraph_.canvas_.getContext("2d");
+ var ctx = this.dygraph_.canvas_ctx_;
ctx.beginPath();
ctx.rect(this.area.x, this.area.y, this.area.w, this.area.h);
ctx.clip();
- ctx = this.dygraph_.hidden_.getContext("2d");
+ ctx = this.dygraph_.hidden_ctx_;
ctx.beginPath();
ctx.rect(this.area.x, this.area.y, this.area.w, this.area.h);
ctx.clip();
this.clearDelay.cancel();
this.clearDelay = null;
}
- var context = this.element.getContext("2d");
+ var context = this.elementContext;
}
catch (e) {
// TODO(danvk): this is broken, since MochiKit.Async is gone.
}
}
- var context = this.element.getContext("2d");
+ var context = this.elementContext;
context.clearRect(0, 0, this.width, this.height);
for (var i = 0; i < this.xlabels.length; i++) {
DygraphCanvasRenderer.prototype.render = function() {
// Draw the new X/Y grid. Lines appear crisper when pixels are rounded to
// half-integers. This prevents them from drawing in two rows/cols.
- var ctx = this.element.getContext("2d");
+ var ctx = this.elementContext;
function halfUp(x){return Math.round(x)+0.5};
function halfDown(y){return Math.round(y)-0.5};
function halfUp(x){return Math.round(x)+0.5};
function halfDown(y){return Math.round(y)-0.5};
- var context = this.element.getContext("2d");
+ var context = this.elementContext;
var labelStyle = {
"position": "absolute",
div.style.width = this.area.w + 'px';
div.style.height = this.attr_('titleHeight') + 'px';
div.style.textAlign = 'center';
- div.style.fontSize = (this.attr_('titleHeight') - 2) + 'px';
+ div.style.fontSize = (this.attr_('titleHeight') - 8) + 'px';
div.style.fontWeight = 'bold';
var class_div = document.createElement("div");
class_div.className = 'dygraph-label dygraph-title';
inner_div.style.top = (box.height / 2 - box.width / 2) + 'px';
inner_div.style.left = (box.width / 2 - box.height / 2) + 'px';
inner_div.style.textAlign = 'center';
+
+ // CSS rotation is an HTML5 feature which is not standardized. Hence every
+ // browser has its own name for the CSS style.
inner_div.style.transform = 'rotate(-90deg)'; // HTML5
inner_div.style.WebkitTransform = 'rotate(-90deg)'; // Safari/Chrome
inner_div.style.MozTransform = 'rotate(-90deg)'; // Firefox
inner_div.style.OTransform = 'rotate(-90deg)'; // Opera
inner_div.style.msTransform = 'rotate(-90deg)'; // IE9
- inner_div.id = 'foo'; // XXX
- // inner_div.style.filter =
- // 'progid:DXImageTransform.Microsoft.BasicImage(rotation=3)';
+
+ if (typeof(document.documentMode) !== 'undefined' &&
+ document.documentMode < 9) {
+ // We're dealing w/ an old version of IE, so we have to rotate the text
+ // using a BasicImage transform. This uses a different origin of rotation
+ // than HTML5 rotation (top left of div vs. its center).
+ inner_div.style.filter =
+ 'progid:DXImageTransform.Microsoft.BasicImage(rotation=3)';
+ inner_div.style.left = '0px';
+ inner_div.style.top = '0px';
+ }
var class_div = document.createElement("div");
class_div.className = 'dygraph-label dygraph-ylabel';
this.container.appendChild(div);
this.annotations.push(div);
- var ctx = this.element.getContext("2d");
+ var ctx = this.elementContext;
ctx.strokeStyle = this.colors[p.name];
ctx.beginPath();
if (!a.attachAtBottom) {
*/
DygraphCanvasRenderer.prototype._renderLineChart = function() {
// TODO(danvk): use this.attr_ for many of these.
- var context = this.element.getContext("2d");
+ var context = this.elementContext;
var colorCount = this.options.colorScheme.length;
var colorScheme = this.options.colorScheme;
var fillAlpha = this.options.fillAlpha;