From fb8eafb73f4099b5eccd8e642f9a34e6eb1cadbc Mon Sep 17 00:00:00 2001 From: Daniel Cruz Date: Thu, 20 Oct 2016 13:12:16 -0700 Subject: [PATCH] Fix annotatinos for stacked bar chart --- caravel/assets/visualizations/nvd3_vis.js | 35 ++++++++++++----------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/caravel/assets/visualizations/nvd3_vis.js b/caravel/assets/visualizations/nvd3_vis.js index f0b2acd6b2c83..1cef68bf20e0a 100644 --- a/caravel/assets/visualizations/nvd3_vis.js +++ b/caravel/assets/visualizations/nvd3_vis.js @@ -299,25 +299,28 @@ function nvd3Vis(slice) { chart.stacked(stacked); if (fd.enable_annotations) { - const chartData = payload.data[0].values; - const latestDataDate = chartData[chartData.length - 1].x; - - const dateValues = {}; - chartData.forEach(function (barData) { - dateValues[barData.x] = true; - }); - let yMax = 0; - payload.annotations.forEach(function (annotation) { - const annotationTimestamp = annotation.timestamp; - if (!(annotationTimestamp in dateValues)) { - if (annotationTimestamp > latestDataDate) { - chartData.push({ x: annotationTimestamp, y: 0 }); + + payload.data.forEach(function (data) { + const chartData = data.values; + const latestDataDate = chartData[chartData.length - 1].x; + + const dateValues = {}; + chartData.forEach(function (barData) { + dateValues[barData.x] = true; + }); + + payload.annotations.forEach(function (annotation) { + const annotationTimestamp = annotation.timestamp; + if (!(annotationTimestamp in dateValues)) { + if (annotationTimestamp > latestDataDate) { + chartData.push({x: annotationTimestamp, y: 0}); + } } - } - yMax = yMax > annotation.value ? - yMax : annotation.value; + yMax = yMax > annotation.value ? + yMax : annotation.value; + }); }); chart.forceY([0, yMax]);