浏览代码

Do not render graph when width is zero, avoids plot errors

Torkel Ödegaard 11 年之前
父节点
当前提交
6ca73f6df0
共有 1 个文件被更改,包括 17 次插入9 次删除
  1. 17 9
      src/app/directives/grafanaGraph.js

+ 17 - 9
src/app/directives/grafanaGraph.js

@@ -15,7 +15,7 @@ function (angular, $, kbn, moment, _) {
       restrict: 'A',
       restrict: 'A',
       template: '<div> </div>',
       template: '<div> </div>',
       link: function(scope, elem) {
       link: function(scope, elem) {
-        var data, plot, annotations;
+        var data, annotations;
         var hiddenData = {};
         var hiddenData = {};
         var dashboard = scope.dashboard;
         var dashboard = scope.dashboard;
         var legendSideLastValue = null;
         var legendSideLastValue = null;
@@ -82,6 +82,10 @@ function (angular, $, kbn, moment, _) {
             render_panel_as_graphite_png(data);
             render_panel_as_graphite_png(data);
             return true;
             return true;
           }
           }
+
+          if (elem.width() === 0) {
+            return;
+          }
         }
         }
 
 
         // Function for rendering panel
         // Function for rendering panel
@@ -165,18 +169,22 @@ function (angular, $, kbn, moment, _) {
 
 
           var sortedSeries = _.sortBy(data, function(series) { return series.zindex; });
           var sortedSeries = _.sortBy(data, function(series) { return series.zindex; });
 
 
-          // if legend is to the right delay plot draw a few milliseconds
-          // so the legend width calculation can be done
+          function callPlot() {
+            try {
+              $.plot(elem, sortedSeries, options);
+            } catch (e) {
+              console.log('flotcharts error', e);
+            }
+
+            addAxisLabels();
+          }
+
           if (shouldDelayDraw(panel)) {
           if (shouldDelayDraw(panel)) {
+            setTimeout(callPlot, 50);
             legendSideLastValue = panel.legend.rightSide;
             legendSideLastValue = panel.legend.rightSide;
-            setTimeout(function() {
-              plot = $.plot(elem, sortedSeries, options);
-              addAxisLabels();
-            }, 50);
           }
           }
           else {
           else {
-            plot = $.plot(elem, sortedSeries, options);
-            addAxisLabels();
+            callPlot();
           }
           }
         }
         }