From f8d77b2a7316fa7fe03ef5e2eb6e7fb8af268847 Mon Sep 17 00:00:00 2001 From: Safwan Samsudeen Date: Wed, 11 Sep 2024 20:40:08 +0530 Subject: [PATCH] fix: today highlight bug --- src/date_utils.js | 1 - src/index.js | 17 +++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/date_utils.js b/src/date_utils.js index 716d2ae..4d2e4f0 100644 --- a/src/date_utils.js +++ b/src/date_utils.js @@ -25,7 +25,6 @@ export default { parse_duration(duration) { const regex = /([0-9]+)(y|m|d|h|min|s|ms)/gm; const matches = regex.exec(duration); - console.log(matches); if (matches !== null) { if (matches[2] === 'y') { return { duration: parseInt(matches[1]), scale: `year` }; diff --git a/src/index.js b/src/index.js index f8ff9f0..a94e8cc 100644 --- a/src/index.js +++ b/src/index.js @@ -516,7 +516,6 @@ export default class Gantt { const { left, y } = this.$header.getBoundingClientRect(); // Check if the button is scrolled out of the container vertically - console.log('heyy'); if ( buttonRect.top < containerRect.top || buttonRect.bottom > containerRect.bottom @@ -640,12 +639,18 @@ export default class Gantt { } } - //compute the horizontal x distance + /** + * 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; + let x = this.options.column_width / 2; if (this.view_is(VIEW_MODE.DAY)) { - let today = date_utils.today(); return { x: x + @@ -689,9 +694,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 { x: left, date } = 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; const top = this.options.header_height + this.options.padding / 2; const height =