From ec14c03455a603ac1945788f1146bca3950952e7 Mon Sep 17 00:00:00 2001 From: wahyu Date: Wed, 27 Dec 2023 10:44:13 +0700 Subject: [PATCH] s curve zoom --- view-mode/function/overlaySCurve.js | 90 ++++++++++++++++++++++++----- 1 file changed, 74 insertions(+), 16 deletions(-) diff --git a/view-mode/function/overlaySCurve.js b/view-mode/function/overlaySCurve.js index 636766c..0ea94ce 100644 --- a/view-mode/function/overlaySCurve.js +++ b/view-mode/function/overlaySCurve.js @@ -95,31 +95,89 @@ function getChartScaleRange(){ return cells; } -function getProgressLine(){ +function getProgressLine() { // As long as the progress data length is same with chart scale range (period) then it's fine. getSCurveData(); // console.log("apa ", return_first); var cumulativePlannedDurations = return_first.data[0].data.percentagePlan; var cumulativeRealDurations = return_first.data[0].data.percentageReal; - cumulativeRealDurations[cumulativeRealDurations.length - 1] = Math.ceil(cumulativeRealDurations[cumulativeRealDurations.length - 1]); - var maxPlan = cumulativePlannedDurations[cumulativePlannedDurations.length - 1] - var maxReal = cumulativeRealDurations[cumulativeRealDurations.length - 1] - var dates = return_first.data[0].data.date; - //jika summary s curve - if (maxReal > 100 || maxPlan > 100) { - var plannedDurations = cumulativePlannedDurations.map((item) => { - return item/maxPlan*100; - }) - var realDurations = cumulativeRealDurations.map((item) => { - return item/maxPlan*100; - }) - return {planned: plannedDurations, real: realDurations, dates: dates}; - } + cumulativeRealDurations[cumulativeRealDurations.length - 1] = Math.ceil(cumulativeRealDurations[cumulativeRealDurations.length - 1]); + var maxPlan = cumulativePlannedDurations[cumulativePlannedDurations.length - 1] + var maxReal = cumulativeRealDurations[cumulativeRealDurations.length - 1] + var dates = return_first.data[0].data.date; + // Determine the appropriate data points based on the Gantt chart zoom level + var chartScaleRange = getChartScaleRange(); + var zoomLevel = gantt.ext.zoom.getCurrentLevel(); + + // Adjust data points based on the zoom level + var plannedDurations, realDurations; + + if (zoomLevel === 2) { + // Adjust data to monthly points + plannedDurations = adjustDataToZoom(dates, cumulativePlannedDurations, chartScaleRange, 2).data; + realDurations = adjustDataToZoom(dates, cumulativeRealDurations, chartScaleRange, 2).data; + dates = adjustDataToZoom(dates, cumulativeRealDurations, chartScaleRange, 2).dates; + } else if (zoomLevel === 1) { + // Adjust data to weekly points + plannedDurations = adjustDataToZoom(dates, cumulativePlannedDurations, chartScaleRange, 1).data; + realDurations = adjustDataToZoom(dates, cumulativeRealDurations, chartScaleRange, 1).data; + dates = adjustDataToZoom(dates, cumulativeRealDurations, chartScaleRange, 1).dates; + } else { + // Default: Use daily data points + plannedDurations = cumulativePlannedDurations; + realDurations = cumulativeRealDurations; + + } + if (maxReal > 100 || maxPlan > 100) { + plannedDurations = plannedDurations.map((item) => { + return item/maxPlan*100; + }) + realDurations = realDurations.map((item) => { + return item/maxReal*100; + }) + } + + return { planned: plannedDurations, real: realDurations, dates: dates }; +} +function adjustDataToZoom(dates, data, chartScaleRange, zoomLevel) { + // Implement logic to adjust data points based on the Gantt chart zoom level + // For example, if zoomLevel is 'month', aggregate daily data to monthly data + + // Placeholder logic: This example assumes that the chartScaleRange is in days + var newData = []; + var newDates = []; + var aggregateValue = 0; + + for (var i = 0; i < data.length; i++) { + aggregateValue = data[i]; + + if (zoomLevel === 2 && i % 30 === 29) { + // Aggregate data for each month (assuming 30 days in a month) + newData.push(aggregateValue); + newDates.push(dates[i]); + aggregateValue = 0; + } else if (zoomLevel === 1 && (i + 1) % 7 === 0) { + // Aggregate data for each week + newData.push(aggregateValue); + newDates.push(dates[i]); + aggregateValue = 0; + } + } + + // If there are remaining data points after the loop, add them to the result + if (aggregateValue > 0) { + newData.push(aggregateValue); + newDates.push(dates[data.length - 1]); + } - return {planned: cumulativePlannedDurations, real: cumulativeRealDurations, dates: dates}; + return { + data: newData, + dates: newDates + }; } function getScalePaddings(values){ + let zoom = gantt.ext.zoom.getCurrentLevel(); var scale = gantt.getScale(); var dataRange = gantt.getSubtaskDates(); // let minDate = new Date();