@progress/kendo-angular-charts
Version:
Kendo UI Charts for Angular - A comprehensive package for creating beautiful and interactive data visualization. Every chart type, stock charts, and sparklines are included.
101 lines (100 loc) • 3.87 kB
JavaScript
/**-----------------------------------------------------------------------------------------
* Copyright © 2025 Progress Software Corporation. All rights reserved.
* Licensed under commercial license. See LICENSE.md in the project root for more information
*-------------------------------------------------------------------------------------------*/
import { Directive, Input } from '@angular/core';
import { PopupService } from '@progress/kendo-angular-popup';
import { LocalizationService } from '@progress/kendo-angular-l10n';
import * as i0 from "@angular/core";
import * as i1 from "@progress/kendo-angular-popup";
import * as i2 from "@progress/kendo-angular-l10n";
const POSITION_MODE = 'absolute';
const COLLISION = { horizontal: "fit", vertical: "fit" };
/**
* @hidden
*/
export class BaseTooltip {
popupService;
localizationService;
animate;
style = {};
templateRef;
popupRef = null;
popupSettings;
constructor(popupService, localizationService) {
this.popupService = popupService;
this.localizationService = localizationService;
}
get active() {
return this.popupRef !== null;
}
show(e) {
const align = e.anchor.align;
const offset = this.position(e.anchor.point);
this.style = e.style;
if (!this.popupRef) {
this.popupRef = this.popupService.open(Object.assign({
offset: offset,
popupAlign: align,
animate: this.animate,
content: this.templateRef,
collision: COLLISION,
positionMode: POSITION_MODE
}, this.popupSettings));
if (this.localizationService.rtl) {
this.popupRef.popupElement.setAttribute('dir', 'rtl');
}
this.onInit();
}
else {
const popup = this.popupRef.popup.instance;
popup.offset = offset;
popup.popupAlign = align;
}
}
onInit() {
/* noop */
}
hide() {
if (this.popupRef) {
this.popupRef.close();
this.popupRef = null;
}
}
ngOnDestroy() {
this.hide();
}
position(offset) {
if (!this.popupSettings || !this.popupSettings.appendTo) {
return offset;
}
const appendTo = this.popupSettings.appendTo.element.nativeElement;
const bbox = appendTo.getBoundingClientRect();
const { scrollLeft, scrollTop } = this.scrollOffset(appendTo);
return {
left: offset.left - bbox.left - scrollLeft,
top: offset.top - bbox.top - scrollTop
};
}
scrollOffset(element) {
if (!element) {
return null;
}
let scrollLeft = element.scrollLeft;
let scrollTop = element.scrollTop;
let parent = element.parentElement;
while (parent) {
scrollLeft += parent.scrollLeft;
scrollTop += parent.scrollTop;
parent = parent.parentElement;
}
return { scrollLeft, scrollTop };
}
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: BaseTooltip, deps: [{ token: i1.PopupService }, { token: i2.LocalizationService }], target: i0.ɵɵFactoryTarget.Directive });
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "16.2.12", type: BaseTooltip, inputs: { popupSettings: "popupSettings" }, ngImport: i0 });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: BaseTooltip, decorators: [{
type: Directive
}], ctorParameters: function () { return [{ type: i1.PopupService }, { type: i2.LocalizationService }]; }, propDecorators: { popupSettings: [{
type: Input
}] } });