cwhi-gantt 1.4.3 → 1.4.5
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 +47 -13
- package/dist/gantt.min.js +1 -1
- package/es/gantt/Bar.js +2 -3
- package/es/utils.js +45 -11
- package/lib/gantt/Bar.js +2 -3
- package/lib/utils.js +45 -11
- package/package.json +2 -1
- package/src/gantt/Bar.js +2 -3
- package/src/utils.js +47 -11
package/dist/gantt.js
CHANGED
|
@@ -380,6 +380,36 @@
|
|
|
380
380
|
}
|
|
381
381
|
return sorted;
|
|
382
382
|
}
|
|
383
|
+
function getScheduleDuration(task) {
|
|
384
|
+
if (task.type === 'milestone') {
|
|
385
|
+
return 0;
|
|
386
|
+
}
|
|
387
|
+
if (task.duration) {
|
|
388
|
+
return task.duration;
|
|
389
|
+
}
|
|
390
|
+
if (task.start && task.end) {
|
|
391
|
+
return Math.round((task.end - task.start) / DAY);
|
|
392
|
+
}
|
|
393
|
+
return 0;
|
|
394
|
+
}
|
|
395
|
+
function getLinkLag(link, sourceTask, targetTask) {
|
|
396
|
+
if (!sourceTask || !targetTask) {
|
|
397
|
+
return null;
|
|
398
|
+
}
|
|
399
|
+
if (link.type === 'SS' && sourceTask.start && targetTask.start) {
|
|
400
|
+
return Math.round((targetTask.start - sourceTask.start) / DAY);
|
|
401
|
+
}
|
|
402
|
+
if (link.type === 'FS' && sourceTask.end && targetTask.start) {
|
|
403
|
+
return Math.round((targetTask.start - sourceTask.end) / DAY);
|
|
404
|
+
}
|
|
405
|
+
if (link.type === 'SF' && sourceTask.start && targetTask.end) {
|
|
406
|
+
return Math.round((targetTask.end - sourceTask.start) / DAY);
|
|
407
|
+
}
|
|
408
|
+
if (link.type === 'FF' && sourceTask.end && targetTask.end) {
|
|
409
|
+
return Math.round((targetTask.end - sourceTask.end) / DAY);
|
|
410
|
+
}
|
|
411
|
+
return null;
|
|
412
|
+
}
|
|
383
413
|
function autoSchedule(tasks, links) {
|
|
384
414
|
var lockMilestone = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
385
415
|
var vmap = {};
|
|
@@ -404,11 +434,10 @@
|
|
|
404
434
|
});
|
|
405
435
|
var sorted = toposort(dag);
|
|
406
436
|
var tmap = {};
|
|
437
|
+
var durationMap = {};
|
|
407
438
|
for (var i = 0; i < tasks.length; i++) {
|
|
408
439
|
var task = tasks[i];
|
|
409
|
-
|
|
410
|
-
task.duration = 0;
|
|
411
|
-
}
|
|
440
|
+
durationMap[task.id] = getScheduleDuration(task);
|
|
412
441
|
tmap[task.id] = i;
|
|
413
442
|
}
|
|
414
443
|
var ins = {};
|
|
@@ -421,7 +450,7 @@
|
|
|
421
450
|
sorted.forEach(function (id) {
|
|
422
451
|
var task = tasks[tmap[id]];
|
|
423
452
|
if (!task) return;
|
|
424
|
-
var days =
|
|
453
|
+
var days = durationMap[id] || 0;
|
|
425
454
|
if (lockMilestone && task.type === 'milestone') {
|
|
426
455
|
return;
|
|
427
456
|
}
|
|
@@ -429,17 +458,19 @@
|
|
|
429
458
|
return;
|
|
430
459
|
}
|
|
431
460
|
if (task.status === 3) {
|
|
461
|
+
if (!task.start) {
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
432
464
|
task.end = addDays(task.start, days);
|
|
433
465
|
return;
|
|
434
466
|
}
|
|
435
467
|
var start = null;
|
|
436
|
-
var end = null;
|
|
437
468
|
for (var _i2 = 0; _i2 < ins[id].length; _i2++) {
|
|
438
469
|
var l = ins[id][_i2];
|
|
439
470
|
var v = tasks[tmap[l.source]];
|
|
440
471
|
if (v && v.start) {
|
|
441
472
|
var s = addDays(v.start, l.lag || 0);
|
|
442
|
-
var e = addDays(s,
|
|
473
|
+
var e = addDays(s, durationMap[l.source] || 0);
|
|
443
474
|
if (l.type === 'SS') {
|
|
444
475
|
start = maxDate(start, s);
|
|
445
476
|
}
|
|
@@ -447,21 +478,24 @@
|
|
|
447
478
|
start = maxDate(start, e);
|
|
448
479
|
}
|
|
449
480
|
if (l.type === 'SF') {
|
|
450
|
-
|
|
481
|
+
start = maxDate(start, addDays(s, -days));
|
|
451
482
|
}
|
|
452
483
|
if (l.type === 'FF') {
|
|
453
|
-
|
|
484
|
+
start = maxDate(start, addDays(e, -days));
|
|
454
485
|
}
|
|
455
486
|
}
|
|
456
487
|
}
|
|
457
|
-
if (end) {
|
|
458
|
-
task.start = addDays(end, -days);
|
|
459
|
-
}
|
|
460
488
|
if (start) {
|
|
461
489
|
task.start = start;
|
|
462
490
|
task.end = addDays(task.start, days);
|
|
463
491
|
}
|
|
464
492
|
});
|
|
493
|
+
links.forEach(function (link) {
|
|
494
|
+
var lag = getLinkLag(link, tasks[tmap[link.source]], tasks[tmap[link.target]]);
|
|
495
|
+
if (lag != null) {
|
|
496
|
+
link.lag = lag;
|
|
497
|
+
}
|
|
498
|
+
});
|
|
465
499
|
}
|
|
466
500
|
|
|
467
501
|
var utils = /*#__PURE__*/Object.freeze({
|
|
@@ -1060,9 +1094,9 @@
|
|
|
1060
1094
|
} else {
|
|
1061
1095
|
// 状态不为完成时
|
|
1062
1096
|
if (v.baselineStart && v.baselineStart < v.start) {
|
|
1063
|
-
if (v.start
|
|
1097
|
+
if (v.start < current) {
|
|
1064
1098
|
milestoneStyle = styles.undoneRed;
|
|
1065
|
-
} else if (v.start
|
|
1099
|
+
} else if (v.start >= current) {
|
|
1066
1100
|
milestoneStyle = styles.undoneYellow;
|
|
1067
1101
|
}
|
|
1068
1102
|
} else {
|
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 autoSchedule(tasks,links){var lockMilestone=arguments.length>2&&arguments[2]!==undefined?arguments[2]:false;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={};for(var i=0;i<tasks.length;i++){var task=tasks[i];if(task.type==="milestone"){task.duration=0}tmap[task.id]=i}var ins={};sorted.forEach(function(id){ins[id]=[]});dag.forEach(function(l){ins[l.target].push(l)});sorted.forEach(function(id){var task=tasks[tmap[id]];if(!task)return;var days=task.duration||0;if(lockMilestone&&task.type==="milestone"){return}if(task.status===2){return}if(task.status===3){task.end=addDays(task.start,days);return}var start=null;var end=null;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,v.duration||0);if(l.type==="SS"){start=maxDate(start,s)}if(l.type==="FS"){start=maxDate(start,e)}if(l.type==="SF"){end=maxDate(end,s)}if(l.type==="FF"){end=maxDate(end,e)}}}if(end){task.start=addDays(end,-days)}if(start){task.start=start;task.end=addDays(task.start,days)}})}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.duration){return task.duration}if(task.start&&task.end){return Math.round((task.end-task.start)/DAY)}return 0}function getLinkLag(link,sourceTask,targetTask){if(!sourceTask||!targetTask){return null}if(link.type==="SS"&&sourceTask.start&&targetTask.start){return Math.round((targetTask.start-sourceTask.start)/DAY)}if(link.type==="FS"&&sourceTask.end&&targetTask.start){return Math.round((targetTask.start-sourceTask.end)/DAY)}if(link.type==="SF"&&sourceTask.start&&targetTask.end){return Math.round((targetTask.end-sourceTask.start)/DAY)}if(link.type==="FF"&&sourceTask.end&&targetTask.end){return Math.round((targetTask.end-sourceTask.end)/DAY)}return null}function autoSchedule(tasks,links){var lockMilestone=arguments.length>2&&arguments[2]!==undefined?arguments[2]:false;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}var ins={};sorted.forEach(function(id){ins[id]=[]});dag.forEach(function(l){ins[l.target].push(l)});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}task.end=addDays(task.start,days);return}var start=null;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==="SS"){start=maxDate(start,s)}if(l.type==="FS"){start=maxDate(start,e)}if(l.type==="SF"){start=maxDate(start,addDays(s,-days))}if(l.type==="FF"){start=maxDate(start,addDays(e,-days))}}}if(start){task.start=start;task.end=addDays(task.start,days)}});links.forEach(function(link){var lag=getLinkLag(link,tasks[tmap[link.source]],tasks[tmap[link.target]]);if(lag!=null){link.lag=lag}})}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})});
|
package/es/gantt/Bar.js
CHANGED
|
@@ -138,7 +138,6 @@ export default function Bar(_ref) {
|
|
|
138
138
|
|
|
139
139
|
// 里程碑颜色计算
|
|
140
140
|
var milestoneStyle = styles.milestone;
|
|
141
|
-
var currentDate = new Date(current);
|
|
142
141
|
if (v.status === 2) {
|
|
143
142
|
// 状态为完成时
|
|
144
143
|
if (v.baselineStart && v.baselineStart >= v.start) {
|
|
@@ -149,9 +148,9 @@ export default function Bar(_ref) {
|
|
|
149
148
|
} else {
|
|
150
149
|
// 状态不为完成时
|
|
151
150
|
if (v.baselineStart && v.baselineStart < v.start) {
|
|
152
|
-
if (v.start
|
|
151
|
+
if (v.start < current) {
|
|
153
152
|
milestoneStyle = styles.undoneRed;
|
|
154
|
-
} else if (v.start
|
|
153
|
+
} else if (v.start >= current) {
|
|
155
154
|
milestoneStyle = styles.undoneYellow;
|
|
156
155
|
}
|
|
157
156
|
} else {
|
package/es/utils.js
CHANGED
|
@@ -233,6 +233,36 @@ export function toposort(links) {
|
|
|
233
233
|
}
|
|
234
234
|
return sorted;
|
|
235
235
|
}
|
|
236
|
+
function getScheduleDuration(task) {
|
|
237
|
+
if (task.type === 'milestone') {
|
|
238
|
+
return 0;
|
|
239
|
+
}
|
|
240
|
+
if (task.duration) {
|
|
241
|
+
return task.duration;
|
|
242
|
+
}
|
|
243
|
+
if (task.start && task.end) {
|
|
244
|
+
return Math.round((task.end - task.start) / DAY);
|
|
245
|
+
}
|
|
246
|
+
return 0;
|
|
247
|
+
}
|
|
248
|
+
function getLinkLag(link, sourceTask, targetTask) {
|
|
249
|
+
if (!sourceTask || !targetTask) {
|
|
250
|
+
return null;
|
|
251
|
+
}
|
|
252
|
+
if (link.type === 'SS' && sourceTask.start && targetTask.start) {
|
|
253
|
+
return Math.round((targetTask.start - sourceTask.start) / DAY);
|
|
254
|
+
}
|
|
255
|
+
if (link.type === 'FS' && sourceTask.end && targetTask.start) {
|
|
256
|
+
return Math.round((targetTask.start - sourceTask.end) / DAY);
|
|
257
|
+
}
|
|
258
|
+
if (link.type === 'SF' && sourceTask.start && targetTask.end) {
|
|
259
|
+
return Math.round((targetTask.end - sourceTask.start) / DAY);
|
|
260
|
+
}
|
|
261
|
+
if (link.type === 'FF' && sourceTask.end && targetTask.end) {
|
|
262
|
+
return Math.round((targetTask.end - sourceTask.end) / DAY);
|
|
263
|
+
}
|
|
264
|
+
return null;
|
|
265
|
+
}
|
|
236
266
|
export function autoSchedule(tasks, links) {
|
|
237
267
|
var lockMilestone = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
238
268
|
var vmap = {};
|
|
@@ -257,11 +287,10 @@ export function autoSchedule(tasks, links) {
|
|
|
257
287
|
});
|
|
258
288
|
var sorted = toposort(dag);
|
|
259
289
|
var tmap = {};
|
|
290
|
+
var durationMap = {};
|
|
260
291
|
for (var i = 0; i < tasks.length; i++) {
|
|
261
292
|
var task = tasks[i];
|
|
262
|
-
|
|
263
|
-
task.duration = 0;
|
|
264
|
-
}
|
|
293
|
+
durationMap[task.id] = getScheduleDuration(task);
|
|
265
294
|
tmap[task.id] = i;
|
|
266
295
|
}
|
|
267
296
|
var ins = {};
|
|
@@ -274,7 +303,7 @@ export function autoSchedule(tasks, links) {
|
|
|
274
303
|
sorted.forEach(function (id) {
|
|
275
304
|
var task = tasks[tmap[id]];
|
|
276
305
|
if (!task) return;
|
|
277
|
-
var days =
|
|
306
|
+
var days = durationMap[id] || 0;
|
|
278
307
|
if (lockMilestone && task.type === 'milestone') {
|
|
279
308
|
return;
|
|
280
309
|
}
|
|
@@ -282,17 +311,19 @@ export function autoSchedule(tasks, links) {
|
|
|
282
311
|
return;
|
|
283
312
|
}
|
|
284
313
|
if (task.status === 3) {
|
|
314
|
+
if (!task.start) {
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
285
317
|
task.end = addDays(task.start, days);
|
|
286
318
|
return;
|
|
287
319
|
}
|
|
288
320
|
var start = null;
|
|
289
|
-
var end = null;
|
|
290
321
|
for (var _i2 = 0; _i2 < ins[id].length; _i2++) {
|
|
291
322
|
var l = ins[id][_i2];
|
|
292
323
|
var v = tasks[tmap[l.source]];
|
|
293
324
|
if (v && v.start) {
|
|
294
325
|
var s = addDays(v.start, l.lag || 0);
|
|
295
|
-
var e = addDays(s,
|
|
326
|
+
var e = addDays(s, durationMap[l.source] || 0);
|
|
296
327
|
if (l.type === 'SS') {
|
|
297
328
|
start = maxDate(start, s);
|
|
298
329
|
}
|
|
@@ -300,19 +331,22 @@ export function autoSchedule(tasks, links) {
|
|
|
300
331
|
start = maxDate(start, e);
|
|
301
332
|
}
|
|
302
333
|
if (l.type === 'SF') {
|
|
303
|
-
|
|
334
|
+
start = maxDate(start, addDays(s, -days));
|
|
304
335
|
}
|
|
305
336
|
if (l.type === 'FF') {
|
|
306
|
-
|
|
337
|
+
start = maxDate(start, addDays(e, -days));
|
|
307
338
|
}
|
|
308
339
|
}
|
|
309
340
|
}
|
|
310
|
-
if (end) {
|
|
311
|
-
task.start = addDays(end, -days);
|
|
312
|
-
}
|
|
313
341
|
if (start) {
|
|
314
342
|
task.start = start;
|
|
315
343
|
task.end = addDays(task.start, days);
|
|
316
344
|
}
|
|
317
345
|
});
|
|
346
|
+
links.forEach(function (link) {
|
|
347
|
+
var lag = getLinkLag(link, tasks[tmap[link.source]], tasks[tmap[link.target]]);
|
|
348
|
+
if (lag != null) {
|
|
349
|
+
link.lag = lag;
|
|
350
|
+
}
|
|
351
|
+
});
|
|
318
352
|
}
|
package/lib/gantt/Bar.js
CHANGED
|
@@ -145,7 +145,6 @@ function Bar(_ref) {
|
|
|
145
145
|
|
|
146
146
|
// 里程碑颜色计算
|
|
147
147
|
var milestoneStyle = styles.milestone;
|
|
148
|
-
var currentDate = new Date(current);
|
|
149
148
|
if (v.status === 2) {
|
|
150
149
|
// 状态为完成时
|
|
151
150
|
if (v.baselineStart && v.baselineStart >= v.start) {
|
|
@@ -156,9 +155,9 @@ function Bar(_ref) {
|
|
|
156
155
|
} else {
|
|
157
156
|
// 状态不为完成时
|
|
158
157
|
if (v.baselineStart && v.baselineStart < v.start) {
|
|
159
|
-
if (v.start
|
|
158
|
+
if (v.start < current) {
|
|
160
159
|
milestoneStyle = styles.undoneRed;
|
|
161
|
-
} else if (v.start
|
|
160
|
+
} else if (v.start >= current) {
|
|
162
161
|
milestoneStyle = styles.undoneYellow;
|
|
163
162
|
}
|
|
164
163
|
} else {
|
package/lib/utils.js
CHANGED
|
@@ -253,6 +253,36 @@ function toposort(links) {
|
|
|
253
253
|
}
|
|
254
254
|
return sorted;
|
|
255
255
|
}
|
|
256
|
+
function getScheduleDuration(task) {
|
|
257
|
+
if (task.type === 'milestone') {
|
|
258
|
+
return 0;
|
|
259
|
+
}
|
|
260
|
+
if (task.duration) {
|
|
261
|
+
return task.duration;
|
|
262
|
+
}
|
|
263
|
+
if (task.start && task.end) {
|
|
264
|
+
return Math.round((task.end - task.start) / DAY);
|
|
265
|
+
}
|
|
266
|
+
return 0;
|
|
267
|
+
}
|
|
268
|
+
function getLinkLag(link, sourceTask, targetTask) {
|
|
269
|
+
if (!sourceTask || !targetTask) {
|
|
270
|
+
return null;
|
|
271
|
+
}
|
|
272
|
+
if (link.type === 'SS' && sourceTask.start && targetTask.start) {
|
|
273
|
+
return Math.round((targetTask.start - sourceTask.start) / DAY);
|
|
274
|
+
}
|
|
275
|
+
if (link.type === 'FS' && sourceTask.end && targetTask.start) {
|
|
276
|
+
return Math.round((targetTask.start - sourceTask.end) / DAY);
|
|
277
|
+
}
|
|
278
|
+
if (link.type === 'SF' && sourceTask.start && targetTask.end) {
|
|
279
|
+
return Math.round((targetTask.end - sourceTask.start) / DAY);
|
|
280
|
+
}
|
|
281
|
+
if (link.type === 'FF' && sourceTask.end && targetTask.end) {
|
|
282
|
+
return Math.round((targetTask.end - sourceTask.end) / DAY);
|
|
283
|
+
}
|
|
284
|
+
return null;
|
|
285
|
+
}
|
|
256
286
|
function autoSchedule(tasks, links) {
|
|
257
287
|
var lockMilestone = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
258
288
|
var vmap = {};
|
|
@@ -277,11 +307,10 @@ function autoSchedule(tasks, links) {
|
|
|
277
307
|
});
|
|
278
308
|
var sorted = toposort(dag);
|
|
279
309
|
var tmap = {};
|
|
310
|
+
var durationMap = {};
|
|
280
311
|
for (var i = 0; i < tasks.length; i++) {
|
|
281
312
|
var task = tasks[i];
|
|
282
|
-
|
|
283
|
-
task.duration = 0;
|
|
284
|
-
}
|
|
313
|
+
durationMap[task.id] = getScheduleDuration(task);
|
|
285
314
|
tmap[task.id] = i;
|
|
286
315
|
}
|
|
287
316
|
var ins = {};
|
|
@@ -294,7 +323,7 @@ function autoSchedule(tasks, links) {
|
|
|
294
323
|
sorted.forEach(function (id) {
|
|
295
324
|
var task = tasks[tmap[id]];
|
|
296
325
|
if (!task) return;
|
|
297
|
-
var days =
|
|
326
|
+
var days = durationMap[id] || 0;
|
|
298
327
|
if (lockMilestone && task.type === 'milestone') {
|
|
299
328
|
return;
|
|
300
329
|
}
|
|
@@ -302,17 +331,19 @@ function autoSchedule(tasks, links) {
|
|
|
302
331
|
return;
|
|
303
332
|
}
|
|
304
333
|
if (task.status === 3) {
|
|
334
|
+
if (!task.start) {
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
305
337
|
task.end = addDays(task.start, days);
|
|
306
338
|
return;
|
|
307
339
|
}
|
|
308
340
|
var start = null;
|
|
309
|
-
var end = null;
|
|
310
341
|
for (var _i2 = 0; _i2 < ins[id].length; _i2++) {
|
|
311
342
|
var l = ins[id][_i2];
|
|
312
343
|
var v = tasks[tmap[l.source]];
|
|
313
344
|
if (v && v.start) {
|
|
314
345
|
var s = addDays(v.start, l.lag || 0);
|
|
315
|
-
var e = addDays(s,
|
|
346
|
+
var e = addDays(s, durationMap[l.source] || 0);
|
|
316
347
|
if (l.type === 'SS') {
|
|
317
348
|
start = maxDate(start, s);
|
|
318
349
|
}
|
|
@@ -320,19 +351,22 @@ function autoSchedule(tasks, links) {
|
|
|
320
351
|
start = maxDate(start, e);
|
|
321
352
|
}
|
|
322
353
|
if (l.type === 'SF') {
|
|
323
|
-
|
|
354
|
+
start = maxDate(start, addDays(s, -days));
|
|
324
355
|
}
|
|
325
356
|
if (l.type === 'FF') {
|
|
326
|
-
|
|
357
|
+
start = maxDate(start, addDays(e, -days));
|
|
327
358
|
}
|
|
328
359
|
}
|
|
329
360
|
}
|
|
330
|
-
if (end) {
|
|
331
|
-
task.start = addDays(end, -days);
|
|
332
|
-
}
|
|
333
361
|
if (start) {
|
|
334
362
|
task.start = start;
|
|
335
363
|
task.end = addDays(task.start, days);
|
|
336
364
|
}
|
|
337
365
|
});
|
|
366
|
+
links.forEach(function (link) {
|
|
367
|
+
var lag = getLinkLag(link, tasks[tmap[link.source]], tasks[tmap[link.target]]);
|
|
368
|
+
if (lag != null) {
|
|
369
|
+
link.lag = lag;
|
|
370
|
+
}
|
|
371
|
+
});
|
|
338
372
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cwhi-gantt",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.5",
|
|
4
4
|
"description": "CWHI Gantt chart library using jsx support SVG, Canvas and SSR,It`s from gantt 3.1.1",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "es/index.js",
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"dist"
|
|
13
13
|
],
|
|
14
14
|
"scripts": {
|
|
15
|
+
"test": "node --no-warnings test/autoSchedule.test.mjs",
|
|
15
16
|
"lint": "eslint src",
|
|
16
17
|
"clean": "rimraf lib es dist",
|
|
17
18
|
"build:lib": "cross-env BABEL_ENV=cjs babel src -d lib",
|
package/src/gantt/Bar.js
CHANGED
|
@@ -113,7 +113,6 @@ export default function Bar({
|
|
|
113
113
|
|
|
114
114
|
// 里程碑颜色计算
|
|
115
115
|
let milestoneStyle = styles.milestone;
|
|
116
|
-
const currentDate = new Date(current)
|
|
117
116
|
if (v.status === 2) {
|
|
118
117
|
// 状态为完成时
|
|
119
118
|
if (v.baselineStart && v.baselineStart >= v.start) {
|
|
@@ -124,9 +123,9 @@ export default function Bar({
|
|
|
124
123
|
} else {
|
|
125
124
|
// 状态不为完成时
|
|
126
125
|
if (v.baselineStart && v.baselineStart < v.start) {
|
|
127
|
-
if (v.start
|
|
126
|
+
if (v.start < current) {
|
|
128
127
|
milestoneStyle = styles.undoneRed;
|
|
129
|
-
} else if (v.start
|
|
128
|
+
} else if (v.start >= current) {
|
|
130
129
|
milestoneStyle = styles.undoneYellow;
|
|
131
130
|
}
|
|
132
131
|
} else {
|
package/src/utils.js
CHANGED
|
@@ -228,6 +228,38 @@ export function toposort(links) {
|
|
|
228
228
|
return sorted;
|
|
229
229
|
}
|
|
230
230
|
|
|
231
|
+
function getScheduleDuration(task) {
|
|
232
|
+
if (task.type === 'milestone') {
|
|
233
|
+
return 0;
|
|
234
|
+
}
|
|
235
|
+
if (task.duration) {
|
|
236
|
+
return task.duration;
|
|
237
|
+
}
|
|
238
|
+
if (task.start && task.end) {
|
|
239
|
+
return Math.round((task.end - task.start) / DAY);
|
|
240
|
+
}
|
|
241
|
+
return 0;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function getLinkLag(link, sourceTask, targetTask) {
|
|
245
|
+
if (!sourceTask || !targetTask) {
|
|
246
|
+
return null;
|
|
247
|
+
}
|
|
248
|
+
if (link.type === 'SS' && sourceTask.start && targetTask.start) {
|
|
249
|
+
return Math.round((targetTask.start - sourceTask.start) / DAY);
|
|
250
|
+
}
|
|
251
|
+
if (link.type === 'FS' && sourceTask.end && targetTask.start) {
|
|
252
|
+
return Math.round((targetTask.start - sourceTask.end) / DAY);
|
|
253
|
+
}
|
|
254
|
+
if (link.type === 'SF' && sourceTask.start && targetTask.end) {
|
|
255
|
+
return Math.round((targetTask.end - sourceTask.start) / DAY);
|
|
256
|
+
}
|
|
257
|
+
if (link.type === 'FF' && sourceTask.end && targetTask.end) {
|
|
258
|
+
return Math.round((targetTask.end - sourceTask.end) / DAY);
|
|
259
|
+
}
|
|
260
|
+
return null;
|
|
261
|
+
}
|
|
262
|
+
|
|
231
263
|
export function autoSchedule(tasks, links, lockMilestone = false) {
|
|
232
264
|
const vmap = {};
|
|
233
265
|
links.forEach((l) => {
|
|
@@ -244,11 +276,10 @@ export function autoSchedule(tasks, links, lockMilestone = false) {
|
|
|
244
276
|
});
|
|
245
277
|
const sorted = toposort(dag);
|
|
246
278
|
const tmap = {};
|
|
279
|
+
const durationMap = {};
|
|
247
280
|
for (let i = 0; i < tasks.length; i++) {
|
|
248
281
|
const task = tasks[i];
|
|
249
|
-
|
|
250
|
-
task.duration = 0;
|
|
251
|
-
}
|
|
282
|
+
durationMap[task.id] = getScheduleDuration(task);
|
|
252
283
|
tmap[task.id] = i;
|
|
253
284
|
}
|
|
254
285
|
const ins = {};
|
|
@@ -261,7 +292,7 @@ export function autoSchedule(tasks, links, lockMilestone = false) {
|
|
|
261
292
|
sorted.forEach((id) => {
|
|
262
293
|
const task = tasks[tmap[id]];
|
|
263
294
|
if (!task) return;
|
|
264
|
-
const days =
|
|
295
|
+
const days = durationMap[id] || 0;
|
|
265
296
|
if (lockMilestone && task.type === 'milestone') {
|
|
266
297
|
return;
|
|
267
298
|
}
|
|
@@ -269,17 +300,19 @@ export function autoSchedule(tasks, links, lockMilestone = false) {
|
|
|
269
300
|
return;
|
|
270
301
|
}
|
|
271
302
|
if (task.status === 3) {
|
|
303
|
+
if (!task.start) {
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
272
306
|
task.end = addDays(task.start, days);
|
|
273
307
|
return;
|
|
274
308
|
}
|
|
275
309
|
let start = null;
|
|
276
|
-
let end = null;
|
|
277
310
|
for (let i = 0; i < ins[id].length; i++) {
|
|
278
311
|
const l = ins[id][i];
|
|
279
312
|
const v = tasks[tmap[l.source]];
|
|
280
313
|
if (v && v.start) {
|
|
281
314
|
const s = addDays(v.start, l.lag || 0);
|
|
282
|
-
const e = addDays(s,
|
|
315
|
+
const e = addDays(s, durationMap[l.source] || 0);
|
|
283
316
|
if (l.type === 'SS') {
|
|
284
317
|
start = maxDate(start, s);
|
|
285
318
|
}
|
|
@@ -287,19 +320,22 @@ export function autoSchedule(tasks, links, lockMilestone = false) {
|
|
|
287
320
|
start = maxDate(start, e);
|
|
288
321
|
}
|
|
289
322
|
if (l.type === 'SF') {
|
|
290
|
-
|
|
323
|
+
start = maxDate(start, addDays(s, -days));
|
|
291
324
|
}
|
|
292
325
|
if (l.type === 'FF') {
|
|
293
|
-
|
|
326
|
+
start = maxDate(start, addDays(e, -days));
|
|
294
327
|
}
|
|
295
328
|
}
|
|
296
329
|
}
|
|
297
|
-
if (end) {
|
|
298
|
-
task.start = addDays(end, -days);
|
|
299
|
-
}
|
|
300
330
|
if (start) {
|
|
301
331
|
task.start = start;
|
|
302
332
|
task.end = addDays(task.start, days);
|
|
303
333
|
}
|
|
304
334
|
});
|
|
335
|
+
links.forEach((link) => {
|
|
336
|
+
const lag = getLinkLag(link, tasks[tmap[link.source]], tasks[tmap[link.target]]);
|
|
337
|
+
if (lag != null) {
|
|
338
|
+
link.lag = lag;
|
|
339
|
+
}
|
|
340
|
+
});
|
|
305
341
|
}
|