From 9012dd21921ff553d61acbdfc41dad298c1ec089 Mon Sep 17 00:00:00 2001 From: Dan Vanderkam Date: Thu, 30 Sep 2010 13:13:16 -0400 Subject: [PATCH] blah --- dygraph-canvas.js | 36 ++++++++++++++++++++++++++++-------- dygraph.js | 12 ++++-------- 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/dygraph-canvas.js b/dygraph-canvas.js index f22f858..edce7a7 100644 --- a/dygraph-canvas.js +++ b/dygraph-canvas.js @@ -132,14 +132,14 @@ DygraphLayout.prototype._evaluateLineTicks = function() { } this.yticks = new Array(); - for (var i = 0; i < 1; i++ ) { + for (var i = 0; i < this.options.yAxes.length; i++ ) { var axis = this.options.yAxes[i]; for (var j = 0; j < axis.ticks.length; j++) { var tick = axis.ticks[j]; var label = tick.label; var pos = 1.0 - (axis.yscale * (tick.v - axis.minyval)); if ((pos >= 0.0) && (pos <= 1.0)) { - this.yticks.push([pos, label]); + this.yticks.push([i, pos, label]); } } } @@ -262,6 +262,7 @@ DygraphCanvasRenderer = function(dygraph, element, layout, options) { // TODO(danvk): consider all axes in this computation. this.area = { + // TODO(danvk): per-axis setting. x: this.options.yAxisLabelWidth + 2 * this.options.axisTickSize, y: 0 }; @@ -335,6 +336,15 @@ DygraphCanvasRenderer.isSupported = function(canvasName) { * Draw an X/Y grid on top of the existing plot */ DygraphCanvasRenderer.prototype.render = function() { + // Shrink the drawing area to accomodate additional y-axes. + if (this.layout.options.yAxes.length == 2) { + // TODO(danvk): per-axis setting. + this.area.w -= (this.options.yAxisLabelWidth + 2 * this.options.axisTickSize); + } else if (this.layout.options.yAxes.length > 2) { + this.dygraph_.error("Only two y-axes are supported at this time. (Trying " + + "to use " + this.layout.yAxes.length + ")"); + } + // Draw the new X/Y grid var ctx = this.element.getContext("2d"); @@ -348,8 +358,9 @@ DygraphCanvasRenderer.prototype.render = function() { ctx.strokeStyle = this.options.gridLineColor; ctx.lineWidth = this.options.axisLineWidth; for (var i = 0; i < ticks.length; i++) { + if (ticks[i][0] != 0) continue; // TODO(danvk): per-axis property var x = this.area.x; - var y = this.area.y + ticks[i][0] * this.area.h; + var y = this.area.y + ticks[i][1] * this.area.h; ctx.beginPath(); ctx.moveTo(x, y); ctx.lineTo(x + this.area.w, y); @@ -364,7 +375,7 @@ DygraphCanvasRenderer.prototype.render = function() { ctx.strokeStyle = this.options.gridLineColor; ctx.lineWidth = this.options.axisLineWidth; for (var i=0; i [low, high] for that series, - * (implicit) per-series axis attributes. * Returns [ axes, seriesToAxisMap ] - * axes = [ { valueRange: [low, high], otherOptions: ..., ticks: [...] } ] + * axes = [ { options } ] * seriesToAxisMap = { seriesName: 0, seriesName2: 1, ... } * indices are into the axes array. */ @@ -2435,6 +2430,7 @@ Dygraph.prototype.updateOptions = function(attrs) { Dygraph.update(this.renderOptions_, attrs); this.labelsFromCSV_ = (this.attr_("labels") == null); + this.computeYaxes_(); // TODO(danvk): this doesn't match the constructor logic this.layout_.updateOptions({ 'errorBars': this.attr_("errorBars") }); -- 2.7.4