From 06764c28a6df1368e68cf1e007897f61c4b458b0 Mon Sep 17 00:00:00 2001 From: Wahyu Ramadhan Date: Tue, 8 Aug 2023 12:04:17 +0700 Subject: [PATCH] Update padding --- view-mode/function/overlaySCurve.js | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/view-mode/function/overlaySCurve.js b/view-mode/function/overlaySCurve.js index fb56d20..087bdb5 100644 --- a/view-mode/function/overlaySCurve.js +++ b/view-mode/function/overlaySCurve.js @@ -121,9 +121,26 @@ function getProgressLine(){ function getScalePaddings(){ var scale = gantt.getScale(); var dataRange = gantt.getSubtaskDates(); + let minDate = new Date(); + let maxDate = new Date(); + + gantt.eachTask(function(task){ + let plannedEarlier = task.planned_start < task.start_date; + let plannedLater = task.planned_end > task.end_date; + + if (plannedEarlier) { + minDate = new Date(Math.min(minDate.getTime(), task.planned_start.getTime())); + } else { + minDate = new Date(Math.min(minDate.getTime(), task.start_date.getTime())); + } + + if (plannedLater) { + maxDate = new Date(Math.max(maxDate.getTime(), task.planned_end.getTime())); + } else { + maxDate = new Date(Math.max(maxDate.getTime(), task.end_date.getTime())); + } + }) - var chartScale = getChartScaleRange(); - var newWidth = scale.col_width; var padding = { left:0, right:0 @@ -132,8 +149,8 @@ function getScalePaddings(){ if(dataRange.start_date){ var yScaleLabelsWidth = 48; // fine tune values in order to align chart with the scale range - padding.left = gantt.posFromDate(dataRange.start_date) - yScaleLabelsWidth; - padding.right = scale.full_width - gantt.posFromDate(dataRange.end_date) - yScaleLabelsWidth; + padding.left = gantt.posFromDate(minDate) - yScaleLabelsWidth; + padding.right = scale.full_width - gantt.posFromDate(maxDate) - yScaleLabelsWidth; padding.top = gantt.config.row_height - 12; padding.bottom = gantt.config.row_height - 12; }