Merge remote-tracking branch 'Jyrsa/fixing'

This commit is contained in:
Bob Monteverde 2012-07-26 17:14:43 -04:00
commit eb1407a39a
2 changed files with 12 additions and 1 deletions

View File

@ -86,11 +86,22 @@ nv.models.sparklinePlus = function() {
.attr('transform', function(d) { return 'translate(' + (pos - 6) + ',' + (-margin.top) + ')' })
//.text(xTickFormat(pos));
.text(xTickFormat(Math.round(x.invert(pos)))); //TODO: refactor this line
var f = function(data, x){
var distance = Math.abs(getX(data[0]) - x) ;
var closestIndex = 0;
for (var i = 0; i < data.length; i++){
if (Math.abs(getX(data[i]) - x) < distance) {
distance = Math.abs(getX(data[i]) -x);
closestIndex = i;
}
}
return closestIndex;
}
hoverY
.attr('transform', function(d) { return 'translate(' + (pos + 6) + ',' + (-margin.top) + ')' })
//.text(data[pos] && yTickFormat(data[pos].y));
.text(yTickFormat(getY(data[Math.round(x.invert(pos))]))); //TODO: refactor this line
.text(yTickFormat(getY(data[f(data, Math.round(x.invert(pos)))]))); //TODO: refactor this line
}
});