From 0b235d3397b66ad397f6248bf872fbc3f24a1ba2 Mon Sep 17 00:00:00 2001 From: Safwan Samsudeen Date: Fri, 5 Apr 2024 16:37:13 +0530 Subject: [PATCH] feat: support empty task list --- src/index.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/index.js b/src/index.js index 3b6a8f2..dbff9e0 100644 --- a/src/index.js +++ b/src/index.js @@ -253,9 +253,12 @@ export default class Gantt { this.gantt_end = task._end; } } + let gantt_start, gantt_end; + if (!this.gantt_start) gantt_start = new Date(); + else gantt_start = date_utils.start_of(this.gantt_start, "day"); + if (!this.gantt_end) gantt_end = new Date(); + else gantt_end = date_utils.start_of(this.gantt_end, "day"); - let gantt_start = date_utils.start_of(this.gantt_start, "day"); - let gantt_end = date_utils.start_of(this.gantt_end, "day"); // add date padding on both sides let viewKey; for (let [key, value] of Object.entries(VIEW_MODE)) { @@ -703,9 +706,9 @@ export default class Gantt { set_width() { const cur_width = this.$svg.getBoundingClientRect().width; - const actual_width = this.$svg - .querySelector(".grid .grid-row") - .getAttribute("width"); + const actual_width = this.$svg.querySelector('.grid .grid-row') ? this.$svg + .querySelector('.grid .grid-row') + .getAttribute('width') : 0; if (cur_width < actual_width) { this.$svg.setAttribute("width", actual_width); } @@ -1000,6 +1003,7 @@ export default class Gantt { * @memberof Gantt */ get_oldest_starting_date() { + if (!this.tasks.length) return new Date() return this.tasks .map((task) => task._start) .reduce((prev_date, cur_date) =>