Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gantt): the fast right (left) dragging start (end) time, the width of the bar is wrong #INFR-7111 #351

Merged
merged 3 commits into from
Apr 11, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions packages/gantt/src/components/bar/bar-drag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ export class GanttBarDrag implements OnDestroy {
/** Horizontal direction in which the list is currently scrolling. */
private _horizontalScrollDirection = AutoScrollHorizontalDirection.NONE;

private flagDays = 0;

constructor(
private dragDrop: DragDrop,
private dom: GanttDomService,
Expand Down Expand Up @@ -376,9 +378,16 @@ export class GanttBarDrag implements OnDestroy {

this.item.updateDate(start, this.item.end);
} else {
if (this.flagDays > 0 && days <= 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (this.flagDays > 0 && days <= 0) { 这个判断有点多余,直接去掉这样处理也没问题

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Copy link
Contributor Author

@minlovehua minlovehua Apr 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我们只需要在days第一次变成负数之后执行style修改。
如果没有这个判断的话,只要时间条一直往反方向拖(开始大于截止或截止小于开始),days就会一直是<0,就会不断进来执行这段style修改,不好。

const oneDayWidth = this.ganttUpper.view.getDateRangeWidth(this.item.end.startOfDay(), this.item.end);
this.barElement.style.width = oneDayWidth + 'px';
const x = this.ganttUpper.view.getXPointByDate(this.item.end);
this.barElement.style.left = x + 'px';
}
this.openDragBackdrop(this.barElement, this.item.end.startOfDay(), this.item.end);
this.item.updateDate(this.item.end.startOfDay(), this.item.end);
}
this.flagDays = days;
} else {
const width = this.item.refs.width + distance;
const end = this.ganttUpper.view.getDateByXPoint(this.item.refs.x + width);
Expand All @@ -392,9 +401,14 @@ export class GanttBarDrag implements OnDestroy {
}
this.item.updateDate(this.item.start, end);
} else {
if (this.flagDays > 0 && days <= 0) {
const oneDayWidth = this.ganttUpper.view.getDateRangeWidth(this.item.start, this.item.start.endOfDay());
this.barElement.style.width = oneDayWidth + 'px';
}
this.openDragBackdrop(this.barElement, this.item.start, this.item.start.endOfDay());
this.item.updateDate(this.item.start, this.item.start.endOfDay());
}
this.flagDays = days;
}
this.dragContainer.dragMoved.emit({ item: this.item.origin });
}
Expand Down