Skip to content

Commit

Permalink
Merge pull request #475 from MercurialUroboros/fix/highlight-issues
Browse files Browse the repository at this point in the history
fix: issues with highlight system and todayDate.
  • Loading branch information
safwansamsudeen authored Dec 2, 2024
2 parents 8f03ba0 + 440d717 commit 79b0e0d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,15 +305,15 @@ export default class Bar {
(timeout = setTimeout(() => {
this.show_popup(e.offsetX || e.layerX);
document.getElementById(
`${task_id}-highlight`,
`highlight-${task_id}`,
).style.display = 'block';
}, 200)),
);

$.on(this.group, 'mouseleave', () => {
clearTimeout(timeout);
this.gantt.popup?.hide?.();
document.getElementById(`${task_id}-highlight`).style.display =
document.getElementById(`highlight-${task_id}`).style.display =
'none';
});
}
Expand Down
3 changes: 1 addition & 2 deletions src/date_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const MINUTE = 'minute';
const SECOND = 'second';
const MILLISECOND = 'millisecond';


export default {
parse_duration(duration) {
const regex = /([0-9]+)(y|m|d|h|min|s|ms)/gm;
Expand Down Expand Up @@ -84,7 +83,7 @@ export default {
month: 'long',
});
const dateTimeFormatShort = new Intl.DateTimeFormat(lang, {
month: "short",
month: 'short',
});
const month_name = dateTimeFormat.format(date);
const month_name_capitalized =
Expand Down
20 changes: 11 additions & 9 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -689,24 +689,25 @@ export default class Gantt {
}

/**
* Compute the horizontal x-axis distance and associated date for the current date and view.
*
* @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.
*/
* Compute the horizontal x-axis distance and associated date for the current date and view.
*
* @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) {
const todayDate = new Date();
if (todayDate < this.gantt_start || todayDate > this.gantt_end) return null;
if (todayDate < this.gantt_start || todayDate > this.gantt_end)
return null;

let x = this.options.column_width / 2;

if (this.view_is(VIEW_MODE.DAY)) {
return {
x:
x +
(date_utils.diff(today, this.gantt_start, 'hour') /
(date_utils.diff(todayDate, this.gantt_start, 'hour') /
this.options.step) *
this.options.column_width,
date: today,
date: todayDate,
};
}

Expand Down Expand Up @@ -746,7 +747,9 @@ export default class Gantt {
this.view_is(VIEW_MODE.YEAR)
) {
// Used as we must find the _end_ of session if view is not Day
const highlightDimensions = this.computeGridHighlightDimensions(this.options.view_mode);
const highlightDimensions = this.computeGridHighlightDimensions(
this.options.view_mode,
);
if (!highlightDimensions) return;
const { x: left, date } = highlightDimensions;
if (!this.dates.find((d) => d.getTime() == date.getTime())) return;
Expand Down Expand Up @@ -1147,7 +1150,6 @@ export default class Gantt {
}

bar_wrapper.classList.add('active');
if (this.popup) this.popup.parent.classList.add('hidden');

if (this.popup) this.popup.parent.classList.add('hidden');

Expand Down

0 comments on commit 79b0e0d

Please sign in to comment.