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