X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;ds=sidebyside;f=dygraph-layout.js;h=28f1f285f0ed5fb307838b19050438a7f10b9651;hb=947ab5a6dd8278d85ff74e42151797cf8b9dbaf4;hp=266e3d0e0a5312105ac79579c7c78c2b581e4abf;hpb=4ab8db0c00008f89d9b9eb3247d7e933965ce9d5;p=dygraphs.git diff --git a/dygraph-layout.js b/dygraph-layout.js index 266e3d0..28f1f28 100644 --- a/dygraph-layout.js +++ b/dygraph-layout.js @@ -129,26 +129,25 @@ DygraphLayout.prototype._evaluateLimits = function() { 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; - - var errorBars = this.attr_("errorBars") || this.attr_("customBars"); + 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. @@ -158,30 +157,18 @@ DygraphLayout.prototype._evaluateLineCharts = function() { } 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. - // Ignore this optimization if there are error bars. - // TODO(antrob): optimize this for graphs with error bars. - if (prevXPx != currXPx || prevYPx != currYPx || errorBars) { - // TODO(antrob): skip over points that lie on a line that is already going to be drawn. - // There is no need to have more than 2 consecutive points that are collinear. - var point = { - // TODO(danvk): here - x: xNormal, - y: yNormal, - xval: xValue, - yval: yValue, - name: setName - }; - this.points.push(point); - } - prevXPx = currXPx; - prevYPx = currYPx; + 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); } };