X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;f=dygraph-layout.js;h=90f7ea235222bcaaffa4e203ec1574f19111b8db;hb=48e614acf3084b9836803f8b014bf0e65f1ca119;hp=4f8656e8b5801f1bdda09622a9993e006caf4a23;hpb=80e653aa7a48cd48dbcaf24dff5d5b99417d91e7;p=dygraphs.git diff --git a/dygraph-layout.js b/dygraph-layout.js index 4f8656e..90f7ea2 100644 --- a/dygraph-layout.js +++ b/dygraph-layout.js @@ -126,62 +126,53 @@ 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(); + // An array to keep track of how many points will be drawn for each set. + // This will allow for the canvas renderer to not have to check every point + // for every data set since the points are added in order of the sets in + // datasets. + this.setPointsLengths = new Array(); + for (var setName in this.datasets) { if (!this.datasets.hasOwnProperty(setName)) continue; var dataset = this.datasets[setName]; var axis = this.dygraph_.axisPropertiesForSeries(setName); - var graphWidth = this.dygraph_.width_; - var graphHeight = this.dygraph_.height_; - var prevXPx = NaN; - var prevYPx = NaN; - var currXPx = NaN; - var currYPx = NaN; - - // Ignore the pixel skipping optimization if there are error bars. - var skip_opt = (this.attr_("errorBars") || - this.attr_("customBars") || - this.annotations.length > 0); + var setPointsLength = 0; for (var j = 0; j < dataset.length; j++) { var item = dataset[j]; 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); - } - - // Current pixel coordinates that the data point would fill. - currXPx = Math.round(xNormal * graphWidth); - currYPx = Math.round(yNormal * graphHeight); - - // Skip over pushing points that lie on the same pixel. - // TODO(antrob): optimize this for graphs with error bars. - if (skip_opt || prevXPx != currXPx || prevYPx != currYPx) { - var point = { - // TODO(danvk): here - x: xNormal, - y: yNormal, - xval: xValue, - yval: yValue, - name: setName - }; - this.points.push(point); - } - prevXPx = currXPx; - prevYPx = currYPx; + 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, + y: yNormal, + xval: xValue, + yval: yValue, + name: setName + }; + this.points.push(point); + setPointsLength += 1; } + this.setPointsLengths.push(setPointsLength); } }; @@ -225,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]); @@ -232,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); } } }