Skip to content

Commit de7d358

Browse files
walkerkayHandsomeButterball
authored andcommitted
feat: scroll side and viewer scroll
1 parent 8cd2420 commit de7d358

File tree

8 files changed

+56
-48
lines changed

8 files changed

+56
-48
lines changed

packages/gantt/src/bar/bar-drag.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ export class GanttBarDrag implements OnDestroy {
226226

227227
private calcDependencyLinePositions(target: HTMLElement, isBefore: boolean) {
228228
const dragHandleWidth = 16;
229-
const container = this.dom.viewer;
229+
const container = this.dom.viewerContainer;
230230
const targetRect = target.getBoundingClientRect();
231231
const containerRect = container.getBoundingClientRect();
232232
const refs = this.item.refs;

packages/gantt/src/bar/bar.component.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ $gantt-bar-dependency-drop-border: 5px;
106106

107107
.gantt-bar {
108108
position: absolute;
109-
background-color: $gantt-item-bg-color;
110109
border-radius: 4px;
111110
z-index: 1;
112111

packages/gantt/src/gantt-dom.service.ts

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Injectable, ElementRef, OnDestroy } from '@angular/core';
2-
import { fromEvent, Subject } from 'rxjs';
2+
import { fromEvent, Subject, merge } from 'rxjs';
33
import { pairwise, map, auditTime, takeUntil } from 'rxjs/operators';
44
import { isNumber } from './utils/helpers';
55

@@ -8,7 +8,7 @@ const scrollThreshold = 50;
88
export enum ScrollDirection {
99
NONE,
1010
LEFT,
11-
RIGHT,
11+
RIGHT
1212
}
1313

1414
export interface ScrollEvent {
@@ -20,52 +20,58 @@ export interface ScrollEvent {
2020
export class GanttDomService implements OnDestroy {
2121
public root: Element;
2222

23-
public viewer: Element;
23+
public sideContainer: Element;
2424

25-
public calendarOverlay: Element;
25+
public viewerContainer: Element;
2626

27-
public side: Element;
27+
public calendarOverlay: Element;
2828

2929
private unsubscribe$ = new Subject<void>();
3030

3131
constructor() {}
3232

3333
private monitorScrollChange() {
34-
fromEvent(this.viewer, 'scroll')
34+
merge(fromEvent(this.viewerContainer, 'scroll'), fromEvent(this.sideContainer, 'scroll'))
3535
.pipe(takeUntil(this.unsubscribe$))
36-
.subscribe(() => {
37-
this.syncScroll();
36+
.subscribe((event) => {
37+
this.syncScroll(event);
3838
});
3939
}
4040

41-
private syncScroll() {
42-
this.calendarOverlay.scrollLeft = this.viewer.scrollLeft;
41+
private syncScroll(event: Event) {
42+
const target = event.target as HTMLElement;
43+
this.calendarOverlay.scrollLeft = this.viewerContainer.scrollLeft;
44+
this.sideContainer.scrollTop = target.scrollTop;
45+
this.viewerContainer.scrollTop = target.scrollTop;
4346
}
4447

4548
initialize(root: ElementRef<HTMLElement>) {
4649
this.root = root.nativeElement;
47-
this.viewer = this.root.getElementsByClassName('gantt-viewer-container')[0];
50+
this.sideContainer = this.root.getElementsByClassName('gantt-side-container')[0];
51+
this.viewerContainer = this.root.getElementsByClassName('gantt-viewer-container')[0];
4852
this.calendarOverlay = this.root.getElementsByClassName('gantt-calendar-overlay')[0];
49-
this.side = this.root.getElementsByClassName('gantt-side')[0];
5053
this.monitorScrollChange();
5154
}
5255

5356
getViewerScroll() {
54-
return fromEvent<Event>(this.viewer, 'scroll').pipe(
55-
map(() => this.viewer.scrollLeft),
57+
return fromEvent<Event>(this.viewerContainer, 'scroll').pipe(
58+
map(() => this.viewerContainer.scrollLeft),
5659
pairwise(),
5760
map(([previous, current]) => {
5861
const event: ScrollEvent = {
59-
target: this.viewer,
60-
direction: ScrollDirection.NONE,
62+
target: this.viewerContainer,
63+
direction: ScrollDirection.NONE
6164
};
6265
if (current - previous < 0) {
63-
if (this.viewer.scrollLeft < scrollThreshold && this.viewer.scrollLeft > 0) {
66+
if (this.viewerContainer.scrollLeft < scrollThreshold && this.viewerContainer.scrollLeft > 0) {
6467
event.direction = ScrollDirection.LEFT;
6568
}
6669
}
6770
if (current - previous > 0) {
68-
if (this.viewer.scrollWidth - this.viewer.clientWidth - this.viewer.scrollLeft < scrollThreshold) {
71+
if (
72+
this.viewerContainer.scrollWidth - this.viewerContainer.clientWidth - this.viewerContainer.scrollLeft <
73+
scrollThreshold
74+
) {
6975
event.direction = ScrollDirection.RIGHT;
7076
}
7177
}
@@ -80,13 +86,9 @@ export class GanttDomService implements OnDestroy {
8086

8187
scrollViewer(left: number) {
8288
if (isNumber(left)) {
83-
const scrollLeft = left - this.viewer.clientWidth / 2;
84-
if (scrollLeft > scrollThreshold) {
85-
this.viewer.scrollLeft = scrollLeft;
86-
} else {
87-
this.viewer.scrollLeft = 0;
88-
}
89-
this.syncScroll();
89+
const scrollLeft = left - this.viewerContainer.clientWidth / 2;
90+
this.viewerContainer.scrollLeft = scrollLeft > scrollThreshold ? scrollLeft : 0;
91+
this.calendarOverlay.scrollLeft = this.viewerContainer.scrollLeft;
9092
}
9193
}
9294

packages/gantt/src/gantt.scss

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
$gantt-header-height: 44px !default;
2-
$gantt-side-width: 200px !default;
3-
$gantt-full-screen-width: 60px !default;
42
$gantt-border-color: #eee !default;
53
$gantt-bg-color: #fff !default;
6-
$gantt-item-bg-color: #fff !default;
4+
5+
// mask
76
$gantt-item-drag-mask-color: #348fe4 !default;
7+
8+
//bar
89
$gantt-bar-layer-bg: #fff !default;
910
$gantt-bar-handle-color: #cacaca !default;
1011
$gantt-bar-handle-height: 12px !default;
@@ -16,15 +17,9 @@ $gantt-date-secondary-color: #333 !default;
1617
$gantt-date-secondary-font-size: 14px !default;
1718
$gantt-date-secondary-weekend-color: #aaa !default;
1819
$gantt-date-secondary-border-color: #ddd !default;
19-
$gantt-date-week-backdrop-bg: rgba(
20-
$color: #f3f3f3,
21-
$alpha: 0.5,
22-
) !default;
20+
$gantt-date-week-backdrop-bg: rgba($color: #f3f3f3, $alpha: 0.5) !default;
2321
$gantt-date-today-color: #ff9f73 !default;
2422

25-
// @import './bar/bar.scss';
26-
// @import './dependencies/dependencies.scss';
27-
2823
@import './calendar/calendar.component.scss';
2924
@import './table/gantt-table.component.scss';
3025
@import './bar/bar.component.scss';
@@ -39,7 +34,22 @@ $gantt-date-today-color: #ff9f73 !default;
3934

4035
.gantt-side {
4136
width: 400px;
42-
border-right: 1px solid #ddd;
37+
38+
.gantt-side-header {
39+
box-sizing: border-box;
40+
height: $gantt-header-height;
41+
overflow: hidden;
42+
border-bottom: 1px solid #eee;
43+
}
44+
45+
.gantt-side-container {
46+
height: calc(100% - #{$gantt-header-height});
47+
overflow: auto;
48+
49+
&::-webkit-scrollbar {
50+
display: none;
51+
}
52+
}
4353
}
4454

4555
.gantt-container {

packages/gantt/src/gantt.styles.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
export const defaultStyles = {
22
lineHeight: 44,
3-
barHeight: 25,
3+
barHeight: 25
44
};
55

66
export type GanttStyles = typeof defaultStyles;
77

8-
export const headerHeight = 50;
8+
export const headerHeight = 44;

packages/gantt/src/table/gantt-table.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<gantt-side>
2-
<div class="gantt-table-header" *ngIf="columns?.length">
2+
<div class="gantt-side-header" *ngIf="columns?.length">
33
<table>
44
<thead>
55
<th *ngFor="let column of columns" [title]="column.name">
@@ -8,7 +8,7 @@
88
</thead>
99
</table>
1010
</div>
11-
<div class="gantt-table-container">
11+
<div class="gantt-side-container">
1212
<ng-container *ngIf="groups.length; else itemsTemplate">
1313
<gantt-table-group *ngFor="let group of groups" [group]="group" [groupHeader]="groupTemplate">
1414
<gantt-table-items [items]="group.items" [columns]="columns"></gantt-table-items>

packages/gantt/src/table/gantt-table.component.scss

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ $gantt-table-td-height: 44px !default;
33
$gantt-table-thead-height: 44px !default;
44
$gantt-table-td-padding: 0 15px !default;
55
$gantt-table-bg: #fff !default;
6-
$gantt-table-border-color: #eee !default;
76

87
@import './group/group.component.scss';
98

@@ -27,8 +26,8 @@ $gantt-table-border-color: #eee !default;
2726
td {
2827
padding: $gantt-table-td-padding;
2928
background-color: $gantt-table-bg;
30-
border-right: 1px solid $gantt-table-border-color;
31-
border-bottom: 1px solid $gantt-table-border-color;
29+
border-right: 1px solid $gantt-border-color;
30+
border-bottom: 1px solid $gantt-border-color;
3231
position: relative;
3332
}
3433

@@ -45,7 +44,4 @@ $gantt-table-border-color: #eee !default;
4544
}
4645
}
4746

48-
.gantt-table-header {
49-
box-sizing: border-box;
50-
}
5147
}

packages/gantt/src/table/group/group.component.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
.gantt-table-group-header-title {
1111
cursor: pointer;
1212
}
13+
border-right: 1px solid $gantt-border-color;
1314
}
1415
}

0 commit comments

Comments
 (0)