2018-05-17 07:24:49 -05:00
|
|
|
import $ from 'jquery';
|
|
|
|
import angular from 'angular';
|
|
|
|
import _ from 'lodash';
|
|
|
|
|
2018-08-29 07:26:50 -05:00
|
|
|
const $win = $(window);
|
2018-05-17 07:24:49 -05:00
|
|
|
|
2018-09-04 10:02:32 -05:00
|
|
|
$.fn.place_tt = (() => {
|
2018-08-29 07:26:50 -05:00
|
|
|
const defaults = {
|
2018-05-17 07:24:49 -05:00
|
|
|
offset: 5,
|
|
|
|
};
|
|
|
|
|
2019-05-13 02:38:19 -05:00
|
|
|
return function(this: any, x: number, y: number, opts: any) {
|
2018-05-17 07:24:49 -05:00
|
|
|
opts = $.extend(true, {}, defaults, opts);
|
|
|
|
|
2018-08-30 03:49:18 -05:00
|
|
|
return this.each(() => {
|
2018-08-29 07:26:50 -05:00
|
|
|
const $tooltip = $(this);
|
|
|
|
let width, height;
|
2018-05-17 07:24:49 -05:00
|
|
|
|
|
|
|
$tooltip.addClass('grafana-tooltip');
|
|
|
|
|
|
|
|
$('#tooltip').remove();
|
|
|
|
$tooltip.appendTo(document.body);
|
|
|
|
|
|
|
|
if (opts.compile) {
|
|
|
|
angular
|
|
|
|
.element(document)
|
|
|
|
.injector()
|
|
|
|
.invoke([
|
|
|
|
'$compile',
|
|
|
|
'$rootScope',
|
2018-09-04 10:02:32 -05:00
|
|
|
($compile, $rootScope) => {
|
2018-08-29 07:26:50 -05:00
|
|
|
const tmpScope = $rootScope.$new(true);
|
2018-05-17 07:24:49 -05:00
|
|
|
_.extend(tmpScope, opts.scopeData);
|
|
|
|
|
|
|
|
$compile($tooltip)(tmpScope);
|
|
|
|
tmpScope.$digest();
|
|
|
|
tmpScope.$destroy();
|
|
|
|
},
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
width = $tooltip.outerWidth(true);
|
|
|
|
height = $tooltip.outerHeight(true);
|
|
|
|
|
|
|
|
$tooltip.css('left', x + opts.offset + width > $win.width() ? x - opts.offset - width : x + opts.offset);
|
|
|
|
$tooltip.css('top', y + opts.offset + height > $win.height() ? y - opts.offset - height : y + opts.offset);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
})();
|