crude fix to broken y axis handling in sparklinesPlys

This commit is contained in:
Jyry Suvilehto 2012-07-26 12:26:31 +00:00
parent c09378e963
commit a25459d2e7

View File

@ -86,11 +86,22 @@ nv.models.sparklinePlus = function() {
.attr('transform', function(d) { return 'translate(' + (pos - 6) + ',' + (-margin.top) + ')' }) .attr('transform', function(d) { return 'translate(' + (pos - 6) + ',' + (-margin.top) + ')' })
//.text(xTickFormat(pos)); //.text(xTickFormat(pos));
.text(xTickFormat(Math.round(x.invert(pos)))); //TODO: refactor this line .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 hoverY
.attr('transform', function(d) { return 'translate(' + (pos + 6) + ',' + (-margin.top) + ')' }) .attr('transform', function(d) { return 'translate(' + (pos + 6) + ',' + (-margin.top) + ')' })
//.text(data[pos] && yTickFormat(data[pos].y)); //.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
} }
}); });