feat: snap_by_day option
This commit is contained in:
parent
8c526b5ed6
commit
c13c0cde4d
57
src/bar.js
57
src/bar.js
@ -538,13 +538,6 @@ export default class Bar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
compute_duration() {
|
compute_duration() {
|
||||||
console.log(
|
|
||||||
date_utils.diff(
|
|
||||||
this.task._end,
|
|
||||||
this.task._start,
|
|
||||||
this.gantt.config.unit,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
this.duration =
|
this.duration =
|
||||||
date_utils.diff(
|
date_utils.diff(
|
||||||
this.task._end,
|
this.task._end,
|
||||||
@ -558,31 +551,31 @@ export default class Bar {
|
|||||||
rem,
|
rem,
|
||||||
position;
|
position;
|
||||||
|
|
||||||
if (this.gantt.view_is('Week')) {
|
// if (this.gantt.view_is('Week')) {
|
||||||
rem = dx % (this.gantt.config.column_width / 7);
|
// rem = dx % (this.gantt.config.column_width / 7);
|
||||||
position =
|
// position =
|
||||||
odx -
|
// odx -
|
||||||
rem +
|
// rem +
|
||||||
(rem < this.gantt.config.column_width / 14
|
// (rem < this.gantt.config.column_width / 14
|
||||||
? 0
|
// ? 0
|
||||||
: this.gantt.config.column_width / 7);
|
// : this.gantt.config.column_width / 7);
|
||||||
} else if (this.gantt.view_is('Month')) {
|
// } else if (this.gantt.view_is('Month')) {
|
||||||
rem = dx % (this.gantt.config.column_width / 30);
|
// rem = dx % (this.gantt.config.column_width / 30);
|
||||||
position =
|
// position =
|
||||||
odx -
|
// odx -
|
||||||
rem +
|
// rem +
|
||||||
(rem < this.gantt.config.column_width / 60
|
// (rem < this.gantt.config.column_width / 60
|
||||||
? 0
|
// ? 0
|
||||||
: this.gantt.config.column_width / 30);
|
// : this.gantt.config.column_width / 30);
|
||||||
} else {
|
// } else {
|
||||||
rem = dx % this.gantt.config.column_width;
|
rem = dx % this.gantt.config.column_width;
|
||||||
position =
|
position =
|
||||||
odx -
|
odx -
|
||||||
rem +
|
rem +
|
||||||
(rem < this.gantt.config.column_width / 2
|
(rem < this.gantt.config.column_width / 2
|
||||||
? 0
|
? 0
|
||||||
: this.gantt.config.column_width);
|
: this.gantt.config.column_width);
|
||||||
}
|
// }
|
||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -110,6 +110,7 @@ const DEFAULT_OPTIONS = {
|
|||||||
auto_move_label: true,
|
auto_move_label: true,
|
||||||
today_button: true,
|
today_button: true,
|
||||||
view_mode_select: false,
|
view_mode_select: false,
|
||||||
|
snap_by_day: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
export { DEFAULT_OPTIONS, DEFAULT_VIEW_MODES };
|
export { DEFAULT_OPTIONS, DEFAULT_VIEW_MODES };
|
||||||
|
|||||||
53
src/index.js
53
src/index.js
@ -575,7 +575,6 @@ export default class Gantt {
|
|||||||
computeGridHighlightDimensions(view_mode) {
|
computeGridHighlightDimensions(view_mode) {
|
||||||
const today = new Date();
|
const today = new Date();
|
||||||
if (today < this.gantt_start || today > this.gantt_end) return null;
|
if (today < this.gantt_start || today > this.gantt_end) return null;
|
||||||
|
|
||||||
if (this.view_is(VIEW_MODE.DAY)) {
|
if (this.view_is(VIEW_MODE.DAY)) {
|
||||||
let diff_in_units = date_utils.diff(
|
let diff_in_units = date_utils.diff(
|
||||||
today,
|
today,
|
||||||
@ -590,18 +589,19 @@ export default class Gantt {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let x = 0;
|
||||||
for (let date of this.dates) {
|
for (let date of this.dates) {
|
||||||
const todayDate = new Date();
|
const todayDate = new Date();
|
||||||
const startDate = new Date(date);
|
const startDate = new Date(date);
|
||||||
const endDate = new Date(date);
|
const endDate = new Date(date);
|
||||||
switch (view_mode) {
|
switch (view_mode.name) {
|
||||||
case VIEW_MODE.WEEK:
|
case VIEW_MODE.WEEK.name:
|
||||||
endDate.setDate(date.getDate() + 7);
|
endDate.setDate(date.getDate() + 7);
|
||||||
break;
|
break;
|
||||||
case VIEW_MODE.MONTH:
|
case VIEW_MODE.MONTH.name:
|
||||||
endDate.setMonth(date.getMonth() + 1);
|
endDate.setMonth(date.getMonth() + 1);
|
||||||
break;
|
break;
|
||||||
case VIEW_MODE.YEAR:
|
case VIEW_MODE.YEAR.name:
|
||||||
endDate.setFullYear(date.getFullYear() + 1);
|
endDate.setFullYear(date.getFullYear() + 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -829,7 +829,6 @@ export default class Gantt {
|
|||||||
(units_since_first_task / this.config.step) *
|
(units_since_first_task / this.config.step) *
|
||||||
this.config.column_width -
|
this.config.column_width -
|
||||||
this.config.column_width;
|
this.config.column_width;
|
||||||
console.log(scroll_pos);
|
|
||||||
parent_element.scrollTo({ left: 400, behavior: 'smooth' });
|
parent_element.scrollTo({ left: 400, behavior: 'smooth' });
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1101,32 +1100,24 @@ export default class Gantt {
|
|||||||
let odx = dx,
|
let odx = dx,
|
||||||
rem,
|
rem,
|
||||||
position;
|
position;
|
||||||
|
let unit_length = 1;
|
||||||
if (this.view_is(VIEW_MODE.WEEK)) {
|
if (this.options.snap_by_day) {
|
||||||
rem = dx % (this.config.column_width / 7);
|
const { duration, scale } = date_utils.parse_duration(
|
||||||
position =
|
this.config.view_mode.step,
|
||||||
odx -
|
);
|
||||||
rem +
|
unit_length =
|
||||||
(rem < this.config.column_width / 14
|
duration *
|
||||||
? 0
|
({ hour: 1 / 24, week: 7, month: 30, year: 365 }[scale] || 1);
|
||||||
: this.config.column_width / 7);
|
|
||||||
} else if (this.view_is(VIEW_MODE.MONTH)) {
|
|
||||||
rem = dx % (this.config.column_width / 30);
|
|
||||||
position =
|
|
||||||
odx -
|
|
||||||
rem +
|
|
||||||
(rem < this.config.column_width / 60
|
|
||||||
? 0
|
|
||||||
: this.config.column_width / 30);
|
|
||||||
} else {
|
|
||||||
rem = dx % this.config.column_width;
|
|
||||||
position =
|
|
||||||
odx -
|
|
||||||
rem +
|
|
||||||
(rem < this.config.column_width / 2
|
|
||||||
? 0
|
|
||||||
: this.config.column_width);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rem = dx % (this.config.column_width / unit_length);
|
||||||
|
position =
|
||||||
|
odx -
|
||||||
|
rem +
|
||||||
|
(rem < this.config.column_width / unit_length / 2
|
||||||
|
? 0
|
||||||
|
: this.config.column_width / unit_length);
|
||||||
|
|
||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user