From 4d3bac028415f5422d6d5255a92e848cb8bf10ff Mon Sep 17 00:00:00 2001 From: Dan Cech Date: Wed, 27 Dec 2017 22:29:19 -0500 Subject: [PATCH] tooltips for function definitions --- .../datasource/graphite/add_graphite_func.js | 52 ++++++++++++++++++- .../datasource/graphite/func_editor.js | 12 +++-- 2 files changed, 59 insertions(+), 5 deletions(-) diff --git a/public/app/plugins/datasource/graphite/add_graphite_func.js b/public/app/plugins/datasource/graphite/add_graphite_func.js index 97c34664ed7..c66176aeb8f 100644 --- a/public/app/plugins/datasource/graphite/add_graphite_func.js +++ b/public/app/plugins/datasource/graphite/add_graphite_func.js @@ -2,13 +2,15 @@ define([ 'angular', 'lodash', 'jquery', + 'rst2html', + 'tether-drop', ], -function (angular, _, $) { +function (angular, _, $, rst2html, Drop) { 'use strict'; angular .module('grafana.directives') - .directive('graphiteAddFunc', function($compile) { + .directive('graphiteAddFunc', function($compile) { var inputTemplate = ''; @@ -81,6 +83,52 @@ function (angular, _, $) { $compile(elem.contents())($scope); }); + + var drops = []; + + $(elem) + .on('mouseenter', 'ul.dropdown-menu li', function () { + while (drops.length > 0) { + drops.pop().remove(); + } + + var funcDef; + try { + funcDef = ctrl.datasource.getFuncDef($('a', this).text()); + } catch (e) { + // ignore + } + + if (funcDef && funcDef.description) { + var shortDesc = funcDef.description; + if (shortDesc.length > 500) { + shortDesc = shortDesc.substring(0, 497) + '...'; + } + + var contentElement = document.createElement('div'); + contentElement.innerHTML = '

' + funcDef.name + '

' + rst2html(shortDesc); + + var drop = new Drop({ + target: this, + content: contentElement, + classes: 'drop-popover', + openOn: 'always', + tetherOptions: { + attachment: 'bottom left', + targetAttachment: 'bottom right', + }, + }); + + drops.push(drop); + + drop.open(); + } + }) + .on('mouseout', 'ul.dropdown-menu li', function() { + while (drops.length > 0) { + drops.pop().remove(); + } + }); } }; }); diff --git a/public/app/plugins/datasource/graphite/func_editor.js b/public/app/plugins/datasource/graphite/func_editor.js index 08c11d6c5b7..764ac0ad22c 100644 --- a/public/app/plugins/datasource/graphite/func_editor.js +++ b/public/app/plugins/datasource/graphite/func_editor.js @@ -9,7 +9,7 @@ function (angular, _, $, rst2html) { angular .module('grafana.directives') - .directive('graphiteFuncEditor', function($compile, templateSrv) { + .directive('graphiteFuncEditor', function($compile, templateSrv, popoverSrv) { var funcSpanTemplate = '{{func.def.name}}('; var paramTemplate = '

' + funcDef.name + '

' + rst2html(funcDef.description) + '', + openOn: 'click', + }); } else { window.open( "http://graphite.readthedocs.org/en/latest/functions.html#graphite.render.functions." + func.def.name,'_blank');