diff --git a/package.json b/package.json index 99cdfe4c..6a1c5a6a 100644 --- a/package.json +++ b/package.json @@ -5,10 +5,12 @@ "ng": "ng", "start:docs": "docgeni serve", "start": "concurrently \"npm run start:docs\" \"ng serve\"", - "build": "ng build", + "build": "ng build gantt", "test": "ng test", "lint": "ng lint", - "e2e": "ng e2e" + "e2e": "ng e2e", + "pub-only": "cd dist/gantt && npm publish --access=public", + "pub": "npm run build && npm run pub-only" }, "private": true, "dependencies": { diff --git a/packages/gantt/src/bar/bar-drag.ts b/packages/gantt/src/bar/bar-drag.ts index ee0de90d..f142234c 100644 --- a/packages/gantt/src/bar/bar-drag.ts +++ b/packages/gantt/src/bar/bar-drag.ts @@ -208,10 +208,10 @@ export class GanttBarDrag implements OnDestroy { } private closeDragBackdrop() { - const dragMaskElement = this.dom.root.querySelector('.gantt-drag-mask') as HTMLElement; - const dragBackdropElement = this.dom.root.querySelector('.gantt-drag-backdrop') as HTMLElement; - dragMaskElement.style.display = 'none'; - dragBackdropElement.style.display = 'none'; + // const dragMaskElement = this.dom.root.querySelector('.gantt-drag-mask') as HTMLElement; + // const dragBackdropElement = this.dom.root.querySelector('.gantt-drag-backdrop') as HTMLElement; + // dragMaskElement.style.display = 'none'; + // dragBackdropElement.style.display = 'none'; } private setDraggingStyles() { diff --git a/packages/gantt/src/calendar/calendar.component.html b/packages/gantt/src/calendar/calendar.component.html index 10e11756..a741116e 100644 --- a/packages/gantt/src/calendar/calendar.component.html +++ b/packages/gantt/src/calendar/calendar.component.html @@ -1,11 +1,14 @@ - +
+ + + + + + +
+ - + {{ point.text }} - + @@ -69,16 +66,5 @@ > - - - - diff --git a/packages/gantt/src/calendar/calendar.component.scss b/packages/gantt/src/calendar/calendar.component.scss index 8d481ad4..0baa8a98 100644 --- a/packages/gantt/src/calendar/calendar.component.scss +++ b/packages/gantt/src/calendar/calendar.component.scss @@ -1,54 +1,67 @@ .gantt-calendar-overlay { - display: block; - height: 100%; - overflow: hidden; - - line { - shape-rendering: crispEdges; - } - - .primary-text { - fill: $gantt-date-primary-color; - font-size: $gantt-date-primary-font-size; - } - - .secondary-text { - fill: $gantt-date-secondary-color; - font-size: $gantt-date-secondary-font-size; - - &-weekend { - fill: $gantt-date-secondary-weekend-color; - } - } - - .primary-text, - .secondary-text { - text-anchor: middle; - } - - .primary-line { - stroke: $gantt-border-color; - } - - .secondary-line { - stroke-dasharray: 2px 3px; - stroke:$gantt-border-color; - } - - .header-line { - stroke: $gantt-border-color; - } - - .secondary-backdrop { - fill: $gantt-date-week-backdrop-bg; - } - - .today-line-angle { - fill: $gantt-date-today-color; - } - - .today-line { - stroke: $gantt-date-today-color; - stroke-width: 2px; - } + display: block; + height: 100%; + overflow: hidden; + + .gantt-calendar-today-overlay { + height: 0; + position: relative; + z-index: 1; + svg{ + display: block; + } + } + + svg { + overflow: visible; + } + + line { + shape-rendering: crispEdges; + } + + .primary-text { + fill: $gantt-date-primary-color; + font-size: $gantt-date-primary-font-size; + } + + .secondary-text { + fill: $gantt-date-secondary-color; + font-size: $gantt-date-secondary-font-size; + + &-weekend { + fill: $gantt-date-secondary-weekend-color; + } + } + + .primary-text, + .secondary-text { + text-anchor: middle; + } + + .primary-line { + stroke: $gantt-border-color; + } + + .secondary-line { + stroke-dasharray: 2px 3px; + stroke: $gantt-border-color; + } + + .header-line { + stroke: $gantt-border-color; + } + + .secondary-backdrop { + fill: $gantt-date-week-backdrop-bg; + } + + .today-line-angle { + fill: $gantt-date-today-color; + } + + .today-line { + stroke: $gantt-date-today-color; + stroke-width: 2px; + } } diff --git a/packages/gantt/src/calendar/calendar.component.ts b/packages/gantt/src/calendar/calendar.component.ts index f693610a..f1696845 100644 --- a/packages/gantt/src/calendar/calendar.component.ts +++ b/packages/gantt/src/calendar/calendar.component.ts @@ -1,9 +1,12 @@ import { Component, OnInit, HostBinding, OnChanges, SimpleChanges, ChangeDetectorRef, OnDestroy, NgZone, Inject } from '@angular/core'; import { GanttDatePoint } from '../class/date-point'; import { Subject } from 'rxjs'; -import { take } from 'rxjs/operators'; +import { take, takeUntil } from 'rxjs/operators'; import { GanttRef, GANTT_REF_TOKEN } from '../gantt-ref'; import { headerHeight } from '../gantt.styles'; +import { isNumber } from '../utils/helpers'; +import { GanttDate } from '../utils/date'; +import { GanttDomService } from 'ngx-gantt/gantt-dom.service'; @Component({ selector: 'gantt-calendar-overlay', @@ -16,6 +19,7 @@ export class GanttCalendarComponent implements OnInit, OnChanges, OnDestroy { public todayPoint: { x: number; + y: number; angle: string; text: string; }; @@ -30,13 +34,42 @@ export class GanttCalendarComponent implements OnInit, OnChanges, OnDestroy { @HostBinding('class.gantt-calendar-overlay') className = true; - constructor(@Inject(GANTT_REF_TOKEN) private ganttRef: GanttRef, private cdr: ChangeDetectorRef, private ngZone: NgZone) {} + constructor( + @Inject(GANTT_REF_TOKEN) private ganttRef: GanttRef, + private cdr: ChangeDetectorRef, + private ngZone: NgZone, + private dom: GanttDomService + ) {} + + private computeTodayPoint() { + const x = this.view.getTodayXPoint(); + if (isNumber(x)) { + this.todayPoint = { + x, + y: this.dom.root.clientHeight, + angle: [`${x - 6},0`, `${x + 5},0`, `${x},5`].join(' '), + text: new GanttDate().format('MM月d日') + }; + } + } ngOnInit() { this.ngZone.onStable.pipe(take(1)).subscribe(() => { - this.cdr.detectChanges(); - this.firstChange = false; + this.ganttRef.view.start$.pipe(takeUntil(this.unsubscribe$)).subscribe(() => { + this.computeTodayPoint(); + this.cdr.detectChanges(); + }); }); + + this.firstChange = false; + + this.dom + .getResize() + .pipe(takeUntil(this.unsubscribe$)) + .subscribe(() => { + this.todayPoint.y = this.dom.root.clientHeight; + this.cdr.detectChanges(); + }); } ngOnChanges(changes: SimpleChanges): void {} diff --git a/packages/gantt/src/gantt-dom.service.ts b/packages/gantt/src/gantt-dom.service.ts index 19b6175f..8423d08b 100644 --- a/packages/gantt/src/gantt-dom.service.ts +++ b/packages/gantt/src/gantt-dom.service.ts @@ -94,7 +94,7 @@ export class GanttDomService implements OnDestroy { return fromEvent(window, 'resize').pipe(auditTime(30)); } - scrollViewer(left: number) { + scrollMainContainer(left: number) { if (isNumber(left)) { const scrollLeft = left - this.mainContainer.clientWidth / 2; this.mainContainer.scrollLeft = scrollLeft > scrollThreshold ? scrollLeft : 0; diff --git a/packages/gantt/src/gantt-upper.ts b/packages/gantt/src/gantt-upper.ts index a83337ab..ed9d9d97 100644 --- a/packages/gantt/src/gantt-upper.ts +++ b/packages/gantt/src/gantt-upper.ts @@ -100,6 +100,9 @@ export abstract class GanttUpper { this.onStable().subscribe(() => { this.dom.initialize(this.elementRef); this.setupViewScroll(); + this.scrollToToday(); + // 优化初始化时Scroll滚动体验问题,通过透明度解决,默认透明度为0,滚动结束后恢复 + this.element.style.opacity = '1'; }); this.view.start$.pipe(takeUntil(this.unsubscribe$)).subscribe(() => { @@ -161,7 +164,9 @@ export abstract class GanttUpper { if (this.groups.length > 0) { this.originItems.forEach((origin) => { const group = this.groupsMap[origin.group_id]; - group.items.push(new GanttItemInternal(origin)); + if (group) { + group.items.push(new GanttItemInternal(origin)); + } }); } else { this.originItems.forEach((origin) => { @@ -213,5 +218,8 @@ export abstract class GanttUpper { return this.ngZone.onStable.pipe(take(1)); } - private scrollToToday() {} + private scrollToToday() { + const x = this.view.getTodayXPoint(); + this.dom.scrollMainContainer(x); + } } diff --git a/packages/gantt/src/gantt.component.html b/packages/gantt/src/gantt.component.html index 90f4133c..74ad4d78 100644 --- a/packages/gantt/src/gantt.component.html +++ b/packages/gantt/src/gantt.component.html @@ -2,6 +2,6 @@
- +
diff --git a/packages/gantt/src/gantt.scss b/packages/gantt/src/gantt.scss index 71227bce..15c88831 100644 --- a/packages/gantt/src/gantt.scss +++ b/packages/gantt/src/gantt.scss @@ -44,6 +44,7 @@ $gantt-date-today-color: #ff9f73 !default; overflow: hidden; display: flex; color: $gantt-color; + opacity: 0; .gantt-side { border-right: 1px solid $gantt-border-color; @@ -51,6 +52,7 @@ $gantt-date-today-color: #ff9f73 !default; z-index: 1; overflow: auto; + &-has-shadow { box-shadow: $gantt-side-shadow; } diff --git a/packages/gantt/src/public-api.ts b/packages/gantt/src/public-api.ts index f9ea6ce3..90c68e9b 100644 --- a/packages/gantt/src/public-api.ts +++ b/packages/gantt/src/public-api.ts @@ -3,5 +3,5 @@ */ export * from './gantt.module'; -export * from './table/gantt-table.component'; -export * from './flat/gantt-flat.component'; +export * from './gantt.component'; +export * from './table/column/column.component';