Skip to content

Commit

Permalink
fix: fix demo and support GanttDate in scrollToDate #INFR-4334
Browse files Browse the repository at this point in the history
  • Loading branch information
HandsomeButterball authored and walkerkay committed Aug 22, 2022
1 parent 71220d7 commit 4f339d7
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 19 deletions.
3 changes: 0 additions & 3 deletions example/src/app/gantt/gantt.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
     
<thy-button thyType="primary" thySize="sm" (click)="print('gantt-example')"> ↓ 导出为图片 </thy-button>
&nbsp; &nbsp; &nbsp;
<span>滚动到:</span>
<thy-date-picker [(ngModel)]="date" (ngModelChange)="dateChange($event)" [thyAllowClear]="false"> </thy-date-picker>
&nbsp; &nbsp; &nbsp;
<span>基线对比:</span>
<thy-switch class="baseline-switch" [(ngModel)]="isBaselineChecked" (ngModelChange)="switchChange()">基线对比 </thy-switch>
</ng-template>
Expand Down
15 changes: 6 additions & 9 deletions example/src/app/gantt/gantt.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, OnInit, HostBinding, ViewChild } from '@angular/core';
import { Component, OnInit, HostBinding, ViewChild, AfterViewInit } from '@angular/core';
import {
GanttBarClickEvent,
GanttViewType,
Expand All @@ -21,7 +21,7 @@ import { randomItems, random } from '../helper';
templateUrl: './gantt.component.html',
providers: [GanttPrintService]
})
export class AppGanttExampleComponent implements OnInit {
export class AppGanttExampleComponent implements OnInit, AfterViewInit {
views = [
{
name: '日',
Expand Down Expand Up @@ -94,8 +94,6 @@ export class AppGanttExampleComponent implements OnInit {
}
};

date = new Date();

@HostBinding('class.gantt-example-component') class = true;

@ViewChild('gantt') ganttComponent: NgxGanttComponent;
Expand All @@ -109,6 +107,10 @@ export class AppGanttExampleComponent implements OnInit {

ngOnInit(): void {}

ngAfterViewInit() {
setTimeout(() => this.ganttComponent.scrollToDate(1627729997), 200);
}

barClick(event: GanttBarClickEvent) {
this.thyNotify.info('Event: barClick', `你点击了 [${event.item.title}]`);
}
Expand Down Expand Up @@ -141,14 +143,9 @@ export class AppGanttExampleComponent implements OnInit {
}

scrollToToday() {
this.date = new Date();
this.ganttComponent.scrollToToday();
}

dateChange(event: number) {
this.ganttComponent.scrollToDate(event);
}

switchChange() {
if (this.isBaselineChecked) {
this.baselineItems = [
Expand Down
3 changes: 0 additions & 3 deletions example/src/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,5 @@ $primary: #348fe4;
.baseline-switch {
display: flex;
}
.thy-calendar-picker {
width: 120px;
}
}
}
3 changes: 2 additions & 1 deletion packages/gantt/src/gantt.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { GANTT_ABSTRACT_TOKEN } from './gantt-abstract';
import { defaultColumnWidth } from './components/table/gantt-table.component';
import { GanttGlobalConfig, GANTT_GLOBAL_CONFIG } from './gantt.config';
import { NgxGanttRootComponent } from './root.component';
import { GanttDate } from './utils/date';
@Component({
selector: 'ngx-gantt',
templateUrl: './gantt.component.html',
Expand Down Expand Up @@ -161,7 +162,7 @@ export class NgxGanttComponent extends GanttUpper implements OnInit, AfterViewIn
this.ganttRoot.scrollToToday();
}

scrollToDate(date: number) {
scrollToDate(date: number | GanttDate) {
this.ganttRoot.scrollToDate(date);
}
}
12 changes: 9 additions & 3 deletions packages/gantt/src/root.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { GanttUpper, GANTT_UPPER_TOKEN } from './gantt-upper';
import { GanttPrintService } from './gantt-print.service';
import { passiveListenerOptions } from './utils/passive-listeners';
import { GanttDragBackdropComponent } from './components/drag-backdrop/drag-backdrop.component';
import { GanttDate } from './public-api';
import { GanttDate } from './utils/date';

@Component({
selector: 'ngx-gantt-root',
Expand Down Expand Up @@ -139,8 +139,14 @@ export class NgxGanttRootComponent implements OnInit, OnDestroy {
this.dom.scrollMainContainer(x);
}

public scrollToDate(date: number) {
const x = this.view.getXPointByDate(new GanttDate(date));
public scrollToDate(date: number | GanttDate) {
let x: number;
if (typeof date === 'number') {
x = this.view.getXPointByDate(new GanttDate(date));
} else {
x = this.view.getXPointByDate(date);
}

this.dom.scrollMainContainer(x);
}
}

0 comments on commit 4f339d7

Please sign in to comment.