From: Robert Konigsberg Date: Wed, 13 Jun 2012 21:27:18 +0000 (-0400) Subject: connectSeparatedPoints is working. This has also improved X-Git-Tag: v1.0.0~238^2^2~23 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=dc2e4ba6e9ba661563f1c42a64cc5be1db362e74;p=dygraphs.git connectSeparatedPoints is working. This has also improved tests/independent-series.html, which was broken with the performance enhancement, but that's still broken. --- diff --git a/auto_tests/tests/simple_drawing.js b/auto_tests/tests/simple_drawing.js index 544bb81..6bafa0d 100644 --- a/auto_tests/tests/simple_drawing.js +++ b/auto_tests/tests/simple_drawing.js @@ -115,6 +115,7 @@ SimpleDrawingTestCase.prototype.testSeparatedPointsDontDraw_expanded = function( [4, 14]], { colors: ['blue']}); var htx = g.hidden_ctx_; + /* var num_lines = 0; var lines = CanvasAssertions.getLinesDrawn(htx); for (var idx = 0; idx < lines.length; idx++) { @@ -124,10 +125,41 @@ SimpleDrawingTestCase.prototype.testSeparatedPointsDontDraw_expanded = function( console.log(line[0].args, line[1].args, color); } } + */ assertEquals(2, CanvasAssertions.numLinesDrawn(htx, '#0000ff')); + CanvasAssertions.assertLineDrawn(htx, [56, 275], [161, 212], + { strokeStyle: '#0000ff', }); CanvasAssertions.assertLineDrawn(htx, [370, 87], [475, 25], { strokeStyle: '#0000ff', }); +} + +SimpleDrawingTestCase.prototype.testSeparatedPointsDontDraw_expanded_connected = function() { + var graph = document.getElementById("graph"); + var g = new Dygraph( + graph, + [[0, 10], + [1, 11], + [2, null], + [3, 13], + [4, 14]], + { colors: ['blue'], connectSeparatedPoints: true}); + var htx = g.hidden_ctx_; + var num_lines = 0; + var lines = CanvasAssertions.getLinesDrawn(htx); + for (var idx = 0; idx < lines.length; idx++) { + var line = lines[idx]; + var color = line[1].properties.strokeStyle; + if (color === "#ff0000" || color === "#0000ff") { + console.log(line[0].args, line[1].args, color); + } + } + + assertEquals(3, CanvasAssertions.numLinesDrawn(htx, '#0000ff')); CanvasAssertions.assertLineDrawn(htx, [56, 275], [161, 212], { strokeStyle: '#0000ff', }); + CanvasAssertions.assertLineDrawn(htx, [161, 212], [370, 87], + { strokeStyle: '#0000ff', }); + CanvasAssertions.assertLineDrawn(htx, [370, 87], [475, 25], + { strokeStyle: '#0000ff', }); } diff --git a/dygraph-canvas.js b/dygraph-canvas.js index 3f1b17b..aff9002 100644 --- a/dygraph-canvas.js +++ b/dygraph-canvas.js @@ -685,7 +685,7 @@ DygraphCanvasRenderer.prototype._renderAnnotations = function() { * * @private */ -DygraphCanvasRenderer.makeNextPointStep_ = function( +DygraphCanvasRenderer.makePointIteratorFunction_ = function( connectSeparatedPoints, points, start, end) { if (connectSeparatedPoints) { return function(j) { @@ -732,13 +732,13 @@ DygraphCanvasRenderer.prototype._drawNonTrivialLine = function( var nextY = null; var point, nextPoint; var pointsOnLine = []; // Array of [canvasx, canvasy] pairs. - var next = DygraphCanvasRenderer.makeNextPointStep_( + var nextFunc = DygraphCanvasRenderer.makePointIteratorFunction_( this.attr_('connectSeparatedPoints'), points, firstIndexInSet, firstIndexInSet + setLength); - for (var j = 0; j < setLength; j = next(j)) { + for (var j = 0; j < setLength; j = nextFunc(j)) { point = points[firstIndexInSet + j]; - nextY = (next(j) < setLength) ? - points[firstIndexInSet + next(j)].canvasy : null; + nextY = (nextFunc(j) < setLength) ? + points[firstIndexInSet + nextFunc(j)].canvasy : null; if (DygraphCanvasRenderer.isNullOrNaN_(point.canvasy)) { if (stepPlot && prevX !== null) { // Draw a horizontal line to the start of the missing data @@ -758,7 +758,7 @@ DygraphCanvasRenderer.prototype._drawNonTrivialLine = function( // Also consider a point to be is "isolated" if it's adjacent to a // null point, excluding the graph edges. if ((j > 0 && !prevX) || - (next(j) < setLength && DygraphCanvasRenderer.isNullOrNaN_(nextY))) { + (nextFunc(j) < setLength && DygraphCanvasRenderer.isNullOrNaN_(nextY))) { isIsolated = true; } } @@ -812,9 +812,13 @@ DygraphCanvasRenderer.prototype._drawTrivialLine = function( ctx.beginPath(); ctx.strokeStyle = color; ctx.lineWidth = strokeWidth; - for (var j = firstIndexInSet; j < firstIndexInSet + setLength; ++j) { + var nextFunc = DygraphCanvasRenderer.makePointIteratorFunction_( + this.attr_('connectSeparatedPoints'), points, firstIndexInSet, + firstIndexInSet + setLength); + for (var j = firstIndexInSet; j < firstIndexInSet + setLength; j = nextFunc(j)) { + var nextJ = nextFunc(j); var point = points[j]; - nextY = (j + 1 < firstIndexInSet + setLength) ? points[j + 1].canvasy : null; + nextY = (nextJ < firstIndexInSet + setLength) ? points[nextJ].canvasy : null; if (DygraphCanvasRenderer.isNullOrNaN_(point.canvasy)) { prevX = prevY = null; } else { @@ -823,7 +827,7 @@ DygraphCanvasRenderer.prototype._drawTrivialLine = function( // Also consider a point to be is "isolated" if it's adjacent to a // null point, excluding the graph edges. if ((j > firstIndexInSet && !prevX) || - ((j + 1 < firstIndexInSet + setLength) && DygraphCanvasRenderer.isNullOrNaN_(nextY))) { + ((nextJ < firstIndexInSet + setLength) && DygraphCanvasRenderer.isNullOrNaN_(nextY))) { isIsolated = true; } } @@ -932,7 +936,7 @@ DygraphCanvasRenderer.prototype._renderLineChart = function() { var setLength = this.layout.setPointsLengths[i]; var afterLastIndexInSet = firstIndexInSet + setLength; - var next = DygraphCanvasRenderer.makeNextPointStep_( + var nextFunc = DygraphCanvasRenderer.makePointIteratorFunction_( this.attr_('connectSeparatedPoints'), points, afterLastIndexInSet); @@ -947,7 +951,7 @@ DygraphCanvasRenderer.prototype._renderLineChart = function() { fillAlpha + ')'; ctx.fillStyle = err_color; ctx.beginPath(); - for (j = firstIndexInSet; j < afterLastIndexInSet; j = next(j)) { + for (j = firstIndexInSet; j < afterLastIndexInSet; j = nextFunc(j)) { point = points[j]; if (point.name == setName) { // TODO(klausw): this is always true if (!Dygraph.isOK(point.y)) { @@ -1004,7 +1008,7 @@ DygraphCanvasRenderer.prototype._renderLineChart = function() { var setLength = this.layout.setPointsLengths[i]; var afterLastIndexInSet = firstIndexInSet + setLength; - var next = DygraphCanvasRenderer.makeNextPointStep_( + var nextFunc = DygraphCanvasRenderer.makePointIteratorFunction_( this.attr_('connectSeparatedPoints'), points, afterLastIndexInSet); @@ -1018,7 +1022,7 @@ DygraphCanvasRenderer.prototype._renderLineChart = function() { fillAlpha + ')'; ctx.fillStyle = err_color; ctx.beginPath(); - for (j = firstIndexInSet; j < afterLastIndexInSet; j = next(j)) { + for (j = firstIndexInSet; j < afterLastIndexInSet; j = nextFunc(j)) { point = points[j]; if (point.name == setName) { // TODO(klausw): this is always true if (!Dygraph.isOK(point.y)) {