diff --git a/src/index.js b/src/index.js index aac473c..0455184 100644 --- a/src/index.js +++ b/src/index.js @@ -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 = {} @@ -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() { @@ -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", ); @@ -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,