gantt-task-react-powern 0.6.31 → 0.6.32

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/index.js CHANGED
@@ -2048,8 +2048,8 @@ var drawPathAndTriangle = function drawPathAndTriangle(taskFrom, taskTo, rowHeig
2048
2048
 
2049
2049
  if (t.actualSegments && t.actualSegments.length > 0) return t.actualSegments[0].x1;
2050
2050
  var candidates = [];
2051
- if (t.x1 !== undefined && t.x1 >= 0) candidates.push(t.x1);
2052
- if (t.actualx1 !== undefined && t.actualx1 >= 0) candidates.push(t.actualx1);
2051
+ if (t.x2 > t.x1) candidates.push(t.x1);
2052
+ if (t.actualx2 > t.actualx1) candidates.push(t.actualx1);
2053
2053
  return candidates.length > 0 ? Math.min.apply(Math, candidates) : 0;
2054
2054
  };
2055
2055
 
@@ -2062,8 +2062,8 @@ var drawPathAndTriangle = function drawPathAndTriangle(taskFrom, taskTo, rowHeig
2062
2062
 
2063
2063
  if (t.actualSegments && t.actualSegments.length > 0) return t.actualSegments[t.actualSegments.length - 1].x2;
2064
2064
  var candidates = [];
2065
- if (t.x2 !== undefined && t.x2 >= 0) candidates.push(t.x2);
2066
- if (t.actualx2 !== undefined && t.actualx2 >= 0) candidates.push(t.actualx2);
2065
+ if (t.x2 > t.x1) candidates.push(t.x2);
2066
+ if (t.actualx2 > t.actualx1) candidates.push(t.actualx2);
2067
2067
  return candidates.length > 0 ? Math.max.apply(Math, candidates) : 0;
2068
2068
  };
2069
2069
 
