Skip to content

Commit

Permalink
feat: scroll to today
Browse files Browse the repository at this point in the history
  • Loading branch information
safwansamsudeen committed Apr 14, 2024
1 parent 94d2cf5 commit 0ebea3d
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export default class Gantt {
language: "en",
readonly: false,
highlight_weekend: true,
scroll_today: true
};
this.options = Object.assign({}, default_options, options);
if (!options.view_mode_padding) options.view_mode_padding = {}
Expand Down Expand Up @@ -337,6 +338,7 @@ export default class Gantt {
this.map_arrows_on_bars();
this.set_width();
this.set_scroll_position();
if (this.options.scroll_today) this.scroll_today()
}

setup_layers() {
Expand Down Expand Up @@ -742,13 +744,17 @@ export default class Gantt {
}
}

set_scroll_position() {
set_scroll_position(date) {
if (!date) {
date = this.gantt_start
}

const parent_element = this.$svg.parentElement;
if (!parent_element) return;

const hours_before_first_task = date_utils.diff(
this.get_oldest_starting_date(),
this.gantt_start,
date,
"hour",
);

Expand All @@ -760,6 +766,12 @@ export default class Gantt {
parent_element.scrollLeft = scroll_pos;
}

scroll_today() {
const oldest = this.get_oldest_starting_date().getTime()
const t = new Date() - oldest
this.set_scroll_position(new Date(this.gantt_start.getTime() - t))
}

bind_grid_click() {
$.on(
this.$svg,
Expand Down

0 comments on commit 0ebea3d

Please sign in to comment.