Skip to content

Commit

Permalink
Merge pull request #692 from musicist288/zero-coordinate-bugs
Browse files Browse the repository at this point in the history
Allow selected points where canvas-y coordinate is 0
  • Loading branch information
danvk committed Nov 16, 2015
2 parents 34b957e + 0b90566 commit dd74404
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 2 deletions.
25 changes: 25 additions & 0 deletions auto_tests/tests/highlight_series_background.js
Expand Up @@ -122,4 +122,29 @@ describe("highlight-series-background", function() {
done();
}, 500);
});

it('testGetSelectionZeroCanvasY', function () {
var graph = document.getElementById("graph");
var calls = []
function callback(g, seriesName, canvasContext, cx, cy, color, pointSize, idx) {
calls.push(arguments);
};

var g = new Dygraph(document.getElementById("graph"),
"X,Y\n" +
"1,5\n" +
"1,10\n" +
"1,12\n",
{
drawHighlightPointCallback: callback,
axes: {
y: {
valueRange: [0, 10]
}
}
});
g.setSelection(1);
var args = calls[0];
assert.equal(args[4], 0);
});
});
26 changes: 26 additions & 0 deletions auto_tests/tests/plugins_legend.js
Expand Up @@ -113,4 +113,30 @@ it('should use a legendFormatter', function() {
assert.equal(calls[2].series[0].y, undefined);
});

it('should include point drawn where canvas-y is 0', function () {
var graph = document.getElementById("graph");
var calls = []
function callback(data) {
calls.push(data);
};

var g = new Dygraph(document.getElementById("graph"),
"X,Y\n" +
"1,5\n" +
"1,10\n" +
"1,12\n",
{
legendFormatter: callback,
axes: {
y: {
valueRange: [0, 10]
}
}
});
g.setSelection(1);
var data = calls[1];
assert.isTrue(data.series[0].isVisible);
assert.notEqual(data.series[0].yHTML, '');
});

});
2 changes: 1 addition & 1 deletion src/dygraph.js
Expand Up @@ -1815,7 +1815,7 @@ Dygraph.prototype.updateSelection_ = function(opt_animFraction) {
ctx.save();
for (i = 0; i < this.selPoints_.length; i++) {
var pt = this.selPoints_[i];
if (!utils.isOK(pt.canvasy)) continue;
if (isNaN(pt.canvasy)) continue;

var circleSize = this.getNumericOption('highlightCircleSize', pt.name);
var callback = this.getFunctionOption("drawHighlightPointCallback", pt.name);
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/legend.js
Expand Up @@ -268,7 +268,7 @@ Legend.generateLegendHTML = function(g, x, sel_points, oneEmWidth, row) {
var seriesData = labelToSeries[pt.name];
seriesData.y = pt.yval;

if ((pt.yval === 0 && !showZeros) || !utils.isOK(pt.canvasy)) {
if ((pt.yval === 0 && !showZeros) || isNaN(pt.canvasy)) {
seriesData.isVisible = false;
continue;
}
Expand Down

0 comments on commit dd74404

Please sign in to comment.