From 87161a6d5d19a3ebc206df4e941ad2a2c95cc77b Mon Sep 17 00:00:00 2001 From: Grace Guo Date: Fri, 26 Oct 2018 17:12:30 -0700 Subject: [PATCH] [fix] hide annotation layer (#6204) --- .../assets/src/visualizations/nvd3/NVD3Vis.js | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/superset/assets/src/visualizations/nvd3/NVD3Vis.js b/superset/assets/src/visualizations/nvd3/NVD3Vis.js index 90a90d315..a67c93fb7 100644 --- a/superset/assets/src/visualizations/nvd3/NVD3Vis.js +++ b/superset/assets/src/visualizations/nvd3/NVD3Vis.js @@ -226,6 +226,7 @@ function nvd3Vis(element, props) { const isExplore = document.querySelector('#explorer-container') !== null; const container = element; container.innerHTML = ''; + const activeAnnotationLayers = annotationLayers.filter(layer => layer.show); let chart; let width = maxWidth; @@ -642,10 +643,9 @@ function nvd3Vis(element, props) { chart.yAxis.axisLabel(yAxisLabel).axisLabelDistance(distance); } - if (isTimeSeries && annotationData && annotationLayers.length > 0) { + if (isTimeSeries && annotationData && activeAnnotationLayers.length > 0) { // Time series annotations add additional data - const timeSeriesAnnotations = annotationLayers - .filter(layer => layer.show) + const timeSeriesAnnotations = activeAnnotationLayers .filter(layer => layer.annotationType === ANNOTATION_TYPES.TIME_SERIES) .reduce((bushel, a) => bushel.concat((annotationData[a.name] || []).map((series) => { @@ -677,9 +677,9 @@ function nvd3Vis(element, props) { window.addEventListener('scroll', throttle(hideTooltips, 250)); // The below code should be run AFTER rendering because chart is updated in call() - if (isTimeSeries && annotationLayers.length > 0) { + if (isTimeSeries && activeAnnotationLayers.length > 0) { // Formula annotations - const formulas = annotationLayers + const formulas = activeAnnotationLayers .filter(a => a.annotationType === ANNOTATION_TYPES.FORMULA) .map(a => ({ ...a, formula: mathjs.parse(a.value) })); @@ -749,10 +749,11 @@ function nvd3Vis(element, props) { if (annotationData) { // Event annotations - annotationLayers.filter(x => ( - x.annotationType === ANNOTATION_TYPES.EVENT && - annotationData && annotationData[x.name] - )).forEach((config, index) => { + activeAnnotationLayers + .filter(x => ( + x.annotationType === ANNOTATION_TYPES.EVENT && + annotationData && annotationData[x.name] + )).forEach((config, index) => { const e = applyNativeColumns(config); // Add event annotation layer const annotations = d3.select(element) @@ -808,10 +809,11 @@ function nvd3Vis(element, props) { }); // Interval annotations - annotationLayers.filter(x => ( - x.annotationType === ANNOTATION_TYPES.INTERVAL && - annotationData && annotationData[x.name] - )).forEach((config, index) => { + activeAnnotationLayers + .filter(x => ( + x.annotationType === ANNOTATION_TYPES.INTERVAL && + annotationData && annotationData[x.name] + )).forEach((config, index) => { const e = applyNativeColumns(config); // Add interval annotation layer const annotations = d3.select(element)