Skip to content

Commit

Permalink
Merge pull request apache#4 in DATA-PLATFORM/caravel from annotation-…
Browse files Browse the repository at this point in the history
…stacked to dev

* commit 'fb8eafb73f4099b5eccd8e642f9a34e6eb1cadbc':
  Fix annotatinos for stacked bar chart
  • Loading branch information
the-dcruz committed Oct 20, 2016
2 parents 37ad1b2 + fb8eafb commit a0e47a0
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions caravel/assets/visualizations/nvd3_vis.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

Expand Down

0 comments on commit a0e47a0

Please sign in to comment.