fix highlighting bugs

This commit is contained in:
safwansamsudeen 2024-12-02 11:52:44 +05:30
parent 2eaa127c5b
commit 8c526b5ed6

View File

@ -201,7 +201,8 @@ export default class Gantt {
let { duration, scale } = date_utils.parse_duration(mode.step); let { duration, scale } = date_utils.parse_duration(mode.step);
this.config.step = duration; this.config.step = duration;
this.config.unit = scale; this.config.unit = scale;
this.config.column_width = mode.column_width || 38; this.config.column_width =
mode.column_width || this.options.column_width;
} }
setup_dates() { setup_dates() {
@ -526,7 +527,6 @@ export default class Gantt {
class: tick_class, class: tick_class,
append_to: this.layers.grid, append_to: this.layers.grid,
}); });
if (this.view_is(VIEW_MODE.MONTH)) { if (this.view_is(VIEW_MODE.MONTH)) {
tick_x += tick_x +=
(date_utils.get_days_in_month(date) * (date_utils.get_days_in_month(date) *
@ -547,7 +547,7 @@ export default class Gantt {
) { ) {
if (d.getDay() === 0 || d.getDay() === 6) { if (d.getDay() === 0 || d.getDay() === 6) {
const x = const x =
(date_utils.diff(d, this.gantt_start, 'hour') / (date_utils.diff(d, this.gantt_start, this.config.unit) /
this.config.step) * this.config.step) *
this.config.column_width; this.config.column_width;
const height = const height =
@ -573,19 +573,19 @@ export default class Gantt {
* @returns Object containing the x-axis distance and date of the current date, or null if the current date is out of the gantt range. * @returns Object containing the x-axis distance and date of the current date, or null if the current date is out of the gantt range.
*/ */
computeGridHighlightDimensions(view_mode) { computeGridHighlightDimensions(view_mode) {
const todayDate = new Date(); const today = new Date();
if (todayDate < this.gantt_start || todayDate > this.gantt_end) if (today < this.gantt_start || today > this.gantt_end) return null;
return null;
let x = this.config.column_width / 2;
if (this.view_is(VIEW_MODE.DAY)) { if (this.view_is(VIEW_MODE.DAY)) {
let diff_in_units = date_utils.diff(
today,
this.gantt_start,
this.config.unit,
);
return { return {
x: x:
x + (diff_in_units / this.config.step) *
(date_utils.diff(today, this.gantt_start, 'hour') / this.config.column_width,
this.config.step) *
this.config.column_width,
date: today, date: today,
}; };
} }
@ -631,7 +631,6 @@ export default class Gantt {
); );
if (!highlightDimensions) return; if (!highlightDimensions) return;
const { x: left, date } = highlightDimensions; const { x: left, date } = highlightDimensions;
if (!this.dates.find((d) => d.getTime() == date.getTime())) return;
const top = this.options.header_height + this.options.padding / 2; const top = this.options.header_height + this.options.padding / 2;
const height = const height =
(this.options.bar_height + this.options.padding) * (this.options.bar_height + this.options.padding) *
@ -819,18 +818,19 @@ export default class Gantt {
} else if (typeof date === 'string') { } else if (typeof date === 'string') {
date = date_utils.parse(date); date = date_utils.parse(date);
} }
const parent_element = this.$svg.parentElement; const parent_element = this.$svg.parentElement;
if (!parent_element) return; if (!parent_element) return;
const units_since_first_task = date_utils.diff(
const hours_before_first_task = date,
date_utils.diff(date, this.gantt_start, 'hour') + 24; this.gantt_start,
this.config.unit,
);
const scroll_pos = const scroll_pos =
(hours_before_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;
parent_element.scrollTo({ left: scroll_pos, behavior: 'smooth' }); console.log(scroll_pos);
parent_element.scrollTo({ left: 400, behavior: 'smooth' });
} }
scroll_today() { scroll_today() {
@ -1143,10 +1143,10 @@ export default class Gantt {
} }
if (Array.isArray(modes)) { if (Array.isArray(modes)) {
return modes.some((mode) => this.config.view_mode.name === mode); return modes.some(view_is);
} }
return false; return this.config.view_mode.name === modes.name;
} }
get_task(id) { get_task(id) {