Skip to content

Commit 49644f2

Browse files
authored
Merge pull request #399 from mariohmol/fix/folder-this-vdebug
fix: replace this.vDebug with ganttObj.vDebug in folder function
2 parents 7e4c719 + 139cc63 commit 49644f2

7 files changed

Lines changed: 319 additions & 89 deletions

File tree

dist/events.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ var folder = function (pID, ganttObj) {
2727
}
2828
}
2929
var bd;
30-
if (this.vDebug) {
30+
if (ganttObj.vDebug) {
3131
bd = new Date();
3232
console.info('after drawDependency', bd);
3333
}
34-
ganttObj.DrawDependencies(this.vDebug);
35-
if (this.vDebug) {
34+
ganttObj.DrawDependencies(ganttObj.vDebug);
35+
if (ganttObj.vDebug) {
3636
var ad = new Date();
3737
console.info('after drawDependency', ad, (ad.getTime() - bd.getTime()));
3838
}

dist/jsgantt.js

Lines changed: 52 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ var GanttChart = function (pDiv, pFormat) {
265265
}
266266
this_1.getColumnOrder().forEach(function (column) {
267267
if (_this[column] == 1 || column === "vAdditionalHeaders") {
268-
(0, draw_columns_1.draw_header)(column, i, vTmpRow_1, _this.vTaskList, _this.vEditable, _this.vEventsChange, _this.vEvents, _this.vDateTaskTableDisplayFormat, _this.vAdditionalHeaders, _this.vFormat, _this.vLangs, _this.vLang, _this.vResources, _this.Draw.bind(_this));
268+
(0, draw_columns_1.draw_header)(column, i, vTmpRow_1, _this.vTaskList, _this.vEditable, _this.vEventsChange, _this.vEvents, _this.vDateTaskTableDisplayFormat, _this.vAdditionalHeaders, _this.vFormat, _this.vLangs, _this.vLang, _this.vResources, _this.Draw.bind(_this), _this.vWorkingDays);
269269
}
270270
});
271271
vNumRows++;
@@ -495,16 +495,16 @@ var GanttChart = function (pDiv, pFormat) {
495495
for (i = 0; i < this.vTaskList.length; i++) {
496496
var curTaskStart = this.vTaskList[i].getStart() ? this.vTaskList[i].getStart() : this.vTaskList[i].getPlanStart();
497497
var curTaskEnd = this.vTaskList[i].getEnd() ? this.vTaskList[i].getEnd() : this.vTaskList[i].getPlanEnd();
498-
var vTaskLeftPx_1 = (0, general_utils_1.getOffset)(vMinDate, curTaskStart, vColWidth, this.vFormat, this.vShowWeekends, this.vFirstDayOfWeek);
499-
var vTaskRightPx = (0, general_utils_1.getOffset)(curTaskStart, curTaskEnd, vColWidth, this.vFormat, this.vShowWeekends, this.vFirstDayOfWeek);
498+
var vTaskLeftPx_1 = (0, general_utils_1.getOffset)(vMinDate, curTaskStart, vColWidth, this.vFormat, this.vShowWeekends, this.vFirstDayOfWeek, this.vWorkingDays);
499+
var vTaskRightPx = (0, general_utils_1.getOffset)(curTaskStart, curTaskEnd, vColWidth, this.vFormat, this.vShowWeekends, this.vFirstDayOfWeek, this.vWorkingDays);
500500
var curTaskPlanStart = void 0, curTaskPlanEnd = void 0;
501501
curTaskPlanStart = this.vTaskList[i].getPlanStart();
502502
curTaskPlanEnd = this.vTaskList[i].getPlanEnd();
503503
var vTaskPlanLeftPx = 0;
504504
var vTaskPlanRightPx = 0;
505505
if (curTaskPlanStart && curTaskPlanEnd) {
506-
vTaskPlanLeftPx = (0, general_utils_1.getOffset)(vMinDate, curTaskPlanStart, vColWidth, this.vFormat, this.vShowWeekends, this.vFirstDayOfWeek);
507-
vTaskPlanRightPx = (0, general_utils_1.getOffset)(curTaskPlanStart, curTaskPlanEnd, vColWidth, this.vFormat, this.vShowWeekends, this.vFirstDayOfWeek);
506+
vTaskPlanLeftPx = (0, general_utils_1.getOffset)(vMinDate, curTaskPlanStart, vColWidth, this.vFormat, this.vShowWeekends, this.vFirstDayOfWeek, this.vWorkingDays);
507+
vTaskPlanRightPx = (0, general_utils_1.getOffset)(curTaskPlanStart, curTaskPlanEnd, vColWidth, this.vFormat, this.vShowWeekends, this.vFirstDayOfWeek, this.vWorkingDays);
508508
}
509509
var vID = this.vTaskList[i].getID();
510510
var vComb = this.vTaskList[i].getParItem() && this.vTaskList[i].getParItem().getGroup() == 2;
@@ -629,7 +629,7 @@ var GanttChart = function (pDiv, pFormat) {
629629
vCaptionStr = vTmpItem.getResource();
630630
break;
631631
case "Duration":
632-
vCaptionStr = vTmpItem.getDuration(this.vFormat, this.vLangs[this.vLang]);
632+
vCaptionStr = vTmpItem.getDuration(this.vFormat, this.vLangs[this.vLang], this.vWorkingDays);
633633
break;
634634
case "Complete":
635635
vCaptionStr = vTmpItem.getCompStr();
@@ -802,12 +802,12 @@ var GanttChart = function (pDiv, pFormat) {
802802
vScrollDate.setMinutes(0, 0, 0);
803803
else
804804
vScrollDate.setHours(0, 0, 0, 0);
805-
vScrollPx = (0, general_utils_1.getOffset)(vMinDate, vScrollDate, vColWidth, this.vFormat, this.vShowWeekends, this.vFirstDayOfWeek) - 30;
805+
vScrollPx = (0, general_utils_1.getOffset)(vMinDate, vScrollDate, vColWidth, this.vFormat, this.vShowWeekends, this.vFirstDayOfWeek, this.vWorkingDays) - 30;
806806
}
807807
this.getChartBody().scrollLeft = vScrollPx;
808808
}
809809
if (vMinDate.getTime() <= new Date().getTime() && vMaxDate.getTime() >= new Date().getTime()) {
810-
this.vTodayPx = (0, general_utils_1.getOffset)(vMinDate, new Date(), vColWidth, this.vFormat, this.vShowWeekends, this.vFirstDayOfWeek);
810+
this.vTodayPx = (0, general_utils_1.getOffset)(vMinDate, new Date(), vColWidth, this.vFormat, this.vShowWeekends, this.vFirstDayOfWeek, this.vWorkingDays);
811811
}
812812
else
813813
this.vTodayPx = -1;
@@ -842,7 +842,7 @@ var GanttChart = function (pDiv, pFormat) {
842842
}
843843
(0, events_1.updateGridHeaderWidth)(this);
844844
this.chartRowDateToX = function (date) {
845-
return (0, general_utils_1.getOffset)(vMinDate, date, vColWidth, this.vFormat, this.vShowWeekends, this.vFirstDayOfWeek);
845+
return (0, general_utils_1.getOffset)(vMinDate, date, vColWidth, this.vFormat, this.vShowWeekends, this.vFirstDayOfWeek, this.vWorkingDays);
846846
};
847847
if (this.vEvents && this.vEvents.afterDraw) {
848848
this.vEvents.afterDraw();
@@ -884,7 +884,7 @@ var COLUMNS_TYPES = {
884884
'vShowCost': 'cost',
885885
'vShowAddEntries': 'addentries'
886886
};
887-
var draw_header = function (column, i, vTmpRow, vTaskList, vEditable, vEventsChange, vEvents, vDateTaskTableDisplayFormat, vAdditionalHeaders, vFormat, vLangs, vLang, vResources, Draw) {
887+
var draw_header = function (column, i, vTmpRow, vTaskList, vEditable, vEventsChange, vEvents, vDateTaskTableDisplayFormat, vAdditionalHeaders, vFormat, vLangs, vLang, vResources, Draw, vWorkingDays) {
888888
var vTmpCell, vTmpDiv;
889889
if ('vShowRes' === column) {
890890
vTmpCell = (0, draw_utils_1.newNode)(vTmpRow, 'td', null, 'gres');
@@ -896,7 +896,7 @@ var draw_header = function (column, i, vTmpRow, vTaskList, vEditable, vEventsCha
896896
}
897897
if ('vShowDur' === column) {
898898
vTmpCell = (0, draw_utils_1.newNode)(vTmpRow, 'td', null, 'gdur');
899-
var text = (0, draw_utils_1.makeInput)(vTaskList[i].getDuration(vFormat, vLangs[vLang]), vEditable, 'text', vTaskList[i].getDuration());
899+
var text = (0, draw_utils_1.makeInput)(vTaskList[i].getDuration(vFormat, vLangs[vLang], vWorkingDays), vEditable, 'text', vTaskList[i].getDuration());
900900
vTmpDiv = (0, draw_utils_1.newNode)(vTmpCell, 'div', null, null, text);
901901
var callback = function (task, e) { return task.setDuration(e.target.value); };
902902
(0, events_1.addListenerInputCell)(vTmpCell, vEventsChange, callback, vTaskList, i, 'dur', Draw);
@@ -1155,12 +1155,12 @@ var folder = function (pID, ganttObj) {
11551155
}
11561156
}
11571157
var bd;
1158-
if (this.vDebug) {
1158+
if (ganttObj.vDebug) {
11591159
bd = new Date();
11601160
console.info('after drawDependency', bd);
11611161
}
1162-
ganttObj.DrawDependencies(this.vDebug);
1163-
if (this.vDebug) {
1162+
ganttObj.DrawDependencies(ganttObj.vDebug);
1163+
if (ganttObj.vDebug) {
11641164
var ad = new Date();
11651165
console.info('after drawDependency', ad, (ad.getTime() - bd.getTime()));
11661166
}
@@ -3542,6 +3542,7 @@ var includeGetSet = function () {
35423542
this.Draw();
35433543
};
35443544
this.setWorkingDays = function (workingDays) { this.vWorkingDays = workingDays; };
3545+
this.getWorkingDays = function () { return this.vWorkingDays; };
35453546
this.setFirstDayOfWeek = function (pVal) { this.vFirstDayOfWeek = parseInt(String(pVal), 10); };
35463547
this.setMinGpLen = function (pMinGpLen) { this.vMinGpLen = pMinGpLen; };
35473548
this.setScrollTo = function (pDate) { this.vScrollTo = pDate; };
@@ -3954,22 +3955,22 @@ var TaskItem = function (pID, pName, pStart, pEnd, pClass, pLink, pMile, pRes, p
39543955
this.getNotes = function () { return vNotes; };
39553956
this.getSortIdx = function () { return vSortIdx; };
39563957
this.getToDelete = function () { return vToDelete; };
3957-
this.getDuration = function (pFormat, pLang) {
3958+
this.getDuration = function (pFormat, pLang, pWorkingDays) {
39583959
if (vMile) {
39593960
vDuration = '-';
39603961
}
39613962
else if (!vEnd && !vStart && vPlanStart && vPlanEnd) {
3962-
return calculateVDuration(pFormat, pLang, this.getPlanStart(), this.getPlanEnd());
3963+
return calculateVDuration(pFormat, pLang, this.getPlanStart(), this.getPlanEnd(), pWorkingDays);
39633964
}
39643965
else if (!vEnd && vDuration) {
39653966
return vDuration;
39663967
}
39673968
else {
3968-
vDuration = calculateVDuration(pFormat, pLang, this.getStart(), this.getEnd());
3969+
vDuration = calculateVDuration(pFormat, pLang, this.getStart(), this.getEnd(), pWorkingDays);
39693970
}
39703971
return vDuration;
39713972
};
3972-
function calculateVDuration(pFormat, pLang, start, end) {
3973+
function calculateVDuration(pFormat, pLang, start, end, pWorkingDays) {
39733974
var vDuration;
39743975
var vUnits = null;
39753976
switch (pFormat) {
@@ -3986,11 +3987,6 @@ var TaskItem = function (pID, pName, pStart, pEnd, pClass, pLink, pMile, pRes, p
39863987
vUnits = pFormat;
39873988
break;
39883989
}
3989-
// let vTaskEnd = new Date(this.getEnd().getTime());
3990-
// if ((vTaskEnd.getTime() - (vTaskEnd.getTimezoneOffset() * 60000)) % (86400000) == 0) {
3991-
// vTaskEnd = new Date(vTaskEnd.getFullYear(), vTaskEnd.getMonth(), vTaskEnd.getDate() + 1, vTaskEnd.getHours(), vTaskEnd.getMinutes(), vTaskEnd.getSeconds());
3992-
// }
3993-
// let tmpPer = (getOffset(this.getStart(), vTaskEnd, 999, vUnits)) / 1000;
39943990
var hours = (end.getTime() - start.getTime()) / 1000 / 60 / 60;
39953991
var tmpPer;
39963992
switch (vUnits) {
@@ -3999,7 +3995,7 @@ var TaskItem = function (pID, pName, pStart, pEnd, pClass, pLink, pMile, pRes, p
39993995
vDuration = tmpPer + ' ' + ((tmpPer != 1) ? pLang['hrs'] : pLang['hr']);
40003996
break;
40013997
case 'day':
4002-
tmpPer = Math.round(hours / 24);
3998+
tmpPer = pWorkingDays ? (0, date_utils_1.countWorkingDays)(start, end, pWorkingDays) : Math.round(hours / 24);
40033999
vDuration = tmpPer + ' ' + ((tmpPer != 1) ? pLang['dys'] : pLang['dy']);
40044000
break;
40054001
case 'week':
@@ -4206,7 +4202,7 @@ var createTaskInfo = function (pTask, templateStrOrFn) {
42064202
if (_this.vShowTaskInfoDur == 1 && !pTask.getMile()) {
42074203
vTmpDiv = (0, draw_utils_1.newNode)(vTaskInfo, 'div', null, 'gTILine gTId');
42084204
(0, draw_utils_1.newNode)(vTmpDiv, 'span', null, 'gTaskLabel', _this.vLangs[_this.vLang]['dur'] + ': ');
4209-
(0, draw_utils_1.newNode)(vTmpDiv, 'span', null, 'gTaskText', pTask.getDuration(_this.vFormat, _this.vLangs[_this.vLang]));
4205+
(0, draw_utils_1.newNode)(vTmpDiv, 'span', null, 'gTaskText', pTask.getDuration(_this.vFormat, _this.vLangs[_this.vLang], _this.vWorkingDays));
42104206
}
42114207
if (_this.vShowTaskInfoComp == 1) {
42124208
vTmpDiv = (0, draw_utils_1.newNode)(vTaskInfo, 'div', null, 'gTILine gTIc');
@@ -4445,7 +4441,7 @@ exports.processRows = processRows;
44454441
},{"./utils/date_utils":11,"./utils/draw_utils":12,"./utils/general_utils":13}],11:[function(require,module,exports){
44464442
"use strict";
44474443
Object.defineProperty(exports, "__esModule", { value: true });
4448-
exports.getIsoWeek = exports.parseDateFormatStr = exports.formatDateStr = exports.parseDateStr = exports.coerceDate = exports.getMaxDate = exports.getMinDate = void 0;
4444+
exports.countWorkingDays = exports.getIsoWeek = exports.parseDateFormatStr = exports.formatDateStr = exports.parseDateStr = exports.coerceDate = exports.getMaxDate = exports.getMinDate = void 0;
44494445
/**
44504446
* Returns the last day of the week (0=Sun … 6=Sat) for a given first day.
44514447
*/
@@ -4776,6 +4772,23 @@ var getIsoWeek = function (pDate) {
47764772
return thisWeek;
47774773
};
47784774
exports.getIsoWeek = getIsoWeek;
4775+
/**
4776+
* Count the number of working days between start (inclusive) and end (exclusive).
4777+
* @param start - start date
4778+
* @param end - end date (exclusive)
4779+
* @param workingDays - map of day-of-week (0=Sun … 6=Sat) to boolean
4780+
*/
4781+
var countWorkingDays = function (start, end, workingDays) {
4782+
var count = 0;
4783+
var cur = new Date(start.getTime());
4784+
while (cur < end) {
4785+
if (workingDays[cur.getDay()])
4786+
count++;
4787+
cur = new Date(cur.getTime() + 86400000);
4788+
}
4789+
return count;
4790+
};
4791+
exports.countWorkingDays = countWorkingDays;
47794792

47804793
},{}],12:[function(require,module,exports){
47814794
"use strict";
@@ -5073,7 +5086,7 @@ var calculateCurrentDateOffset = function (curTaskStart, curTaskEnd) {
50735086
return (tmpTaskEnd - tmpTaskStart);
50745087
};
50755088
exports.calculateCurrentDateOffset = calculateCurrentDateOffset;
5076-
var getOffset = function (pStartDate, pEndDate, pColWidth, pFormat, pShowWeekends, pFirstDayOfWeek) {
5089+
var getOffset = function (pStartDate, pEndDate, pColWidth, pFormat, pShowWeekends, pFirstDayOfWeek, pWorkingDays) {
50775090
if (pFirstDayOfWeek === void 0) { pFirstDayOfWeek = 1; }
50785091
var DAY_CELL_MARGIN_WIDTH = 3; // Cell margin for 'day' format
50795092
var WEEK_CELL_MARGIN_WIDTH = 3; // Cell margin for 'week' format
@@ -5089,7 +5102,18 @@ var getOffset = function (pStartDate, pEndDate, pColWidth, pFormat, pShowWeekend
50895102
var vTaskRight = (0, exports.calculateCurrentDateOffset)(curTaskStart, curTaskEnd) / oneHour;
50905103
var vPosTmpDate;
50915104
if (pFormat == 'day') {
5092-
if (!pShowWeekends) {
5105+
if (pWorkingDays) {
5106+
var start = curTaskStart;
5107+
var end = curTaskEnd;
5108+
var countNonWorking = 0;
5109+
while (start < end) {
5110+
if (!pWorkingDays[start.getDay()])
5111+
countNonWorking++;
5112+
start = new Date(start.getTime() + 24 * oneHour);
5113+
}
5114+
vTaskRight -= countNonWorking * 24;
5115+
}
5116+
else if (!pShowWeekends) {
50935117
var start = curTaskStart;
50945118
var end = curTaskEnd;
50955119
var countWeekends = 0;

docs/demo.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,23 @@ <h3 class="row">Hide and Show Properties</h3>
345345
</div>
346346
</td>
347347
</tr>
348+
<tr style="border-top:1px solid #ffe082">
349+
<td style="padding:6px 8px;vertical-align:top">
350+
<a href="https://github.com/jsGanttImproved/jsgantt-improved/issues/68" target="_blank" style="color:#0066cc">#68</a>
351+
</td>
352+
<td style="padding:6px 8px;vertical-align:top" colspan="2">
353+
<strong>Working days: configurable duration and bar width.</strong><br>
354+
<code>setWorkingDays({ 0:false, 1:true, 2:true, 3:true, 4:true, 5:true, 6:false })</code>
355+
makes the gantt skip non-working days in duration counts and bar widths (Mon–Fri only in this example).
356+
<br><br>
357+
<button onclick="load68Demo(null)" style="padding:4px 10px;margin-right:8px">All days (default)</button>
358+
<button onclick="load68Demo({0:false,1:true,2:true,3:true,4:true,5:true,6:false})" style="padding:4px 10px;margin-right:8px">Mon–Fri only</button>
359+
<button onclick="load68Demo({0:false,1:true,2:true,3:true,4:true,5:true,6:true})" style="padding:4px 10px;margin-right:8px">Mon–Sat</button>
360+
<br><br>
361+
<span style="font-family:sans-serif;font-size:12px">Duration shown: </span>
362+
<span id="demo68-status" style="color:#0066cc;font-family:monospace"></span>
363+
</td>
364+
</tr>
348365
<tr style="border-top:1px solid #ffe082">
349366
<td style="padding:6px 8px;vertical-align:top">
350367
<a href="https://github.com/jsGanttImproved/jsgantt-improved/issues/376" target="_blank" style="color:#0066cc">#376</a>

docs/index.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,4 +369,24 @@ function demo376Remove() {
369369
}
370370
}
371371

372+
function load68Demo(workingDays) {
373+
g = new JSGantt.GanttChart(document.getElementById("embedded-Gantt"), "day");
374+
g.setOptions({
375+
vFormat: "day",
376+
vFormatArr: ["Day"],
377+
vShowDur: 1,
378+
vShowRes: 0, vShowCost: 0, vShowComp: 0,
379+
vShowStartDate: 1, vShowEndDate: 1,
380+
vEditable: false,
381+
});
382+
if (workingDays) g.setWorkingDays(workingDays);
383+
g.AddTaskItem(new JSGantt.TaskItem(1, "Task A (Mon–Mon)", "2025-01-06", "2025-01-13", "gtaskblue", "", 0, "Me", 0, 0, 0, 1, "", "", "", g));
384+
g.AddTaskItem(new JSGantt.TaskItem(2, "Task B (Mon–Fri)", "2025-01-13", "2025-01-17", "gtaskgreen", "", 0, "Me", 0, 0, 0, 1, "", "", "", g));
385+
g.Draw();
386+
var dur = "";
387+
var cell = document.querySelector("#embedded-Gantt .gduration div");
388+
if (cell) dur = cell.innerText.trim();
389+
document.getElementById("demo68-status").textContent = dur || "(draw to see)";
390+
}
391+
372392
start("pt");

0 commit comments

Comments
 (0)