This is an automated email from the ASF dual-hosted git repository.

graceguo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git


The following commit(s) were added to refs/heads/master by this push:
     new 73f7f81  [Bug fix] Fixed/Refactored annotation layer code so that 
non-timeseries annotations are applied based on the updated chart object after 
adding all data (#4630)
73f7f81 is described below

commit 73f7f817d30f960f16611f01ac8daee52ad92830
Author: EvelynTurner <36863942+evelyntur...@users.noreply.github.com>
AuthorDate: Fri Mar 23 02:10:40 2018 -0400

    [Bug fix] Fixed/Refactored annotation layer code so that non-timeseries 
annotations are applied based on the updated chart object after adding all data 
(#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
---
 superset/assets/visualizations/nvd3_vis.js | 53 ++++++++++++++----------------
 1 file changed, 24 insertions(+), 29 deletions(-)

diff --git a/superset/assets/visualizations/nvd3_vis.js 
b/superset/assets/visualizations/nvd3_vis.js
index 7cfb1c3..9ce02bd 100644
--- a/superset/assets/visualizations/nvd3_vis.js
+++ b/superset/assets/visualizations/nvd3_vis.js
@@ -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)
@@ -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)
@@ -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 &&
@@ -674,7 +695,6 @@ function nvd3Vis(slice, payload) {
             }
           });
 
-
           // Interval annotations
           annotationLayers.filter(x => (
             x.annotationType === AnnotationTypes.INTERVAL &&
@@ -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;
   };

-- 
To stop receiving notification emails like this one, please contact
grace...@apache.org.

Reply via email to