@@ -3585,7 +3585,12 @@ var TaskGanttContent = function TaskGanttContent(_ref) {
3585
3585
 
3586
3586
  var getArrows = function getArrows(isCritical, criticalPathType) {
3587
3587
  return tasks.flatMap(function (_task) {
3588
- var _live = ganttEvent.changedTask && ganttEvent.changedTask.id === _task.id ? ganttEvent.changedTask : _task;
3588
+ var a = ganttEvent.action;
3589
+ var isDraggingThis = (a === "move" || a === "start" || a === "end" || a === "progress") && !!ganttEvent.changedTask && ganttEvent.changedTask.id === _task.id;
3590
+
3591
+ var _live = isDraggingThis ? _extends({}, ganttEvent.changedTask, {
3592
+ y: _task.y
3593
+ }) : _task;
3589
3594
 
3590
3595
  var task = _live.start.getTime() > 0 && _live.end.getTime() > 0 ? _live : undefined;
3591
3596
 
@@ -3594,13 +3599,16 @@ var TaskGanttContent = function TaskGanttContent(_ref) {
3594
3599
  }
3595
3600
 
3596
3601
  return task.barChildren.map(function (child) {
3597
- if (task.x2 > task.x1 || task.actualx2 > task.actualx1) {
3602
+ var taskTo = tasks[child.index];
3603
+ var fromDrawable = task.x2 > task.x1 || task.actualx2 > task.actualx1;
3604
+ var toDrawable = !!taskTo && (taskTo.x2 > taskTo.x1 || taskTo.actualx2 > taskTo.actualx1);
3605
+
3606
+ if (fromDrawable && toDrawable) {
3598
3607
  var _task$criticalPathArr;
3599
3608
 
3600
3609
  var criticalTask = (_task$criticalPathArr = task.criticalPathArrows) === null || _task$criticalPathArr === void 0 ? void 0 : _task$criticalPathArr.find(function (arrow) {
3601
- return arrow.taskId === tasks[child.index].id && (!!arrow.criticalPathType ? arrow.criticalPathType === criticalPathType : !criticalPathType);
3610
+ return arrow.taskId === taskTo.id && (!!arrow.criticalPathType ? arrow.criticalPathType === criticalPathType : !criticalPathType);
3602
3611
  });
3603
- var taskTo = tasks[child.index];
3604
3612
  var yFrom = task.y + taskHeight / 2;
3605
3613
  var yTo = taskTo.y + taskHeight / 2;
3606
3614
  var minY = Math.min(yFrom, yTo);
@@ -3612,9 +3620,9 @@ var TaskGanttContent = function TaskGanttContent(_ref) {
3612
3620
 
3613
3621
  if (!!criticalTask === isCritical) {
3614
3622
  return React__default.createElement(Arrow, {
3615
- key: "Arrow from " + task.id + " to " + tasks[child.index].id + (isCritical ? "-critical" : ""),
3623
+ key: "Arrow from " + task.id + " to " + taskTo.id + (isCritical ? "-critical" : ""),
3616
3624
  taskFrom: task,
3617
- taskTo: tasks[child.index],
3625
+ taskTo: taskTo,
3618
3626
  rowHeight: rowHeight,
3619
3627
  dependencyType: child.dependencyType,
3620
3628
  taskHeight: taskHeight,
@@ -4034,17 +4042,46 @@ var Gantt = function Gantt(_ref) {
4034
4042
  React.useEffect(function () {
4035
4043
  if (columnWidthProp != null) return;
4036
4044
  if (svgContainerWidth <= 0) return;
4045
+ var minVisible = VIEW_MODE_DEFAULT_VISIBLE_COUNT[viewMode];
4046
+ if (!minVisible) return;
4047
+ var maxVisible = VIEW_MODE_MAX_VISIBLE_COUNT[viewMode];
4048
+ var prevViewMode = computedForViewModeRef.current;
4049
+
4050
+ if (prevViewMode != null && prevViewMode !== viewMode && computedColumnWidth != null) {
4051
+ var visible = svgContainerWidth / computedColumnWidth;
4052
+ var oldMin = VIEW_MODE_DEFAULT_VISIBLE_COUNT[prevViewMode];
4053
+ var oldMax = VIEW_MODE_MAX_VISIBLE_COUNT[prevViewMode];
4054
+ var _next = computedColumnWidth;
4055
+
4056
+ if (maxVisible && oldMin != null && oldMax != null && oldMax > oldMin) {
4057
+ var t = Math.min(1, Math.max(0, (visible - oldMin) / (oldMax - oldMin)));
4058
+ var targetVisible = minVisible + t * (maxVisible - minVisible);
4059
+ _next = Math.floor(svgContainerWidth / targetVisible);
4060
+ } else if (visible < minVisible) {
4061
+ _next = Math.floor(svgContainerWidth / minVisible);
4062
+ } else if (maxVisible && visible > maxVisible) {
4063
+ _next = Math.ceil(svgContainerWidth / maxVisible);
4064
+ }
4065
+
4066
+ _next = Math.max(20, _next);
4067
+ computedForViewModeRef.current = viewMode;
4068
+ userResizedRef.current = true;
4069
+
4070
+ if (_next !== computedColumnWidth) {
4071
+ setComputedColumnWidth(_next);
4072
+ }
4073
+
4074
+ return;
4075
+ }
4076
+
4037
4077
  var alreadySnappedForView = computedForViewModeRef.current === viewMode && computedColumnWidth != null;
4038
4078
  if (userResizedRef.current && alreadySnappedForView) return;
4039
- var target = VIEW_MODE_DEFAULT_VISIBLE_COUNT[viewMode];
4040
- if (!target) return;
4041
- var next = Math.max(20, Math.floor(svgContainerWidth / target));
4079
+ var next = Math.max(20, Math.floor(svgContainerWidth / minVisible));
4080
+ computedForViewModeRef.current = viewMode;
4042
4081
 
4043
4082
  if (next !== computedColumnWidth) {
4044
4083
  setComputedColumnWidth(next);
4045
4084
  }
4046
-
4047
- computedForViewModeRef.current = viewMode;
4048
4085
  }, [viewMode, svgContainerWidth, columnWidthProp, computedColumnWidth]);
4049
4086
  var columnWidth = (_ref3 = columnWidthProp != null ? columnWidthProp : computedColumnWidth) != null ? _ref3 : 60;
4050
4087
  var effectiveColumnWidth = React.useMemo(function () {
@@ -4329,7 +4366,7 @@ var Gantt = function Gantt(_ref) {
4329
4366
  };
4330
4367
 
4331
4368
  var handleScrollX = function handleScrollX(event) {
4332
- if (scrollX !== event.currentTarget.scrollLeft) {
4369
+ if (scrollX !== event.currentTarget.scrollLeft && !ignoreScrollEvent) {
4333
4370
  setScrollX(event.currentTarget.scrollLeft);
4334
4371
  setIgnoreScrollEvent(true);
4335
4372
  } else {
@@ -4639,6 +4676,9 @@ function topologicalOrderingHelper(taskID, taskMap, sortedTaskList) {
4639
4676
  return true;
4640
4677
  }
4641
4678
  function getCriticalPaths(leafTasks) {
4679
+ leafTasks = leafTasks.filter(function (t) {
4680
+ return t.type !== "milestone" && (t.start.getTime() !== 0 || t.end.getTime() !== 0);
4681
+ });
4642
4682
  var taskMap = {};
4643
4683
 
4644
4684
  for (var i = 0; i < leafTasks.length; i++) {
@@ -4821,28 +4861,26 @@ function computeCriticalPath(taskID, taskMap) {
4821
4861
  taskMap[taskID].paths[1].visited = false;
4822
4862
  }
4823
4863
  }
4824
-
4825
- if (paths.length === 0) {
4826
- var immediateChildDuration = taskMap[taskID].end - taskMap[taskID].start + depDuration - overlap - offTime;
4827
-
4828
- if (taskMap[taskID].paths.length < 2) {
4829
- taskMap[taskID].paths.push({
4830
- duration: immediateChildDuration,
4831
- task: dependents[j],
4832
- parent: taskID,
4833
- visited: false
4834
- });
4835
- } else if (immediateChildDuration > taskMap[taskID].paths[0].duration) {
4836
- taskMap[taskID].paths[0].duration = immediateChildDuration;
4837
- taskMap[taskID].paths[0].task = dependents[j];
4838
- taskMap[taskID].paths[0].parent = taskID;
4839
- taskMap[taskID].paths[0].visited = false;
4840
- } else if (immediateChildDuration > taskMap[taskID].paths[1].duration) {
4841
- taskMap[taskID].paths[1].duration = immediateChildDuration;
4842
- taskMap[taskID].paths[1].task = dependents[j];
4843
- taskMap[taskID].paths[1].parent = taskID;
4844
- taskMap[taskID].paths[1].visited = false;
4845
- }
4864
+ } else {
4865
+ var immediateChildDuration = taskMap[taskID].end - taskMap[taskID].start + depDuration - overlap - offTime;
4866
+
4867
+ if (taskMap[taskID].paths.length < 2) {
4868
+ taskMap[taskID].paths.push({
4869
+ duration: immediateChildDuration,
4870
+ task: dependents[j],
4871
+ parent: taskID,
4872
+ visited: false
4873
+ });
4874
+ } else if (immediateChildDuration > taskMap[taskID].paths[0].duration) {
4875
+ taskMap[taskID].paths[0].duration = immediateChildDuration;
4876
+ taskMap[taskID].paths[0].task = dependents[j];
4877
+ taskMap[taskID].paths[0].parent = taskID;
4878
+ taskMap[taskID].paths[0].visited = false;
4879
+ } else if (immediateChildDuration > taskMap[taskID].paths[1].duration) {
4880
+ taskMap[taskID].paths[1].duration = immediateChildDuration;
4881
+ taskMap[taskID].paths[1].task = dependents[j];
4882
+ taskMap[taskID].paths[1].parent = taskID;
4883
+ taskMap[taskID].paths[1].visited = false;
4846
4884
  }
4847
4885
  }
4848
4886
  }