Skip to content

Commit

Permalink
fix: fix date calc logic of overall drag bar
Browse files Browse the repository at this point in the history
  • Loading branch information
walkerkay committed Feb 24, 2022
1 parent 5fba2f8 commit 8ade33b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
20 changes: 12 additions & 8 deletions packages/gantt/src/components/bar/bar-drag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,22 @@ export class GanttBarDrag implements OnDestroy {
this.dragContainer.dragStarted.emit({ item: this.item.origin });
});
dragRef.moved.subscribe((event) => {
const x = this.item.refs.x + event.distance.x;
const start = this.ganttUpper.view.getDateByXPoint(x);
const end = this.ganttUpper.view.getDateByXPoint(x + this.item.refs.width);
this.openDragBackdrop(this.barElement, this.ganttUpper.view.getDateByXPoint(x), end);
const currentX = this.item.refs.x + event.distance.x;
const currentDate = this.ganttUpper.view.getDateByXPoint(currentX);
const currentStartX = this.ganttUpper.view.getXPointByDate(currentDate);
const dayWidth = this.ganttUpper.view.getDayOccupancyWidth(currentDate);
const diffDays = differenceInCalendarDays(this.item.end.value, this.item.start.value);
let start = currentDate;
let end = currentDate.addDays(diffDays);
if (currentX > currentStartX + dayWidth / 2) {
start = start.addDays(1);
end = end.addDays(1);
}
this.openDragBackdrop(this.barElement, start, end);
this.item.updateDate(start, end);
this.dragContainer.dragMoved.emit({ item: this.item.origin });
});
dragRef.ended.subscribe((event) => {
const days = differenceInCalendarDays(this.item.end.value, this.item.start.value);
const start = this.ganttUpper.view.getDateByXPoint(this.item.refs.x + event.distance.x);
const end = start.addDays(days);
this.item.updateDate(start, end);
this.clearDraggingStyles();
this.closeDragBackdrop();
event.source.reset();
Expand Down
4 changes: 2 additions & 2 deletions packages/gantt/src/components/links/links.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
OnChanges
} from '@angular/core';
import { merge, Subject } from 'rxjs';
import { takeUntil, skip } from 'rxjs/operators';
import { takeUntil, skip, debounceTime } from 'rxjs/operators';
import { GanttGroupInternal } from '../../class/group';
import { GanttItemInternal, GanttItem } from './../../class/item';
import { GanttLineClickEvent } from '../../class/event';
Expand Down Expand Up @@ -89,7 +89,7 @@ export class GanttLinksComponent implements OnInit, OnChanges, OnDestroy {
this.ganttUpper.dragEnded,
this.ganttUpper.linkDragEnded
)
.pipe(takeUntil(this.unsubscribe$), skip(1))
.pipe(takeUntil(this.unsubscribe$), skip(1), debounceTime(0))
.subscribe(() => {
this.elementRef.nativeElement.style.visibility = 'visible';
this.buildLinks();
Expand Down

0 comments on commit 8ade33b

Please sign in to comment.