From 34fedff86a8f5eb1a95e49eef611ea1079b304cf Mon Sep 17 00:00:00 2001 From: Dan Vanderkam Date: Mon, 30 Nov 2009 11:16:03 -0500 Subject: [PATCH] remove DOM and Style dependencies --- dygraph-canvas.js | 26 ++++++++++++++++---------- generate-combined.sh | 2 +- tests/customLabel.html | 2 +- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/dygraph-canvas.js b/dygraph-canvas.js index 8a2c17b..271e21a 100644 --- a/dygraph-canvas.js +++ b/dygraph-canvas.js @@ -323,14 +323,21 @@ DygraphCanvasRenderer.prototype._renderAxis = function() { var context = this.element.getContext("2d"); - var labelStyle = {"style": - {"position": "absolute", - "fontSize": this.options.axisLabelFontSize + "px", - "zIndex": 10, - "color": this.options.axisLabelColor.toRGBString(), - "width": this.options.axisLabelWidth + "px", - "overflow": "hidden" + var labelStyle = { + "position": "absolute", + "fontSize": this.options.axisLabelFontSize + "px", + "zIndex": 10, + "color": this.options.axisLabelColor.toRGBString(), + "width": this.options.axisLabelWidth + "px", + "overflow": "hidden" + }; + var makeDiv = function(txt) { + var div = document.createElement("div"); + for (var name in labelStyle) { + div.style[name] = labelStyle[name]; } + div.appendChild(document.createTextNode(txt)); + return div; }; // axis lines @@ -338,7 +345,6 @@ DygraphCanvasRenderer.prototype._renderAxis = function() { context.strokeStyle = this.options.axisLineColor.toRGBString(); context.lineWidth = this.options.axisLineWidth; - if (this.options.drawYAxis) { if (this.layout.yticks) { for (var i = 0; i < this.layout.yticks.length; i++) { @@ -352,7 +358,7 @@ DygraphCanvasRenderer.prototype._renderAxis = function() { context.closePath(); context.stroke(); - var label = DIV(labelStyle, tick[1]); + var label = makeDiv(tick[1]); var top = (y - this.options.axisLabelFontSize / 2); if (top < 0) top = 0; @@ -401,7 +407,7 @@ DygraphCanvasRenderer.prototype._renderAxis = function() { context.closePath(); context.stroke(); - var label = DIV(labelStyle, tick[1]); + var label = makeDiv(tick[1]); label.style.textAlign = "center"; label.style.bottom = "0px"; diff --git a/generate-combined.sh b/generate-combined.sh index 50f785a..d27cc98 100755 --- a/generate-combined.sh +++ b/generate-combined.sh @@ -6,7 +6,7 @@ # Do the same for MochiKit. This save another 77k. cd mochikit_v14 ./scripts/pack.py \ -Base Color DOM Style \ +Base Color \ > /tmp/mochikit-packed.js cd .. diff --git a/tests/customLabel.html b/tests/customLabel.html index 4672767..8753183 100644 --- a/tests/customLabel.html +++ b/tests/customLabel.html @@ -25,7 +25,7 @@ 'top': '210px' }, labelsSeparateLines: true, - yAxisLabelWidth: 10 + yAxisLabelWidth: 20 } ); -- 2.7.4