cwhi-gantt 1.5.0 → 1.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/gantt.js +179 -3
- package/dist/gantt.min.js +1 -1
- package/es/gantt/Bar.js +17 -1
- package/es/utils.js +162 -2
- package/lib/gantt/Bar.js +17 -1
- package/lib/utils.js +162 -2
- package/package.json +1 -1
- package/src/gantt/Bar.js +15 -1
- package/src/utils.js +158 -3
package/dist/gantt.js
CHANGED
|
@@ -458,7 +458,7 @@
|
|
|
458
458
|
return true;
|
|
459
459
|
}
|
|
460
460
|
function isOverdueUnstartedTask(task, currentDate, lockMilestone) {
|
|
461
|
-
return Boolean(task && task.start && task.start
|
|
461
|
+
return Boolean(task && task.start && task.start <= currentDate && canAdjustUnstartedTask(task, lockMilestone));
|
|
462
462
|
}
|
|
463
463
|
function getOverdueRootTaskIds(id, ins, tasks, tmap, currentDate, lockMilestone) {
|
|
464
464
|
var roots = new Set();
|
|
@@ -500,9 +500,85 @@
|
|
|
500
500
|
});
|
|
501
501
|
return forcedStartMap;
|
|
502
502
|
}
|
|
503
|
+
function getAutoScheduleDebugConfig(debugOptions) {
|
|
504
|
+
var options = debugOptions;
|
|
505
|
+
if (options == null && typeof globalThis !== 'undefined') {
|
|
506
|
+
options = globalThis.__GANTT_AUTO_SCHEDULE_DEBUG__;
|
|
507
|
+
}
|
|
508
|
+
if (!options) {
|
|
509
|
+
return null;
|
|
510
|
+
}
|
|
511
|
+
if (options === true) {
|
|
512
|
+
return {
|
|
513
|
+
taskIds: null
|
|
514
|
+
};
|
|
515
|
+
}
|
|
516
|
+
if (options.enabled === false) {
|
|
517
|
+
return null;
|
|
518
|
+
}
|
|
519
|
+
var taskIds = null;
|
|
520
|
+
if (Array.isArray(options.taskIds) && options.taskIds.length) {
|
|
521
|
+
taskIds = new Set(options.taskIds.map(function (id) {
|
|
522
|
+
return String(id);
|
|
523
|
+
}));
|
|
524
|
+
}
|
|
525
|
+
return {
|
|
526
|
+
taskIds: taskIds
|
|
527
|
+
};
|
|
528
|
+
}
|
|
529
|
+
function shouldLogAutoScheduleTask(debugConfig, taskId) {
|
|
530
|
+
if (!debugConfig) {
|
|
531
|
+
return false;
|
|
532
|
+
}
|
|
533
|
+
if (!debugConfig.taskIds) {
|
|
534
|
+
return true;
|
|
535
|
+
}
|
|
536
|
+
return debugConfig.taskIds.has(String(taskId));
|
|
537
|
+
}
|
|
538
|
+
function formatAutoScheduleDebugDate(value) {
|
|
539
|
+
if (value == null) {
|
|
540
|
+
return value;
|
|
541
|
+
}
|
|
542
|
+
if (typeof value.toISOString === 'function') {
|
|
543
|
+
if (Number.isNaN(value.valueOf())) {
|
|
544
|
+
return 'Invalid Date';
|
|
545
|
+
}
|
|
546
|
+
return value.toISOString();
|
|
547
|
+
}
|
|
548
|
+
return value;
|
|
549
|
+
}
|
|
550
|
+
function getAutoScheduleTaskSnapshot(task, scheduleDuration) {
|
|
551
|
+
if (!task) {
|
|
552
|
+
return null;
|
|
553
|
+
}
|
|
554
|
+
return {
|
|
555
|
+
id: task.id,
|
|
556
|
+
status: task.status,
|
|
557
|
+
statusType: _typeof(task.status),
|
|
558
|
+
start: formatAutoScheduleDebugDate(task.start),
|
|
559
|
+
startType: _typeof(task.start),
|
|
560
|
+
startIsDate: task.start instanceof Date,
|
|
561
|
+
end: formatAutoScheduleDebugDate(task.end),
|
|
562
|
+
endType: _typeof(task.end),
|
|
563
|
+
endIsDate: task.end instanceof Date,
|
|
564
|
+
duration: task.duration,
|
|
565
|
+
scheduleDuration: scheduleDuration,
|
|
566
|
+
type: task.type || null
|
|
567
|
+
};
|
|
568
|
+
}
|
|
569
|
+
function logAutoSchedule(debugConfig, taskId, stage, payload) {
|
|
570
|
+
if (!shouldLogAutoScheduleTask(debugConfig, taskId)) {
|
|
571
|
+
return;
|
|
572
|
+
}
|
|
573
|
+
console.log('[autoSchedule]', stage, _objectSpread$4({
|
|
574
|
+
taskId: taskId
|
|
575
|
+
}, payload));
|
|
576
|
+
}
|
|
503
577
|
function autoSchedule(tasks, links) {
|
|
504
578
|
var lockMilestone = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
505
579
|
var currentDate = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : new Date();
|
|
580
|
+
var debugOptions = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : null;
|
|
581
|
+
var debugConfig = getAutoScheduleDebugConfig(debugOptions);
|
|
506
582
|
var vmap = {};
|
|
507
583
|
links.forEach(function (l) {
|
|
508
584
|
vmap[l.source] = {
|
|
@@ -543,18 +619,53 @@
|
|
|
543
619
|
});
|
|
544
620
|
var scheduleDate = normalizeScheduleDate(currentDate);
|
|
545
621
|
var forcedStartMap = getForcedStartMap(sorted, ins, tasks, tmap, scheduleDate, lockMilestone);
|
|
622
|
+
if (debugConfig) {
|
|
623
|
+
console.log('[autoSchedule]', 'context', {
|
|
624
|
+
currentDate: formatAutoScheduleDebugDate(currentDate),
|
|
625
|
+
currentDateType: _typeof(currentDate),
|
|
626
|
+
scheduleDate: formatAutoScheduleDebugDate(scheduleDate),
|
|
627
|
+
lockMilestone: lockMilestone,
|
|
628
|
+
sorted: sorted
|
|
629
|
+
});
|
|
630
|
+
}
|
|
546
631
|
sorted.forEach(function (id) {
|
|
547
632
|
var task = tasks[tmap[id]];
|
|
548
|
-
if (!task)
|
|
633
|
+
if (!task) {
|
|
634
|
+
logAutoSchedule(debugConfig, id, 'missing-task', {});
|
|
635
|
+
return;
|
|
636
|
+
}
|
|
549
637
|
var days = durationMap[id] || 0;
|
|
638
|
+
logAutoSchedule(debugConfig, id, 'before-task', {
|
|
639
|
+
task: getAutoScheduleTaskSnapshot(task, days),
|
|
640
|
+
forcedStart: formatAutoScheduleDebugDate(forcedStartMap[id]),
|
|
641
|
+
isOverdueUnstarted: isOverdueUnstartedTask(task, scheduleDate, lockMilestone),
|
|
642
|
+
incomingLinks: ins[id].map(function (link) {
|
|
643
|
+
return {
|
|
644
|
+
id: link.id,
|
|
645
|
+
source: link.source,
|
|
646
|
+
target: link.target,
|
|
647
|
+
type: link.type,
|
|
648
|
+
lag: link.lag
|
|
649
|
+
};
|
|
650
|
+
})
|
|
651
|
+
});
|
|
550
652
|
if (lockMilestone && task.type === 'milestone') {
|
|
653
|
+
logAutoSchedule(debugConfig, id, 'skip-locked-milestone', {
|
|
654
|
+
task: getAutoScheduleTaskSnapshot(task, days)
|
|
655
|
+
});
|
|
551
656
|
return;
|
|
552
657
|
}
|
|
553
658
|
if (task.status === 2) {
|
|
659
|
+
logAutoSchedule(debugConfig, id, 'skip-completed', {
|
|
660
|
+
task: getAutoScheduleTaskSnapshot(task, days)
|
|
661
|
+
});
|
|
554
662
|
return;
|
|
555
663
|
}
|
|
556
664
|
if (task.status === 3) {
|
|
557
665
|
if (!task.start) {
|
|
666
|
+
logAutoSchedule(debugConfig, id, 'skip-started-without-start', {
|
|
667
|
+
task: getAutoScheduleTaskSnapshot(task, days)
|
|
668
|
+
});
|
|
558
669
|
return;
|
|
559
670
|
}
|
|
560
671
|
var end = addDays(task.start, days);
|
|
@@ -564,6 +675,19 @@
|
|
|
564
675
|
if (v && v.start) {
|
|
565
676
|
var s = addDays(v.start, l.lag || 0);
|
|
566
677
|
var e = addDays(s, durationMap[l.source] || 0);
|
|
678
|
+
logAutoSchedule(debugConfig, id, 'started-task-link-check', {
|
|
679
|
+
link: {
|
|
680
|
+
id: l.id,
|
|
681
|
+
source: l.source,
|
|
682
|
+
target: l.target,
|
|
683
|
+
type: l.type,
|
|
684
|
+
lag: l.lag
|
|
685
|
+
},
|
|
686
|
+
sourceTask: getAutoScheduleTaskSnapshot(v, durationMap[l.source] || 0),
|
|
687
|
+
candidateStart: formatAutoScheduleDebugDate(s),
|
|
688
|
+
candidateEnd: formatAutoScheduleDebugDate(e),
|
|
689
|
+
previousEnd: formatAutoScheduleDebugDate(end)
|
|
690
|
+
});
|
|
567
691
|
if (l.type === 'SF') {
|
|
568
692
|
end = maxDate(end, s);
|
|
569
693
|
}
|
|
@@ -574,6 +698,9 @@
|
|
|
574
698
|
}
|
|
575
699
|
task.end = end;
|
|
576
700
|
task.duration = (task.end - task.start) / DAY;
|
|
701
|
+
logAutoSchedule(debugConfig, id, 'after-started-task', {
|
|
702
|
+
task: getAutoScheduleTaskSnapshot(task, days)
|
|
703
|
+
});
|
|
577
704
|
return;
|
|
578
705
|
}
|
|
579
706
|
var start = null;
|
|
@@ -581,21 +708,54 @@
|
|
|
581
708
|
var _l = ins[id][_i3];
|
|
582
709
|
var _v = tasks[tmap[_l.source]];
|
|
583
710
|
var candidate = getConstraintStart(_l, _v, days, durationMap[_l.source] || 0);
|
|
711
|
+
logAutoSchedule(debugConfig, id, 'constraint-check', {
|
|
712
|
+
link: {
|
|
713
|
+
id: _l.id,
|
|
714
|
+
source: _l.source,
|
|
715
|
+
target: _l.target,
|
|
716
|
+
type: _l.type,
|
|
717
|
+
lag: _l.lag
|
|
718
|
+
},
|
|
719
|
+
sourceTask: getAutoScheduleTaskSnapshot(_v, durationMap[_l.source] || 0),
|
|
720
|
+
previousStart: formatAutoScheduleDebugDate(start),
|
|
721
|
+
candidate: formatAutoScheduleDebugDate(candidate)
|
|
722
|
+
});
|
|
584
723
|
if (candidate) {
|
|
585
724
|
start = maxDate(start, candidate);
|
|
586
725
|
}
|
|
587
726
|
}
|
|
588
727
|
if (forcedStartMap[id]) {
|
|
728
|
+
logAutoSchedule(debugConfig, id, 'forced-start-check', {
|
|
729
|
+
previousStart: formatAutoScheduleDebugDate(start),
|
|
730
|
+
forcedStart: formatAutoScheduleDebugDate(forcedStartMap[id])
|
|
731
|
+
});
|
|
589
732
|
start = maxDate(start, forcedStartMap[id]);
|
|
590
733
|
}
|
|
591
734
|
if (start) {
|
|
592
735
|
task.start = start;
|
|
593
736
|
task.end = addDays(task.start, days);
|
|
737
|
+
logAutoSchedule(debugConfig, id, 'after-task', {
|
|
738
|
+
task: getAutoScheduleTaskSnapshot(task, days)
|
|
739
|
+
});
|
|
740
|
+
return;
|
|
594
741
|
}
|
|
742
|
+
logAutoSchedule(debugConfig, id, 'no-start-change', {
|
|
743
|
+
task: getAutoScheduleTaskSnapshot(task, days)
|
|
744
|
+
});
|
|
595
745
|
});
|
|
596
746
|
links.forEach(function (vLink) {
|
|
597
747
|
var lag = getLinkLag(vLink, tasks[tmap[vLink.source]], tasks[tmap[vLink.target]], durationMap[vLink.source] || 0);
|
|
598
748
|
vLink.calculateLag = lag != null ? lag : vLink.lag || 0;
|
|
749
|
+
if (shouldLogAutoScheduleTask(debugConfig, vLink.source) || shouldLogAutoScheduleTask(debugConfig, vLink.target)) {
|
|
750
|
+
console.log('[autoSchedule]', 'link-lag-sync', {
|
|
751
|
+
linkId: vLink.id,
|
|
752
|
+
source: vLink.source,
|
|
753
|
+
target: vLink.target,
|
|
754
|
+
type: vLink.type,
|
|
755
|
+
lag: vLink.lag,
|
|
756
|
+
calculateLag: vLink.calculateLag
|
|
757
|
+
});
|
|
758
|
+
}
|
|
599
759
|
});
|
|
600
760
|
}
|
|
601
761
|
|
|
@@ -1051,6 +1211,14 @@
|
|
|
1051
1211
|
if (!val) return null;
|
|
1052
1212
|
return typeof val.getTime === 'function' ? val.getTime() : val;
|
|
1053
1213
|
}
|
|
1214
|
+
function shouldShowBaselineEndDelay(v) {
|
|
1215
|
+
if (!v || v.type === 'group') {
|
|
1216
|
+
return false;
|
|
1217
|
+
}
|
|
1218
|
+
var baselineEnd = getTime(v.baselineEnd);
|
|
1219
|
+
var actualStart = getTime(v.start);
|
|
1220
|
+
return baselineEnd != null && actualStart != null && actualStart >= baselineEnd;
|
|
1221
|
+
}
|
|
1054
1222
|
|
|
1055
1223
|
// 根据 status 和日期计算活动条颜色
|
|
1056
1224
|
// status: 1=未开始 2=已完成 3=已开始
|
|
@@ -1061,6 +1229,12 @@
|
|
|
1061
1229
|
var is100Percent = percent >= 0.999999;
|
|
1062
1230
|
var blFinish = getTime(v.baselineEnd);
|
|
1063
1231
|
var actualFinish = getTime(v.end);
|
|
1232
|
+
if (shouldShowBaselineEndDelay(v)) {
|
|
1233
|
+
return {
|
|
1234
|
+
front: styles.undoneRed,
|
|
1235
|
+
back: styles.undoneRed
|
|
1236
|
+
};
|
|
1237
|
+
}
|
|
1064
1238
|
|
|
1065
1239
|
// 处理已完成状态或100%进度的情况 (status=2 或 100%进度)
|
|
1066
1240
|
if (status === 2 || is100Percent && type === 'group') {
|
|
@@ -1185,7 +1359,9 @@
|
|
|
1185
1359
|
|
|
1186
1360
|
// 里程碑颜色计算
|
|
1187
1361
|
var milestoneStyle = styles.milestone;
|
|
1188
|
-
if (v
|
|
1362
|
+
if (shouldShowBaselineEndDelay(v)) {
|
|
1363
|
+
milestoneStyle = styles.undoneRed;
|
|
1364
|
+
} else if (v.status === 2) {
|
|
1189
1365
|
// 状态为完成时
|
|
1190
1366
|
if (v.baselineStart && v.baselineStart >= v.start) {
|
|
1191
1367
|
milestoneStyle = styles.completedGreen;
|
package/dist/gantt.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(global,factory){typeof exports==="object"&&typeof module!=="undefined"?factory(exports):typeof define==="function"&&define.amd?define(["exports"],factory):(global=typeof globalThis!=="undefined"?globalThis:global||self,factory(global.Gantt={}))})(this,function(exports){"use strict";function getDefaultExportFromCjs(x){return x&&x.__esModule&&Object.prototype.hasOwnProperty.call(x,"default")?x["default"]:x}function createCommonjsModule(fn,basedir,module){return module={path:basedir,exports:{},require:function(path,base){return commonjsRequire(path,base===undefined||base===null?module.path:base)}},fn(module,module.exports),module.exports}function commonjsRequire(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}var _extends_1=createCommonjsModule(function(module){function _extends(){return module.exports=_extends=Object.assign?Object.assign.bind():function(n){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var r in t)({}).hasOwnProperty.call(t,r)&&(n[r]=t[r])}return n},module.exports.__esModule=true,module.exports["default"]=module.exports,_extends.apply(null,arguments)}module.exports=_extends,module.exports.__esModule=true,module.exports["default"]=module.exports});var _extends=getDefaultExportFromCjs(_extends_1);var _typeof_1=createCommonjsModule(function(module){function _typeof(o){"@babel/helpers - typeof";return module.exports=_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(o){return typeof o}:function(o){return o&&"function"==typeof Symbol&&o.constructor===Symbol&&o!==Symbol.prototype?"symbol":typeof o},module.exports.__esModule=true,module.exports["default"]=module.exports,_typeof(o)}module.exports=_typeof,module.exports.__esModule=true,module.exports["default"]=module.exports});var _typeof=getDefaultExportFromCjs(_typeof_1);var toPrimitive_1=createCommonjsModule(function(module){var _typeof=_typeof_1["default"];function toPrimitive(t,r){if("object"!=_typeof(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var i=e.call(t,r||"default");if("object"!=_typeof(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(t)}module.exports=toPrimitive,module.exports.__esModule=true,module.exports["default"]=module.exports});var toPropertyKey_1=createCommonjsModule(function(module){var _typeof=_typeof_1["default"];function toPropertyKey(t){var i=toPrimitive_1(t,"string");return"symbol"==_typeof(i)?i:i+""}module.exports=toPropertyKey,module.exports.__esModule=true,module.exports["default"]=module.exports});var defineProperty=createCommonjsModule(function(module){function _defineProperty(e,r,t){return(r=toPropertyKey_1(r))in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}module.exports=_defineProperty,module.exports.__esModule=true,module.exports["default"]=module.exports});var _defineProperty=getDefaultExportFromCjs(defineProperty);var classCallCheck=createCommonjsModule(function(module){function _classCallCheck(a,n){if(!(a instanceof n))throw new TypeError("Cannot call a class as a function")}module.exports=_classCallCheck,module.exports.__esModule=true,module.exports["default"]=module.exports});var _classCallCheck=getDefaultExportFromCjs(classCallCheck);var createClass=createCommonjsModule(function(module){function _defineProperties(e,r){for(var t=0;t<r.length;t++){var o=r[t];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,toPropertyKey_1(o.key),o)}}function _createClass(e,r,t){return r&&_defineProperties(e.prototype,r),t&&_defineProperties(e,t),Object.defineProperty(e,"prototype",{writable:!1}),e}module.exports=_createClass,module.exports.__esModule=true,module.exports["default"]=module.exports});var _createClass=getDefaultExportFromCjs(createClass);function ownKeys$5(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);r&&(o=o.filter(function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable})),t.push.apply(t,o)}return t}function _objectSpread$5(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?ownKeys$5(Object(t),!0).forEach(function(r){_defineProperty(e,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):ownKeys$5(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})}return e}function addChild(c,childNodes){if(c===null||c===undefined)return;if(typeof c==="string"||typeof c==="number"){childNodes.push(c.toString())}else if(Array.isArray(c)){for(var i=0;i<c.length;i++){addChild(c[i],childNodes)}}else{childNodes.push(c)}}function h(tag,props){var childNodes=[];for(var _len=arguments.length,children=new Array(_len>2?_len-2:0),_key=2;_key<_len;_key++){children[_key-2]=arguments[_key]}addChild(children,childNodes);if(typeof tag==="function"){return tag(_objectSpread$5(_objectSpread$5({},props),{},{children:childNodes}))}return{tag:tag,props:props,children:childNodes}}function ownKeys$4(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);r&&(o=o.filter(function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable})),t.push.apply(t,o)}return t}function _objectSpread$4(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?ownKeys$4(Object(t),!0).forEach(function(r){_defineProperty(e,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):ownKeys$4(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})}return e}var DAY=24*3600*1e3;function addDays(date,days){var d=new Date(date.valueOf());d.setDate(d.getDate()+days);return d}function getDates(begin,end){var dates=[];var s=new Date(begin);s.setHours(24,0,0,0);while(s.getTime()<=end){dates.push(s.getTime());s=addDays(s,1)}return dates}var ctx=null;function textWidth(text,font,pad){ctx=ctx||document.createElement("canvas").getContext("2d");ctx.font=font;return ctx.measureText(text).width+pad}function formatMonth(date){var y=date.getFullYear();var m=date.getMonth()+1;return"".concat(y,"/").concat(m>9?m:"0".concat(m))}function formatDay(date){var m=date.getMonth()+1;var d=date.getDate();return"".concat(m,"/").concat(d)}function minDate(a,b){if(a&&b){return a>b?b:a}return a||b}function maxDate(a,b){if(a&&b){return a<b?b:a}return a||b}function max(list,defaultValue){if(list.length){return Math.max.apply(null,list)}return defaultValue}function p2s(arr){return arr.map(function(p){return"".concat(p[0],",").concat(p[1])}).join(" ")}function s2p(str){return str.split(" ").map(function(s){var p=s.split(",");return[parseFloat(p[0]),parseFloat(p[1])]})}function walkLevel(nodes,level){for(var i=0;i<nodes.length;i++){var node=nodes[i];node.level="".concat(level).concat(i+1);node.text="".concat(node.level," ").concat(node.name);walkLevel(node.children,"".concat(node.level,"."))}}function walkDates(nodes){var start=null;var end=null;var baselineStart=null;var baselineEnd=null;var percent=0;for(var i=0;i<nodes.length;i++){var node=nodes[i];if(node.children.length){var tmp=walkDates(node.children);node.start=tmp.start;node.end=tmp.end;node.baselineStart=tmp.baselineStart;node.baselineEnd=tmp.baselineEnd;node.percent=tmp.percent;if(node.start&&node.end){node.duration=(node.end-node.start)/DAY}else{node.duration=0}if(node.baselineStart&&node.baselineEnd){node.baselineDuration=(node.baselineEnd-node.baselineStart)/DAY}else{node.baselineDuration=0}}else{node.percent=node.percent||0;if(node.start&&node.end!=null){node.end=addDays(node.start,node.duration||0)}if(node.baselineStart&&node.baselineDuration!=null){node.baselineEnd=addDays(node.baselineStart,node.baselineDuration)}if(node.type==="milestone"){node.baselineEnd=node.baselineStart;node.end=node.start}}start=minDate(start,node.start);end=maxDate(end,node.end);baselineStart=minDate(baselineStart,node.baselineStart);baselineEnd=maxDate(baselineEnd,node.baselineEnd);percent+=node.percent}if(nodes.length){percent/=nodes.length}return{start:start,end:end,baselineStart:baselineStart,baselineEnd:baselineEnd,percent:percent}}function formatData(tasks,links,walk){var map={};var tmp=tasks.map(function(t,i){map[t.id]=i;return _objectSpread$4(_objectSpread$4({},t),{},{children:[],links:[]})});var roots=[];tmp.forEach(function(t){var parent=tmp[map[t.parent]];if(parent){parent.children.push(t)}else{roots.push(t)}});links.forEach(function(l){var s=tmp[map[l.source]];var t=tmp[map[l.target]];if(s&&t){s.links.push(l)}});walkLevel(roots,"");walkDates(roots);if(walk){walk(roots)}var list=[];roots.forEach(function(r){var stack=[];stack.push(r);while(stack.length){var node=stack.pop();var len=node.children.length;if(len){node.type="group"}list.push(node);for(var i=len-1;i>=0;i--){stack.push(node.children[i])}}});return list}function hasPath(vmap,a,b){var stack=[];stack.push(vmap[a]);while(stack.length){var v=stack.pop();if(v.id===b){return true}for(var i=0;i<v.links.length;i++){stack.push(v.links[i])}}return false}function toposort(links){var vmap={};links.forEach(function(l){var init=function init(id){return{id:id,out:[],in:0}};vmap[l.source]=init(l.source);vmap[l.target]=init(l.target)});for(var i=0;i<links.length;i++){var l=links[i];vmap[l.target]["in"]++;vmap[l.source].out.push(i)}var s=Object.keys(vmap).map(function(k){return vmap[k].id}).filter(function(id){return!vmap[id]["in"]});var sorted=[];while(s.length){var id=s.pop();sorted.push(id);for(var _i=0;_i<vmap[id].out.length;_i++){var index=vmap[id].out[_i];var v=vmap[links[index].target];v["in"]--;if(!v["in"]){s.push(v.id)}}}return sorted}function getScheduleDuration(task){if(task.type==="milestone"){return 0}if(task.start&&task.end){return Math.round((task.end-task.start)/DAY)}if(task.duration!=null){return task.duration}return 0}function getTaskEnd(task,duration){if(!task||!task.start){return null}if(task.end){return task.end}return addDays(task.start,duration||0)}function getConstraintStart(link,sourceTask,targetDuration,sourceDuration){if(!sourceTask||!sourceTask.start){return null}var lag=link.lag||0;var sourceEnd=getTaskEnd(sourceTask,sourceDuration);if(link.type==="SS"){return addDays(sourceTask.start,lag)}if(link.type==="FS"&&sourceEnd){return addDays(sourceEnd,lag)}if(link.type==="SF"){return addDays(addDays(sourceTask.start,lag),-targetDuration)}if(link.type==="FF"&&sourceEnd){return addDays(addDays(sourceEnd,lag),-targetDuration)}return null}function getLinkLag(link,sourceTask,targetTask,sourceDuration){if(!sourceTask||!targetTask){return null}var sourceEnd=getTaskEnd(sourceTask,sourceDuration);if(link.type==="SS"&&sourceTask.start&&targetTask.start){return Math.round((targetTask.start-sourceTask.start)/DAY)}if(link.type==="FS"&&sourceEnd&&targetTask.start){return Math.round((targetTask.start-sourceEnd)/DAY)}if(link.type==="SF"&&sourceTask.start&&targetTask.end){return Math.round((targetTask.end-sourceTask.start)/DAY)}if(link.type==="FF"&&sourceEnd&&targetTask.end){return Math.round((targetTask.end-sourceEnd)/DAY)}return null}function normalizeScheduleDate(date){var value=new Date(date.valueOf());value.setHours(0,0,0,0);return value}function isUnstartedTask(task){return task&&task.status===1}function canAdjustUnstartedTask(task,lockMilestone){if(!isUnstartedTask(task)){return false}if(lockMilestone&&task.type==="milestone"){return false}return true}function isOverdueUnstartedTask(task,currentDate,lockMilestone){return Boolean(task&&task.start&&task.start<currentDate&&canAdjustUnstartedTask(task,lockMilestone))}function getOverdueRootTaskIds(id,ins,tasks,tmap,currentDate,lockMilestone){var roots=new Set;var visited=new Set;var stack=[id];while(stack.length){var currentId=stack.pop();if(visited.has(currentId)){continue}visited.add(currentId);var hasOverduePredecessor=false;var incomingLinks=ins[currentId]||[];for(var i=0;i<incomingLinks.length;i++){var sourceId=incomingLinks[i].source;var sourceTask=tasks[tmap[sourceId]];if(isOverdueUnstartedTask(sourceTask,currentDate,lockMilestone)){hasOverduePredecessor=true;stack.push(sourceId)}}if(!hasOverduePredecessor){roots.add(currentId)}}return roots}function getForcedStartMap(sorted,ins,tasks,tmap,currentDate,lockMilestone){var forcedStartMap={};sorted.forEach(function(id){var task=tasks[tmap[id]];if(!isOverdueUnstartedTask(task,currentDate,lockMilestone)){return}var roots=getOverdueRootTaskIds(id,ins,tasks,tmap,currentDate,lockMilestone);roots.forEach(function(rootId){forcedStartMap[rootId]=currentDate})});return forcedStartMap}function autoSchedule(tasks,links){var lockMilestone=arguments.length>2&&arguments[2]!==undefined?arguments[2]:false;var currentDate=arguments.length>3&&arguments[3]!==undefined?arguments[3]:new Date;var vmap={};links.forEach(function(l){vmap[l.source]={id:l.source,links:[]};vmap[l.target]={id:l.target,links:[]}});var dag=[];links.forEach(function(l){var source=l.source,target=l.target;if(!hasPath(vmap,target,source)){dag.push(l);vmap[source].links.push(vmap[target])}});var sorted=toposort(dag);var tmap={};var durationMap={};for(var i=0;i<tasks.length;i++){var task=tasks[i];durationMap[task.id]=getScheduleDuration(task);tmap[task.id]=i;if(!sorted.includes(task.id)){sorted.push(task.id)}}var ins={};sorted.forEach(function(id){ins[id]=[]});dag.forEach(function(l){ins[l.target].push(l)});var scheduleDate=normalizeScheduleDate(currentDate);var forcedStartMap=getForcedStartMap(sorted,ins,tasks,tmap,scheduleDate,lockMilestone);sorted.forEach(function(id){var task=tasks[tmap[id]];if(!task)return;var days=durationMap[id]||0;if(lockMilestone&&task.type==="milestone"){return}if(task.status===2){return}if(task.status===3){if(!task.start){return}var end=addDays(task.start,days);for(var _i2=0;_i2<ins[id].length;_i2++){var l=ins[id][_i2];var v=tasks[tmap[l.source]];if(v&&v.start){var s=addDays(v.start,l.lag||0);var e=addDays(s,durationMap[l.source]||0);if(l.type==="SF"){end=maxDate(end,s)}if(l.type==="FF"){end=maxDate(end,e)}}}task.end=end;task.duration=(task.end-task.start)/DAY;return}var start=null;for(var _i3=0;_i3<ins[id].length;_i3++){var _l=ins[id][_i3];var _v=tasks[tmap[_l.source]];var candidate=getConstraintStart(_l,_v,days,durationMap[_l.source]||0);if(candidate){start=maxDate(start,candidate)}}if(forcedStartMap[id]){start=maxDate(start,forcedStartMap[id])}if(start){task.start=start;task.end=addDays(task.start,days)}});links.forEach(function(vLink){var lag=getLinkLag(vLink,tasks[tmap[vLink.source]],tasks[tmap[vLink.target]],durationMap[vLink.source]||0);vLink.calculateLag=lag!=null?lag:vLink.lag||0})}var utils=Object.freeze({__proto__:null,DAY:DAY,addDays:addDays,getDates:getDates,textWidth:textWidth,formatMonth:formatMonth,formatDay:formatDay,minDate:minDate,maxDate:maxDate,max:max,p2s:p2s,s2p:s2p,formatData:formatData,hasPath:hasPath,toposort:toposort,autoSchedule:autoSchedule});function Layout(_ref){var styles=_ref.styles,width=_ref.width,height=_ref.height,offsetY=_ref.offsetY,thickWidth=_ref.thickWidth,maxTextWidth=_ref.maxTextWidth;var x0=thickWidth/2;var W=width-thickWidth;var H=height-thickWidth;return h("g",null,h("rect",{x:x0,y:x0,width:W,height:H,style:styles.box}),h("line",{x1:0,x2:width,y1:offsetY-x0,y2:offsetY-x0,style:styles.bline}),h("line",{x1:maxTextWidth,x2:width,y1:offsetY/2,y2:offsetY/2,style:styles.line}))}function YearMonth(_ref){var styles=_ref.styles,dates=_ref.dates,unit=_ref.unit,offsetY=_ref.offsetY,minTime=_ref.minTime,maxTime=_ref.maxTime,maxTextWidth=_ref.maxTextWidth;var months=dates.filter(function(v){return new Date(v).getDate()===1});months.unshift(minTime);months.push(maxTime);var ticks=[];var x0=maxTextWidth;var y2=offsetY/2;var len=months.length-1;for(var i=0;i<len;i++){var cur=new Date(months[i]);var str=formatMonth(cur);var x=x0+(months[i]-minTime)/unit;var t=(months[i+1]-months[i])/unit;ticks.push(h("g",null,h("line",{x1:x,x2:x,y1:0,y2:y2,style:styles.line}),t>50?h("text",{x:x+t/2,y:offsetY*.25,style:styles.text3},str):null))}return h("g",null,ticks)}function DayHeader(_ref){var styles=_ref.styles,unit=_ref.unit,minTime=_ref.minTime,maxTime=_ref.maxTime,height=_ref.height,offsetY=_ref.offsetY,maxTextWidth=_ref.maxTextWidth;var dates=getDates(minTime,maxTime);var ticks=[];var x0=maxTextWidth;var y0=offsetY/2;var RH=height-y0;var len=dates.length-1;for(var i=0;i<len;i++){var cur=new Date(dates[i]);var day=cur.getDay();var x=x0+(dates[i]-minTime)/unit;var t=(dates[i+1]-dates[i])/unit;ticks.push(h("g",null,day===0||day===6?h("rect",{x:x,y:y0,width:t,height:RH,style:styles.week}):null,h("line",{x1:x,x2:x,y1:y0,y2:offsetY,style:styles.line}),h("text",{x:x+t/2,y:offsetY*.75,style:styles.text3},cur.getDate()),i===len-1?h("line",{x1:x+t,x2:x+t,y1:y0,y2:offsetY,style:styles.line}):null))}return h("g",null,h(YearMonth,{styles:styles,unit:unit,dates:dates,offsetY:offsetY,minTime:minTime,maxTime:maxTime,maxTextWidth:maxTextWidth}),ticks)}function WeekHeader(_ref){var styles=_ref.styles,unit=_ref.unit,minTime=_ref.minTime,maxTime=_ref.maxTime,height=_ref.height,offsetY=_ref.offsetY,maxTextWidth=_ref.maxTextWidth;var dates=getDates(minTime,maxTime);var weeks=dates.filter(function(v){return new Date(v).getDay()===0});weeks.push(maxTime);var ticks=[];var x0=maxTextWidth;var y0=offsetY;var RH=height-y0;var d=DAY/unit;var len=weeks.length-1;for(var i=0;i<len;i++){var cur=new Date(weeks[i]);var x=x0+(weeks[i]-minTime)/unit;var curDay=cur.getDate();var prevDay=addDays(cur,-1).getDate();ticks.push(h("g",null,h("rect",{x:x-d,y:y0,width:d*2,height:RH,style:styles.week}),h("line",{x1:x,x2:x,y1:offsetY/2,y2:offsetY,style:styles.line}),h("text",{x:x+3,y:offsetY*.75,style:styles.text2},curDay),x-x0>28?h("text",{x:x-3,y:offsetY*.75,style:styles.text1},prevDay):null))}return h("g",null,h(YearMonth,{styles:styles,unit:unit,dates:dates,offsetY:offsetY,minTime:minTime,maxTime:maxTime,maxTextWidth:maxTextWidth}),ticks)}function Year(_ref){var styles=_ref.styles,months=_ref.months,unit=_ref.unit,offsetY=_ref.offsetY,minTime=_ref.minTime,maxTime=_ref.maxTime,maxTextWidth=_ref.maxTextWidth;var years=months.filter(function(v){return new Date(v).getMonth()===0});years.unshift(minTime);years.push(maxTime);var ticks=[];var x0=maxTextWidth;var y2=offsetY/2;var len=years.length-1;for(var i=0;i<len;i++){var cur=new Date(years[i]);var x=x0+(years[i]-minTime)/unit;var t=(years[i+1]-years[i])/unit;ticks.push(h("g",null,h("line",{x1:x,x2:x,y1:0,y2:y2,style:styles.line}),t>35?h("text",{x:x+t/2,y:offsetY*.25,style:styles.text3},cur.getFullYear()):null))}return h("g",null,ticks)}function MonthHeader(_ref){var styles=_ref.styles,unit=_ref.unit,minTime=_ref.minTime,maxTime=_ref.maxTime,offsetY=_ref.offsetY,maxTextWidth=_ref.maxTextWidth;var MONTH=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];var dates=getDates(minTime,maxTime);var months=dates.filter(function(v){return new Date(v).getDate()===1});months.unshift(minTime);months.push(maxTime);var ticks=[];var x0=maxTextWidth;var y0=offsetY/2;var len=months.length-1;for(var i=0;i<len;i++){var cur=new Date(months[i]);var month=cur.getMonth();var x=x0+(months[i]-minTime)/unit;var t=(months[i+1]-months[i])/unit;ticks.push(h("g",null,h("line",{x1:x,x2:x,y1:y0,y2:offsetY,style:styles.line}),t>30?h("text",{x:x+t/2,y:offsetY*.75,style:styles.text3},MONTH[month]):null))}return h("g",null,h(Year,{styles:styles,unit:unit,months:months,offsetY:offsetY,minTime:minTime,maxTime:maxTime,maxTextWidth:maxTextWidth}),ticks)}function Grid(_ref){var styles=_ref.styles,data=_ref.data,width=_ref.width,height=_ref.height,offsetY=_ref.offsetY,rowHeight=_ref.rowHeight,maxTextWidth=_ref.maxTextWidth;return h("g",null,data.map(function(v,i){var y=(i+1)*rowHeight+offsetY;return h("line",{key:i,x1:0,x2:width,y1:y,y2:y,style:styles.line})}),h("line",{x1:maxTextWidth,x2:maxTextWidth,y1:0,y2:height,style:styles.bline}))}function Labels(_ref){var styles=_ref.styles,data=_ref.data,_onClick=_ref.onClick,rowHeight=_ref.rowHeight,offsetY=_ref.offsetY;return h("g",null,data.map(function(v,i){return h("text",{key:i,x:10,y:(i+.5)*rowHeight+offsetY,class:"gantt-label",style:styles.label,onClick:function onClick(){return _onClick(v)}},v.text)}))}function LinkLine(_ref){var styles=_ref.styles,data=_ref.data,unit=_ref.unit,offsetY=_ref.offsetY,minTime=_ref.minTime,rowHeight=_ref.rowHeight,barHeight=_ref.barHeight,maxTextWidth=_ref.maxTextWidth;var x0=maxTextWidth;var y0=rowHeight/2+offsetY;var map={};data.forEach(function(v,i){map[v.id]=i});return h("g",null,data.map(function(s,i){if(!s.end||!s.start||!s.links){return null}return s.links.map(function(l){var j=map[l.target];var e=data[j];if(!e||!e.start||!e.end)return null;var gap=12;var arrow=6;var mgap=e.type==="milestone"?barHeight/2:0;var y1=y0+i*rowHeight;var y2=y0+j*rowHeight;var vgap=barHeight/2+4;if(y1>y2){vgap=-vgap}if(l.type==="FS"){var x1=x0+(s.end-minTime)/unit;var x2=x0+(e.start-minTime)/unit-mgap;var p1=[[x1,y1],[x1+gap,y1]];if(x2-x1>=2*gap){p1.push([x1+gap,y2])}else{p1.push([x1+gap,y2-vgap]);p1.push([x2-gap,y2-vgap]);p1.push([x2-gap,y2])}p1.push([x2-arrow,y2]);var p2=[[x2-arrow,y2-arrow],[x2,y2],[x2-arrow,y2+arrow]];return h("g",null,h("polyline",{points:p2s(p1),style:styles.link}),h("polygon",{points:p2s(p2),style:styles.linkArrow}))}if(l.type==="FF"){var _x=x0+(s.end-minTime)/unit;var _x2=x0+(e.end-minTime)/unit+mgap;var _p=[[_x,y1],[_x+gap,y1]];if(_x2<=_x){_p.push([_x+gap,y2])}else{_p.push([_x+gap,y2-vgap]);_p.push([_x2+gap,y2-vgap]);_p.push([_x2+gap,y2])}_p.push([_x2+arrow,y2]);var _p2=[[_x2+arrow,y2-arrow],[_x2,y2],[_x2+arrow,y2+arrow]];return h("g",null,h("polyline",{points:p2s(_p),style:styles.link}),h("polygon",{points:p2s(_p2),style:styles.linkArrow}))}if(l.type==="SS"){var _x3=x0+(s.start-minTime)/unit;var _x4=x0+(e.start-minTime)/unit-mgap;var _p3=[[_x3,y1],[_x3-gap,y1]];if(_x3<=_x4){_p3.push([_x3-gap,y2])}else{_p3.push([_x3-gap,y2-vgap]);_p3.push([_x4-gap,y2-vgap]);_p3.push([_x4-gap,y2])}_p3.push([_x4-arrow,y2]);var _p4=[[_x4-arrow,y2-arrow],[_x4,y2],[_x4-arrow,y2+arrow]];return h("g",null,h("polyline",{points:p2s(_p3),style:styles.link}),h("polygon",{points:p2s(_p4),style:styles.linkArrow}))}if(l.type==="SF"){var _x5=x0+(s.start-minTime)/unit;var _x6=x0+(e.end-minTime)/unit+mgap;var _p5=[[_x5,y1],[_x5-gap,y1]];if(_x5-_x6>=2*gap){_p5.push([_x5-gap,y2])}else{_p5.push([_x5-gap,y2-vgap]);_p5.push([_x6+gap,y2-vgap]);_p5.push([_x6+gap,y2])}_p5.push([_x6+arrow,y2]);var _p6=[[_x6+arrow,y2-arrow],[_x6,y2],[_x6+arrow,y2+arrow]];return h("g",null,h("polyline",{points:p2s(_p5),style:styles.link}),h("polygon",{points:p2s(_p6),style:styles.linkArrow}))}return null})}))}function getTime(val){if(!val)return null;return typeof val.getTime==="function"?val.getTime():val}function getBarColors(v,current,styles){var status=v.status;var type=v.type;var percent=v.percent||0;var is100Percent=percent>=.999999;var blFinish=getTime(v.baselineEnd);var actualFinish=getTime(v.end);if(status===2||is100Percent&&type==="group"){var isLate=blFinish!=null&&actualFinish!=null&&actualFinish>blFinish;var color=isLate?styles.undoneRed:styles.completedGreen;return{front:color,back:color}}if(status===1||status===3||status==null&&type==="group"){var doneStyle=styles.doneBlue;var undoneStyle=styles.undoneLightGreen;if(blFinish!=null){var currentAfterBL=current>blFinish;var currentBeforeBL=current<blFinish;var actualAfterBL=actualFinish!=null?actualFinish>blFinish:false;var actualMissing=actualFinish==null;var _isLate=currentAfterBL&&(actualAfterBL||actualMissing);var isExpectedOverdue=currentBeforeBL&&actualAfterBL;var isExpectedOnTime=currentBeforeBL&&!actualAfterBL;if(currentAfterBL||_isLate){undoneStyle=styles.undoneRed}else if(isExpectedOverdue){undoneStyle=styles.undoneYellow}else if(isExpectedOnTime){undoneStyle=styles.undoneLightGreen}}return{front:doneStyle,back:undoneStyle}}return null}function Bar(_ref){var styles=_ref.styles,data=_ref.data,unit=_ref.unit,height=_ref.height,offsetY=_ref.offsetY,minTime=_ref.minTime;_ref.showDelay;var rowHeight=_ref.rowHeight,barHeight=_ref.barHeight,baselineHeight=_ref.baselineHeight,_ref$rowPadding=_ref.rowPadding,rowPadding=_ref$rowPadding===void 0?10:_ref$rowPadding,_ref$rowGap=_ref.rowGap,rowGap=_ref$rowGap===void 0?2:_ref$rowGap,maxTextWidth=_ref.maxTextWidth,current=_ref.current,onClick=_ref.onClick;var x0=maxTextWidth;var cur=x0+(current-minTime)/unit;return h("g",null,current>minTime?h("line",{x1:cur,x2:cur,y1:offsetY,y2:height,style:styles.cline}):null,data.map(function(v,i){var handler=function handler(){return onClick(v)};var y=offsetY+i*rowHeight+rowPadding;var cy=y+barHeight/2;var hasStartEnd=v.start&&v.end;var hasBaselineOnly=!hasStartEnd&&v.baselineStart&&v.baselineEnd;if(hasBaselineOnly){var _baselineWidth=(v.baselineEnd-v.baselineStart)/unit;if(_baselineWidth<=0)return null;var _bx=x0+(v.baselineStart-minTime)/unit;var _baselineCy=y+barHeight+rowGap+baselineHeight/2;return h("g",{key:i,class:"gantt-bar",style:{cursor:"pointer"},onClick:handler},h("text",{x:_bx-4,y:_baselineCy,style:styles.text1},formatDay(v.baselineStart)),h("text",{x:_bx+_baselineWidth+4,y:_baselineCy,style:styles.text2},formatDay(v.baselineEnd)),h("rect",{x:_bx,y:y+barHeight+rowGap,width:_baselineWidth,height:baselineHeight,rx:1.2,ry:1.2,style:styles.baseline,onClick:handler}))}if(!v.end||!v.start){return null}var x=x0+(v.start-minTime)/unit;if(v.type==="milestone"){var size=barHeight/2;var points=[[x,cy-size],[x+size,cy],[x,cy+size],[x-size,cy]].map(function(p){return"".concat(p[0],",").concat(p[1])}).join(" ");var milestoneStyle=styles.milestone;if(v.status===2){if(v.baselineStart&&v.baselineStart>=v.start){milestoneStyle=styles.completedGreen}else if(v.baselineStart&&v.baselineStart<v.start){milestoneStyle=styles.undoneRed}}else{if(v.baselineStart&&v.baselineStart<v.start){if(v.start<current){milestoneStyle=styles.undoneRed}else if(v.start>=current){milestoneStyle=styles.undoneYellow}}else{milestoneStyle=styles.completedGreen}}var _baseline=null;if(v.baselineStart){var _bx2=x0+(v.baselineStart-minTime)/unit;var _baselineCy2=y+barHeight+rowGap+baselineHeight/2;var baselineSize=baselineHeight;var baselinePoints=[[_bx2,_baselineCy2-baselineSize],[_bx2+baselineSize,_baselineCy2],[_bx2,_baselineCy2+baselineSize],[_bx2-baselineSize,_baselineCy2]].map(function(p){return"".concat(p[0],",").concat(p[1])}).join(" ");_baseline=h("g",null,h("text",{x:_bx2-10,y:_baselineCy2,style:styles.text1},formatDay(v.baselineStart)),h("polygon",{points:baselinePoints,style:styles.baseline}),h("circle",{class:"gantt-ctrl-start","data-id":v.id,cx:_bx2,cy:_baselineCy2,r:6,style:styles.ctrl}))}return h("g",{key:i,class:"gantt-bar",style:{cursor:"pointer"},onClick:handler},h("text",{x:x-10,y:cy,style:styles.text1},formatDay(v.start)),h("polygon",{points:points,style:milestoneStyle,onClick:handler}),h("circle",{class:"gantt-ctrl-start","data-id":v.id,cx:x,cy:cy,r:6,style:styles.ctrl}),_baseline)}var w1=(v.end-v.start)/unit;var w2=w1*v.percent;if(w1<=0){return null}var bar;var statusColors=getBarColors(v,current,styles);if(statusColors){bar={back:statusColors.back,front:statusColors.front}}else{bar=v.type==="group"?{back:styles.groupBack,front:styles.groupFront}:{back:styles.taskBack,front:styles.taskFront}}var baselineWidth=(v.baselineEnd-v.baselineStart)/unit;var bx=x0+(v.baselineStart-minTime)/unit;var baselineCy=y+barHeight+rowGap+baselineHeight/2;var baseline=v.baselineStart&&v.baselineEnd&&baselineWidth>0?h("g",null,h("text",{x:bx-4,y:baselineCy,style:styles.text1},formatDay(v.baselineStart)),h("text",{x:bx+baselineWidth+4,y:baselineCy,style:styles.text2},formatDay(v.baselineEnd)),h("rect",{x:bx,y:y+barHeight+rowGap,width:baselineWidth,height:baselineHeight,rx:1.2,ry:1.2,style:styles.baseline})):null;return h("g",{key:i,class:"gantt-bar",style:{cursor:"pointer"},onClick:handler},h("text",{x:x-4,y:cy,style:styles.text1},formatDay(v.start)),h("text",{x:x+w1+4,y:cy,style:styles.text2},formatDay(v.end)),h("rect",{x:x,y:y,width:w1,height:barHeight,rx:1.8,ry:1.8,style:bar.back,onClick:handler}),w2>1e-6?h("rect",{x:x,y:y,width:w2,height:barHeight,rx:1.8,ry:1.8,style:bar.front}):null,baseline,v.type==="group"?null:h("g",null,h("circle",{class:"gantt-ctrl-start","data-id":v.id,cx:x-12,cy:cy,r:6,style:styles.ctrl}),h("circle",{class:"gantt-ctrl-finish","data-id":v.id,cx:x+w1+12,cy:cy,r:6,style:styles.ctrl})))}))}function ownKeys$3(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);r&&(o=o.filter(function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable})),t.push.apply(t,o)}return t}function _objectSpread$3(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?ownKeys$3(Object(t),!0).forEach(function(r){_defineProperty(e,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):ownKeys$3(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})}return e}var SIZE="14px";var TYPE='-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif';function getFont(_ref){var _ref$fontSize=_ref.fontSize,fontSize=_ref$fontSize===void 0?SIZE:_ref$fontSize,_ref$fontFamily=_ref.fontFamily,fontFamily=_ref$fontFamily===void 0?TYPE:_ref$fontFamily;return"bold ".concat(fontSize," ").concat(fontFamily)}function getStyles(_ref2){var _ref2$bgColor=_ref2.bgColor,bgColor=_ref2$bgColor===void 0?"#fff":_ref2$bgColor,_ref2$lineColor=_ref2.lineColor,lineColor=_ref2$lineColor===void 0?"#eee":_ref2$lineColor,_ref2$redLineColor=_ref2.redLineColor,redLineColor=_ref2$redLineColor===void 0?"#f04134":_ref2$redLineColor,_ref2$groupBack=_ref2.groupBack,groupBack=_ref2$groupBack===void 0?"#3db9d3":_ref2$groupBack,_ref2$groupFront=_ref2.groupFront,groupFront=_ref2$groupFront===void 0?"#299cb4":_ref2$groupFront,_ref2$taskBack=_ref2.taskBack,taskBack=_ref2$taskBack===void 0?"#65c16f":_ref2$taskBack,_ref2$taskFront=_ref2.taskFront,taskFront=_ref2$taskFront===void 0?"#46ad51":_ref2$taskFront,_ref2$taskProgress=_ref2.taskProgress,taskProgress=_ref2$taskProgress===void 0?"#1890ff":_ref2$taskProgress,_ref2$milestone=_ref2.milestone,milestone=_ref2$milestone===void 0?"#d33daf":_ref2$milestone,_ref2$warning=_ref2.warning,warning=_ref2$warning===void 0?"#faad14":_ref2$warning,_ref2$danger=_ref2.danger,danger=_ref2$danger===void 0?"#f5222d":_ref2$danger,_ref2$critical=_ref2.critical,critical=_ref2$critical===void 0?"#ff4d4f":_ref2$critical,_ref2$link=_ref2.link,link=_ref2$link===void 0?"#ffa011":_ref2$link,_ref2$baseline=_ref2.baseline,baseline=_ref2$baseline===void 0?"#3c3c3c":_ref2$baseline,_ref2$completedGreen=_ref2.completedGreen,completedGreen=_ref2$completedGreen===void 0?"#46ad51":_ref2$completedGreen,_ref2$doneBlue=_ref2.doneBlue,doneBlue=_ref2$doneBlue===void 0?"#1890ff":_ref2$doneBlue,_ref2$undoneRed=_ref2.undoneRed,undoneRed=_ref2$undoneRed===void 0?"#f5222d":_ref2$undoneRed,_ref2$undoneYellow=_ref2.undoneYellow,undoneYellow=_ref2$undoneYellow===void 0?"#faad14":_ref2$undoneYellow,_ref2$undoneLightGree=_ref2.undoneLightGreen,undoneLightGreen=_ref2$undoneLightGree===void 0?"#95de64":_ref2$undoneLightGree,_ref2$textColor=_ref2.textColor,textColor=_ref2$textColor===void 0?"#222":_ref2$textColor,_ref2$lightTextColor=_ref2.lightTextColor,lightTextColor=_ref2$lightTextColor===void 0?"#999":_ref2$lightTextColor,_ref2$lineWidth=_ref2.lineWidth,lineWidth=_ref2$lineWidth===void 0?"1px":_ref2$lineWidth,_ref2$thickLineWidth=_ref2.thickLineWidth,thickLineWidth=_ref2$thickLineWidth===void 0?"1.4px":_ref2$thickLineWidth,_ref2$fontSize=_ref2.fontSize,fontSize=_ref2$fontSize===void 0?SIZE:_ref2$fontSize,_ref2$smallFontSize=_ref2.smallFontSize,smallFontSize=_ref2$smallFontSize===void 0?"12px":_ref2$smallFontSize,_ref2$fontFamily=_ref2.fontFamily,fontFamily=_ref2$fontFamily===void 0?TYPE:_ref2$fontFamily,_ref2$whiteSpace=_ref2.whiteSpace,whiteSpace=_ref2$whiteSpace===void 0?"pre":_ref2$whiteSpace;var line={stroke:lineColor,"stroke-width":lineWidth};var redLine={stroke:redLineColor,"stroke-width":lineWidth};var thickLine={stroke:lineColor,"stroke-width":thickLineWidth};var text={fill:textColor,"dominant-baseline":"central","font-size":fontSize,"font-family":fontFamily,"white-space":whiteSpace};var smallText={fill:lightTextColor,"font-size":smallFontSize};return{week:{fill:"rgba(252, 248, 227, .6)"},box:_objectSpread$3(_objectSpread$3({},thickLine),{},{fill:bgColor}),line:line,cline:redLine,bline:thickLine,label:text,groupLabel:_objectSpread$3(_objectSpread$3({},text),{},{"font-weight":"600"}),text1:_objectSpread$3(_objectSpread$3(_objectSpread$3({},text),smallText),{},{"text-anchor":"end"}),text2:_objectSpread$3(_objectSpread$3({},text),smallText),text3:_objectSpread$3(_objectSpread$3(_objectSpread$3({},text),smallText),{},{"text-anchor":"middle"}),link:{stroke:link,"stroke-width":"1.5px",fill:"none"},linkArrow:{fill:link},milestone:{fill:milestone},groupBack:{fill:groupBack},groupFront:{fill:groupFront},groupProgress:{fill:groupFront},taskBack:{fill:taskBack},taskFront:{fill:taskFront},taskProgress:{fill:taskProgress},warning:{fill:warning},danger:{fill:danger},critical:{fill:critical},completedGreen:{fill:completedGreen},doneBlue:{fill:doneBlue},undoneRed:{fill:undoneRed},undoneYellow:{fill:undoneYellow},undoneLightGreen:{fill:undoneLightGreen},baseline:{fill:baseline,opacity:.5},ctrl:{display:"none",fill:"#f0f0f0",stroke:"#929292","stroke-width":"1px"}}}var UNIT={day:DAY/28,week:7*DAY/56,month:30*DAY/56};function NOOP(){}function Gantt(_ref){var _ref$data=_ref.data,data=_ref$data===void 0?[]:_ref$data,_ref$onClick=_ref.onClick,onClick=_ref$onClick===void 0?NOOP:_ref$onClick,_ref$viewMode=_ref.viewMode,viewMode=_ref$viewMode===void 0?"week":_ref$viewMode,_ref$maxTextWidth=_ref.maxTextWidth,maxTextWidth=_ref$maxTextWidth===void 0?140:_ref$maxTextWidth,_ref$offsetY=_ref.offsetY,offsetY=_ref$offsetY===void 0?60:_ref$offsetY,_ref$rowHeight=_ref.rowHeight,rowHeight=_ref$rowHeight===void 0?40:_ref$rowHeight;_ref.barHeight;var _ref$thickWidth=_ref.thickWidth,thickWidth=_ref$thickWidth===void 0?1.4:_ref$thickWidth,_ref$styleOptions=_ref.styleOptions,styleOptions=_ref$styleOptions===void 0?{}:_ref$styleOptions,_ref$showLinks=_ref.showLinks,showLinks=_ref$showLinks===void 0?true:_ref$showLinks,_ref$showDelay=_ref.showDelay,showDelay=_ref$showDelay===void 0?true:_ref$showDelay,start=_ref.start,end=_ref.end;var unit=UNIT[viewMode];var minTime=start.getTime()-unit*48;var maxTime=end.getTime()+unit*48;var width=(maxTime-minTime)/unit+maxTextWidth;var height=data.length*rowHeight+offsetY;var box="0 0 ".concat(width," ").concat(height);var current=Date.now();var styles=getStyles(styleOptions);var rowPadding=10;var ROW_GAP=2;var usable=rowHeight-rowPadding*2-ROW_GAP;var progressBarHeight=Math.floor(usable*2/3);var baselineHeight=Math.floor(usable/3);return h("svg",{width:width,height:height,viewBox:box},h(Layout,{styles:styles,width:width,height:height,offsetY:offsetY,thickWidth:thickWidth,maxTextWidth:maxTextWidth}),viewMode==="day"?h(DayHeader,{styles:styles,unit:unit,height:height,offsetY:offsetY,minTime:minTime,maxTime:maxTime,maxTextWidth:maxTextWidth}):null,viewMode==="week"?h(WeekHeader,{styles:styles,unit:unit,height:height,offsetY:offsetY,minTime:minTime,maxTime:maxTime,maxTextWidth:maxTextWidth}):null,viewMode==="month"?h(MonthHeader,{styles:styles,unit:unit,offsetY:offsetY,minTime:minTime,maxTime:maxTime,maxTextWidth:maxTextWidth}):null,h(Grid,{styles:styles,data:data,width:width,height:height,offsetY:offsetY,rowHeight:rowHeight,maxTextWidth:maxTextWidth}),maxTextWidth>0?h(Labels,{styles:styles,data:data,onClick:onClick,offsetY:offsetY,rowHeight:rowHeight}):null,showLinks?h(LinkLine,{styles:styles,data:data,unit:unit,height:height,current:current,offsetY:offsetY,minTime:minTime,rowHeight:rowHeight,barHeight:progressBarHeight,maxTextWidth:maxTextWidth}):null,h(Bar,{styles:styles,data:data,unit:unit,height:height,current:current,offsetY:offsetY,minTime:minTime,onClick:onClick,showDelay:showDelay,rowHeight:rowHeight,barHeight:progressBarHeight,baselineHeight:baselineHeight,rowPadding:rowPadding,rowGap:ROW_GAP,maxTextWidth:maxTextWidth}))}var NS="http://www.w3.org/2000/svg";var doc=document;function applyProperties(node,props){Object.keys(props).forEach(function(k){var v=props[k];if(k==="style"&&_typeof(v)==="object"){Object.keys(v).forEach(function(sk){node.style[sk]=v[sk]})}else if(k==="onClick"){if(typeof v==="function"){node.addEventListener("click",v)}}else{node.setAttribute(k,v)}})}function render$2(vnode,ctx){var tag=vnode.tag,props=vnode.props,children=vnode.children;var node=doc.createElementNS(NS,tag);if(props){applyProperties(node,props)}children.forEach(function(v){node.appendChild(typeof v==="string"?doc.createTextNode(v):render$2(v))});return node}function ownKeys$2(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);r&&(o=o.filter(function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable})),t.push.apply(t,o)}return t}function _objectSpread$2(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?ownKeys$2(Object(t),!0).forEach(function(r){_defineProperty(e,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):ownKeys$2(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})}return e}var SVGGantt=function(){function SVGGantt(element,data){var options=arguments.length>2&&arguments[2]!==undefined?arguments[2]:{};_classCallCheck(this,SVGGantt);this.dom=typeof element==="string"?document.querySelector(element):element;this.format(data);this.options=options;this.render()}return _createClass(SVGGantt,[{key:"format",value:function format(data){this.data=data;var start=null;var end=null;data.forEach(function(v){start=minDate(start,v.start);end=maxDate(end,v.end);if(v.baselineStart){start=minDate(start,v.baselineStart)}if(v.baselineEnd){end=maxDate(end,v.baselineEnd)}});this.start=start||new Date;this.end=end||new Date}},{key:"setData",value:function setData(data){this.format(data);this.render()}},{key:"setOptions",value:function setOptions(options){this.options=_objectSpread$2(_objectSpread$2({},this.options),options);this.render()}},{key:"render",value:function render(){var data=this.data,start=this.start,end=this.end,options=this.options;if(this.tree){this.dom.removeChild(this.tree)}if(options.maxTextWidth===undefined){var font=getFont(options.styleOptions||{});var w=function w(v){return textWidth(v.text,font,20)};options.maxTextWidth=max(data.map(w),0)}var props=_objectSpread$2(_objectSpread$2({},options),{},{start:start,end:end});this.tree=render$2(h(Gantt,_extends({data:data},props)));this.dom.appendChild(this.tree)}}])}();function render$1(vnode,ctx,e){var tag=vnode.tag,props=vnode.props,children=vnode.children;if(tag==="svg"){var width=props.width,height=props.height;ctx.width=width;ctx.height=height}if(tag==="line"){var x1=props.x1,x2=props.x2,y1=props.y1,y2=props.y2,_props$style=props.style,style=_props$style===void 0?{}:_props$style;if(style.stroke){ctx.strokeStyle=style.stroke;ctx.lineWidth=parseFloat(style["stroke-width"]||1)}ctx.beginPath();ctx.moveTo(x1,y1);ctx.lineTo(x2,y2);ctx.stroke()}if(tag==="polyline"||tag==="polygon"){var points=props.points,_props$style2=props.style,_style=_props$style2===void 0?{}:_props$style2;var p=s2p(points);var originalOpacity=ctx.globalAlpha;if(_style.opacity!==undefined){ctx.globalAlpha=parseFloat(_style.opacity)}if(_style.stroke){ctx.strokeStyle=_style.stroke;ctx.lineWidth=parseFloat(_style["stroke-width"]||1)}if(_style.fill){ctx.fillStyle=_style.fill}ctx.beginPath();ctx.moveTo(p[0][0],p[0][1]);for(var i=1;i<p.length;i++){ctx.lineTo(p[i][0],p[i][1])}if(tag==="polyline"){ctx.stroke()}else{ctx.fill()}ctx.globalAlpha=originalOpacity}if(tag==="rect"){var x=props.x,y=props.y,_width=props.width,_height=props.height,_props$rx=props.rx,rx=_props$rx===void 0?0:_props$rx,_props$ry=props.ry,ry=_props$ry===void 0?0:_props$ry,onClick=props.onClick,_props$style3=props.style,_style2=_props$style3===void 0?{}:_props$style3;ctx.beginPath();ctx.moveTo(x+rx,y);ctx.lineTo(x+_width-rx,y);ctx.quadraticCurveTo(x+_width,y,x+_width,y+ry);ctx.lineTo(x+_width,y+_height-ry);ctx.quadraticCurveTo(x+_width,y+_height,x+_width-rx,y+_height);ctx.lineTo(x+rx,y+_height);ctx.quadraticCurveTo(x,y+_height,x,y+_height-ry);ctx.lineTo(x,y+ry);ctx.quadraticCurveTo(x,y,x+rx,y);if(e&&onClick&&ctx.isPointInPath(e.x,e.y)){onClick()}ctx.closePath();var _originalOpacity=ctx.globalAlpha;if(_style2.opacity!==undefined){ctx.globalAlpha=parseFloat(_style2.opacity)}if(_style2.fill){ctx.fillStyle=_style2.fill}ctx.fill();if(_style2.stroke){ctx.strokeStyle=_style2.stroke;ctx.lineWidth=parseFloat(_style2["stroke-width"]||1);ctx.stroke()}ctx.globalAlpha=_originalOpacity}if(tag==="text"){var _x=props.x,_y=props.y,_style3=props.style;if(_style3){ctx.fillStyle=_style3.fill;var BL={central:"middle",middle:"middle",hanging:"hanging",alphabetic:"alphabetic",ideographic:"ideographic"};var AL={start:"start",middle:"center",end:"end"};ctx.textBaseline=BL[_style3["dominant-baseline"]]||"alphabetic";ctx.textAlign=AL[_style3["text-anchor"]]||"start";ctx.font="".concat(_style3["font-weight"]||""," ").concat(_style3["font-size"]," ").concat(_style3["font-family"])}ctx.fillText(children.join(""),_x,_y)}children.forEach(function(v){if(typeof v!=="string"){render$1(v,ctx,e)}})}function createContext(dom){var canvas=typeof dom==="string"?document.querySelector(dom):dom;var ctx=canvas.getContext("2d");var backingStore=ctx.webkitBackingStorePixelRatio||ctx.mozBackingStorePixelRatio||ctx.msBackingStorePixelRatio||ctx.oBackingStorePixelRatio||ctx.backingStorePixelRatio||1;var ratio=(window.devicePixelRatio||1)/backingStore;["width","height"].forEach(function(key){Object.defineProperty(ctx,key,{get:function get(){return canvas[key]/ratio},set:function set(v){canvas[key]=v*ratio;canvas.style[key]="".concat(v,"px");ctx.scale(ratio,ratio)},enumerable:true,configurable:true})});canvas.addEventListener("click",function(e){if(!ctx.onClick)return;var rect=canvas.getBoundingClientRect();ctx.onClick({x:(e.clientX-rect.left)*ratio,y:(e.clientY-rect.top)*ratio})});return ctx}function ownKeys$1(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);r&&(o=o.filter(function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable})),t.push.apply(t,o)}return t}function _objectSpread$1(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?ownKeys$1(Object(t),!0).forEach(function(r){_defineProperty(e,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):ownKeys$1(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})}return e}var CanvasGantt=function(){function CanvasGantt(element,data){var _this=this;var options=arguments.length>2&&arguments[2]!==undefined?arguments[2]:{};_classCallCheck(this,CanvasGantt);this.ctx=createContext(element);this.format(data);this.options=options;this.render();this.ctx.onClick=function(e){return _this.render(e)}}return _createClass(CanvasGantt,[{key:"format",value:function format(data){this.data=data;var start=null;var end=null;data.forEach(function(v){start=minDate(start,v.start);end=maxDate(end,v.end);if(v.baselineStart){start=minDate(start,v.baselineStart)}if(v.baselineEnd){end=maxDate(end,v.baselineEnd)}});this.start=start||new Date;this.end=end||new Date}},{key:"setData",value:function setData(data){this.format(data);this.render()}},{key:"setOptions",value:function setOptions(options){this.options=_objectSpread$1(_objectSpread$1({},this.options),options);this.render()}},{key:"render",value:function render(e){var data=this.data,start=this.start,end=this.end,options=this.options;if(options.maxTextWidth===undefined){var font=getFont(options.styleOptions||{});var w=function w(v){return textWidth(v.text,font,20)};options.maxTextWidth=max(data.map(w),0)}var props=_objectSpread$1(_objectSpread$1({},options),{},{start:start,end:end});render$1(h(Gantt,_extends({data:data},props)),this.ctx,e)}}])}();function attrEscape(str){return String(str).replace(/&/g,"&").replace(/</g,"<").replace(/"/g,""").replace(/\t/g,"	").replace(/\n/g,"
").replace(/\r/g,"
")}function escape(str){return String(str).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/\r/g,"
")}function render(vnode,ctx){var tag=vnode.tag,props=vnode.props,children=vnode.children;var tokens=[];tokens.push("<".concat(tag));Object.keys(props||{}).forEach(function(k){var v=props[k];if(k==="onClick")return;if(k==="style"&&_typeof(v)==="object"){v=Object.keys(v).map(function(i){return"".concat(i,":").concat(v[i],";")}).join("")}tokens.push(" ".concat(k,'="').concat(attrEscape(v),'"'))});if(!children||!children.length){tokens.push(" />");return tokens.join("")}tokens.push(">");children.forEach(function(v){if(typeof v==="string"){tokens.push(escape(v))}else{tokens.push(render(v))}});tokens.push("</".concat(tag,">"));return tokens.join("")}function ownKeys(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);r&&(o=o.filter(function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable})),t.push.apply(t,o)}return t}function _objectSpread(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?ownKeys(Object(t),!0).forEach(function(r){_defineProperty(e,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):ownKeys(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})}return e}var StrGantt=function(){function StrGantt(data){var options=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};_classCallCheck(this,StrGantt);this.format(data);this.options=options}return _createClass(StrGantt,[{key:"format",value:function format(data){this.data=data;var start=null;var end=null;data.forEach(function(v){start=minDate(start,v.start);end=maxDate(end,v.end);if(v.baselineStart){start=minDate(start,v.baselineStart)}if(v.baselineEnd){end=maxDate(end,v.baselineEnd)}});this.start=start||new Date;this.end=end||new Date}},{key:"setData",value:function setData(data){this.format(data)}},{key:"setOptions",value:function setOptions(options){this.options=_objectSpread(_objectSpread({},this.options),options)}},{key:"render",value:function render$1(){var data=this.data,start=this.start,end=this.end,options=this.options;var props=_objectSpread(_objectSpread({},options),{},{start:start,end:end});return render(h(Gantt,_extends({data:data},props)))}}])}();exports.CanvasGantt=CanvasGantt;exports.SVGGantt=SVGGantt;exports.StrGantt=StrGantt;exports["default"]=CanvasGantt;exports.utils=utils;Object.defineProperty(exports,"__esModule",{value:true})});
|
|
1
|
+
(function(global,factory){typeof exports==="object"&&typeof module!=="undefined"?factory(exports):typeof define==="function"&&define.amd?define(["exports"],factory):(global=typeof globalThis!=="undefined"?globalThis:global||self,factory(global.Gantt={}))})(this,function(exports){"use strict";function getDefaultExportFromCjs(x){return x&&x.__esModule&&Object.prototype.hasOwnProperty.call(x,"default")?x["default"]:x}function createCommonjsModule(fn,basedir,module){return module={path:basedir,exports:{},require:function(path,base){return commonjsRequire(path,base===undefined||base===null?module.path:base)}},fn(module,module.exports),module.exports}function commonjsRequire(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}var _extends_1=createCommonjsModule(function(module){function _extends(){return module.exports=_extends=Object.assign?Object.assign.bind():function(n){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var r in t)({}).hasOwnProperty.call(t,r)&&(n[r]=t[r])}return n},module.exports.__esModule=true,module.exports["default"]=module.exports,_extends.apply(null,arguments)}module.exports=_extends,module.exports.__esModule=true,module.exports["default"]=module.exports});var _extends=getDefaultExportFromCjs(_extends_1);var _typeof_1=createCommonjsModule(function(module){function _typeof(o){"@babel/helpers - typeof";return module.exports=_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(o){return typeof o}:function(o){return o&&"function"==typeof Symbol&&o.constructor===Symbol&&o!==Symbol.prototype?"symbol":typeof o},module.exports.__esModule=true,module.exports["default"]=module.exports,_typeof(o)}module.exports=_typeof,module.exports.__esModule=true,module.exports["default"]=module.exports});var _typeof=getDefaultExportFromCjs(_typeof_1);var toPrimitive_1=createCommonjsModule(function(module){var _typeof=_typeof_1["default"];function toPrimitive(t,r){if("object"!=_typeof(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var i=e.call(t,r||"default");if("object"!=_typeof(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(t)}module.exports=toPrimitive,module.exports.__esModule=true,module.exports["default"]=module.exports});var toPropertyKey_1=createCommonjsModule(function(module){var _typeof=_typeof_1["default"];function toPropertyKey(t){var i=toPrimitive_1(t,"string");return"symbol"==_typeof(i)?i:i+""}module.exports=toPropertyKey,module.exports.__esModule=true,module.exports["default"]=module.exports});var defineProperty=createCommonjsModule(function(module){function _defineProperty(e,r,t){return(r=toPropertyKey_1(r))in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}module.exports=_defineProperty,module.exports.__esModule=true,module.exports["default"]=module.exports});var _defineProperty=getDefaultExportFromCjs(defineProperty);var classCallCheck=createCommonjsModule(function(module){function _classCallCheck(a,n){if(!(a instanceof n))throw new TypeError("Cannot call a class as a function")}module.exports=_classCallCheck,module.exports.__esModule=true,module.exports["default"]=module.exports});var _classCallCheck=getDefaultExportFromCjs(classCallCheck);var createClass=createCommonjsModule(function(module){function _defineProperties(e,r){for(var t=0;t<r.length;t++){var o=r[t];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,toPropertyKey_1(o.key),o)}}function _createClass(e,r,t){return r&&_defineProperties(e.prototype,r),t&&_defineProperties(e,t),Object.defineProperty(e,"prototype",{writable:!1}),e}module.exports=_createClass,module.exports.__esModule=true,module.exports["default"]=module.exports});var _createClass=getDefaultExportFromCjs(createClass);function ownKeys$5(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);r&&(o=o.filter(function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable})),t.push.apply(t,o)}return t}function _objectSpread$5(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?ownKeys$5(Object(t),!0).forEach(function(r){_defineProperty(e,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):ownKeys$5(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})}return e}function addChild(c,childNodes){if(c===null||c===undefined)return;if(typeof c==="string"||typeof c==="number"){childNodes.push(c.toString())}else if(Array.isArray(c)){for(var i=0;i<c.length;i++){addChild(c[i],childNodes)}}else{childNodes.push(c)}}function h(tag,props){var childNodes=[];for(var _len=arguments.length,children=new Array(_len>2?_len-2:0),_key=2;_key<_len;_key++){children[_key-2]=arguments[_key]}addChild(children,childNodes);if(typeof tag==="function"){return tag(_objectSpread$5(_objectSpread$5({},props),{},{children:childNodes}))}return{tag:tag,props:props,children:childNodes}}function ownKeys$4(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);r&&(o=o.filter(function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable})),t.push.apply(t,o)}return t}function _objectSpread$4(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?ownKeys$4(Object(t),!0).forEach(function(r){_defineProperty(e,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):ownKeys$4(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})}return e}var DAY=24*3600*1e3;function addDays(date,days){var d=new Date(date.valueOf());d.setDate(d.getDate()+days);return d}function getDates(begin,end){var dates=[];var s=new Date(begin);s.setHours(24,0,0,0);while(s.getTime()<=end){dates.push(s.getTime());s=addDays(s,1)}return dates}var ctx=null;function textWidth(text,font,pad){ctx=ctx||document.createElement("canvas").getContext("2d");ctx.font=font;return ctx.measureText(text).width+pad}function formatMonth(date){var y=date.getFullYear();var m=date.getMonth()+1;return"".concat(y,"/").concat(m>9?m:"0".concat(m))}function formatDay(date){var m=date.getMonth()+1;var d=date.getDate();return"".concat(m,"/").concat(d)}function minDate(a,b){if(a&&b){return a>b?b:a}return a||b}function maxDate(a,b){if(a&&b){return a<b?b:a}return a||b}function max(list,defaultValue){if(list.length){return Math.max.apply(null,list)}return defaultValue}function p2s(arr){return arr.map(function(p){return"".concat(p[0],",").concat(p[1])}).join(" ")}function s2p(str){return str.split(" ").map(function(s){var p=s.split(",");return[parseFloat(p[0]),parseFloat(p[1])]})}function walkLevel(nodes,level){for(var i=0;i<nodes.length;i++){var node=nodes[i];node.level="".concat(level).concat(i+1);node.text="".concat(node.level," ").concat(node.name);walkLevel(node.children,"".concat(node.level,"."))}}function walkDates(nodes){var start=null;var end=null;var baselineStart=null;var baselineEnd=null;var percent=0;for(var i=0;i<nodes.length;i++){var node=nodes[i];if(node.children.length){var tmp=walkDates(node.children);node.start=tmp.start;node.end=tmp.end;node.baselineStart=tmp.baselineStart;node.baselineEnd=tmp.baselineEnd;node.percent=tmp.percent;if(node.start&&node.end){node.duration=(node.end-node.start)/DAY}else{node.duration=0}if(node.baselineStart&&node.baselineEnd){node.baselineDuration=(node.baselineEnd-node.baselineStart)/DAY}else{node.baselineDuration=0}}else{node.percent=node.percent||0;if(node.start&&node.end!=null){node.end=addDays(node.start,node.duration||0)}if(node.baselineStart&&node.baselineDuration!=null){node.baselineEnd=addDays(node.baselineStart,node.baselineDuration)}if(node.type==="milestone"){node.baselineEnd=node.baselineStart;node.end=node.start}}start=minDate(start,node.start);end=maxDate(end,node.end);baselineStart=minDate(baselineStart,node.baselineStart);baselineEnd=maxDate(baselineEnd,node.baselineEnd);percent+=node.percent}if(nodes.length){percent/=nodes.length}return{start:start,end:end,baselineStart:baselineStart,baselineEnd:baselineEnd,percent:percent}}function formatData(tasks,links,walk){var map={};var tmp=tasks.map(function(t,i){map[t.id]=i;return _objectSpread$4(_objectSpread$4({},t),{},{children:[],links:[]})});var roots=[];tmp.forEach(function(t){var parent=tmp[map[t.parent]];if(parent){parent.children.push(t)}else{roots.push(t)}});links.forEach(function(l){var s=tmp[map[l.source]];var t=tmp[map[l.target]];if(s&&t){s.links.push(l)}});walkLevel(roots,"");walkDates(roots);if(walk){walk(roots)}var list=[];roots.forEach(function(r){var stack=[];stack.push(r);while(stack.length){var node=stack.pop();var len=node.children.length;if(len){node.type="group"}list.push(node);for(var i=len-1;i>=0;i--){stack.push(node.children[i])}}});return list}function hasPath(vmap,a,b){var stack=[];stack.push(vmap[a]);while(stack.length){var v=stack.pop();if(v.id===b){return true}for(var i=0;i<v.links.length;i++){stack.push(v.links[i])}}return false}function toposort(links){var vmap={};links.forEach(function(l){var init=function init(id){return{id:id,out:[],in:0}};vmap[l.source]=init(l.source);vmap[l.target]=init(l.target)});for(var i=0;i<links.length;i++){var l=links[i];vmap[l.target]["in"]++;vmap[l.source].out.push(i)}var s=Object.keys(vmap).map(function(k){return vmap[k].id}).filter(function(id){return!vmap[id]["in"]});var sorted=[];while(s.length){var id=s.pop();sorted.push(id);for(var _i=0;_i<vmap[id].out.length;_i++){var index=vmap[id].out[_i];var v=vmap[links[index].target];v["in"]--;if(!v["in"]){s.push(v.id)}}}return sorted}function getScheduleDuration(task){if(task.type==="milestone"){return 0}if(task.start&&task.end){return Math.round((task.end-task.start)/DAY)}if(task.duration!=null){return task.duration}return 0}function getTaskEnd(task,duration){if(!task||!task.start){return null}if(task.end){return task.end}return addDays(task.start,duration||0)}function getConstraintStart(link,sourceTask,targetDuration,sourceDuration){if(!sourceTask||!sourceTask.start){return null}var lag=link.lag||0;var sourceEnd=getTaskEnd(sourceTask,sourceDuration);if(link.type==="SS"){return addDays(sourceTask.start,lag)}if(link.type==="FS"&&sourceEnd){return addDays(sourceEnd,lag)}if(link.type==="SF"){return addDays(addDays(sourceTask.start,lag),-targetDuration)}if(link.type==="FF"&&sourceEnd){return addDays(addDays(sourceEnd,lag),-targetDuration)}return null}function getLinkLag(link,sourceTask,targetTask,sourceDuration){if(!sourceTask||!targetTask){return null}var sourceEnd=getTaskEnd(sourceTask,sourceDuration);if(link.type==="SS"&&sourceTask.start&&targetTask.start){return Math.round((targetTask.start-sourceTask.start)/DAY)}if(link.type==="FS"&&sourceEnd&&targetTask.start){return Math.round((targetTask.start-sourceEnd)/DAY)}if(link.type==="SF"&&sourceTask.start&&targetTask.end){return Math.round((targetTask.end-sourceTask.start)/DAY)}if(link.type==="FF"&&sourceEnd&&targetTask.end){return Math.round((targetTask.end-sourceEnd)/DAY)}return null}function normalizeScheduleDate(date){var value=new Date(date.valueOf());value.setHours(0,0,0,0);return value}function isUnstartedTask(task){return task&&task.status===1}function canAdjustUnstartedTask(task,lockMilestone){if(!isUnstartedTask(task)){return false}if(lockMilestone&&task.type==="milestone"){return false}return true}function isOverdueUnstartedTask(task,currentDate,lockMilestone){return Boolean(task&&task.start&&task.start<=currentDate&&canAdjustUnstartedTask(task,lockMilestone))}function getOverdueRootTaskIds(id,ins,tasks,tmap,currentDate,lockMilestone){var roots=new Set;var visited=new Set;var stack=[id];while(stack.length){var currentId=stack.pop();if(visited.has(currentId)){continue}visited.add(currentId);var hasOverduePredecessor=false;var incomingLinks=ins[currentId]||[];for(var i=0;i<incomingLinks.length;i++){var sourceId=incomingLinks[i].source;var sourceTask=tasks[tmap[sourceId]];if(isOverdueUnstartedTask(sourceTask,currentDate,lockMilestone)){hasOverduePredecessor=true;stack.push(sourceId)}}if(!hasOverduePredecessor){roots.add(currentId)}}return roots}function getForcedStartMap(sorted,ins,tasks,tmap,currentDate,lockMilestone){var forcedStartMap={};sorted.forEach(function(id){var task=tasks[tmap[id]];if(!isOverdueUnstartedTask(task,currentDate,lockMilestone)){return}var roots=getOverdueRootTaskIds(id,ins,tasks,tmap,currentDate,lockMilestone);roots.forEach(function(rootId){forcedStartMap[rootId]=currentDate})});return forcedStartMap}function getAutoScheduleDebugConfig(debugOptions){var options=debugOptions;if(options==null&&typeof globalThis!=="undefined"){options=globalThis.__GANTT_AUTO_SCHEDULE_DEBUG__}if(!options){return null}if(options===true){return{taskIds:null}}if(options.enabled===false){return null}var taskIds=null;if(Array.isArray(options.taskIds)&&options.taskIds.length){taskIds=new Set(options.taskIds.map(function(id){return String(id)}))}return{taskIds:taskIds}}function shouldLogAutoScheduleTask(debugConfig,taskId){if(!debugConfig){return false}if(!debugConfig.taskIds){return true}return debugConfig.taskIds.has(String(taskId))}function formatAutoScheduleDebugDate(value){if(value==null){return value}if(typeof value.toISOString==="function"){if(Number.isNaN(value.valueOf())){return"Invalid Date"}return value.toISOString()}return value}function getAutoScheduleTaskSnapshot(task,scheduleDuration){if(!task){return null}return{id:task.id,status:task.status,statusType:_typeof(task.status),start:formatAutoScheduleDebugDate(task.start),startType:_typeof(task.start),startIsDate:task.start instanceof Date,end:formatAutoScheduleDebugDate(task.end),endType:_typeof(task.end),endIsDate:task.end instanceof Date,duration:task.duration,scheduleDuration:scheduleDuration,type:task.type||null}}function logAutoSchedule(debugConfig,taskId,stage,payload){if(!shouldLogAutoScheduleTask(debugConfig,taskId)){return}console.log("[autoSchedule]",stage,_objectSpread$4({taskId:taskId},payload))}function autoSchedule(tasks,links){var lockMilestone=arguments.length>2&&arguments[2]!==undefined?arguments[2]:false;var currentDate=arguments.length>3&&arguments[3]!==undefined?arguments[3]:new Date;var debugOptions=arguments.length>4&&arguments[4]!==undefined?arguments[4]:null;var debugConfig=getAutoScheduleDebugConfig(debugOptions);var vmap={};links.forEach(function(l){vmap[l.source]={id:l.source,links:[]};vmap[l.target]={id:l.target,links:[]}});var dag=[];links.forEach(function(l){var source=l.source,target=l.target;if(!hasPath(vmap,target,source)){dag.push(l);vmap[source].links.push(vmap[target])}});var sorted=toposort(dag);var tmap={};var durationMap={};for(var i=0;i<tasks.length;i++){var task=tasks[i];durationMap[task.id]=getScheduleDuration(task);tmap[task.id]=i;if(!sorted.includes(task.id)){sorted.push(task.id)}}var ins={};sorted.forEach(function(id){ins[id]=[]});dag.forEach(function(l){ins[l.target].push(l)});var scheduleDate=normalizeScheduleDate(currentDate);var forcedStartMap=getForcedStartMap(sorted,ins,tasks,tmap,scheduleDate,lockMilestone);if(debugConfig){console.log("[autoSchedule]","context",{currentDate:formatAutoScheduleDebugDate(currentDate),currentDateType:_typeof(currentDate),scheduleDate:formatAutoScheduleDebugDate(scheduleDate),lockMilestone:lockMilestone,sorted:sorted})}sorted.forEach(function(id){var task=tasks[tmap[id]];if(!task){logAutoSchedule(debugConfig,id,"missing-task",{});return}var days=durationMap[id]||0;logAutoSchedule(debugConfig,id,"before-task",{task:getAutoScheduleTaskSnapshot(task,days),forcedStart:formatAutoScheduleDebugDate(forcedStartMap[id]),isOverdueUnstarted:isOverdueUnstartedTask(task,scheduleDate,lockMilestone),incomingLinks:ins[id].map(function(link){return{id:link.id,source:link.source,target:link.target,type:link.type,lag:link.lag}})});if(lockMilestone&&task.type==="milestone"){logAutoSchedule(debugConfig,id,"skip-locked-milestone",{task:getAutoScheduleTaskSnapshot(task,days)});return}if(task.status===2){logAutoSchedule(debugConfig,id,"skip-completed",{task:getAutoScheduleTaskSnapshot(task,days)});return}if(task.status===3){if(!task.start){logAutoSchedule(debugConfig,id,"skip-started-without-start",{task:getAutoScheduleTaskSnapshot(task,days)});return}var end=addDays(task.start,days);for(var _i2=0;_i2<ins[id].length;_i2++){var l=ins[id][_i2];var v=tasks[tmap[l.source]];if(v&&v.start){var s=addDays(v.start,l.lag||0);var e=addDays(s,durationMap[l.source]||0);logAutoSchedule(debugConfig,id,"started-task-link-check",{link:{id:l.id,source:l.source,target:l.target,type:l.type,lag:l.lag},sourceTask:getAutoScheduleTaskSnapshot(v,durationMap[l.source]||0),candidateStart:formatAutoScheduleDebugDate(s),candidateEnd:formatAutoScheduleDebugDate(e),previousEnd:formatAutoScheduleDebugDate(end)});if(l.type==="SF"){end=maxDate(end,s)}if(l.type==="FF"){end=maxDate(end,e)}}}task.end=end;task.duration=(task.end-task.start)/DAY;logAutoSchedule(debugConfig,id,"after-started-task",{task:getAutoScheduleTaskSnapshot(task,days)});return}var start=null;for(var _i3=0;_i3<ins[id].length;_i3++){var _l=ins[id][_i3];var _v=tasks[tmap[_l.source]];var candidate=getConstraintStart(_l,_v,days,durationMap[_l.source]||0);logAutoSchedule(debugConfig,id,"constraint-check",{link:{id:_l.id,source:_l.source,target:_l.target,type:_l.type,lag:_l.lag},sourceTask:getAutoScheduleTaskSnapshot(_v,durationMap[_l.source]||0),previousStart:formatAutoScheduleDebugDate(start),candidate:formatAutoScheduleDebugDate(candidate)});if(candidate){start=maxDate(start,candidate)}}if(forcedStartMap[id]){logAutoSchedule(debugConfig,id,"forced-start-check",{previousStart:formatAutoScheduleDebugDate(start),forcedStart:formatAutoScheduleDebugDate(forcedStartMap[id])});start=maxDate(start,forcedStartMap[id])}if(start){task.start=start;task.end=addDays(task.start,days);logAutoSchedule(debugConfig,id,"after-task",{task:getAutoScheduleTaskSnapshot(task,days)});return}logAutoSchedule(debugConfig,id,"no-start-change",{task:getAutoScheduleTaskSnapshot(task,days)})});links.forEach(function(vLink){var lag=getLinkLag(vLink,tasks[tmap[vLink.source]],tasks[tmap[vLink.target]],durationMap[vLink.source]||0);vLink.calculateLag=lag!=null?lag:vLink.lag||0;if(shouldLogAutoScheduleTask(debugConfig,vLink.source)||shouldLogAutoScheduleTask(debugConfig,vLink.target)){console.log("[autoSchedule]","link-lag-sync",{linkId:vLink.id,source:vLink.source,target:vLink.target,type:vLink.type,lag:vLink.lag,calculateLag:vLink.calculateLag})}})}var utils=Object.freeze({__proto__:null,DAY:DAY,addDays:addDays,getDates:getDates,textWidth:textWidth,formatMonth:formatMonth,formatDay:formatDay,minDate:minDate,maxDate:maxDate,max:max,p2s:p2s,s2p:s2p,formatData:formatData,hasPath:hasPath,toposort:toposort,autoSchedule:autoSchedule});function Layout(_ref){var styles=_ref.styles,width=_ref.width,height=_ref.height,offsetY=_ref.offsetY,thickWidth=_ref.thickWidth,maxTextWidth=_ref.maxTextWidth;var x0=thickWidth/2;var W=width-thickWidth;var H=height-thickWidth;return h("g",null,h("rect",{x:x0,y:x0,width:W,height:H,style:styles.box}),h("line",{x1:0,x2:width,y1:offsetY-x0,y2:offsetY-x0,style:styles.bline}),h("line",{x1:maxTextWidth,x2:width,y1:offsetY/2,y2:offsetY/2,style:styles.line}))}function YearMonth(_ref){var styles=_ref.styles,dates=_ref.dates,unit=_ref.unit,offsetY=_ref.offsetY,minTime=_ref.minTime,maxTime=_ref.maxTime,maxTextWidth=_ref.maxTextWidth;var months=dates.filter(function(v){return new Date(v).getDate()===1});months.unshift(minTime);months.push(maxTime);var ticks=[];var x0=maxTextWidth;var y2=offsetY/2;var len=months.length-1;for(var i=0;i<len;i++){var cur=new Date(months[i]);var str=formatMonth(cur);var x=x0+(months[i]-minTime)/unit;var t=(months[i+1]-months[i])/unit;ticks.push(h("g",null,h("line",{x1:x,x2:x,y1:0,y2:y2,style:styles.line}),t>50?h("text",{x:x+t/2,y:offsetY*.25,style:styles.text3},str):null))}return h("g",null,ticks)}function DayHeader(_ref){var styles=_ref.styles,unit=_ref.unit,minTime=_ref.minTime,maxTime=_ref.maxTime,height=_ref.height,offsetY=_ref.offsetY,maxTextWidth=_ref.maxTextWidth;var dates=getDates(minTime,maxTime);var ticks=[];var x0=maxTextWidth;var y0=offsetY/2;var RH=height-y0;var len=dates.length-1;for(var i=0;i<len;i++){var cur=new Date(dates[i]);var day=cur.getDay();var x=x0+(dates[i]-minTime)/unit;var t=(dates[i+1]-dates[i])/unit;ticks.push(h("g",null,day===0||day===6?h("rect",{x:x,y:y0,width:t,height:RH,style:styles.week}):null,h("line",{x1:x,x2:x,y1:y0,y2:offsetY,style:styles.line}),h("text",{x:x+t/2,y:offsetY*.75,style:styles.text3},cur.getDate()),i===len-1?h("line",{x1:x+t,x2:x+t,y1:y0,y2:offsetY,style:styles.line}):null))}return h("g",null,h(YearMonth,{styles:styles,unit:unit,dates:dates,offsetY:offsetY,minTime:minTime,maxTime:maxTime,maxTextWidth:maxTextWidth}),ticks)}function WeekHeader(_ref){var styles=_ref.styles,unit=_ref.unit,minTime=_ref.minTime,maxTime=_ref.maxTime,height=_ref.height,offsetY=_ref.offsetY,maxTextWidth=_ref.maxTextWidth;var dates=getDates(minTime,maxTime);var weeks=dates.filter(function(v){return new Date(v).getDay()===0});weeks.push(maxTime);var ticks=[];var x0=maxTextWidth;var y0=offsetY;var RH=height-y0;var d=DAY/unit;var len=weeks.length-1;for(var i=0;i<len;i++){var cur=new Date(weeks[i]);var x=x0+(weeks[i]-minTime)/unit;var curDay=cur.getDate();var prevDay=addDays(cur,-1).getDate();ticks.push(h("g",null,h("rect",{x:x-d,y:y0,width:d*2,height:RH,style:styles.week}),h("line",{x1:x,x2:x,y1:offsetY/2,y2:offsetY,style:styles.line}),h("text",{x:x+3,y:offsetY*.75,style:styles.text2},curDay),x-x0>28?h("text",{x:x-3,y:offsetY*.75,style:styles.text1},prevDay):null))}return h("g",null,h(YearMonth,{styles:styles,unit:unit,dates:dates,offsetY:offsetY,minTime:minTime,maxTime:maxTime,maxTextWidth:maxTextWidth}),ticks)}function Year(_ref){var styles=_ref.styles,months=_ref.months,unit=_ref.unit,offsetY=_ref.offsetY,minTime=_ref.minTime,maxTime=_ref.maxTime,maxTextWidth=_ref.maxTextWidth;var years=months.filter(function(v){return new Date(v).getMonth()===0});years.unshift(minTime);years.push(maxTime);var ticks=[];var x0=maxTextWidth;var y2=offsetY/2;var len=years.length-1;for(var i=0;i<len;i++){var cur=new Date(years[i]);var x=x0+(years[i]-minTime)/unit;var t=(years[i+1]-years[i])/unit;ticks.push(h("g",null,h("line",{x1:x,x2:x,y1:0,y2:y2,style:styles.line}),t>35?h("text",{x:x+t/2,y:offsetY*.25,style:styles.text3},cur.getFullYear()):null))}return h("g",null,ticks)}function MonthHeader(_ref){var styles=_ref.styles,unit=_ref.unit,minTime=_ref.minTime,maxTime=_ref.maxTime,offsetY=_ref.offsetY,maxTextWidth=_ref.maxTextWidth;var MONTH=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];var dates=getDates(minTime,maxTime);var months=dates.filter(function(v){return new Date(v).getDate()===1});months.unshift(minTime);months.push(maxTime);var ticks=[];var x0=maxTextWidth;var y0=offsetY/2;var len=months.length-1;for(var i=0;i<len;i++){var cur=new Date(months[i]);var month=cur.getMonth();var x=x0+(months[i]-minTime)/unit;var t=(months[i+1]-months[i])/unit;ticks.push(h("g",null,h("line",{x1:x,x2:x,y1:y0,y2:offsetY,style:styles.line}),t>30?h("text",{x:x+t/2,y:offsetY*.75,style:styles.text3},MONTH[month]):null))}return h("g",null,h(Year,{styles:styles,unit:unit,months:months,offsetY:offsetY,minTime:minTime,maxTime:maxTime,maxTextWidth:maxTextWidth}),ticks)}function Grid(_ref){var styles=_ref.styles,data=_ref.data,width=_ref.width,height=_ref.height,offsetY=_ref.offsetY,rowHeight=_ref.rowHeight,maxTextWidth=_ref.maxTextWidth;return h("g",null,data.map(function(v,i){var y=(i+1)*rowHeight+offsetY;return h("line",{key:i,x1:0,x2:width,y1:y,y2:y,style:styles.line})}),h("line",{x1:maxTextWidth,x2:maxTextWidth,y1:0,y2:height,style:styles.bline}))}function Labels(_ref){var styles=_ref.styles,data=_ref.data,_onClick=_ref.onClick,rowHeight=_ref.rowHeight,offsetY=_ref.offsetY;return h("g",null,data.map(function(v,i){return h("text",{key:i,x:10,y:(i+.5)*rowHeight+offsetY,class:"gantt-label",style:styles.label,onClick:function onClick(){return _onClick(v)}},v.text)}))}function LinkLine(_ref){var styles=_ref.styles,data=_ref.data,unit=_ref.unit,offsetY=_ref.offsetY,minTime=_ref.minTime,rowHeight=_ref.rowHeight,barHeight=_ref.barHeight,maxTextWidth=_ref.maxTextWidth;var x0=maxTextWidth;var y0=rowHeight/2+offsetY;var map={};data.forEach(function(v,i){map[v.id]=i});return h("g",null,data.map(function(s,i){if(!s.end||!s.start||!s.links){return null}return s.links.map(function(l){var j=map[l.target];var e=data[j];if(!e||!e.start||!e.end)return null;var gap=12;var arrow=6;var mgap=e.type==="milestone"?barHeight/2:0;var y1=y0+i*rowHeight;var y2=y0+j*rowHeight;var vgap=barHeight/2+4;if(y1>y2){vgap=-vgap}if(l.type==="FS"){var x1=x0+(s.end-minTime)/unit;var x2=x0+(e.start-minTime)/unit-mgap;var p1=[[x1,y1],[x1+gap,y1]];if(x2-x1>=2*gap){p1.push([x1+gap,y2])}else{p1.push([x1+gap,y2-vgap]);p1.push([x2-gap,y2-vgap]);p1.push([x2-gap,y2])}p1.push([x2-arrow,y2]);var p2=[[x2-arrow,y2-arrow],[x2,y2],[x2-arrow,y2+arrow]];return h("g",null,h("polyline",{points:p2s(p1),style:styles.link}),h("polygon",{points:p2s(p2),style:styles.linkArrow}))}if(l.type==="FF"){var _x=x0+(s.end-minTime)/unit;var _x2=x0+(e.end-minTime)/unit+mgap;var _p=[[_x,y1],[_x+gap,y1]];if(_x2<=_x){_p.push([_x+gap,y2])}else{_p.push([_x+gap,y2-vgap]);_p.push([_x2+gap,y2-vgap]);_p.push([_x2+gap,y2])}_p.push([_x2+arrow,y2]);var _p2=[[_x2+arrow,y2-arrow],[_x2,y2],[_x2+arrow,y2+arrow]];return h("g",null,h("polyline",{points:p2s(_p),style:styles.link}),h("polygon",{points:p2s(_p2),style:styles.linkArrow}))}if(l.type==="SS"){var _x3=x0+(s.start-minTime)/unit;var _x4=x0+(e.start-minTime)/unit-mgap;var _p3=[[_x3,y1],[_x3-gap,y1]];if(_x3<=_x4){_p3.push([_x3-gap,y2])}else{_p3.push([_x3-gap,y2-vgap]);_p3.push([_x4-gap,y2-vgap]);_p3.push([_x4-gap,y2])}_p3.push([_x4-arrow,y2]);var _p4=[[_x4-arrow,y2-arrow],[_x4,y2],[_x4-arrow,y2+arrow]];return h("g",null,h("polyline",{points:p2s(_p3),style:styles.link}),h("polygon",{points:p2s(_p4),style:styles.linkArrow}))}if(l.type==="SF"){var _x5=x0+(s.start-minTime)/unit;var _x6=x0+(e.end-minTime)/unit+mgap;var _p5=[[_x5,y1],[_x5-gap,y1]];if(_x5-_x6>=2*gap){_p5.push([_x5-gap,y2])}else{_p5.push([_x5-gap,y2-vgap]);_p5.push([_x6+gap,y2-vgap]);_p5.push([_x6+gap,y2])}_p5.push([_x6+arrow,y2]);var _p6=[[_x6+arrow,y2-arrow],[_x6,y2],[_x6+arrow,y2+arrow]];return h("g",null,h("polyline",{points:p2s(_p5),style:styles.link}),h("polygon",{points:p2s(_p6),style:styles.linkArrow}))}return null})}))}function getTime(val){if(!val)return null;return typeof val.getTime==="function"?val.getTime():val}function shouldShowBaselineEndDelay(v){if(!v||v.type==="group"){return false}var baselineEnd=getTime(v.baselineEnd);var actualStart=getTime(v.start);return baselineEnd!=null&&actualStart!=null&&actualStart>=baselineEnd}function getBarColors(v,current,styles){var status=v.status;var type=v.type;var percent=v.percent||0;var is100Percent=percent>=.999999;var blFinish=getTime(v.baselineEnd);var actualFinish=getTime(v.end);if(shouldShowBaselineEndDelay(v)){return{front:styles.undoneRed,back:styles.undoneRed}}if(status===2||is100Percent&&type==="group"){var isLate=blFinish!=null&&actualFinish!=null&&actualFinish>blFinish;var color=isLate?styles.undoneRed:styles.completedGreen;return{front:color,back:color}}if(status===1||status===3||status==null&&type==="group"){var doneStyle=styles.doneBlue;var undoneStyle=styles.undoneLightGreen;if(blFinish!=null){var currentAfterBL=current>blFinish;var currentBeforeBL=current<blFinish;var actualAfterBL=actualFinish!=null?actualFinish>blFinish:false;var actualMissing=actualFinish==null;var _isLate=currentAfterBL&&(actualAfterBL||actualMissing);var isExpectedOverdue=currentBeforeBL&&actualAfterBL;var isExpectedOnTime=currentBeforeBL&&!actualAfterBL;if(currentAfterBL||_isLate){undoneStyle=styles.undoneRed}else if(isExpectedOverdue){undoneStyle=styles.undoneYellow}else if(isExpectedOnTime){undoneStyle=styles.undoneLightGreen}}return{front:doneStyle,back:undoneStyle}}return null}function Bar(_ref){var styles=_ref.styles,data=_ref.data,unit=_ref.unit,height=_ref.height,offsetY=_ref.offsetY,minTime=_ref.minTime;_ref.showDelay;var rowHeight=_ref.rowHeight,barHeight=_ref.barHeight,baselineHeight=_ref.baselineHeight,_ref$rowPadding=_ref.rowPadding,rowPadding=_ref$rowPadding===void 0?10:_ref$rowPadding,_ref$rowGap=_ref.rowGap,rowGap=_ref$rowGap===void 0?2:_ref$rowGap,maxTextWidth=_ref.maxTextWidth,current=_ref.current,onClick=_ref.onClick;var x0=maxTextWidth;var cur=x0+(current-minTime)/unit;return h("g",null,current>minTime?h("line",{x1:cur,x2:cur,y1:offsetY,y2:height,style:styles.cline}):null,data.map(function(v,i){var handler=function handler(){return onClick(v)};var y=offsetY+i*rowHeight+rowPadding;var cy=y+barHeight/2;var hasStartEnd=v.start&&v.end;var hasBaselineOnly=!hasStartEnd&&v.baselineStart&&v.baselineEnd;if(hasBaselineOnly){var _baselineWidth=(v.baselineEnd-v.baselineStart)/unit;if(_baselineWidth<=0)return null;var _bx=x0+(v.baselineStart-minTime)/unit;var _baselineCy=y+barHeight+rowGap+baselineHeight/2;return h("g",{key:i,class:"gantt-bar",style:{cursor:"pointer"},onClick:handler},h("text",{x:_bx-4,y:_baselineCy,style:styles.text1},formatDay(v.baselineStart)),h("text",{x:_bx+_baselineWidth+4,y:_baselineCy,style:styles.text2},formatDay(v.baselineEnd)),h("rect",{x:_bx,y:y+barHeight+rowGap,width:_baselineWidth,height:baselineHeight,rx:1.2,ry:1.2,style:styles.baseline,onClick:handler}))}if(!v.end||!v.start){return null}var x=x0+(v.start-minTime)/unit;if(v.type==="milestone"){var size=barHeight/2;var points=[[x,cy-size],[x+size,cy],[x,cy+size],[x-size,cy]].map(function(p){return"".concat(p[0],",").concat(p[1])}).join(" ");var milestoneStyle=styles.milestone;if(shouldShowBaselineEndDelay(v)){milestoneStyle=styles.undoneRed}else if(v.status===2){if(v.baselineStart&&v.baselineStart>=v.start){milestoneStyle=styles.completedGreen}else if(v.baselineStart&&v.baselineStart<v.start){milestoneStyle=styles.undoneRed}}else{if(v.baselineStart&&v.baselineStart<v.start){if(v.start<current){milestoneStyle=styles.undoneRed}else if(v.start>=current){milestoneStyle=styles.undoneYellow}}else{milestoneStyle=styles.completedGreen}}var _baseline=null;if(v.baselineStart){var _bx2=x0+(v.baselineStart-minTime)/unit;var _baselineCy2=y+barHeight+rowGap+baselineHeight/2;var baselineSize=baselineHeight;var baselinePoints=[[_bx2,_baselineCy2-baselineSize],[_bx2+baselineSize,_baselineCy2],[_bx2,_baselineCy2+baselineSize],[_bx2-baselineSize,_baselineCy2]].map(function(p){return"".concat(p[0],",").concat(p[1])}).join(" ");_baseline=h("g",null,h("text",{x:_bx2-10,y:_baselineCy2,style:styles.text1},formatDay(v.baselineStart)),h("polygon",{points:baselinePoints,style:styles.baseline}),h("circle",{class:"gantt-ctrl-start","data-id":v.id,cx:_bx2,cy:_baselineCy2,r:6,style:styles.ctrl}))}return h("g",{key:i,class:"gantt-bar",style:{cursor:"pointer"},onClick:handler},h("text",{x:x-10,y:cy,style:styles.text1},formatDay(v.start)),h("polygon",{points:points,style:milestoneStyle,onClick:handler}),h("circle",{class:"gantt-ctrl-start","data-id":v.id,cx:x,cy:cy,r:6,style:styles.ctrl}),_baseline)}var w1=(v.end-v.start)/unit;var w2=w1*v.percent;if(w1<=0){return null}var bar;var statusColors=getBarColors(v,current,styles);if(statusColors){bar={back:statusColors.back,front:statusColors.front}}else{bar=v.type==="group"?{back:styles.groupBack,front:styles.groupFront}:{back:styles.taskBack,front:styles.taskFront}}var baselineWidth=(v.baselineEnd-v.baselineStart)/unit;var bx=x0+(v.baselineStart-minTime)/unit;var baselineCy=y+barHeight+rowGap+baselineHeight/2;var baseline=v.baselineStart&&v.baselineEnd&&baselineWidth>0?h("g",null,h("text",{x:bx-4,y:baselineCy,style:styles.text1},formatDay(v.baselineStart)),h("text",{x:bx+baselineWidth+4,y:baselineCy,style:styles.text2},formatDay(v.baselineEnd)),h("rect",{x:bx,y:y+barHeight+rowGap,width:baselineWidth,height:baselineHeight,rx:1.2,ry:1.2,style:styles.baseline})):null;return h("g",{key:i,class:"gantt-bar",style:{cursor:"pointer"},onClick:handler},h("text",{x:x-4,y:cy,style:styles.text1},formatDay(v.start)),h("text",{x:x+w1+4,y:cy,style:styles.text2},formatDay(v.end)),h("rect",{x:x,y:y,width:w1,height:barHeight,rx:1.8,ry:1.8,style:bar.back,onClick:handler}),w2>1e-6?h("rect",{x:x,y:y,width:w2,height:barHeight,rx:1.8,ry:1.8,style:bar.front}):null,baseline,v.type==="group"?null:h("g",null,h("circle",{class:"gantt-ctrl-start","data-id":v.id,cx:x-12,cy:cy,r:6,style:styles.ctrl}),h("circle",{class:"gantt-ctrl-finish","data-id":v.id,cx:x+w1+12,cy:cy,r:6,style:styles.ctrl})))}))}function ownKeys$3(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);r&&(o=o.filter(function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable})),t.push.apply(t,o)}return t}function _objectSpread$3(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?ownKeys$3(Object(t),!0).forEach(function(r){_defineProperty(e,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):ownKeys$3(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})}return e}var SIZE="14px";var TYPE='-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif';function getFont(_ref){var _ref$fontSize=_ref.fontSize,fontSize=_ref$fontSize===void 0?SIZE:_ref$fontSize,_ref$fontFamily=_ref.fontFamily,fontFamily=_ref$fontFamily===void 0?TYPE:_ref$fontFamily;return"bold ".concat(fontSize," ").concat(fontFamily)}function getStyles(_ref2){var _ref2$bgColor=_ref2.bgColor,bgColor=_ref2$bgColor===void 0?"#fff":_ref2$bgColor,_ref2$lineColor=_ref2.lineColor,lineColor=_ref2$lineColor===void 0?"#eee":_ref2$lineColor,_ref2$redLineColor=_ref2.redLineColor,redLineColor=_ref2$redLineColor===void 0?"#f04134":_ref2$redLineColor,_ref2$groupBack=_ref2.groupBack,groupBack=_ref2$groupBack===void 0?"#3db9d3":_ref2$groupBack,_ref2$groupFront=_ref2.groupFront,groupFront=_ref2$groupFront===void 0?"#299cb4":_ref2$groupFront,_ref2$taskBack=_ref2.taskBack,taskBack=_ref2$taskBack===void 0?"#65c16f":_ref2$taskBack,_ref2$taskFront=_ref2.taskFront,taskFront=_ref2$taskFront===void 0?"#46ad51":_ref2$taskFront,_ref2$taskProgress=_ref2.taskProgress,taskProgress=_ref2$taskProgress===void 0?"#1890ff":_ref2$taskProgress,_ref2$milestone=_ref2.milestone,milestone=_ref2$milestone===void 0?"#d33daf":_ref2$milestone,_ref2$warning=_ref2.warning,warning=_ref2$warning===void 0?"#faad14":_ref2$warning,_ref2$danger=_ref2.danger,danger=_ref2$danger===void 0?"#f5222d":_ref2$danger,_ref2$critical=_ref2.critical,critical=_ref2$critical===void 0?"#ff4d4f":_ref2$critical,_ref2$link=_ref2.link,link=_ref2$link===void 0?"#ffa011":_ref2$link,_ref2$baseline=_ref2.baseline,baseline=_ref2$baseline===void 0?"#3c3c3c":_ref2$baseline,_ref2$completedGreen=_ref2.completedGreen,completedGreen=_ref2$completedGreen===void 0?"#46ad51":_ref2$completedGreen,_ref2$doneBlue=_ref2.doneBlue,doneBlue=_ref2$doneBlue===void 0?"#1890ff":_ref2$doneBlue,_ref2$undoneRed=_ref2.undoneRed,undoneRed=_ref2$undoneRed===void 0?"#f5222d":_ref2$undoneRed,_ref2$undoneYellow=_ref2.undoneYellow,undoneYellow=_ref2$undoneYellow===void 0?"#faad14":_ref2$undoneYellow,_ref2$undoneLightGree=_ref2.undoneLightGreen,undoneLightGreen=_ref2$undoneLightGree===void 0?"#95de64":_ref2$undoneLightGree,_ref2$textColor=_ref2.textColor,textColor=_ref2$textColor===void 0?"#222":_ref2$textColor,_ref2$lightTextColor=_ref2.lightTextColor,lightTextColor=_ref2$lightTextColor===void 0?"#999":_ref2$lightTextColor,_ref2$lineWidth=_ref2.lineWidth,lineWidth=_ref2$lineWidth===void 0?"1px":_ref2$lineWidth,_ref2$thickLineWidth=_ref2.thickLineWidth,thickLineWidth=_ref2$thickLineWidth===void 0?"1.4px":_ref2$thickLineWidth,_ref2$fontSize=_ref2.fontSize,fontSize=_ref2$fontSize===void 0?SIZE:_ref2$fontSize,_ref2$smallFontSize=_ref2.smallFontSize,smallFontSize=_ref2$smallFontSize===void 0?"12px":_ref2$smallFontSize,_ref2$fontFamily=_ref2.fontFamily,fontFamily=_ref2$fontFamily===void 0?TYPE:_ref2$fontFamily,_ref2$whiteSpace=_ref2.whiteSpace,whiteSpace=_ref2$whiteSpace===void 0?"pre":_ref2$whiteSpace;var line={stroke:lineColor,"stroke-width":lineWidth};var redLine={stroke:redLineColor,"stroke-width":lineWidth};var thickLine={stroke:lineColor,"stroke-width":thickLineWidth};var text={fill:textColor,"dominant-baseline":"central","font-size":fontSize,"font-family":fontFamily,"white-space":whiteSpace};var smallText={fill:lightTextColor,"font-size":smallFontSize};return{week:{fill:"rgba(252, 248, 227, .6)"},box:_objectSpread$3(_objectSpread$3({},thickLine),{},{fill:bgColor}),line:line,cline:redLine,bline:thickLine,label:text,groupLabel:_objectSpread$3(_objectSpread$3({},text),{},{"font-weight":"600"}),text1:_objectSpread$3(_objectSpread$3(_objectSpread$3({},text),smallText),{},{"text-anchor":"end"}),text2:_objectSpread$3(_objectSpread$3({},text),smallText),text3:_objectSpread$3(_objectSpread$3(_objectSpread$3({},text),smallText),{},{"text-anchor":"middle"}),link:{stroke:link,"stroke-width":"1.5px",fill:"none"},linkArrow:{fill:link},milestone:{fill:milestone},groupBack:{fill:groupBack},groupFront:{fill:groupFront},groupProgress:{fill:groupFront},taskBack:{fill:taskBack},taskFront:{fill:taskFront},taskProgress:{fill:taskProgress},warning:{fill:warning},danger:{fill:danger},critical:{fill:critical},completedGreen:{fill:completedGreen},doneBlue:{fill:doneBlue},undoneRed:{fill:undoneRed},undoneYellow:{fill:undoneYellow},undoneLightGreen:{fill:undoneLightGreen},baseline:{fill:baseline,opacity:.5},ctrl:{display:"none",fill:"#f0f0f0",stroke:"#929292","stroke-width":"1px"}}}var UNIT={day:DAY/28,week:7*DAY/56,month:30*DAY/56};function NOOP(){}function Gantt(_ref){var _ref$data=_ref.data,data=_ref$data===void 0?[]:_ref$data,_ref$onClick=_ref.onClick,onClick=_ref$onClick===void 0?NOOP:_ref$onClick,_ref$viewMode=_ref.viewMode,viewMode=_ref$viewMode===void 0?"week":_ref$viewMode,_ref$maxTextWidth=_ref.maxTextWidth,maxTextWidth=_ref$maxTextWidth===void 0?140:_ref$maxTextWidth,_ref$offsetY=_ref.offsetY,offsetY=_ref$offsetY===void 0?60:_ref$offsetY,_ref$rowHeight=_ref.rowHeight,rowHeight=_ref$rowHeight===void 0?40:_ref$rowHeight;_ref.barHeight;var _ref$thickWidth=_ref.thickWidth,thickWidth=_ref$thickWidth===void 0?1.4:_ref$thickWidth,_ref$styleOptions=_ref.styleOptions,styleOptions=_ref$styleOptions===void 0?{}:_ref$styleOptions,_ref$showLinks=_ref.showLinks,showLinks=_ref$showLinks===void 0?true:_ref$showLinks,_ref$showDelay=_ref.showDelay,showDelay=_ref$showDelay===void 0?true:_ref$showDelay,start=_ref.start,end=_ref.end;var unit=UNIT[viewMode];var minTime=start.getTime()-unit*48;var maxTime=end.getTime()+unit*48;var width=(maxTime-minTime)/unit+maxTextWidth;var height=data.length*rowHeight+offsetY;var box="0 0 ".concat(width," ").concat(height);var current=Date.now();var styles=getStyles(styleOptions);var rowPadding=10;var ROW_GAP=2;var usable=rowHeight-rowPadding*2-ROW_GAP;var progressBarHeight=Math.floor(usable*2/3);var baselineHeight=Math.floor(usable/3);return h("svg",{width:width,height:height,viewBox:box},h(Layout,{styles:styles,width:width,height:height,offsetY:offsetY,thickWidth:thickWidth,maxTextWidth:maxTextWidth}),viewMode==="day"?h(DayHeader,{styles:styles,unit:unit,height:height,offsetY:offsetY,minTime:minTime,maxTime:maxTime,maxTextWidth:maxTextWidth}):null,viewMode==="week"?h(WeekHeader,{styles:styles,unit:unit,height:height,offsetY:offsetY,minTime:minTime,maxTime:maxTime,maxTextWidth:maxTextWidth}):null,viewMode==="month"?h(MonthHeader,{styles:styles,unit:unit,offsetY:offsetY,minTime:minTime,maxTime:maxTime,maxTextWidth:maxTextWidth}):null,h(Grid,{styles:styles,data:data,width:width,height:height,offsetY:offsetY,rowHeight:rowHeight,maxTextWidth:maxTextWidth}),maxTextWidth>0?h(Labels,{styles:styles,data:data,onClick:onClick,offsetY:offsetY,rowHeight:rowHeight}):null,showLinks?h(LinkLine,{styles:styles,data:data,unit:unit,height:height,current:current,offsetY:offsetY,minTime:minTime,rowHeight:rowHeight,barHeight:progressBarHeight,maxTextWidth:maxTextWidth}):null,h(Bar,{styles:styles,data:data,unit:unit,height:height,current:current,offsetY:offsetY,minTime:minTime,onClick:onClick,showDelay:showDelay,rowHeight:rowHeight,barHeight:progressBarHeight,baselineHeight:baselineHeight,rowPadding:rowPadding,rowGap:ROW_GAP,maxTextWidth:maxTextWidth}))}var NS="http://www.w3.org/2000/svg";var doc=document;function applyProperties(node,props){Object.keys(props).forEach(function(k){var v=props[k];if(k==="style"&&_typeof(v)==="object"){Object.keys(v).forEach(function(sk){node.style[sk]=v[sk]})}else if(k==="onClick"){if(typeof v==="function"){node.addEventListener("click",v)}}else{node.setAttribute(k,v)}})}function render$2(vnode,ctx){var tag=vnode.tag,props=vnode.props,children=vnode.children;var node=doc.createElementNS(NS,tag);if(props){applyProperties(node,props)}children.forEach(function(v){node.appendChild(typeof v==="string"?doc.createTextNode(v):render$2(v))});return node}function ownKeys$2(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);r&&(o=o.filter(function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable})),t.push.apply(t,o)}return t}function _objectSpread$2(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?ownKeys$2(Object(t),!0).forEach(function(r){_defineProperty(e,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):ownKeys$2(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})}return e}var SVGGantt=function(){function SVGGantt(element,data){var options=arguments.length>2&&arguments[2]!==undefined?arguments[2]:{};_classCallCheck(this,SVGGantt);this.dom=typeof element==="string"?document.querySelector(element):element;this.format(data);this.options=options;this.render()}return _createClass(SVGGantt,[{key:"format",value:function format(data){this.data=data;var start=null;var end=null;data.forEach(function(v){start=minDate(start,v.start);end=maxDate(end,v.end);if(v.baselineStart){start=minDate(start,v.baselineStart)}if(v.baselineEnd){end=maxDate(end,v.baselineEnd)}});this.start=start||new Date;this.end=end||new Date}},{key:"setData",value:function setData(data){this.format(data);this.render()}},{key:"setOptions",value:function setOptions(options){this.options=_objectSpread$2(_objectSpread$2({},this.options),options);this.render()}},{key:"render",value:function render(){var data=this.data,start=this.start,end=this.end,options=this.options;if(this.tree){this.dom.removeChild(this.tree)}if(options.maxTextWidth===undefined){var font=getFont(options.styleOptions||{});var w=function w(v){return textWidth(v.text,font,20)};options.maxTextWidth=max(data.map(w),0)}var props=_objectSpread$2(_objectSpread$2({},options),{},{start:start,end:end});this.tree=render$2(h(Gantt,_extends({data:data},props)));this.dom.appendChild(this.tree)}}])}();function render$1(vnode,ctx,e){var tag=vnode.tag,props=vnode.props,children=vnode.children;if(tag==="svg"){var width=props.width,height=props.height;ctx.width=width;ctx.height=height}if(tag==="line"){var x1=props.x1,x2=props.x2,y1=props.y1,y2=props.y2,_props$style=props.style,style=_props$style===void 0?{}:_props$style;if(style.stroke){ctx.strokeStyle=style.stroke;ctx.lineWidth=parseFloat(style["stroke-width"]||1)}ctx.beginPath();ctx.moveTo(x1,y1);ctx.lineTo(x2,y2);ctx.stroke()}if(tag==="polyline"||tag==="polygon"){var points=props.points,_props$style2=props.style,_style=_props$style2===void 0?{}:_props$style2;var p=s2p(points);var originalOpacity=ctx.globalAlpha;if(_style.opacity!==undefined){ctx.globalAlpha=parseFloat(_style.opacity)}if(_style.stroke){ctx.strokeStyle=_style.stroke;ctx.lineWidth=parseFloat(_style["stroke-width"]||1)}if(_style.fill){ctx.fillStyle=_style.fill}ctx.beginPath();ctx.moveTo(p[0][0],p[0][1]);for(var i=1;i<p.length;i++){ctx.lineTo(p[i][0],p[i][1])}if(tag==="polyline"){ctx.stroke()}else{ctx.fill()}ctx.globalAlpha=originalOpacity}if(tag==="rect"){var x=props.x,y=props.y,_width=props.width,_height=props.height,_props$rx=props.rx,rx=_props$rx===void 0?0:_props$rx,_props$ry=props.ry,ry=_props$ry===void 0?0:_props$ry,onClick=props.onClick,_props$style3=props.style,_style2=_props$style3===void 0?{}:_props$style3;ctx.beginPath();ctx.moveTo(x+rx,y);ctx.lineTo(x+_width-rx,y);ctx.quadraticCurveTo(x+_width,y,x+_width,y+ry);ctx.lineTo(x+_width,y+_height-ry);ctx.quadraticCurveTo(x+_width,y+_height,x+_width-rx,y+_height);ctx.lineTo(x+rx,y+_height);ctx.quadraticCurveTo(x,y+_height,x,y+_height-ry);ctx.lineTo(x,y+ry);ctx.quadraticCurveTo(x,y,x+rx,y);if(e&&onClick&&ctx.isPointInPath(e.x,e.y)){onClick()}ctx.closePath();var _originalOpacity=ctx.globalAlpha;if(_style2.opacity!==undefined){ctx.globalAlpha=parseFloat(_style2.opacity)}if(_style2.fill){ctx.fillStyle=_style2.fill}ctx.fill();if(_style2.stroke){ctx.strokeStyle=_style2.stroke;ctx.lineWidth=parseFloat(_style2["stroke-width"]||1);ctx.stroke()}ctx.globalAlpha=_originalOpacity}if(tag==="text"){var _x=props.x,_y=props.y,_style3=props.style;if(_style3){ctx.fillStyle=_style3.fill;var BL={central:"middle",middle:"middle",hanging:"hanging",alphabetic:"alphabetic",ideographic:"ideographic"};var AL={start:"start",middle:"center",end:"end"};ctx.textBaseline=BL[_style3["dominant-baseline"]]||"alphabetic";ctx.textAlign=AL[_style3["text-anchor"]]||"start";ctx.font="".concat(_style3["font-weight"]||""," ").concat(_style3["font-size"]," ").concat(_style3["font-family"])}ctx.fillText(children.join(""),_x,_y)}children.forEach(function(v){if(typeof v!=="string"){render$1(v,ctx,e)}})}function createContext(dom){var canvas=typeof dom==="string"?document.querySelector(dom):dom;var ctx=canvas.getContext("2d");var backingStore=ctx.webkitBackingStorePixelRatio||ctx.mozBackingStorePixelRatio||ctx.msBackingStorePixelRatio||ctx.oBackingStorePixelRatio||ctx.backingStorePixelRatio||1;var ratio=(window.devicePixelRatio||1)/backingStore;["width","height"].forEach(function(key){Object.defineProperty(ctx,key,{get:function get(){return canvas[key]/ratio},set:function set(v){canvas[key]=v*ratio;canvas.style[key]="".concat(v,"px");ctx.scale(ratio,ratio)},enumerable:true,configurable:true})});canvas.addEventListener("click",function(e){if(!ctx.onClick)return;var rect=canvas.getBoundingClientRect();ctx.onClick({x:(e.clientX-rect.left)*ratio,y:(e.clientY-rect.top)*ratio})});return ctx}function ownKeys$1(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);r&&(o=o.filter(function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable})),t.push.apply(t,o)}return t}function _objectSpread$1(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?ownKeys$1(Object(t),!0).forEach(function(r){_defineProperty(e,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):ownKeys$1(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})}return e}var CanvasGantt=function(){function CanvasGantt(element,data){var _this=this;var options=arguments.length>2&&arguments[2]!==undefined?arguments[2]:{};_classCallCheck(this,CanvasGantt);this.ctx=createContext(element);this.format(data);this.options=options;this.render();this.ctx.onClick=function(e){return _this.render(e)}}return _createClass(CanvasGantt,[{key:"format",value:function format(data){this.data=data;var start=null;var end=null;data.forEach(function(v){start=minDate(start,v.start);end=maxDate(end,v.end);if(v.baselineStart){start=minDate(start,v.baselineStart)}if(v.baselineEnd){end=maxDate(end,v.baselineEnd)}});this.start=start||new Date;this.end=end||new Date}},{key:"setData",value:function setData(data){this.format(data);this.render()}},{key:"setOptions",value:function setOptions(options){this.options=_objectSpread$1(_objectSpread$1({},this.options),options);this.render()}},{key:"render",value:function render(e){var data=this.data,start=this.start,end=this.end,options=this.options;if(options.maxTextWidth===undefined){var font=getFont(options.styleOptions||{});var w=function w(v){return textWidth(v.text,font,20)};options.maxTextWidth=max(data.map(w),0)}var props=_objectSpread$1(_objectSpread$1({},options),{},{start:start,end:end});render$1(h(Gantt,_extends({data:data},props)),this.ctx,e)}}])}();function attrEscape(str){return String(str).replace(/&/g,"&").replace(/</g,"<").replace(/"/g,""").replace(/\t/g,"	").replace(/\n/g,"
").replace(/\r/g,"
")}function escape(str){return String(str).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/\r/g,"
")}function render(vnode,ctx){var tag=vnode.tag,props=vnode.props,children=vnode.children;var tokens=[];tokens.push("<".concat(tag));Object.keys(props||{}).forEach(function(k){var v=props[k];if(k==="onClick")return;if(k==="style"&&_typeof(v)==="object"){v=Object.keys(v).map(function(i){return"".concat(i,":").concat(v[i],";")}).join("")}tokens.push(" ".concat(k,'="').concat(attrEscape(v),'"'))});if(!children||!children.length){tokens.push(" />");return tokens.join("")}tokens.push(">");children.forEach(function(v){if(typeof v==="string"){tokens.push(escape(v))}else{tokens.push(render(v))}});tokens.push("</".concat(tag,">"));return tokens.join("")}function ownKeys(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);r&&(o=o.filter(function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable})),t.push.apply(t,o)}return t}function _objectSpread(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?ownKeys(Object(t),!0).forEach(function(r){_defineProperty(e,r,t[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):ownKeys(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})}return e}var StrGantt=function(){function StrGantt(data){var options=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};_classCallCheck(this,StrGantt);this.format(data);this.options=options}return _createClass(StrGantt,[{key:"format",value:function format(data){this.data=data;var start=null;var end=null;data.forEach(function(v){start=minDate(start,v.start);end=maxDate(end,v.end);if(v.baselineStart){start=minDate(start,v.baselineStart)}if(v.baselineEnd){end=maxDate(end,v.baselineEnd)}});this.start=start||new Date;this.end=end||new Date}},{key:"setData",value:function setData(data){this.format(data)}},{key:"setOptions",value:function setOptions(options){this.options=_objectSpread(_objectSpread({},this.options),options)}},{key:"render",value:function render$1(){var data=this.data,start=this.start,end=this.end,options=this.options;var props=_objectSpread(_objectSpread({},options),{},{start:start,end:end});return render(h(Gantt,_extends({data:data},props)))}}])}();exports.CanvasGantt=CanvasGantt;exports.SVGGantt=SVGGantt;exports.StrGantt=StrGantt;exports["default"]=CanvasGantt;exports.utils=utils;Object.defineProperty(exports,"__esModule",{value:true})});
|
package/es/gantt/Bar.js
CHANGED
|
@@ -4,6 +4,14 @@ function getTime(val) {
|
|
|
4
4
|
if (!val) return null;
|
|
5
5
|
return typeof val.getTime === 'function' ? val.getTime() : val;
|
|
6
6
|
}
|
|
7
|
+
function shouldShowBaselineEndDelay(v) {
|
|
8
|
+
if (!v || v.type === 'group') {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
var baselineEnd = getTime(v.baselineEnd);
|
|
12
|
+
var actualStart = getTime(v.start);
|
|
13
|
+
return baselineEnd != null && actualStart != null && actualStart >= baselineEnd;
|
|
14
|
+
}
|
|
7
15
|
|
|
8
16
|
// 根据 status 和日期计算活动条颜色
|
|
9
17
|
// status: 1=未开始 2=已完成 3=已开始
|
|
@@ -14,6 +22,12 @@ function getBarColors(v, current, styles) {
|
|
|
14
22
|
var is100Percent = percent >= 0.999999;
|
|
15
23
|
var blFinish = getTime(v.baselineEnd);
|
|
16
24
|
var actualFinish = getTime(v.end);
|
|
25
|
+
if (shouldShowBaselineEndDelay(v)) {
|
|
26
|
+
return {
|
|
27
|
+
front: styles.undoneRed,
|
|
28
|
+
back: styles.undoneRed
|
|
29
|
+
};
|
|
30
|
+
}
|
|
17
31
|
|
|
18
32
|
// 处理已完成状态或100%进度的情况 (status=2 或 100%进度)
|
|
19
33
|
if (status === 2 || is100Percent && type === 'group') {
|
|
@@ -138,7 +152,9 @@ export default function Bar(_ref) {
|
|
|
138
152
|
|
|
139
153
|
// 里程碑颜色计算
|
|
140
154
|
var milestoneStyle = styles.milestone;
|
|
141
|
-
if (v
|
|
155
|
+
if (shouldShowBaselineEndDelay(v)) {
|
|
156
|
+
milestoneStyle = styles.undoneRed;
|
|
157
|
+
} else if (v.status === 2) {
|
|
142
158
|
// 状态为完成时
|
|
143
159
|
if (v.baselineStart && v.baselineStart >= v.start) {
|
|
144
160
|
milestoneStyle = styles.completedGreen;
|
package/es/utils.js
CHANGED
|
@@ -311,7 +311,7 @@ function canAdjustUnstartedTask(task, lockMilestone) {
|
|
|
311
311
|
return true;
|
|
312
312
|
}
|
|
313
313
|
function isOverdueUnstartedTask(task, currentDate, lockMilestone) {
|
|
314
|
-
return Boolean(task && task.start && task.start
|
|
314
|
+
return Boolean(task && task.start && task.start <= currentDate && canAdjustUnstartedTask(task, lockMilestone));
|
|
315
315
|
}
|
|
316
316
|
function getOverdueRootTaskIds(id, ins, tasks, tmap, currentDate, lockMilestone) {
|
|
317
317
|
var roots = new Set();
|
|
@@ -353,9 +353,85 @@ function getForcedStartMap(sorted, ins, tasks, tmap, currentDate, lockMilestone)
|
|
|
353
353
|
});
|
|
354
354
|
return forcedStartMap;
|
|
355
355
|
}
|
|
356
|
+
function getAutoScheduleDebugConfig(debugOptions) {
|
|
357
|
+
var options = debugOptions;
|
|
358
|
+
if (options == null && typeof globalThis !== 'undefined') {
|
|
359
|
+
options = globalThis.__GANTT_AUTO_SCHEDULE_DEBUG__;
|
|
360
|
+
}
|
|
361
|
+
if (!options) {
|
|
362
|
+
return null;
|
|
363
|
+
}
|
|
364
|
+
if (options === true) {
|
|
365
|
+
return {
|
|
366
|
+
taskIds: null
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
if (options.enabled === false) {
|
|
370
|
+
return null;
|
|
371
|
+
}
|
|
372
|
+
var taskIds = null;
|
|
373
|
+
if (Array.isArray(options.taskIds) && options.taskIds.length) {
|
|
374
|
+
taskIds = new Set(options.taskIds.map(function (id) {
|
|
375
|
+
return String(id);
|
|
376
|
+
}));
|
|
377
|
+
}
|
|
378
|
+
return {
|
|
379
|
+
taskIds: taskIds
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
function shouldLogAutoScheduleTask(debugConfig, taskId) {
|
|
383
|
+
if (!debugConfig) {
|
|
384
|
+
return false;
|
|
385
|
+
}
|
|
386
|
+
if (!debugConfig.taskIds) {
|
|
387
|
+
return true;
|
|
388
|
+
}
|
|
389
|
+
return debugConfig.taskIds.has(String(taskId));
|
|
390
|
+
}
|
|
391
|
+
function formatAutoScheduleDebugDate(value) {
|
|
392
|
+
if (value == null) {
|
|
393
|
+
return value;
|
|
394
|
+
}
|
|
395
|
+
if (typeof value.toISOString === 'function') {
|
|
396
|
+
if (Number.isNaN(value.valueOf())) {
|
|
397
|
+
return 'Invalid Date';
|
|
398
|
+
}
|
|
399
|
+
return value.toISOString();
|
|
400
|
+
}
|
|
401
|
+
return value;
|
|
402
|
+
}
|
|
403
|
+
function getAutoScheduleTaskSnapshot(task, scheduleDuration) {
|
|
404
|
+
if (!task) {
|
|
405
|
+
return null;
|
|
406
|
+
}
|
|
407
|
+
return {
|
|
408
|
+
id: task.id,
|
|
409
|
+
status: task.status,
|
|
410
|
+
statusType: _typeof(task.status),
|
|
411
|
+
start: formatAutoScheduleDebugDate(task.start),
|
|
412
|
+
startType: _typeof(task.start),
|
|
413
|
+
startIsDate: task.start instanceof Date,
|
|
414
|
+
end: formatAutoScheduleDebugDate(task.end),
|
|
415
|
+
endType: _typeof(task.end),
|
|
416
|
+
endIsDate: task.end instanceof Date,
|
|
417
|
+
duration: task.duration,
|
|
418
|
+
scheduleDuration: scheduleDuration,
|
|
419
|
+
type: task.type || null
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
function logAutoSchedule(debugConfig, taskId, stage, payload) {
|
|
423
|
+
if (!shouldLogAutoScheduleTask(debugConfig, taskId)) {
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
console.log('[autoSchedule]', stage, _objectSpread({
|
|
427
|
+
taskId: taskId
|
|
428
|
+
}, payload));
|
|
429
|
+
}
|
|
356
430
|
export function autoSchedule(tasks, links) {
|
|
357
431
|
var lockMilestone = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
358
432
|
var currentDate = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : new Date();
|
|
433
|
+
var debugOptions = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : null;
|
|
434
|
+
var debugConfig = getAutoScheduleDebugConfig(debugOptions);
|
|
359
435
|
var vmap = {};
|
|
360
436
|
links.forEach(function (l) {
|
|
361
437
|
vmap[l.source] = {
|
|
@@ -396,18 +472,53 @@ export function autoSchedule(tasks, links) {
|
|
|
396
472
|
});
|
|
397
473
|
var scheduleDate = normalizeScheduleDate(currentDate);
|
|
398
474
|
var forcedStartMap = getForcedStartMap(sorted, ins, tasks, tmap, scheduleDate, lockMilestone);
|
|
475
|
+
if (debugConfig) {
|
|
476
|
+
console.log('[autoSchedule]', 'context', {
|
|
477
|
+
currentDate: formatAutoScheduleDebugDate(currentDate),
|
|
478
|
+
currentDateType: _typeof(currentDate),
|
|
479
|
+
scheduleDate: formatAutoScheduleDebugDate(scheduleDate),
|
|
480
|
+
lockMilestone: lockMilestone,
|
|
481
|
+
sorted: sorted
|
|
482
|
+
});
|
|
483
|
+
}
|
|
399
484
|
sorted.forEach(function (id) {
|
|
400
485
|
var task = tasks[tmap[id]];
|
|
401
|
-
if (!task)
|
|
486
|
+
if (!task) {
|
|
487
|
+
logAutoSchedule(debugConfig, id, 'missing-task', {});
|
|
488
|
+
return;
|
|
489
|
+
}
|
|
402
490
|
var days = durationMap[id] || 0;
|
|
491
|
+
logAutoSchedule(debugConfig, id, 'before-task', {
|
|
492
|
+
task: getAutoScheduleTaskSnapshot(task, days),
|
|
493
|
+
forcedStart: formatAutoScheduleDebugDate(forcedStartMap[id]),
|
|
494
|
+
isOverdueUnstarted: isOverdueUnstartedTask(task, scheduleDate, lockMilestone),
|
|
495
|
+
incomingLinks: ins[id].map(function (link) {
|
|
496
|
+
return {
|
|
497
|
+
id: link.id,
|
|
498
|
+
source: link.source,
|
|
499
|
+
target: link.target,
|
|
500
|
+
type: link.type,
|
|
501
|
+
lag: link.lag
|
|
502
|
+
};
|
|
503
|
+
})
|
|
504
|
+
});
|
|
403
505
|
if (lockMilestone && task.type === 'milestone') {
|
|
506
|
+
logAutoSchedule(debugConfig, id, 'skip-locked-milestone', {
|
|
507
|
+
task: getAutoScheduleTaskSnapshot(task, days)
|
|
508
|
+
});
|
|
404
509
|
return;
|
|
405
510
|
}
|
|
406
511
|
if (task.status === 2) {
|
|
512
|
+
logAutoSchedule(debugConfig, id, 'skip-completed', {
|
|
513
|
+
task: getAutoScheduleTaskSnapshot(task, days)
|
|
514
|
+
});
|
|
407
515
|
return;
|
|
408
516
|
}
|
|
409
517
|
if (task.status === 3) {
|
|
410
518
|
if (!task.start) {
|
|
519
|
+
logAutoSchedule(debugConfig, id, 'skip-started-without-start', {
|
|
520
|
+
task: getAutoScheduleTaskSnapshot(task, days)
|
|
521
|
+
});
|
|
411
522
|
return;
|
|
412
523
|
}
|
|
413
524
|
var end = addDays(task.start, days);
|
|
@@ -417,6 +528,19 @@ export function autoSchedule(tasks, links) {
|
|
|
417
528
|
if (v && v.start) {
|
|
418
529
|
var s = addDays(v.start, l.lag || 0);
|
|
419
530
|
var e = addDays(s, durationMap[l.source] || 0);
|
|
531
|
+
logAutoSchedule(debugConfig, id, 'started-task-link-check', {
|
|
532
|
+
link: {
|
|
533
|
+
id: l.id,
|
|
534
|
+
source: l.source,
|
|
535
|
+
target: l.target,
|
|
536
|
+
type: l.type,
|
|
537
|
+
lag: l.lag
|
|
538
|
+
},
|
|
539
|
+
sourceTask: getAutoScheduleTaskSnapshot(v, durationMap[l.source] || 0),
|
|
540
|
+
candidateStart: formatAutoScheduleDebugDate(s),
|
|
541
|
+
candidateEnd: formatAutoScheduleDebugDate(e),
|
|
542
|
+
previousEnd: formatAutoScheduleDebugDate(end)
|
|
543
|
+
});
|
|
420
544
|
if (l.type === 'SF') {
|
|
421
545
|
end = maxDate(end, s);
|
|
422
546
|
}
|
|
@@ -427,6 +551,9 @@ export function autoSchedule(tasks, links) {
|
|
|
427
551
|
}
|
|
428
552
|
task.end = end;
|
|
429
553
|
task.duration = (task.end - task.start) / DAY;
|
|
554
|
+
logAutoSchedule(debugConfig, id, 'after-started-task', {
|
|
555
|
+
task: getAutoScheduleTaskSnapshot(task, days)
|
|
556
|
+
});
|
|
430
557
|
return;
|
|
431
558
|
}
|
|
432
559
|
var start = null;
|
|
@@ -434,20 +561,53 @@ export function autoSchedule(tasks, links) {
|
|
|
434
561
|
var _l = ins[id][_i3];
|
|
435
562
|
var _v = tasks[tmap[_l.source]];
|
|
436
563
|
var candidate = getConstraintStart(_l, _v, days, durationMap[_l.source] || 0);
|
|
564
|
+
logAutoSchedule(debugConfig, id, 'constraint-check', {
|
|
565
|
+
link: {
|
|
566
|
+
id: _l.id,
|
|
567
|
+
source: _l.source,
|
|
568
|
+
target: _l.target,
|
|
569
|
+
type: _l.type,
|
|
570
|
+
lag: _l.lag
|
|
571
|
+
},
|
|
572
|
+
sourceTask: getAutoScheduleTaskSnapshot(_v, durationMap[_l.source] || 0),
|
|
573
|
+
previousStart: formatAutoScheduleDebugDate(start),
|
|
574
|
+
candidate: formatAutoScheduleDebugDate(candidate)
|
|
575
|
+
});
|
|
437
576
|
if (candidate) {
|
|
438
577
|
start = maxDate(start, candidate);
|
|
439
578
|
}
|
|
440
579
|
}
|
|
441
580
|
if (forcedStartMap[id]) {
|
|
581
|
+
logAutoSchedule(debugConfig, id, 'forced-start-check', {
|
|
582
|
+
previousStart: formatAutoScheduleDebugDate(start),
|
|
583
|
+
forcedStart: formatAutoScheduleDebugDate(forcedStartMap[id])
|
|
584
|
+
});
|
|
442
585
|
start = maxDate(start, forcedStartMap[id]);
|
|
443
586
|
}
|
|
444
587
|
if (start) {
|
|
445
588
|
task.start = start;
|
|
446
589
|
task.end = addDays(task.start, days);
|
|
590
|
+
logAutoSchedule(debugConfig, id, 'after-task', {
|
|
591
|
+
task: getAutoScheduleTaskSnapshot(task, days)
|
|
592
|
+
});
|
|
593
|
+
return;
|
|
447
594
|
}
|
|
595
|
+
logAutoSchedule(debugConfig, id, 'no-start-change', {
|
|
596
|
+
task: getAutoScheduleTaskSnapshot(task, days)
|
|
597
|
+
});
|
|
448
598
|
});
|
|
449
599
|
links.forEach(function (vLink) {
|
|
450
600
|
var lag = getLinkLag(vLink, tasks[tmap[vLink.source]], tasks[tmap[vLink.target]], durationMap[vLink.source] || 0);
|
|
451
601
|
vLink.calculateLag = lag != null ? lag : vLink.lag || 0;
|
|
602
|
+
if (shouldLogAutoScheduleTask(debugConfig, vLink.source) || shouldLogAutoScheduleTask(debugConfig, vLink.target)) {
|
|
603
|
+
console.log('[autoSchedule]', 'link-lag-sync', {
|
|
604
|
+
linkId: vLink.id,
|
|
605
|
+
source: vLink.source,
|
|
606
|
+
target: vLink.target,
|
|
607
|
+
type: vLink.type,
|
|
608
|
+
lag: vLink.lag,
|
|
609
|
+
calculateLag: vLink.calculateLag
|
|
610
|
+
});
|
|
611
|
+
}
|
|
452
612
|
});
|
|
453
613
|
}
|
package/lib/gantt/Bar.js
CHANGED
|
@@ -11,6 +11,14 @@ function getTime(val) {
|
|
|
11
11
|
if (!val) return null;
|
|
12
12
|
return typeof val.getTime === 'function' ? val.getTime() : val;
|
|
13
13
|
}
|
|
14
|
+
function shouldShowBaselineEndDelay(v) {
|
|
15
|
+
if (!v || v.type === 'group') {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
var baselineEnd = getTime(v.baselineEnd);
|
|
19
|
+
var actualStart = getTime(v.start);
|
|
20
|
+
return baselineEnd != null && actualStart != null && actualStart >= baselineEnd;
|
|
21
|
+
}
|
|
14
22
|
|
|
15
23
|
// 根据 status 和日期计算活动条颜色
|
|
16
24
|
// status: 1=未开始 2=已完成 3=已开始
|
|
@@ -21,6 +29,12 @@ function getBarColors(v, current, styles) {
|
|
|
21
29
|
var is100Percent = percent >= 0.999999;
|
|
22
30
|
var blFinish = getTime(v.baselineEnd);
|
|
23
31
|
var actualFinish = getTime(v.end);
|
|
32
|
+
if (shouldShowBaselineEndDelay(v)) {
|
|
33
|
+
return {
|
|
34
|
+
front: styles.undoneRed,
|
|
35
|
+
back: styles.undoneRed
|
|
36
|
+
};
|
|
37
|
+
}
|
|
24
38
|
|
|
25
39
|
// 处理已完成状态或100%进度的情况 (status=2 或 100%进度)
|
|
26
40
|
if (status === 2 || is100Percent && type === 'group') {
|
|
@@ -145,7 +159,9 @@ function Bar(_ref) {
|
|
|
145
159
|
|
|
146
160
|
// 里程碑颜色计算
|
|
147
161
|
var milestoneStyle = styles.milestone;
|
|
148
|
-
if (v
|
|
162
|
+
if (shouldShowBaselineEndDelay(v)) {
|
|
163
|
+
milestoneStyle = styles.undoneRed;
|
|
164
|
+
} else if (v.status === 2) {
|
|
149
165
|
// 状态为完成时
|
|
150
166
|
if (v.baselineStart && v.baselineStart >= v.start) {
|
|
151
167
|
milestoneStyle = styles.completedGreen;
|
package/lib/utils.js
CHANGED
|
@@ -331,7 +331,7 @@ function canAdjustUnstartedTask(task, lockMilestone) {
|
|
|
331
331
|
return true;
|
|
332
332
|
}
|
|
333
333
|
function isOverdueUnstartedTask(task, currentDate, lockMilestone) {
|
|
334
|
-
return Boolean(task && task.start && task.start
|
|
334
|
+
return Boolean(task && task.start && task.start <= currentDate && canAdjustUnstartedTask(task, lockMilestone));
|
|
335
335
|
}
|
|
336
336
|
function getOverdueRootTaskIds(id, ins, tasks, tmap, currentDate, lockMilestone) {
|
|
337
337
|
var roots = new Set();
|
|
@@ -373,9 +373,85 @@ function getForcedStartMap(sorted, ins, tasks, tmap, currentDate, lockMilestone)
|
|
|
373
373
|
});
|
|
374
374
|
return forcedStartMap;
|
|
375
375
|
}
|
|
376
|
+
function getAutoScheduleDebugConfig(debugOptions) {
|
|
377
|
+
var options = debugOptions;
|
|
378
|
+
if (options == null && typeof globalThis !== 'undefined') {
|
|
379
|
+
options = globalThis.__GANTT_AUTO_SCHEDULE_DEBUG__;
|
|
380
|
+
}
|
|
381
|
+
if (!options) {
|
|
382
|
+
return null;
|
|
383
|
+
}
|
|
384
|
+
if (options === true) {
|
|
385
|
+
return {
|
|
386
|
+
taskIds: null
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
if (options.enabled === false) {
|
|
390
|
+
return null;
|
|
391
|
+
}
|
|
392
|
+
var taskIds = null;
|
|
393
|
+
if (Array.isArray(options.taskIds) && options.taskIds.length) {
|
|
394
|
+
taskIds = new Set(options.taskIds.map(function (id) {
|
|
395
|
+
return String(id);
|
|
396
|
+
}));
|
|
397
|
+
}
|
|
398
|
+
return {
|
|
399
|
+
taskIds: taskIds
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
function shouldLogAutoScheduleTask(debugConfig, taskId) {
|
|
403
|
+
if (!debugConfig) {
|
|
404
|
+
return false;
|
|
405
|
+
}
|
|
406
|
+
if (!debugConfig.taskIds) {
|
|
407
|
+
return true;
|
|
408
|
+
}
|
|
409
|
+
return debugConfig.taskIds.has(String(taskId));
|
|
410
|
+
}
|
|
411
|
+
function formatAutoScheduleDebugDate(value) {
|
|
412
|
+
if (value == null) {
|
|
413
|
+
return value;
|
|
414
|
+
}
|
|
415
|
+
if (typeof value.toISOString === 'function') {
|
|
416
|
+
if (Number.isNaN(value.valueOf())) {
|
|
417
|
+
return 'Invalid Date';
|
|
418
|
+
}
|
|
419
|
+
return value.toISOString();
|
|
420
|
+
}
|
|
421
|
+
return value;
|
|
422
|
+
}
|
|
423
|
+
function getAutoScheduleTaskSnapshot(task, scheduleDuration) {
|
|
424
|
+
if (!task) {
|
|
425
|
+
return null;
|
|
426
|
+
}
|
|
427
|
+
return {
|
|
428
|
+
id: task.id,
|
|
429
|
+
status: task.status,
|
|
430
|
+
statusType: _typeof(task.status),
|
|
431
|
+
start: formatAutoScheduleDebugDate(task.start),
|
|
432
|
+
startType: _typeof(task.start),
|
|
433
|
+
startIsDate: task.start instanceof Date,
|
|
434
|
+
end: formatAutoScheduleDebugDate(task.end),
|
|
435
|
+
endType: _typeof(task.end),
|
|
436
|
+
endIsDate: task.end instanceof Date,
|
|
437
|
+
duration: task.duration,
|
|
438
|
+
scheduleDuration: scheduleDuration,
|
|
439
|
+
type: task.type || null
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
function logAutoSchedule(debugConfig, taskId, stage, payload) {
|
|
443
|
+
if (!shouldLogAutoScheduleTask(debugConfig, taskId)) {
|
|
444
|
+
return;
|
|
445
|
+
}
|
|
446
|
+
console.log('[autoSchedule]', stage, _objectSpread({
|
|
447
|
+
taskId: taskId
|
|
448
|
+
}, payload));
|
|
449
|
+
}
|
|
376
450
|
function autoSchedule(tasks, links) {
|
|
377
451
|
var lockMilestone = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
378
452
|
var currentDate = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : new Date();
|
|
453
|
+
var debugOptions = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : null;
|
|
454
|
+
var debugConfig = getAutoScheduleDebugConfig(debugOptions);
|
|
379
455
|
var vmap = {};
|
|
380
456
|
links.forEach(function (l) {
|
|
381
457
|
vmap[l.source] = {
|
|
@@ -416,18 +492,53 @@ function autoSchedule(tasks, links) {
|
|
|
416
492
|
});
|
|
417
493
|
var scheduleDate = normalizeScheduleDate(currentDate);
|
|
418
494
|
var forcedStartMap = getForcedStartMap(sorted, ins, tasks, tmap, scheduleDate, lockMilestone);
|
|
495
|
+
if (debugConfig) {
|
|
496
|
+
console.log('[autoSchedule]', 'context', {
|
|
497
|
+
currentDate: formatAutoScheduleDebugDate(currentDate),
|
|
498
|
+
currentDateType: _typeof(currentDate),
|
|
499
|
+
scheduleDate: formatAutoScheduleDebugDate(scheduleDate),
|
|
500
|
+
lockMilestone: lockMilestone,
|
|
501
|
+
sorted: sorted
|
|
502
|
+
});
|
|
503
|
+
}
|
|
419
504
|
sorted.forEach(function (id) {
|
|
420
505
|
var task = tasks[tmap[id]];
|
|
421
|
-
if (!task)
|
|
506
|
+
if (!task) {
|
|
507
|
+
logAutoSchedule(debugConfig, id, 'missing-task', {});
|
|
508
|
+
return;
|
|
509
|
+
}
|
|
422
510
|
var days = durationMap[id] || 0;
|
|
511
|
+
logAutoSchedule(debugConfig, id, 'before-task', {
|
|
512
|
+
task: getAutoScheduleTaskSnapshot(task, days),
|
|
513
|
+
forcedStart: formatAutoScheduleDebugDate(forcedStartMap[id]),
|
|
514
|
+
isOverdueUnstarted: isOverdueUnstartedTask(task, scheduleDate, lockMilestone),
|
|
515
|
+
incomingLinks: ins[id].map(function (link) {
|
|
516
|
+
return {
|
|
517
|
+
id: link.id,
|
|
518
|
+
source: link.source,
|
|
519
|
+
target: link.target,
|
|
520
|
+
type: link.type,
|
|
521
|
+
lag: link.lag
|
|
522
|
+
};
|
|
523
|
+
})
|
|
524
|
+
});
|
|
423
525
|
if (lockMilestone && task.type === 'milestone') {
|
|
526
|
+
logAutoSchedule(debugConfig, id, 'skip-locked-milestone', {
|
|
527
|
+
task: getAutoScheduleTaskSnapshot(task, days)
|
|
528
|
+
});
|
|
424
529
|
return;
|
|
425
530
|
}
|
|
426
531
|
if (task.status === 2) {
|
|
532
|
+
logAutoSchedule(debugConfig, id, 'skip-completed', {
|
|
533
|
+
task: getAutoScheduleTaskSnapshot(task, days)
|
|
534
|
+
});
|
|
427
535
|
return;
|
|
428
536
|
}
|
|
429
537
|
if (task.status === 3) {
|
|
430
538
|
if (!task.start) {
|
|
539
|
+
logAutoSchedule(debugConfig, id, 'skip-started-without-start', {
|
|
540
|
+
task: getAutoScheduleTaskSnapshot(task, days)
|
|
541
|
+
});
|
|
431
542
|
return;
|
|
432
543
|
}
|
|
433
544
|
var end = addDays(task.start, days);
|
|
@@ -437,6 +548,19 @@ function autoSchedule(tasks, links) {
|
|
|
437
548
|
if (v && v.start) {
|
|
438
549
|
var s = addDays(v.start, l.lag || 0);
|
|
439
550
|
var e = addDays(s, durationMap[l.source] || 0);
|
|
551
|
+
logAutoSchedule(debugConfig, id, 'started-task-link-check', {
|
|
552
|
+
link: {
|
|
553
|
+
id: l.id,
|
|
554
|
+
source: l.source,
|
|
555
|
+
target: l.target,
|
|
556
|
+
type: l.type,
|
|
557
|
+
lag: l.lag
|
|
558
|
+
},
|
|
559
|
+
sourceTask: getAutoScheduleTaskSnapshot(v, durationMap[l.source] || 0),
|
|
560
|
+
candidateStart: formatAutoScheduleDebugDate(s),
|
|
561
|
+
candidateEnd: formatAutoScheduleDebugDate(e),
|
|
562
|
+
previousEnd: formatAutoScheduleDebugDate(end)
|
|
563
|
+
});
|
|
440
564
|
if (l.type === 'SF') {
|
|
441
565
|
end = maxDate(end, s);
|
|
442
566
|
}
|
|
@@ -447,6 +571,9 @@ function autoSchedule(tasks, links) {
|
|
|
447
571
|
}
|
|
448
572
|
task.end = end;
|
|
449
573
|
task.duration = (task.end - task.start) / DAY;
|
|
574
|
+
logAutoSchedule(debugConfig, id, 'after-started-task', {
|
|
575
|
+
task: getAutoScheduleTaskSnapshot(task, days)
|
|
576
|
+
});
|
|
450
577
|
return;
|
|
451
578
|
}
|
|
452
579
|
var start = null;
|
|
@@ -454,20 +581,53 @@ function autoSchedule(tasks, links) {
|
|
|
454
581
|
var _l = ins[id][_i3];
|
|
455
582
|
var _v = tasks[tmap[_l.source]];
|
|
456
583
|
var candidate = getConstraintStart(_l, _v, days, durationMap[_l.source] || 0);
|
|
584
|
+
logAutoSchedule(debugConfig, id, 'constraint-check', {
|
|
585
|
+
link: {
|
|
586
|
+
id: _l.id,
|
|
587
|
+
source: _l.source,
|
|
588
|
+
target: _l.target,
|
|
589
|
+
type: _l.type,
|
|
590
|
+
lag: _l.lag
|
|
591
|
+
},
|
|
592
|
+
sourceTask: getAutoScheduleTaskSnapshot(_v, durationMap[_l.source] || 0),
|
|
593
|
+
previousStart: formatAutoScheduleDebugDate(start),
|
|
594
|
+
candidate: formatAutoScheduleDebugDate(candidate)
|
|
595
|
+
});
|
|
457
596
|
if (candidate) {
|
|
458
597
|
start = maxDate(start, candidate);
|
|
459
598
|
}
|
|
460
599
|
}
|
|
461
600
|
if (forcedStartMap[id]) {
|
|
601
|
+
logAutoSchedule(debugConfig, id, 'forced-start-check', {
|
|
602
|
+
previousStart: formatAutoScheduleDebugDate(start),
|
|
603
|
+
forcedStart: formatAutoScheduleDebugDate(forcedStartMap[id])
|
|
604
|
+
});
|
|
462
605
|
start = maxDate(start, forcedStartMap[id]);
|
|
463
606
|
}
|
|
464
607
|
if (start) {
|
|
465
608
|
task.start = start;
|
|
466
609
|
task.end = addDays(task.start, days);
|
|
610
|
+
logAutoSchedule(debugConfig, id, 'after-task', {
|
|
611
|
+
task: getAutoScheduleTaskSnapshot(task, days)
|
|
612
|
+
});
|
|
613
|
+
return;
|
|
467
614
|
}
|
|
615
|
+
logAutoSchedule(debugConfig, id, 'no-start-change', {
|
|
616
|
+
task: getAutoScheduleTaskSnapshot(task, days)
|
|
617
|
+
});
|
|
468
618
|
});
|
|
469
619
|
links.forEach(function (vLink) {
|
|
470
620
|
var lag = getLinkLag(vLink, tasks[tmap[vLink.source]], tasks[tmap[vLink.target]], durationMap[vLink.source] || 0);
|
|
471
621
|
vLink.calculateLag = lag != null ? lag : vLink.lag || 0;
|
|
622
|
+
if (shouldLogAutoScheduleTask(debugConfig, vLink.source) || shouldLogAutoScheduleTask(debugConfig, vLink.target)) {
|
|
623
|
+
console.log('[autoSchedule]', 'link-lag-sync', {
|
|
624
|
+
linkId: vLink.id,
|
|
625
|
+
source: vLink.source,
|
|
626
|
+
target: vLink.target,
|
|
627
|
+
type: vLink.type,
|
|
628
|
+
lag: vLink.lag,
|
|
629
|
+
calculateLag: vLink.calculateLag
|
|
630
|
+
});
|
|
631
|
+
}
|
|
472
632
|
});
|
|
473
633
|
}
|
package/package.json
CHANGED
package/src/gantt/Bar.js
CHANGED
|
@@ -6,6 +6,15 @@ function getTime(val) {
|
|
|
6
6
|
return typeof val.getTime === 'function' ? val.getTime() : val;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
+
function shouldShowBaselineEndDelay(v) {
|
|
10
|
+
if (!v || v.type === 'group') {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
const baselineEnd = getTime(v.baselineEnd);
|
|
14
|
+
const actualStart = getTime(v.start);
|
|
15
|
+
return baselineEnd != null && actualStart != null && actualStart >= baselineEnd;
|
|
16
|
+
}
|
|
17
|
+
|
|
9
18
|
// 根据 status 和日期计算活动条颜色
|
|
10
19
|
// status: 1=未开始 2=已完成 3=已开始
|
|
11
20
|
function getBarColors(v, current, styles) {
|
|
@@ -15,6 +24,9 @@ function getBarColors(v, current, styles) {
|
|
|
15
24
|
const is100Percent = percent >= 0.999999;
|
|
16
25
|
const blFinish = getTime(v.baselineEnd);
|
|
17
26
|
const actualFinish = getTime(v.end);
|
|
27
|
+
if (shouldShowBaselineEndDelay(v)) {
|
|
28
|
+
return { front: styles.undoneRed, back: styles.undoneRed };
|
|
29
|
+
}
|
|
18
30
|
|
|
19
31
|
// 处理已完成状态或100%进度的情况 (status=2 或 100%进度)
|
|
20
32
|
if (status === 2 || (is100Percent && type === 'group')) {
|
|
@@ -113,7 +125,9 @@ export default function Bar({
|
|
|
113
125
|
|
|
114
126
|
// 里程碑颜色计算
|
|
115
127
|
let milestoneStyle = styles.milestone;
|
|
116
|
-
if (v
|
|
128
|
+
if (shouldShowBaselineEndDelay(v)) {
|
|
129
|
+
milestoneStyle = styles.undoneRed;
|
|
130
|
+
} else if (v.status === 2) {
|
|
117
131
|
// 状态为完成时
|
|
118
132
|
if (v.baselineStart && v.baselineStart >= v.start) {
|
|
119
133
|
milestoneStyle = styles.completedGreen;
|
package/src/utils.js
CHANGED
|
@@ -315,7 +315,7 @@ function canAdjustUnstartedTask(task, lockMilestone) {
|
|
|
315
315
|
function isOverdueUnstartedTask(task, currentDate, lockMilestone) {
|
|
316
316
|
return Boolean(task
|
|
317
317
|
&& task.start
|
|
318
|
-
&& task.start
|
|
318
|
+
&& task.start <= currentDate
|
|
319
319
|
&& canAdjustUnstartedTask(task, lockMilestone));
|
|
320
320
|
}
|
|
321
321
|
|
|
@@ -368,7 +368,79 @@ function getForcedStartMap(sorted, ins, tasks, tmap, currentDate, lockMilestone)
|
|
|
368
368
|
return forcedStartMap;
|
|
369
369
|
}
|
|
370
370
|
|
|
371
|
-
|
|
371
|
+
function getAutoScheduleDebugConfig(debugOptions) {
|
|
372
|
+
let options = debugOptions;
|
|
373
|
+
if (options == null && typeof globalThis !== 'undefined') {
|
|
374
|
+
options = globalThis.__GANTT_AUTO_SCHEDULE_DEBUG__;
|
|
375
|
+
}
|
|
376
|
+
if (!options) {
|
|
377
|
+
return null;
|
|
378
|
+
}
|
|
379
|
+
if (options === true) {
|
|
380
|
+
return { taskIds: null };
|
|
381
|
+
}
|
|
382
|
+
if (options.enabled === false) {
|
|
383
|
+
return null;
|
|
384
|
+
}
|
|
385
|
+
let taskIds = null;
|
|
386
|
+
if (Array.isArray(options.taskIds) && options.taskIds.length) {
|
|
387
|
+
taskIds = new Set(options.taskIds.map((id) => String(id)));
|
|
388
|
+
}
|
|
389
|
+
return { taskIds };
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
function shouldLogAutoScheduleTask(debugConfig, taskId) {
|
|
393
|
+
if (!debugConfig) {
|
|
394
|
+
return false;
|
|
395
|
+
}
|
|
396
|
+
if (!debugConfig.taskIds) {
|
|
397
|
+
return true;
|
|
398
|
+
}
|
|
399
|
+
return debugConfig.taskIds.has(String(taskId));
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
function formatAutoScheduleDebugDate(value) {
|
|
403
|
+
if (value == null) {
|
|
404
|
+
return value;
|
|
405
|
+
}
|
|
406
|
+
if (typeof value.toISOString === 'function') {
|
|
407
|
+
if (Number.isNaN(value.valueOf())) {
|
|
408
|
+
return 'Invalid Date';
|
|
409
|
+
}
|
|
410
|
+
return value.toISOString();
|
|
411
|
+
}
|
|
412
|
+
return value;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
function getAutoScheduleTaskSnapshot(task, scheduleDuration) {
|
|
416
|
+
if (!task) {
|
|
417
|
+
return null;
|
|
418
|
+
}
|
|
419
|
+
return {
|
|
420
|
+
id: task.id,
|
|
421
|
+
status: task.status,
|
|
422
|
+
statusType: typeof task.status,
|
|
423
|
+
start: formatAutoScheduleDebugDate(task.start),
|
|
424
|
+
startType: typeof task.start,
|
|
425
|
+
startIsDate: task.start instanceof Date,
|
|
426
|
+
end: formatAutoScheduleDebugDate(task.end),
|
|
427
|
+
endType: typeof task.end,
|
|
428
|
+
endIsDate: task.end instanceof Date,
|
|
429
|
+
duration: task.duration,
|
|
430
|
+
scheduleDuration,
|
|
431
|
+
type: task.type || null
|
|
432
|
+
};
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
function logAutoSchedule(debugConfig, taskId, stage, payload) {
|
|
436
|
+
if (!shouldLogAutoScheduleTask(debugConfig, taskId)) {
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
439
|
+
console.log('[autoSchedule]', stage, { taskId, ...payload });
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
export function autoSchedule(tasks, links, lockMilestone = false, currentDate = new Date(), debugOptions = null) {
|
|
443
|
+
const debugConfig = getAutoScheduleDebugConfig(debugOptions);
|
|
372
444
|
const vmap = {};
|
|
373
445
|
links.forEach((l) => {
|
|
374
446
|
vmap[l.source] = { id: l.source, links: [] };
|
|
@@ -402,18 +474,51 @@ export function autoSchedule(tasks, links, lockMilestone = false, currentDate =
|
|
|
402
474
|
});
|
|
403
475
|
const scheduleDate = normalizeScheduleDate(currentDate);
|
|
404
476
|
const forcedStartMap = getForcedStartMap(sorted, ins, tasks, tmap, scheduleDate, lockMilestone);
|
|
477
|
+
if (debugConfig) {
|
|
478
|
+
console.log('[autoSchedule]', 'context', {
|
|
479
|
+
currentDate: formatAutoScheduleDebugDate(currentDate),
|
|
480
|
+
currentDateType: typeof currentDate,
|
|
481
|
+
scheduleDate: formatAutoScheduleDebugDate(scheduleDate),
|
|
482
|
+
lockMilestone,
|
|
483
|
+
sorted
|
|
484
|
+
});
|
|
485
|
+
}
|
|
405
486
|
sorted.forEach((id) => {
|
|
406
487
|
const task = tasks[tmap[id]];
|
|
407
|
-
if (!task)
|
|
488
|
+
if (!task) {
|
|
489
|
+
logAutoSchedule(debugConfig, id, 'missing-task', {});
|
|
490
|
+
return;
|
|
491
|
+
}
|
|
408
492
|
const days = durationMap[id] || 0;
|
|
493
|
+
logAutoSchedule(debugConfig, id, 'before-task', {
|
|
494
|
+
task: getAutoScheduleTaskSnapshot(task, days),
|
|
495
|
+
forcedStart: formatAutoScheduleDebugDate(forcedStartMap[id]),
|
|
496
|
+
isOverdueUnstarted: isOverdueUnstartedTask(task, scheduleDate, lockMilestone),
|
|
497
|
+
incomingLinks: ins[id].map((link) => ({
|
|
498
|
+
id: link.id,
|
|
499
|
+
source: link.source,
|
|
500
|
+
target: link.target,
|
|
501
|
+
type: link.type,
|
|
502
|
+
lag: link.lag
|
|
503
|
+
}))
|
|
504
|
+
});
|
|
409
505
|
if (lockMilestone && task.type === 'milestone') {
|
|
506
|
+
logAutoSchedule(debugConfig, id, 'skip-locked-milestone', {
|
|
507
|
+
task: getAutoScheduleTaskSnapshot(task, days)
|
|
508
|
+
});
|
|
410
509
|
return;
|
|
411
510
|
}
|
|
412
511
|
if (task.status === 2) {
|
|
512
|
+
logAutoSchedule(debugConfig, id, 'skip-completed', {
|
|
513
|
+
task: getAutoScheduleTaskSnapshot(task, days)
|
|
514
|
+
});
|
|
413
515
|
return;
|
|
414
516
|
}
|
|
415
517
|
if (task.status === 3) {
|
|
416
518
|
if (!task.start) {
|
|
519
|
+
logAutoSchedule(debugConfig, id, 'skip-started-without-start', {
|
|
520
|
+
task: getAutoScheduleTaskSnapshot(task, days)
|
|
521
|
+
});
|
|
417
522
|
return;
|
|
418
523
|
}
|
|
419
524
|
let end = addDays(task.start, days);
|
|
@@ -423,6 +528,19 @@ export function autoSchedule(tasks, links, lockMilestone = false, currentDate =
|
|
|
423
528
|
if (v && v.start) {
|
|
424
529
|
const s = addDays(v.start, l.lag || 0);
|
|
425
530
|
const e = addDays(s, durationMap[l.source] || 0);
|
|
531
|
+
logAutoSchedule(debugConfig, id, 'started-task-link-check', {
|
|
532
|
+
link: {
|
|
533
|
+
id: l.id,
|
|
534
|
+
source: l.source,
|
|
535
|
+
target: l.target,
|
|
536
|
+
type: l.type,
|
|
537
|
+
lag: l.lag
|
|
538
|
+
},
|
|
539
|
+
sourceTask: getAutoScheduleTaskSnapshot(v, durationMap[l.source] || 0),
|
|
540
|
+
candidateStart: formatAutoScheduleDebugDate(s),
|
|
541
|
+
candidateEnd: formatAutoScheduleDebugDate(e),
|
|
542
|
+
previousEnd: formatAutoScheduleDebugDate(end)
|
|
543
|
+
});
|
|
426
544
|
if (l.type === 'SF') {
|
|
427
545
|
end = maxDate(end, s);
|
|
428
546
|
}
|
|
@@ -433,6 +551,9 @@ export function autoSchedule(tasks, links, lockMilestone = false, currentDate =
|
|
|
433
551
|
}
|
|
434
552
|
task.end = end;
|
|
435
553
|
task.duration = (task.end - task.start) / DAY;
|
|
554
|
+
logAutoSchedule(debugConfig, id, 'after-started-task', {
|
|
555
|
+
task: getAutoScheduleTaskSnapshot(task, days)
|
|
556
|
+
});
|
|
436
557
|
return;
|
|
437
558
|
}
|
|
438
559
|
let start = null;
|
|
@@ -440,20 +561,54 @@ export function autoSchedule(tasks, links, lockMilestone = false, currentDate =
|
|
|
440
561
|
const l = ins[id][i];
|
|
441
562
|
const v = tasks[tmap[l.source]];
|
|
442
563
|
const candidate = getConstraintStart(l, v, days, durationMap[l.source] || 0);
|
|
564
|
+
logAutoSchedule(debugConfig, id, 'constraint-check', {
|
|
565
|
+
link: {
|
|
566
|
+
id: l.id,
|
|
567
|
+
source: l.source,
|
|
568
|
+
target: l.target,
|
|
569
|
+
type: l.type,
|
|
570
|
+
lag: l.lag
|
|
571
|
+
},
|
|
572
|
+
sourceTask: getAutoScheduleTaskSnapshot(v, durationMap[l.source] || 0),
|
|
573
|
+
previousStart: formatAutoScheduleDebugDate(start),
|
|
574
|
+
candidate: formatAutoScheduleDebugDate(candidate)
|
|
575
|
+
});
|
|
443
576
|
if (candidate) {
|
|
444
577
|
start = maxDate(start, candidate);
|
|
445
578
|
}
|
|
446
579
|
}
|
|
447
580
|
if (forcedStartMap[id]) {
|
|
581
|
+
logAutoSchedule(debugConfig, id, 'forced-start-check', {
|
|
582
|
+
previousStart: formatAutoScheduleDebugDate(start),
|
|
583
|
+
forcedStart: formatAutoScheduleDebugDate(forcedStartMap[id])
|
|
584
|
+
});
|
|
448
585
|
start = maxDate(start, forcedStartMap[id]);
|
|
449
586
|
}
|
|
450
587
|
if (start) {
|
|
451
588
|
task.start = start;
|
|
452
589
|
task.end = addDays(task.start, days);
|
|
590
|
+
logAutoSchedule(debugConfig, id, 'after-task', {
|
|
591
|
+
task: getAutoScheduleTaskSnapshot(task, days)
|
|
592
|
+
});
|
|
593
|
+
return;
|
|
453
594
|
}
|
|
595
|
+
logAutoSchedule(debugConfig, id, 'no-start-change', {
|
|
596
|
+
task: getAutoScheduleTaskSnapshot(task, days)
|
|
597
|
+
});
|
|
454
598
|
});
|
|
455
599
|
links.forEach((vLink) => {
|
|
456
600
|
const lag = getLinkLag(vLink, tasks[tmap[vLink.source]], tasks[tmap[vLink.target]], durationMap[vLink.source] || 0);
|
|
457
601
|
vLink.calculateLag = lag != null ? lag : (vLink.lag || 0);
|
|
602
|
+
if (shouldLogAutoScheduleTask(debugConfig, vLink.source)
|
|
603
|
+
|| shouldLogAutoScheduleTask(debugConfig, vLink.target)) {
|
|
604
|
+
console.log('[autoSchedule]', 'link-lag-sync', {
|
|
605
|
+
linkId: vLink.id,
|
|
606
|
+
source: vLink.source,
|
|
607
|
+
target: vLink.target,
|
|
608
|
+
type: vLink.type,
|
|
609
|
+
lag: vLink.lag,
|
|
610
|
+
calculateLag: vLink.calculateLag
|
|
611
|
+
});
|
|
612
|
+
}
|
|
458
613
|
});
|
|
459
614
|
}
|