@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.
222 lines (219 loc) • 11.6 kB
JavaScript
/**-----------------------------------------------------------------------------------------
* Copyright © 2024 Progress Software Corporation. All rights reserved.
* Licensed under commercial license. See LICENSE.md in the project root for more information
*-------------------------------------------------------------------------------------------*/
import { Component, TemplateRef, ViewChild, Input, NgZone, Output, EventEmitter } from '@angular/core';
import { SeriesTooltipTemplateDirective } from './series-tooltip-template.directive';
import { SharedTooltipTemplateDirective } from './shared-tooltip-template.directive';
import { TooltipTemplatePoint } from './tooltip-template-point';
import { BaseTooltip } from './base-tooltip';
import { hasParent } from '../../common/has-parent';
import { TooltipTemplateService } from '../../common/tooltip-template.service';
import { PopupService, POPUP_CONTAINER } from '@progress/kendo-angular-popup';
import { bodyFactory } from './body-factory';
import { LocalizationService } from '@progress/kendo-angular-l10n';
import { NgClass, NgStyle, NgIf, NgTemplateOutlet, NgFor } from '@angular/common';
import * as i0 from "@angular/core";
import * as i1 from "@progress/kendo-angular-popup";
import * as i2 from "../../common/tooltip-template.service";
import * as i3 from "@progress/kendo-angular-l10n";
const SHARED_TOOLTIP_CLASS = 'k-chart-shared-tooltip';
const TOOLTIP_CLASS = "k-chart-tooltip";
/**
* @hidden
*/
export class TooltipPopupComponent extends BaseTooltip {
popupService;
templateService;
localizationService;
ngZone;
seriesTooltipTemplateRef;
seriesSharedTooltipTemplateRef;
seriesTooltipContext = {};
seriesSharedTooltipContext = {};
shared;
defaultSeriesTooltipTemplate;
defaultSharedTooltipTemplate;
templateRef;
animate = true;
classNames;
wrapperClass = 'k-chart-tooltip-wrapper';
leave = new EventEmitter();
popupClasses = {};
mouseleaveSubscription;
constructor(popupService, templateService, localizationService, ngZone) {
super(popupService, localizationService);
this.popupService = popupService;
this.templateService = templateService;
this.localizationService = localizationService;
this.ngZone = ngZone;
}
show(e) {
this.shared = e.shared;
this.popupClasses = Object.assign({
[SHARED_TOOLTIP_CLASS]: e.shared,
[TOOLTIP_CLASS]: true,
[e.className]: !!e.className
}, this.classNames);
if (!e.shared) {
this.seriesTooltipContext = new TooltipTemplatePoint(e.point, e.format);
this.seriesTooltipTemplateRef = this.pointTemplateRef(e.point);
}
else {
this.seriesSharedTooltipTemplateRef = this.templateService.getSharedTemplate()
|| this.defaultSharedTooltipTemplate.templateRef;
this.seriesSharedTooltipContext = this.sharedTemplateContext(e);
}
super.show(e);
}
containsElement(element) {
if (this.popupRef) {
return hasParent(element, this.popupRef.popupElement);
}
}
sharedTemplateContext(e) {
const points = e.points;
const nameColumn = points.filter((point) => typeof point.series.name !== 'undefined').length > 0;
const colorMarker = e.series.length > 1;
let colspan = 1;
if (nameColumn) {
colspan++;
}
if (colorMarker) {
colspan++;
}
return {
category: e.category,
categoryText: e.categoryText,
colorMarker: colorMarker,
colspan: colspan,
nameColumn: nameColumn,
points: this.wrapPoints(e.points, e.format)
};
}
pointTemplateRef(point) {
return this.templateService.getTemplate(point.series.index) || this.defaultSeriesTooltipTemplate.templateRef;
}
wrapPoints(points, format) {
const result = [];
for (let idx = 0; idx < points.length; idx++) {
const point = points[idx];
const template = this.pointTemplateRef(point);
const pointFormat = ((point.options || {}).tooltip || {}).format || format;
result.push(new TooltipTemplatePoint(point, pointFormat, template));
}
return result;
}
onInit() {
this.ngZone.runOutsideAngular(() => {
this.mouseleaveSubscription = this.popupRef.popupElement.addEventListener('mouseleave', (args) => {
this.leave.emit(args);
});
});
this.popupRef.popupElement.className += ` ${this.wrapperClass}`;
}
hide() {
if (this.mouseleaveSubscription) {
this.mouseleaveSubscription();
this.mouseleaveSubscription = null;
}
super.hide();
}
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: TooltipPopupComponent, deps: [{ token: i1.PopupService }, { token: i2.TooltipTemplateService }, { token: i3.LocalizationService }, { token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Component });
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "16.2.12", type: TooltipPopupComponent, isStandalone: true, selector: "kendo-chart-tooltip-popup", inputs: { animate: "animate", classNames: "classNames", wrapperClass: "wrapperClass" }, outputs: { leave: "leave" }, providers: [PopupService, {
provide: POPUP_CONTAINER,
useFactory: bodyFactory
}], viewQueries: [{ propertyName: "defaultSeriesTooltipTemplate", first: true, predicate: SeriesTooltipTemplateDirective, descendants: true }, { propertyName: "defaultSharedTooltipTemplate", first: true, predicate: SharedTooltipTemplateDirective, descendants: true }, { propertyName: "templateRef", first: true, predicate: ["content"], descendants: true, static: true }], usesInheritance: true, ngImport: i0, template: `
<ng-template #content>
<div [ngClass]="popupClasses" [ngStyle]="style">
<ng-template [ngTemplateOutlet]="seriesTooltipTemplateRef" *ngIf="!shared"
[ngTemplateOutletContext]="seriesTooltipContext">
</ng-template>
<ng-template [ngTemplateOutlet]="seriesSharedTooltipTemplateRef" *ngIf="shared"
[ngTemplateOutletContext]="seriesSharedTooltipContext">
</ng-template>
</div>
</ng-template>
<ng-template kendoChartSeriesTooltipTemplate let-formattedValue="formattedValue">
<span [innerHTML]="formattedValue"></span>
</ng-template>
<ng-template kendoChartSharedTooltipTemplate let-points="points" let-categoryText="categoryText" let-colspan="colspan" let-colorMarker="colorMarker" let-nameColumn="nameColumn" >
<table>
<tr><th [attr.colspan]='colspan'> {{ categoryText }} </th></tr>
<tr *ngFor="let point of points">
<td *ngIf="colorMarker"><span class='k-chart-shared-tooltip-marker' [style.background-color]='point.series.color'></span></td>
<td *ngIf="nameColumn">
<ng-container *ngIf="point.series.name !== undefined">{{ point.series.name }}</ng-container>
<ng-container *ngIf="point.series.name === undefined"> </ng-container>
</td>
<td>
<ng-template [ngTemplateOutlet]="point.template"
[ngTemplateOutletContext]="point">
</ng-template>
</td>
</tr>
</table>
</ng-template>
`, isInline: true, dependencies: [{ kind: "directive", type: NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }, { kind: "directive", type: NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "directive", type: SeriesTooltipTemplateDirective, selector: "[kendoChartSeriesTooltipTemplate]" }, { kind: "directive", type: SharedTooltipTemplateDirective, selector: "[kendoChartSharedTooltipTemplate]" }, { kind: "directive", type: NgFor, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }] });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: TooltipPopupComponent, decorators: [{
type: Component,
args: [{
providers: [PopupService, {
provide: POPUP_CONTAINER,
useFactory: bodyFactory
}],
selector: 'kendo-chart-tooltip-popup',
template: `
<ng-template #content>
<div [ngClass]="popupClasses" [ngStyle]="style">
<ng-template [ngTemplateOutlet]="seriesTooltipTemplateRef" *ngIf="!shared"
[ngTemplateOutletContext]="seriesTooltipContext">
</ng-template>
<ng-template [ngTemplateOutlet]="seriesSharedTooltipTemplateRef" *ngIf="shared"
[ngTemplateOutletContext]="seriesSharedTooltipContext">
</ng-template>
</div>
</ng-template>
<ng-template kendoChartSeriesTooltipTemplate let-formattedValue="formattedValue">
<span [innerHTML]="formattedValue"></span>
</ng-template>
<ng-template kendoChartSharedTooltipTemplate let-points="points" let-categoryText="categoryText" let-colspan="colspan" let-colorMarker="colorMarker" let-nameColumn="nameColumn" >
<table>
<tr><th [attr.colspan]='colspan'> {{ categoryText }} </th></tr>
<tr *ngFor="let point of points">
<td *ngIf="colorMarker"><span class='k-chart-shared-tooltip-marker' [style.background-color]='point.series.color'></span></td>
<td *ngIf="nameColumn">
<ng-container *ngIf="point.series.name !== undefined">{{ point.series.name }}</ng-container>
<ng-container *ngIf="point.series.name === undefined"> </ng-container>
</td>
<td>
<ng-template [ngTemplateOutlet]="point.template"
[ngTemplateOutletContext]="point">
</ng-template>
</td>
</tr>
</table>
</ng-template>
`,
standalone: true,
imports: [NgClass, NgStyle, NgIf, NgTemplateOutlet, SeriesTooltipTemplateDirective, SharedTooltipTemplateDirective, NgFor]
}]
}], ctorParameters: function () { return [{ type: i1.PopupService }, { type: i2.TooltipTemplateService }, { type: i3.LocalizationService }, { type: i0.NgZone }]; }, propDecorators: { defaultSeriesTooltipTemplate: [{
type: ViewChild,
args: [SeriesTooltipTemplateDirective, { static: false }]
}], defaultSharedTooltipTemplate: [{
type: ViewChild,
args: [SharedTooltipTemplateDirective, { static: false }]
}], templateRef: [{
type: ViewChild,
args: ['content', { static: true }]
}], animate: [{
type: Input
}], classNames: [{
type: Input
}], wrapperClass: [{
type: Input
}], leave: [{
type: Output
}] } });