From 0f20de1c01823dd14dadff582c264a05605ee67b Mon Sep 17 00:00:00 2001 From: Dan Vanderkam Date: Wed, 18 Jul 2012 10:01:02 -0500 Subject: [PATCH 1/1] faster, a few tests failing --- dygraph-canvas.js | 54 +++++++++++++++++++++++++++++++++++++++--------------- dygraph-utils.js | 1 + phantom-driver.js | 2 +- 3 files changed, 41 insertions(+), 16 deletions(-) diff --git a/dygraph-canvas.js b/dygraph-canvas.js index 3d4b880..887c6ff 100644 --- a/dygraph-canvas.js +++ b/dygraph-canvas.js @@ -235,10 +235,12 @@ DygraphCanvasRenderer._getIteratorPredicate = function(connectSeparatedPoints) { return connectSeparatedPoints ? DygraphCanvasRenderer._predicateThatSkipsEmptyPoints : null; -} +}; DygraphCanvasRenderer._predicateThatSkipsEmptyPoints = - function(array, idx) { return array[idx].yval !== null; } + function(array, idx) { + return array[idx].yval !== null; +}; /** * @@ -304,8 +306,16 @@ DygraphCanvasRenderer.prototype._drawSeries = function( ctx.strokeStyle = color; ctx.lineWidth = strokeWidth; - while (iter.hasNext) { - point = iter.next(); + for (var i = iter.start_; i < iter.end_; i++) { + // while (iter.hasNext) { + point = iter.array_[i]; + if (iter.predicate_) { + while (i < iter.end_ && !iter.predicate_(iter.array_, i)) { + i++; + } + if (i == iter.end_) break; + } + if (point.canvasy === null || point.canvasy != point.canvasy) { if (stepPlot && prevCanvasX !== null) { // Draw a horizontal line to the start of the missing data @@ -314,19 +324,33 @@ DygraphCanvasRenderer.prototype._drawSeries = function( } prevCanvasX = prevCanvasY = null; } else { - nextCanvasY = iter.hasNext ? iter.peek.canvasy : null; - // TODO: we calculate isNullOrNaN for this point, and the next, and then, - // when we iterate, test for isNullOrNaN again. Why bother? - var isNextCanvasYNullOrNaN = nextCanvasY === null || nextCanvasY != nextCanvasY; - isIsolated = (!prevCanvasX && isNextCanvasYNullOrNaN); - if (drawGapPoints) { - // Also consider a point to be "isolated" if it's adjacent to a - // null point, excluding the graph edges. - if ((!first && !prevCanvasX) || - (iter.hasNext && isNextCanvasYNullOrNaN)) { - isIsolated = true; + isIsolated = false; + if (drawGapPoints || !prevCanvasX) { + // nextCanvasY = iter.hasNext ? iter.peek.canvasy : null; + // var next_i = i + 1; + // while (next_i < iter.end_ && (!iter.predicate_ || !iter.predicate_(iter.array_, next_i))) { + // next_i++; + // } + iter.nextIdx_ = i; + var peek = iter.next(); + nextCanvasY = peek ? peek.canvasy : null; + // nextCanvasY = next_i < iter.end_ ? iter.array_[next_i].canvasy : null; + + // TODO: we calculate isNullOrNaN for this point, and the next, and then, + // when we iterate, test for isNullOrNaN again. Why bother? + var isNextCanvasYNullOrNaN = nextCanvasY === null || + nextCanvasY != nextCanvasY; + isIsolated = (!prevCanvasX && isNextCanvasYNullOrNaN); + if (drawGapPoints) { + // Also consider a point to be "isolated" if it's adjacent to a + // null point, excluding the graph edges. + if ((!first && !prevCanvasX) || + (iter.hasNext && isNextCanvasYNullOrNaN)) { + isIsolated = true; + } } } + if (prevCanvasX !== null) { if (strokeWidth) { if (stepPlot) { diff --git a/dygraph-utils.js b/dygraph-utils.js index 7aeca8d..d3a31d5 100644 --- a/dygraph-utils.js +++ b/dygraph-utils.js @@ -686,6 +686,7 @@ Dygraph.Iterator = function(array, start, length, predicate) { length = length || array.length; this.hasNext = true; // Use to identify if there's another element. this.peek = null; // Use for look-ahead + this.start_ = start; this.array_ = array; this.predicate_ = predicate; this.end_ = Math.min(array.length, start + length); diff --git a/phantom-driver.js b/phantom-driver.js index 009c634..6e4c18e 100644 --- a/phantom-driver.js +++ b/phantom-driver.js @@ -80,7 +80,7 @@ page.open(url, function(status) { for (var test in caseResults) { if (caseResults[test] !== true) { num_failing++; - failures.push(testCase + '.' + test + ' failed'); + failures.push(testCase + '.' + test); } else { // console.log(testCase + '.' + test + ' passed'); num_passing++; -- 2.7.4