jsGanttImproved / jsgantt-improved

Javascript Gantt: fully featured gantt chart component built entirely with JS and CSS. No images or external libs required.
https://jsganttimproved.github.io/jsgantt-improved
Other
483 stars 250 forks source link

Calculated min date uses current date as a minimum instead of the actual task minimum date #355

Open Moult opened 3 years ago

Moult commented 3 years ago

In this line of code, vDate defaults to the current date: https://github.com/jsGanttImproved/jsgantt-improved/blob/7d696916467dee891f2f33640fbcc7612f89a984/src/utils/date_utils.ts#L6

Also problematically, in this line of code, functions like getStart default to the current date if no date is found (such as when the task is a group and has no start/end): https://github.com/jsGanttImproved/jsgantt-improved/blob/7d696916467dee891f2f33640fbcc7612f89a984/src/utils/date_utils.ts#L13-L14

When these two behaviours are combined it means that when your first grouped task has a min date of sometime in the future, the gantt chat always begins at today, even if vMinDate is specified.

This can be very troublesome when doing projects where the project begins a few years in the future, as you will have many years of nothing happening.

2021-10-29-171420_1919x358_scrot

Sample code:

<link href="jsgantt.css" rel="stylesheet" type="text/css"/>
<script src="jsgantt.js" type="text/javascript"></script>
<div style="position:relative" class="gantt" id="GanttChartDIV"></div>
<script type="text/javascript">
var g = new JSGantt.GanttChart(document.getElementById('GanttChartDIV'), 'week');
g.setOptions({
    vCaptionType: 'Complete',  // Set to Show Caption : None,Caption,Resource,Duration,Complete,
    vQuarterColWidth: 36,
    vDateTaskDisplayFormat: 'day dd month yyyy', // Shown in tool tip box
    vDayMajorDateDisplayFormat: 'mon yyyy - Week ww',// Set format to dates in the "Major" header of the "Day" view
    vWeekMinorDateDisplayFormat: 'dd mon', // Set format to display dates in the "Minor" header of the "Week" view
    vLang: 'en',
    //vMinDate: new Date('2027-01-01'),
    vShowTaskInfoLink: 1, // Show link in tool tip (0/1)
    vShowEndWeekDate: 0,  // Show/Hide the date for the last day of the week in header for daily
    vUseSingleCell: 10000, // Set the threshold cell per table row (Helps performance for large data.
    vFormatArr: ['Day', 'Week', 'Month', 'Quarter'], // Even with setUseSingleCell using Hour format on such a large chart can cause issues in some browsers,
    vTotalHeight: 900,
});
var json_data = `
[{"pID": 540527, "pName": "foo", "pStart": "", "pEnd": "", "pPlanStart": "", "pPlanEnd": "", "pMile": 0, "pComp": 0, "pGroup": 1, "pParent": 540526, "pOpen": 1, "pCost": 1, "pClass": "ggroupblack", "pDepend": ""}, {"pID": 540529, "pName": "bar", "pStart": "2027-01-01T00:00:00", "pEnd": "2027-01-29T00:00:00", "pPlanStart": "2027-01-01T00:00:00", "pPlanEnd": "2027-01-29T00:00:00", "pMile": 0, "pComp": 0, "pGroup": 0, "pParent": 540527, "pOpen": 1, "pCost": 1, "pClass": "gtaskred", "pDepend": ""}, {"pID": 540535, "pName": "asdf", "pStart": "2027-01-15T00:00:00", "pEnd": "2027-01-29T00:00:00", "pPlanStart": "2027-01-15T00:00:00", "pPlanEnd": "2027-01-29T00:00:00", "pMile": 0, "pComp": 0, "pGroup": 0, "pParent": 540527, "pOpen": 1, "pCost": 1, "pClass": "gtaskred", "pDepend": "540529FS"}, {"pID": 540545, "pName": "asdf", "pStart": "2027-01-29T00:00:00", "pEnd": "2027-02-12T00:00:00", "pPlanStart": "2027-01-29T00:00:00", "pPlanEnd": "2027-02-12T00:00:00", "pMile": 0, "pComp": 0, "pGroup": 0, "pParent": 540527, "pOpen": 1, "pCost": 1, "pClass": "gtaskred", "pDepend": "540535FS"}, {"pID": 540554, "pName": "asdf", "pStart": "2027-02-12T00:00:00", "pEnd": "2027-02-26T00:00:00", "pPlanStart": "2027-02-12T00:00:00", "pPlanEnd": "2027-02-26T00:00:00", "pMile": 0, "pComp": 0, "pGroup": 0, "pParent": 540527, "pOpen": 1, "pCost": 1, "pClass": "gtaskred", "pDepend": "540545FS"}, {"pID": 540563, "pName": "asdf", "pStart": "2027-02-26T00:00:00", "pEnd": "2027-03-12T00:00:00", "pPlanStart": "2027-02-26T00:00:00", "pPlanEnd": "2027-03-12T00:00:00", "pMile": 0, "pComp": 0, "pGroup": 0, "pParent": 540527, "pOpen": 1, "pCost": 1, "pClass": "gtaskred", "pDepend": "540554FS"}, {"pID": 540572, "pName": "asdf", "pStart": "2027-03-12T00:00:00", "pEnd": "2027-03-26T00:00:00", "pPlanStart": "2027-03-12T00:00:00", "pPlanEnd": "2027-03-26T00:00:00", "pMile": 0, "pComp": 0, "pGroup": 0, "pParent": 540527, "pOpen": 1, "pCost": 1, "pClass": "gtaskred", "pDepend": "540563FS"}, {"pID": 540581, "pName": "asdf", "pStart": "2027-03-26T00:00:00", "pEnd": "2027-04-09T00:00:00", "pPlanStart": "2027-03-26T00:00:00", "pPlanEnd": "2027-04-09T00:00:00", "pMile": 0, "pComp": 0, "pGroup": 0, "pParent": 540527, "pOpen": 1, "pCost": 1, "pClass": "gtaskred", "pDepend": "540572FS"}, {"pID": 540590, "pName": "asdf", "pStart": "2027-04-09T00:00:00", "pEnd": "2027-04-23T00:00:00", "pPlanStart": "2027-04-09T00:00:00", "pPlanEnd": "2027-04-23T00:00:00", "pMile": 0, "pComp": 0, "pGroup": 0, "pParent": 540527, "pOpen": 1, "pCost": 1, "pClass": "gtaskred", "pDepend": "540581FS"}, {"pID": 540599, "pName": "asdf", "pStart": "2027-04-23T00:00:00", "pEnd": "2027-05-07T00:00:00", "pPlanStart": "2027-04-23T00:00:00", "pPlanEnd": "2027-05-07T00:00:00", "pMile": 0, "pComp": 0, "pGroup": 0, "pParent": 540527, "pOpen": 1, "pCost": 1, "pClass": "gtaskred", "pDepend": "540590FS"}, {"pID": 540608, "pName": "asdf", "pStart": "2027-05-07T00:00:00", "pEnd": "2027-05-21T00:00:00", "pPlanStart": "2027-05-07T00:00:00", "pPlanEnd": "2027-05-21T00:00:00", "pMile": 0, "pComp": 0, "pGroup": 0, "pParent": 540527, "pOpen": 1, "pCost": 1, "pClass": "gtaskred", "pDepend": "540599FS"}, {"pID": 540617, "pName": "Foo", "pStart": "2027-01-29T00:00:00", "pEnd": "2027-02-08T00:00:00", "pPlanStart": "2027-01-29T00:00:00", "pPlanEnd": "2027-02-08T00:00:00", "pMile": 0, "pComp": 0, "pGroup": 0, "pParent": 540527, "pOpen": 1, "pCost": 1, "pClass": "gtaskblue", "pDepend": "540529FS"}]
`;
JSGantt.parseJSONString(json_data, g);
g.Draw();
</script>
mariohmol commented 1 year ago

Thanks for that!

Because a group task could have start and end date, that basically take the min date and max date from the children tasks.

So the getMinDate method, returns the current date just if you dont have tasks. When you have tasks it will start to find the min with minDate or the first task list. https://github.com/jsGanttImproved/jsgantt-improved/blob/7d696916467dee891f2f33640fbcc7612f89a984/src/utils/date_utils.ts#L9

Seems to be correct, no?