From 873d3d7c4a611a964a64a56fc51076bc49d57841 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Fri, 14 Nov 2014 09:33:03 +0100 Subject: [PATCH] SinglestatPanel: Added integration with drilldown link feature, if a drilldown link is present the entire singlestat panel will act as a link, with hover tooltip containing the link name, #951, #1041 --- src/app/directives/panelMenu.js | 3 +- src/app/panels/singlestat/module.js | 1 + src/app/panels/singlestat/singleStatPanel.js | 33 ++++++++++++++++++-- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/app/directives/panelMenu.js b/src/app/directives/panelMenu.js index 892062b9bd5..a4eb3bd210d 100644 --- a/src/app/directives/panelMenu.js +++ b/src/app/directives/panelMenu.js @@ -68,7 +68,8 @@ function (angular, $, _) { elem.append($link); $scope.$watchCollection('panel.links', function(newValue) { - $link.toggleClass('has-panel-links', newValue ? newValue.length > 0 : false); + var showIcon = (newValue ? newValue.length > 0 : false) && $scope.panel.title !== ''; + $link.toggleClass('has-panel-links', showIcon); }); function dismiss(time) { diff --git a/src/app/panels/singlestat/module.js b/src/app/panels/singlestat/module.js index e5297b30069..c17b5afea38 100644 --- a/src/app/panels/singlestat/module.js +++ b/src/app/panels/singlestat/module.js @@ -27,6 +27,7 @@ function (angular, app, _, TimeSeries, kbn, PanelMeta) { // Set and populate defaults var _d = { + links: [], maxDataPoints: 100, interval: null, targets: [{}], diff --git a/src/app/panels/singlestat/singleStatPanel.js b/src/app/panels/singlestat/singleStatPanel.js index 2c9f8b2613b..ccfd3ad8045 100644 --- a/src/app/panels/singlestat/singleStatPanel.js +++ b/src/app/panels/singlestat/singleStatPanel.js @@ -11,7 +11,7 @@ function (angular, app, _, $) { var module = angular.module('grafana.panels.singlestat', []); app.useModule(module); - module.directive('singlestatPanel', function() { + module.directive('singlestatPanel', function($location, linkSrv, $timeout) { return { link: function(scope, elem) { @@ -100,7 +100,7 @@ function (angular, app, _, $) { plotCss.bottom = "0px"; plotCss.left = "-5px"; plotCss.width = (width - 10) + 'px'; - plotCss.height = Math.floor(height * 0.3) + "px"; + plotCss.height = Math.floor(height * 0.25) + "px"; } plotCanvas.css(plotCss); @@ -167,7 +167,36 @@ function (angular, app, _, $) { if (panel.sparkline.show) { addSparkline(); } + + elem.toggleClass('pointer', panel.links.length > 0); } + + // drilldown link tooltip + var drilldownTooltip = $('
gello
"'); + + elem.mouseleave(function() { + if (panel.links.length === 0) { return;} + drilldownTooltip.detach(); + }); + + elem.click(function() { + if (panel.links.length === 0) { return; } + + var linkInfo = linkSrv.getPanelLinkAnchorInfo(panel.links[0]); + if (linkInfo.href[0] === '#') { linkInfo.href = linkInfo.href.substring(1); } + + $timeout(function() { $location.path(linkInfo.href); }); + + drilldownTooltip.detach(); + }); + + elem.mousemove(function(e) { + if (panel.links.length === 0) { return;} + + drilldownTooltip.text('click to go to: ' + panel.links[0].title); + + drilldownTooltip.place_tt(e.clientX+20, e.clientY-15); + }); } }; });