mirror of https://github.com/grafana/grafana
Big refactoring/rewrite for how annotation tooltips are shown, also work on #1474
parent
e76d2ec9c2
commit
494ede5bbf
@ -0,0 +1,36 @@ |
||||
define([ |
||||
'angular', |
||||
'lodash' |
||||
], |
||||
function (angular) { |
||||
'use strict'; |
||||
|
||||
angular |
||||
.module('grafana.directives') |
||||
.directive('annotationTooltip', function($sanitize, dashboardSrv) { |
||||
return { |
||||
scope: { tagColorFromName: "=" }, |
||||
link: function (scope, element) { |
||||
var title = $sanitize(scope.annoation.title); |
||||
var dashboard = dashboardSrv.getCurrent(); |
||||
var time = '<i>' + dashboard.formatDate(scope.annotation.time) + '</i>'; |
||||
|
||||
var tooltip = '<div class="graph-tooltip small"><div class="graph-tooltip-time">'+ title + ' ' + time + '</div> ' ; |
||||
|
||||
if (options.tags) { |
||||
var tags = $sanitize(options.tags); |
||||
tooltip += '<span class="label label-tag" tag-color-from-name="\'asd\'">' + (tags || '') + '</span><br/>'; |
||||
} |
||||
|
||||
if (options.text) { |
||||
var text = $sanitize(options.text); |
||||
tooltip += text.replace(/\n/g, '<br/>'); |
||||
} |
||||
|
||||
tooltip += "</small>"; |
||||
} |
||||
}; |
||||
}); |
||||
|
||||
}); |
||||
|
@ -0,0 +1,40 @@ |
||||
define([ |
||||
'angular', |
||||
'jquery', |
||||
'lodash' |
||||
], |
||||
function (angular, $) { |
||||
'use strict'; |
||||
|
||||
angular |
||||
.module('grafana.directives') |
||||
.directive('annotationTooltip', function($sanitize, dashboardSrv, $compile) { |
||||
return { |
||||
link: function (scope, element) { |
||||
var event = scope.event; |
||||
var title = $sanitize(event.title); |
||||
var dashboard = dashboardSrv.getCurrent(); |
||||
var time = '<i>' + dashboard.formatDate(event.min) + '</i>'; |
||||
|
||||
var tooltip = '<div class="graph-tooltip small"><div class="graph-tooltip-time">' + title + ' ' + time + '</div> ' ; |
||||
|
||||
if (event.text) { |
||||
var text = $sanitize(event.text); |
||||
tooltip += text.replace(/\n/g, '<br>') + '<br>'; |
||||
} |
||||
|
||||
if (event.tags && event.tags.length > 0) { |
||||
tooltip += '<span class="label label-tag" ng-repeat="tag in event.tags" tag-color-from-name="tag">{{tag}}</span><br/>'; |
||||
} |
||||
|
||||
tooltip += "</div>"; |
||||
|
||||
var $tooltip = $(tooltip); |
||||
$tooltip.appendTo(element); |
||||
|
||||
$compile(element.contents())(scope); |
||||
} |
||||
}; |
||||
}); |
||||
|
||||
}); |
Loading…
Reference in new issue