Explorar o código

graph(create annotation): refactor, fix two modal after range selection

bind create annotation handler directly to plotclick event, not to global graph-click
Alexander Zobnin %!s(int64=8) %!d(string=hai) anos
pai
achega
8a1c35e1c2
Modificáronse 1 ficheiros con 14 adicións e 16 borrados
  1. 14 16
      public/app/plugins/panel/graph/graph.ts

+ 14 - 16
public/app/plugins/panel/graph/graph.ts

@@ -79,22 +79,6 @@ coreModule.directive('grafanaGraph', function($rootScope, timeSrv) {
         }
         }
       }, scope);
       }, scope);
 
 
-      appEvents.on('graph-click', (event) => {
-        // Add event only for selected panel
-        let thisPanelEvent = event.panel.id === ctrl.panel.id;
-
-        // Select time for new annotation
-        let createAnnotation = event.pos.ctrlKey || event.pos.metaKey;
-        if (createAnnotation && thisPanelEvent) {
-          let timeRange = {
-            from: event.pos.x,
-            to: null
-          };
-
-          ctrl.showAddAnnotationModal(timeRange);
-        }
-      }, scope);
-
       function getLegendHeight(panelHeight) {
       function getLegendHeight(panelHeight) {
         if (!panel.legend.show || panel.legend.rightSide) {
         if (!panel.legend.show || panel.legend.rightSide) {
           return 0;
           return 0;
@@ -670,6 +654,20 @@ coreModule.directive('grafanaGraph', function($rootScope, timeSrv) {
         }
         }
       });
       });
 
 
+      elem.bind("plotclick", function (event, pos, item) {
+        // Skip if range selected (added in "plotselected" event handler)
+        let isRangeSelection = pos.x !== pos.x1;
+        let createAnnotation = !isRangeSelection && (pos.ctrlKey || pos.metaKey);
+        if (createAnnotation) {
+          let timeRange = {
+            from: pos.x,
+            to: null
+          };
+
+          ctrl.showAddAnnotationModal(timeRange);
+        }
+      });
+
       scope.$on('$destroy', function() {
       scope.$on('$destroy', function() {
         tooltip.destroy();
         tooltip.destroy();
         elem.off();
         elem.off();