Browse Source

add series override option to hide tooltip (#12378)

* add series override option to hide tooltip

* fix test

* invert option

* fix test

* remove initialization
Mitsuhiro Tanda 7 years ago
parent
commit
04fcd2a054

+ 4 - 0
public/app/core/time_series2.ts

@@ -76,6 +76,7 @@ export default class TimeSeries {
   valueFormater: any;
   valueFormater: any;
   stats: any;
   stats: any;
   legend: boolean;
   legend: boolean;
+  hideTooltip: boolean;
   allIsNull: boolean;
   allIsNull: boolean;
   allIsZero: boolean;
   allIsZero: boolean;
   decimals: number;
   decimals: number;
@@ -181,6 +182,9 @@ export default class TimeSeries {
       if (override.legend !== void 0) {
       if (override.legend !== void 0) {
         this.legend = override.legend;
         this.legend = override.legend;
       }
       }
+      if (override.hideTooltip !== void 0) {
+        this.hideTooltip = override.hideTooltip;
+      }
 
 
       if (override.yaxis !== void 0) {
       if (override.yaxis !== void 0) {
         this.yaxis = override.yaxis;
         this.yaxis = override.yaxis;

+ 5 - 0
public/app/plugins/panel/graph/graph_tooltip.ts

@@ -81,6 +81,11 @@ export default function GraphTooltip(elem, dashboard, scope, getSeriesFn) {
         continue;
         continue;
       }
       }
 
 
+      if (series.hideTooltip) {
+        results[0].push({ hidden: true, value: 0 });
+        continue;
+      }
+
       hoverIndex = this.findHoverIndexFromData(pos.x, series);
       hoverIndex = this.findHoverIndexFromData(pos.x, series);
       hoverDistance = pos.x - series.data[hoverIndex][0];
       hoverDistance = pos.x - series.data[hoverIndex][0];
       pointTime = series.data[hoverIndex][0];
       pointTime = series.data[hoverIndex][0];

+ 1 - 0
public/app/plugins/panel/graph/series_overrides_ctrl.ts

@@ -152,6 +152,7 @@ export function SeriesOverridesCtrl($scope, $element, popoverSrv) {
   $scope.addOverrideOption('Z-index', 'zindex', [-3, -2, -1, 0, 1, 2, 3]);
   $scope.addOverrideOption('Z-index', 'zindex', [-3, -2, -1, 0, 1, 2, 3]);
   $scope.addOverrideOption('Transform', 'transform', ['negative-Y']);
   $scope.addOverrideOption('Transform', 'transform', ['negative-Y']);
   $scope.addOverrideOption('Legend', 'legend', [true, false]);
   $scope.addOverrideOption('Legend', 'legend', [true, false]);
+  $scope.addOverrideOption('Hide in tooltip', 'hideTooltip', [true, false]);
   $scope.updateCurrentOverrides();
   $scope.updateCurrentOverrides();
 }
 }
 
 

+ 10 - 1
public/app/plugins/panel/graph/specs/graph_tooltip.jest.ts

@@ -68,7 +68,10 @@ describe('findHoverIndexFromData', function() {
 
 
 describeSharedTooltip('steppedLine false, stack false', function(ctx) {
 describeSharedTooltip('steppedLine false, stack false', function(ctx) {
   ctx.setup(function() {
   ctx.setup(function() {
-    ctx.data = [{ data: [[10, 15], [12, 20]], lines: {} }, { data: [[10, 2], [12, 3]], lines: {} }];
+    ctx.data = [
+      { data: [[10, 15], [12, 20]], lines: {}, hideTooltip: false },
+      { data: [[10, 2], [12, 3]], lines: {}, hideTooltip: false },
+    ];
     ctx.pos = { x: 11 };
     ctx.pos = { x: 11 };
   });
   });
 
 
@@ -105,6 +108,7 @@ describeSharedTooltip('steppedLine false, stack true, individual false', functio
           points: [[10, 15], [12, 20]],
           points: [[10, 15], [12, 20]],
         },
         },
         stack: true,
         stack: true,
+        hideTooltip: false,
       },
       },
       {
       {
         data: [[10, 2], [12, 3]],
         data: [[10, 2], [12, 3]],
@@ -114,6 +118,7 @@ describeSharedTooltip('steppedLine false, stack true, individual false', functio
           points: [[10, 2], [12, 3]],
           points: [[10, 2], [12, 3]],
         },
         },
         stack: true,
         stack: true,
+        hideTooltip: false,
       },
       },
     ];
     ];
     ctx.ctrl.panel.stack = true;
     ctx.ctrl.panel.stack = true;
@@ -136,6 +141,7 @@ describeSharedTooltip('steppedLine false, stack true, individual false, series s
           points: [[10, 15], [12, 20]],
           points: [[10, 15], [12, 20]],
         },
         },
         stack: true,
         stack: true,
+        hideTooltip: false,
       },
       },
       {
       {
         data: [[10, 2], [12, 3]],
         data: [[10, 2], [12, 3]],
@@ -145,6 +151,7 @@ describeSharedTooltip('steppedLine false, stack true, individual false, series s
           points: [[10, 2], [12, 3]],
           points: [[10, 2], [12, 3]],
         },
         },
         stack: false,
         stack: false,
+        hideTooltip: false,
       },
       },
     ];
     ];
     ctx.ctrl.panel.stack = true;
     ctx.ctrl.panel.stack = true;
@@ -167,6 +174,7 @@ describeSharedTooltip('steppedLine false, stack true, individual true', function
           points: [[10, 15], [12, 20]],
           points: [[10, 15], [12, 20]],
         },
         },
         stack: true,
         stack: true,
+        hideTooltip: false,
       },
       },
       {
       {
         data: [[10, 2], [12, 3]],
         data: [[10, 2], [12, 3]],
@@ -176,6 +184,7 @@ describeSharedTooltip('steppedLine false, stack true, individual true', function
           points: [[10, 2], [12, 3]],
           points: [[10, 2], [12, 3]],
         },
         },
         stack: false,
         stack: false,
+        hideTooltip: false,
       },
       },
     ];
     ];
     ctx.ctrl.panel.stack = true;
     ctx.ctrl.panel.stack = true;