UNPKG

@progress/kendo-angular-gauges

Version:
206 lines (205 loc) 9.14 kB
/**----------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the project root for more information *-------------------------------------------------------------------------------------------*/ import { HostBinding, Component, NgZone, Input, ChangeDetectionStrategy, ContentChild, ViewChild, ElementRef, Renderer2, ChangeDetectorRef } from '@angular/core'; import { ConfigurationService, ThemeService } from '../services'; import { IntlService } from '@progress/kendo-angular-intl'; import { LocalizationService, L10N_PREFIX } from '@progress/kendo-angular-l10n'; import { GaugeComponent } from '../base-components'; import { ArcCenterTemplateDirective } from './arc-center-template.directive'; import { ArcGauge } from '@progress/kendo-charts'; import { drawDOM } from '@progress/kendo-drawing'; import { ResizeSensorComponent } from '@progress/kendo-angular-common'; import { NgTemplateOutlet } from '@angular/common'; import * as i0 from "@angular/core"; import * as i1 from "../services"; import * as i2 from "@progress/kendo-angular-intl"; import * as i3 from "@progress/kendo-angular-l10n"; /** * Represents the [Kendo UI ArcGauge component for Angular]({% slug overview_arcgauge_gauges %}). * * @example * ```ts * import { Component } from '@angular/core'; * * @Component({ * selector: 'my-app', * template: ` * <kendo-arcgauge [value]="value" [scale]="{ max: 100 }"> * <ng-template kendoArcGaugeCenterTemplate let-value="value"> * {{ value }}% * </ng-template> * </kendo-arcgauge> * ` * }) * class AppComponent { * public value: number = 10; * } * ``` * * @remarks * Supported children components are: {@link ArcScaleComponent}, {@link ArcLabelsComponent}, {@link ArcGaugeAreaComponent}, {@link ColorsComponent}. */ export class ArcGaugeComponent extends GaugeComponent { changeDetector; /** * Sets the value of the gauge. */ value; /** * Sets the color of the value pointer. Accepts a valid CSS color string, including hex and rgb. */ color; /** * Sets the color ranges of the value pointer. */ colors; /** * Sets the opacity of the value pointer. */ opacity; /** * Sets the scale options of the ArcGauge. */ scale; centerTemplate; labelElement; className = true; centerTemplateContext = {}; constructor(changeDetector, configurationService, themeService, intlService, localizationService, element, renderer, ngZone) { super(configurationService, themeService, intlService, localizationService, element, renderer, ngZone); this.changeDetector = changeDetector; } ngOnInit() { super.ngOnInit(); if (this.element) { this.renderer.setStyle(this.element.nativeElement, 'position', 'relative'); } } ngAfterViewChecked() { super.ngAfterViewChecked(); if (this.labelElement && !this.centerTemplate) { this.changeDetector.detectChanges(); } else if (!this.labelElement && this.centerTemplate) { this.updateCenterTemplate(); } } /** * Exports the Gauge as a Drawing `Scene`. * * @returns A promise that resolves with the export visual. */ exportVisual() { return drawDOM(this.element.nativeElement); } /** * Detects the size of the container and redraws the Gauge. * Resizing happens automatically unless you set the `resizeRateLimit` option to `0`. */ resize() { super.resize(); this.updateCenterTemplate(); } createInstance(element, options, theme, context) { this.instance = new ArcGauge(element, options, theme, context); this.updateElements(); } updateOptions() { super.updateOptions(); this.updateElements(); } setValues() { const value = this.configurationService.readValue(); this.instance.value(value); this.updateCenterTemplate(); } updateElements() { this.resizeSensor.acceptSize(); this.updateCenterTemplate(); } updateCenterTemplate() { if (!this.instance || !this.centerTemplate) { return; } this.centerTemplateContext.value = this.instance.value(); this.centerTemplateContext.color = this.instance.currentColor(); this.changeDetector.detectChanges(); this.positionLabel(); } positionLabel() { if (!this.labelElement) { return; } const element = this.labelElement.nativeElement; const width = element.offsetWidth; const height = element.offsetHeight; const position = this.instance.centerLabelPosition(width, height); element.style.top = `${position.top}px`; element.style.left = `${position.left}px`; } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: ArcGaugeComponent, deps: [{ token: i0.ChangeDetectorRef }, { token: i1.ConfigurationService }, { token: i1.ThemeService }, { token: i2.IntlService }, { token: i3.LocalizationService }, { token: i0.ElementRef }, { token: i0.Renderer2 }, { token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Component }); static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "18.2.14", type: ArcGaugeComponent, isStandalone: true, selector: "kendo-arcgauge", inputs: { value: "value", color: "color", colors: "colors", opacity: "opacity", scale: "scale" }, host: { properties: { "class.k-arcgauge": "this.className" } }, providers: [ ConfigurationService, LocalizationService, { provide: L10N_PREFIX, useValue: 'kendo.arcgauge' } ], queries: [{ propertyName: "centerTemplate", first: true, predicate: ArcCenterTemplateDirective, descendants: true }], viewQueries: [{ propertyName: "labelElement", first: true, predicate: ["label"], descendants: true }], exportAs: ["kendoArcGauge"], usesInheritance: true, ngImport: i0, template: ` <div #surface class='k-chart-surface'></div> @if (centerTemplate) { <div class="k-arcgauge-label" #label> <ng-template [ngTemplateOutlet]="centerTemplate.templateRef" [ngTemplateOutletContext]="centerTemplateContext"></ng-template> </div> } <kendo-resize-sensor (resize)="onResize()" [rateLimit]="resizeRateLimit"></kendo-resize-sensor> `, isInline: true, dependencies: [{ kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "component", type: ResizeSensorComponent, selector: "kendo-resize-sensor", inputs: ["rateLimit"], outputs: ["resize"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: ArcGaugeComponent, decorators: [{ type: Component, args: [{ changeDetection: ChangeDetectionStrategy.OnPush, exportAs: 'kendoArcGauge', providers: [ ConfigurationService, LocalizationService, { provide: L10N_PREFIX, useValue: 'kendo.arcgauge' } ], selector: 'kendo-arcgauge', template: ` <div #surface class='k-chart-surface'></div> @if (centerTemplate) { <div class="k-arcgauge-label" #label> <ng-template [ngTemplateOutlet]="centerTemplate.templateRef" [ngTemplateOutletContext]="centerTemplateContext"></ng-template> </div> } <kendo-resize-sensor (resize)="onResize()" [rateLimit]="resizeRateLimit"></kendo-resize-sensor> `, standalone: true, imports: [NgTemplateOutlet, ResizeSensorComponent] }] }], ctorParameters: () => [{ type: i0.ChangeDetectorRef }, { type: i1.ConfigurationService }, { type: i1.ThemeService }, { type: i2.IntlService }, { type: i3.LocalizationService }, { type: i0.ElementRef }, { type: i0.Renderer2 }, { type: i0.NgZone }], propDecorators: { value: [{ type: Input }], color: [{ type: Input }], colors: [{ type: Input }], opacity: [{ type: Input }], scale: [{ type: Input }], centerTemplate: [{ type: ContentChild, args: [ArcCenterTemplateDirective, { static: false }] }], labelElement: [{ type: ViewChild, args: ["label", { static: false }] }], className: [{ type: HostBinding, args: ['class.k-arcgauge'] }] } });