The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/public/app/core/directives/annotation_tooltip.js

60 lines
1.6 KiB

define([
'jquery',
'lodash',
'../core_module',
],
function ($, _, coreModule) {
'use strict';
coreModule.default.directive('annotationTooltip', function($sanitize, dashboardSrv, $compile) {
function sanitizeString(str) {
try {
return $sanitize(str);
}
catch(err) {
console.log('Could not sanitize annotation string, html escaping instead');
return _.escape(str);
}
}
return {
link: function (scope, element) {
var event = scope.event;
var title = sanitizeString(event.title);
var dashboard = dashboardSrv.getCurrent();
var time = '<i>' + dashboard.formatDate(event.min) + '</i>';
var tooltip = '<div class="graph-annotation">';
tooltip += '<div class="graph-annotation-title">' + title + "</div>";
if (event.text) {
var text = sanitizeString(event.text);
tooltip += text.replace(/\n/g, '<br>') + '<br>';
}
var tags = event.tags;
if (_.isString(event.tags)) {
tags = event.tags.split(',');
if (tags.length === 1) {
tags = event.tags.split(' ');
}
}
if (tags && tags.length) {
scope.tags = tags;
tooltip += '<span class="label label-tag small" ng-repeat="tag in tags" tag-color-from-name="tag">{{tag}}</span><br/>';
}
tooltip += '<div class="graph-annotation-time">' + time + '</div>' ;
tooltip += "</div>";
var $tooltip = $(tooltip);
$tooltip.appendTo(element);
$compile(element.contents())(scope);
}
};
});
});