Fixed bug in stackedAreaChart where the tooltip highlight lines would not show up for negative stacked charts.

master
Robin Hu 11 years ago
parent 168b9703c2
commit 4983f2c6df

@ -3,7 +3,7 @@
var nv = window.nv || {};
nv.version = '1.1.14b';
nv.version = '1.1.15b';
nv.dev = true //set false when in production
window.nv = nv;
@ -14086,7 +14086,13 @@ nv.models.stackedAreaChart = function() {
var yValue = chart.yScale().invert(e.mouseY);
var yDistMax = Infinity, indexToHighlight = null;
allData.forEach(function(series,i) {
if ( yValue >= series.stackedValue.y0 && yValue <= (series.stackedValue.y0 + series.stackedValue.y))
//To handle situation where the stacked area chart is negative, we need to use absolute values
//when checking if the mouse Y value is within the stack area.
yValue = Math.abs(yValue);
var stackedY0 = Math.abs(series.stackedValue.y0);
var stackedY = Math.abs(series.stackedValue.y);
if ( yValue >= stackedY0 && yValue <= (stackedY + stackedY0))
{
indexToHighlight = i;
return;

@ -2,7 +2,7 @@
var nv = window.nv || {};
nv.version = '1.1.14b';
nv.version = '1.1.15b';
nv.dev = true //set false when in production
window.nv = nv;

@ -376,7 +376,13 @@ nv.models.stackedAreaChart = function() {
var yValue = chart.yScale().invert(e.mouseY);
var yDistMax = Infinity, indexToHighlight = null;
allData.forEach(function(series,i) {
if ( yValue >= series.stackedValue.y0 && yValue <= (series.stackedValue.y0 + series.stackedValue.y))
//To handle situation where the stacked area chart is negative, we need to use absolute values
//when checking if the mouse Y value is within the stack area.
yValue = Math.abs(yValue);
var stackedY0 = Math.abs(series.stackedValue.y0);
var stackedY = Math.abs(series.stackedValue.y);
if ( yValue >= stackedY0 && yValue <= (stackedY + stackedY0))
{
indexToHighlight = i;
return;

@ -19,6 +19,7 @@
<div class='chart half' id='chart6'>Total random points<button>Select chart</button><svg></svg></div>
<div class='chart half' id='chart7'>Less than four points, old tooltips<button>Select chart</button><svg></svg></div>
<div class='chart half' id='chart8'>No data<svg></svg></div>
<div class='chart half' id='chart9'>Data is all negative<svg></svg></div>
<script src="../lib/d3.v3.js"></script>
<script src="../nv.d3.js"></script>
@ -317,4 +318,5 @@ defaultChartConfig("chart5", histcatexplong_withholes);
defaultChartConfig("chart6", totalRandom(), false);
defaultChartConfig("chart7", nPoints(),false);
defaultChartConfig("chart8", []);
defaultChartConfig("chart9", histcatexpshort,true);
</script>

Loading…
Cancel
Save