Skip to content

Commit

Permalink
Fix for #301: now it will display point only for the first min value,…
Browse files Browse the repository at this point in the history
… the last max value, and the current value.
  • Loading branch information
Ricardo committed Nov 2, 2012
1 parent 819f71c commit b9d8000
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
19 changes: 14 additions & 5 deletions nv.d3.js
Expand Up @@ -9484,11 +9484,20 @@ nv.models.sparkline = function() {
// TODO: Add CURRENT data point (Need Min, Mac, Current / Most recent)
var points = wrap.selectAll('circle.nv-point')
.data(function(data) {
return data.map(function(d,i) {
if (y.domain().indexOf(getY(d,i)) != -1 || getX(d,i) == x.domain()[1]) d.pointIndex = i;
return d;
})
.filter(function(d) { return typeof d.pointIndex != 'undefined' })
var yValues = data.map(function(d, i) { return getY(d,i); });
function pointIndex(index) {
if (index != -1) {
var result = data[index];
result.pointIndex = index;
return result;
} else {
return null;
}
}
var maxPoint = pointIndex(yValues.lastIndexOf(y.domain()[1])),
minPoint = pointIndex(yValues.indexOf(y.domain()[0])),
currentPoint = pointIndex(yValues.length - 1);
return [minPoint, maxPoint, currentPoint].filter(function (d) {return d != null;});
});
points.enter().append('circle');
points.exit().remove();
Expand Down

0 comments on commit b9d8000

Please sign in to comment.