Skip to content

Commit

Permalink
feat: support dragMinWidth in view options #INFR-6074
Browse files Browse the repository at this point in the history
  • Loading branch information
HandsomeButterball committed Feb 1, 2023
1 parent d583aaf commit 61374e4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
3 changes: 2 additions & 1 deletion example/src/app/gantt-custom-view/custom-day-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ const viewOptions: GanttViewOptions = {
end: new GanttDate().endOfYear().endOfWeek({ weekStartsOn: 1 }),
addAmount: 1,
addUnit: 'month',
fillDays: 1
fillDays: 1,
dragMinWidth: 50
};

export class GanttViewCustom extends GanttView {
Expand Down
9 changes: 5 additions & 4 deletions packages/gantt/src/components/bar/bar-drag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export class GanttBarDrag implements OnDestroy {
private createBarHandleDrags() {
const dragRefs = [];
const handles = this.barElement.querySelectorAll<HTMLElement>('.drag-handles .handle');
const minWidth = this.ganttUpper.view.options.dragMinWidth || dragMinWidth;
handles.forEach((handle, index) => {
const isBefore = index === 0;
const dragRef = this.dragDrop.createDrag(handle);
Expand All @@ -149,7 +150,7 @@ export class GanttBarDrag implements OnDestroy {
const x = this.item.refs.x + event.distance.x;
const width = this.item.refs.width + event.distance.x * -1;
const start = this.ganttUpper.view.getDateByXPoint(x);
if (width > dragMinWidth) {
if (width > minWidth) {
this.barElement.style.width = width + 'px';
this.barElement.style.left = x + 'px';
this.openDragBackdrop(this.barElement, start, this.item.end);
Expand All @@ -158,7 +159,7 @@ export class GanttBarDrag implements OnDestroy {
} else {
const width = this.item.refs.width + event.distance.x;
const end = this.ganttUpper.view.getDateByXPoint(this.item.refs.x + width);
if (width > dragMinWidth) {
if (width > minWidth) {
this.barElement.style.width = width + 'px';
this.openDragBackdrop(this.barElement, this.item.start, end);
this.item.updateDate(this.item.start, end);
Expand All @@ -171,12 +172,12 @@ export class GanttBarDrag implements OnDestroy {
dragRef.ended.subscribe((event) => {
if (isBefore) {
const width = this.item.refs.width + event.distance.x * -1;
if (width <= dragMinWidth) {
if (width <= minWidth) {
this.item.updateDate(this.item.end.startOfDay(), this.item.end);
}
} else {
const width = this.item.refs.width + event.distance.x;
if (width <= dragMinWidth) {
if (width <= minWidth) {
this.item.updateDate(this.item.start, this.item.start.endOfDay());
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/gantt/src/views/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface GanttViewOptions {
addAmount?: number;
addUnit?: GanttDateUtil;
dateFormat?: GanttDateFormat;
dragMinWidth?: number;
// fill days when start or end is null
fillDays?: number;
// custom key and value
Expand Down Expand Up @@ -84,7 +85,6 @@ export abstract class GanttView {

// 获取一级时间网格合并后的宽度
abstract getPrimaryWidth(): number;

// 获取当前视图下每一天占用的宽度
abstract getDayOccupancyWidth(date: GanttDate): number;

Expand Down

0 comments on commit 61374e4

Please sign in to comment.