UNPKG

@progress/kendo-angular-gantt

Version:
91 lines (90 loc) 3.98 kB
/**----------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the project root for more information *-------------------------------------------------------------------------------------------*/ import { ChangeDetectorRef, Injectable, Renderer2 } from '@angular/core'; import { isDocumentAvailable } from '@progress/kendo-angular-common'; import * as i0 from "@angular/core"; const MS_PER_SECOND = 1000; const MS_PER_MINUTE = 60 * MS_PER_SECOND; /** * @hidden */ export class CurrentTimeMarkerService { renderer; cdr; container; slots = []; rows = []; currentTimeMarker; rowHeight; rtl; activeView; get deltaOffset() { if (this.slotIndex >= 0) { const total = this.slots[this.slotIndex].end.getTime() - this.slots[this.slotIndex].start.getTime(); if (total > 0) { const currentTimeValue = this.now.getTime() - this.slots[this.slotIndex].start.getTime(); const fractionInsideCell = currentTimeValue / total; const deltaOffsetToSlot = this.slotIndex * this.slotWidth; const deltaOffsetInsideSlot = fractionInsideCell * this.slotWidth; return deltaOffsetToSlot + deltaOffsetInsideSlot; } return 0; } } get slotWidth() { return this.slots[0]?.slotWidth; } get slotIndex() { return this.slots.indexOf(this.slots.find((slot) => slot.start <= this.now && slot.end > this.now)); } get height() { return this.rows.length * this.rowHeight; } get interval() { if (typeof (this.currentTimeMarker) === 'boolean') { return MS_PER_MINUTE; } return this.currentTimeMarker?.updateInterval || MS_PER_MINUTE; } now = new Date(Date.now()); currentTimeTimeout; timeMarkerDiv; constructor(renderer, cdr) { this.renderer = renderer; this.cdr = cdr; } ngOnDestroy() { clearTimeout(this.currentTimeTimeout); } removeTimeMarker() { if (this.timeMarkerDiv) { this.renderer.removeChild(this.container.nativeElement, this.timeMarkerDiv); clearTimeout(this.currentTimeTimeout); this.cdr.detectChanges(); } } createTimeMarker = () => { if (!isDocumentAvailable()) { return; } this.removeTimeMarker(); if (this.slotIndex >= 0) { this.now = new Date(Date.now()); this.timeMarkerDiv = this.renderer.createElement('div'); this.renderer.addClass(this.timeMarkerDiv, 'k-current-time'); this.renderer.setStyle(this.timeMarkerDiv, 'width', '1px'); this.renderer.setStyle(this.timeMarkerDiv, 'top', '0px'); this.renderer.setStyle(this.timeMarkerDiv, `${this.rtl ? 'right' : 'left'}`, this.deltaOffset + 'px'); this.renderer.appendChild(this.container.nativeElement, this.timeMarkerDiv); this.renderer.setStyle(this.timeMarkerDiv, 'height', this.height + 'px'); this.currentTimeTimeout = setTimeout(this.createTimeMarker, this.interval || MS_PER_MINUTE); } }; static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: CurrentTimeMarkerService, deps: [{ token: i0.Renderer2 }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Injectable }); static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: CurrentTimeMarkerService }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: CurrentTimeMarkerService, decorators: [{ type: Injectable }], ctorParameters: () => [{ type: i0.Renderer2 }, { type: i0.ChangeDetectorRef }] });