浏览代码

feat(thresholds): hide threshold handles when second y axis is shown

Torkel Ödegaard 9 年之前
父节点
当前提交
7242dc2ebe
共有 2 个文件被更改,包括 17 次插入5 次删除
  1. 1 1
      public/app/plugins/panel/graph/graph.js
  2. 16 4
      public/app/plugins/panel/graph/threshold_manager.ts

+ 1 - 1
public/app/plugins/panel/graph/graph.js

@@ -177,7 +177,7 @@ function (angular, $, moment, _, kbn, GraphTooltip, thresholdManExports) {
           }
           }
 
 
           // give space to alert editing
           // give space to alert editing
-          thresholdManager.prepare(elem);
+          thresholdManager.prepare(elem, data);
 
 
           var stack = panel.stack ? true : null;
           var stack = panel.stack ? true : null;
 
 

+ 16 - 4
public/app/plugins/panel/graph/threshold_manager.ts

@@ -10,6 +10,7 @@ export class ThresholdManager {
   height: any;
   height: any;
   thresholds: any;
   thresholds: any;
   needsCleanup: boolean;
   needsCleanup: boolean;
+  hasSecondYAxis: any;
 
 
   constructor(private panelCtrl) {}
   constructor(private panelCtrl) {}
 
 
@@ -109,8 +110,20 @@ export class ThresholdManager {
     handleElem.css({top: handleTopPos});
     handleElem.css({top: handleTopPos});
   }
   }
 
 
-  prepare(elem) {
-    if (this.panelCtrl.editingThresholds) {
+  shouldDrawHandles() {
+    return !this.hasSecondYAxis && this.panelCtrl.editingThresholds && this.panelCtrl.panel.thresholds.length > 0;
+  }
+
+  prepare(elem, data) {
+    this.hasSecondYAxis = false;
+    for (var i = 0; i < data.length; i++) {
+      if (data[i].yaxis > 1) {
+        this.hasSecondYAxis = true;
+        break;
+      }
+    }
+
+    if (this.shouldDrawHandles()) {
       var thresholdMargin = this.panelCtrl.panel.thresholds.length > 1 ? '220px' : '110px';
       var thresholdMargin = this.panelCtrl.panel.thresholds.length > 1 ? '220px' : '110px';
       elem.css('margin-right', thresholdMargin);
       elem.css('margin-right', thresholdMargin);
     } else if (this.needsCleanup) {
     } else if (this.needsCleanup) {
@@ -127,8 +140,7 @@ export class ThresholdManager {
       this.cleanUp();
       this.cleanUp();
     }
     }
 
 
-    // if no thresholds or not editing alerts skip rendering handles
-    if (this.thresholds.length === 0 || !this.panelCtrl.editingThresholds) {
+    if (!this.shouldDrawHandles()) {
       return;
       return;
     }
     }