From: Dan Vanderkam Date: Thu, 11 Aug 2011 21:24:28 +0000 (-0400) Subject: Fix display of error bars when using logscale X-Git-Tag: v1.0.0~424 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=7f02898088f43f0bd97e6b9f7f54ee3b0cf630a6;p=dygraphs.git Fix display of error bars when using logscale --- diff --git a/dygraph-canvas.js b/dygraph-canvas.js index f08210d..9a162db 100644 --- a/dygraph-canvas.js +++ b/dygraph-canvas.js @@ -662,12 +662,10 @@ DygraphCanvasRenderer.prototype._renderLineChart = function() { // TODO(danvk): here if (stepPlot) { - var newYs = [ prevY - point.errorPlus * yscale, - prevY + point.errorMinus * yscale ]; + var newYs = [ point.y_bottom, point.y_top ]; prevY = point.y; } else { - var newYs = [ point.y - point.errorPlus * yscale, - point.y + point.errorMinus * yscale ]; + var newYs = [ point.y_bottom, point.y_top ]; } newYs[0] = this.area.h * newYs[0] + this.area.y; newYs[1] = this.area.h * newYs[1] + this.area.y; diff --git a/dygraph-layout.js b/dygraph-layout.js index 28f1f28..90f7ea2 100644 --- a/dygraph-layout.js +++ b/dygraph-layout.js @@ -126,6 +126,14 @@ DygraphLayout.prototype._evaluateLimits = function() { } }; +DygraphLayout._calcYNormal = function(axis, value) { + if (axis.logscale) { + return 1.0 - ((Dygraph.log10(value) - Dygraph.log10(axis.minyval)) * axis.ylogscale); + } else { + return 1.0 - ((value - axis.minyval) * axis.yscale); + } +}; + DygraphLayout.prototype._evaluateLineCharts = function() { // add all the rects this.points = new Array(); @@ -148,15 +156,11 @@ DygraphLayout.prototype._evaluateLineCharts = function() { var xValue = parseFloat(dataset[j][0]); var yValue = parseFloat(dataset[j][1]); - // Range from 0-1 where 0 represents top and 1 represents bottom - var xNormal = (xValue - this.minxval) * this.xscale; // Range from 0-1 where 0 represents left and 1 represents right. - var yNormal; - if (axis.logscale) { - yNormal = 1.0 - ((Dygraph.log10(yValue) - Dygraph.log10(axis.minyval)) * axis.ylogscale); - } else { - yNormal = 1.0 - ((yValue - axis.minyval) * axis.yscale); - } + var xNormal = (xValue - this.minxval) * this.xscale; + // Range from 0-1 where 0 represents top and 1 represents bottom + var yNormal = DygraphLayout._calcYNormal(axis, yValue); + var point = { // TODO(danvk): here x: xNormal, @@ -212,6 +216,7 @@ DygraphLayout.prototype.evaluateWithError = function() { if (!this.datasets.hasOwnProperty(setName)) continue; var j = 0; var dataset = this.datasets[setName]; + var axis = this.dygraph_.axisPropertiesForSeries(setName); for (var j = 0; j < dataset.length; j++, i++) { var item = dataset[j]; var xv = parseFloat(item[0]); @@ -219,8 +224,13 @@ DygraphLayout.prototype.evaluateWithError = function() { if (xv == this.points[i].xval && yv == this.points[i].yval) { - this.points[i].errorMinus = parseFloat(item[2]); - this.points[i].errorPlus = parseFloat(item[3]); + var errorMinus = parseFloat(item[2]); + var errorPlus = parseFloat(item[3]); + + var yv_minus = yv - errorMinus; + var yv_plus = yv + errorPlus; + this.points[i].y_top = DygraphLayout._calcYNormal(axis, yv_minus); + this.points[i].y_bottom = DygraphLayout._calcYNormal(axis, yv_plus); } } }