From f865ec34fa50bea0af90ebe494e982c89d471802 Mon Sep 17 00:00:00 2001 From: ark_65 Date: Mon, 3 Jul 2023 16:15:45 +0800 Subject: [PATCH] fix: fix misalignment when scrollbar scrolls to the edge --- packages/gantt/src/gantt.component.html | 9 ++++--- packages/gantt/src/gantt.component.ts | 28 +++++++++++++++++++++- packages/gantt/src/root.component.html | 9 ++++--- packages/gantt/src/root.component.ts | 32 +++++++++++++++++++++++-- 4 files changed, 69 insertions(+), 9 deletions(-) diff --git a/packages/gantt/src/gantt.component.html b/packages/gantt/src/gantt.component.html index 15a856e4..a431e23a 100644 --- a/packages/gantt/src/gantt.component.html +++ b/packages/gantt/src/gantt.component.html @@ -2,7 +2,7 @@
- +
@@ -15,7 +15,7 @@ [maxBufferPx]="styles.lineHeight * 20" > -
+
- +
{ + this.updateScrollBarOffset(); + }); } private buildFlatItems() { @@ -235,6 +251,16 @@ export class NgxGanttComponent extends GanttUpper implements OnInit, OnChanges, this.viewportItems = [...this.viewportItems]; } + private updateScrollBarOffset() { + if (this.ganttMainContent?.nativeElement) { + const ganttMainContainer = this.ganttMainContent.nativeElement; + const verticalScrollbarWidth = ganttMainContainer.offsetWidth - ganttMainContainer.clientWidth; + const horizontalScrollbarHeight = ganttMainContainer.offsetHeight - ganttMainContainer.clientHeight; + this.verticalScrollbarWidth = verticalScrollbarWidth; + this.horizontalScrollbarHeight = horizontalScrollbarHeight; + } + } + expandChildren(item: GanttItemInternal) { if (!item.expanded) { item.setExpand(true); diff --git a/packages/gantt/src/root.component.html b/packages/gantt/src/root.component.html index 9675bc8b..a9d9745a 100644 --- a/packages/gantt/src/root.component.html +++ b/packages/gantt/src/root.component.html @@ -1,11 +1,14 @@ -
+
- - + +
diff --git a/packages/gantt/src/root.component.ts b/packages/gantt/src/root.component.ts index d19952db..0d633c59 100644 --- a/packages/gantt/src/root.component.ts +++ b/packages/gantt/src/root.component.ts @@ -9,7 +9,9 @@ import { Input, Optional, OnDestroy, - ViewChild + ViewChild, + AfterViewInit, + HostListener } from '@angular/core'; import { GanttDomService, ScrollDirection } from './gantt-dom.service'; import { GanttDragContainer } from './gantt-drag-container'; @@ -29,7 +31,7 @@ import { GanttDate } from './utils/date'; class: 'gantt' } }) -export class NgxGanttRootComponent implements OnInit, OnDestroy { +export class NgxGanttRootComponent implements OnInit, AfterViewInit, OnDestroy { @Input() sideWidth: number; @ContentChild('sideTemplate', { static: true }) sideTemplate: TemplateRef; @@ -39,12 +41,21 @@ export class NgxGanttRootComponent implements OnInit, OnDestroy { /** The native `` element. */ @ViewChild(GanttDragBackdropComponent, { static: true, read: ElementRef }) backdrop: ElementRef; + verticalScrollbarWidth = 0; + + horizontalScrollbarHeight = 0; + private unsubscribe$ = new Subject(); private get view() { return this.ganttUpper.view; } + @HostListener('window:resize') + onWindowResize() { + this.updateScrollBarOffset(); + } + constructor( private elementRef: ElementRef, private ngZone: NgZone, @@ -80,6 +91,23 @@ export class NgxGanttRootComponent implements OnInit, OnDestroy { }); } + ngAfterViewInit() { + setTimeout(() => { + this.updateScrollBarOffset(); + }); + } + + updateScrollBarOffset() { + if (this.mainTemplate?.elementRef) { + const ganttMainContainer = + this.mainTemplate.elementRef.nativeElement.previousElementSibling.querySelector('.gantt-main').firstChild; + const verticalScrollbarWidth = ganttMainContainer.offsetWidth - ganttMainContainer.clientWidth; + const horizontalScrollbarHeight = ganttMainContainer.offsetHeight - ganttMainContainer.clientHeight; + this.verticalScrollbarWidth = verticalScrollbarWidth; + this.horizontalScrollbarHeight = horizontalScrollbarHeight; + } + } + ngOnDestroy(): void { this.unsubscribe$.next(); }