Skip to content

Commit

Permalink
[Bug fix] Fixed/Refactored annotation layer code so that non-timeseri…
Browse files Browse the repository at this point in the history
…es annotations are applied based on the updated chart object after adding all data (apache#4630)

* Fix how the annotation layer interpretes the timestamp string without timezone info; use it as UTC

* [Bug fix] Fixed/Refactored annotation layer code so that non-timeseries annotations are applied based on the updated chart object after adding all data

* [Bug fix] Fixed/Refactored annotation layer code so that non-timeseries annotations are applied based on the updated chart object after adding all data

* Fixed indentation
  • Loading branch information
EvelynTurner authored and michellethomas committed May 23, 2018
1 parent d679905 commit 8b2563f
Showing 1 changed file with 24 additions and 29 deletions.
53 changes: 24 additions & 29 deletions superset/assets/visualizations/nvd3_vis.js
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,28 @@ function nvd3Vis(slice, payload) {
chart.yAxis.axisLabel(fd.y_axis_label).axisLabelDistance(distance);
}

const annotationLayers = (slice.formData.annotation_layers || []).filter(x => x.show);
if (isTimeSeries && annotationLayers && slice.annotationData) {
// Time series annotations add additional data
const timeSeriesAnnotations = annotationLayers
.filter(a => a.annotationType === AnnotationTypes.TIME_SERIES).reduce((bushel, a) =>
bushel.concat((slice.annotationData[a.name] || []).map((series) => {
if (!series) {
return {};
}
const key = Array.isArray(series.key) ?
`${a.name}, ${series.key.join(', ')}` : a.name;
return {
...series,
key,
color: a.color,
strokeWidth: a.width,
classed: `${a.opacity} ${a.style}`,
};
})), []);
data.push(...timeSeriesAnnotations);
}

// render chart
svg
.datum(data)
Expand All @@ -544,8 +566,7 @@ function nvd3Vis(slice, payload) {
// on scroll, hide tooltips. throttle to only 4x/second.
$(window).scroll(throttle(hideTooltips, 250));

const annotationLayers = (slice.formData.annotation_layers || []).filter(x => x.show);

// The below code should be run AFTER rendering because chart is updated in call()
if (isTimeSeries && annotationLayers) {
// Formula annotations
const formulas = annotationLayers.filter(a => a.annotationType === AnnotationTypes.FORMULA)
Expand Down Expand Up @@ -620,7 +641,7 @@ function nvd3Vis(slice, payload) {
'<div>' + body.join(', ') + '</div>';
});

if (slice.annotationData && Object.keys(slice.annotationData).length) {
if (slice.annotationData) {
// Event annotations
annotationLayers.filter(x => (
x.annotationType === AnnotationTypes.EVENT &&
Expand Down Expand Up @@ -674,7 +695,6 @@ function nvd3Vis(slice, payload) {
}
});


// Interval annotations
annotationLayers.filter(x => (
x.annotationType === AnnotationTypes.INTERVAL &&
Expand Down Expand Up @@ -737,33 +757,8 @@ function nvd3Vis(slice, payload) {
.call(tip);
}
});

// Time series annotations
const timeSeriesAnnotations = annotationLayers
.filter(a => a.annotationType === AnnotationTypes.TIME_SERIES).reduce((bushel, a) =>
bushel.concat((slice.annotationData[a.name] || []).map((series) => {
if (!series) {
return {};
}
const key = Array.isArray(series.key) ?
`${a.name}, ${series.key.join(', ')}` : a.name;
return {
...series,
key,
color: a.color,
strokeWidth: a.width,
classed: `${a.opacity} ${a.style}`,
};
})), []);
data.push(...timeSeriesAnnotations);
}
}

// rerender chart
svg.datum(data)
.attr('height', height)
.attr('width', width)
.call(chart);
}
return chart;
};
Expand Down

0 comments on commit 8b2563f

Please sign in to comment.