gantt-task-react-powern 0.4.24 → 0.4.26

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.
@@ -1877,7 +1877,8 @@ var Project = function Project(_ref) {
1877
1877
  height: task.height,
1878
1878
  rx: task.barCornerRadius,
1879
1879
  ry: task.barCornerRadius,
1880
- className: styles$8.projectBackground
1880
+ className: styles$8.projectBackground,
1881
+ stroke: task.styles.criticalPathColor
1881
1882
  }), React.createElement("rect", {
1882
1883
  x: task.progressX,
1883
1884
  width: task.progressWidth,
@@ -1885,7 +1886,8 @@ var Project = function Project(_ref) {
1885
1886
  height: task.height,
1886
1887
  ry: task.barCornerRadius,
1887
1888
  rx: task.barCornerRadius,
1888
- fill: processColor
1889
+ fill: processColor,
1890
+ stroke: task.styles.criticalPathColor
1889
1891
  }), React.createElement("rect", {
1890
1892
  fill: barColor,
1891
1893
  x: task.x1,
@@ -1894,15 +1896,18 @@ var Project = function Project(_ref) {
1894
1896
  height: task.height / 2,
1895
1897
  rx: task.barCornerRadius,
1896
1898
  ry: task.barCornerRadius,
1897
- className: styles$8.projectTop
1899
+ className: styles$8.projectTop,
1900
+ stroke: task.styles.criticalPathColor
1898
1901
  }), React.createElement("polygon", {
1899
1902
  className: styles$8.projectTop,
1900
1903
  points: projectLeftTriangle,
1901
- fill: barColor
1904
+ fill: barColor,
1905
+ stroke: task.styles.criticalPathColor
1902
1906
  }), React.createElement("polygon", {
1903
1907
  className: styles$8.projectTop,
1904
1908
  points: projectRightTriangle,
1905
- fill: barColor
1909
+ fill: barColor,
1910
+ stroke: task.styles.criticalPathColor
1906
1911
  }));
1907
1912
  };
1908
1913
 
@@ -2524,6 +2529,7 @@ var Gantt = function Gantt(_ref) {
2524
2529
  primaryPath = _getCriticalPaths[0],
2525
2530
  secondaryPath = _getCriticalPaths[1];
2526
2531
 
2532
+ uncolorAll(tasks);
2527
2533
  colorPath(secondaryPath, "#00ff00", tasks);
2528
2534
  colorPath(primaryPath, "#ff0000", tasks);
2529
2535
  setBarTasks(convertToBarTasks(filteredTasks, newDates, columnWidth, rowHeight, taskHeight, barCornerRadius, handleWidth, rtl, barProgressColor, barProgressSelectedColor, barBackgroundColor, barBackgroundSelectedColor, projectProgressColor, projectProgressSelectedColor, projectBackgroundColor, projectBackgroundSelectedColor, milestoneBackgroundColor, milestoneBackgroundSelectedColor));
@@ -2740,89 +2746,162 @@ var Gantt = function Gantt(_ref) {
2740
2746
  }
2741
2747
  };
2742
2748
 
2749
+ function topologicalOrderingHelper(taskID, taskMap, sortedTaskList) {
2750
+ if (!taskMap[taskID]) return false;
2751
+ if (taskMap[taskID].finished) return true;
2752
+ if (taskMap[taskID].started) return false;
2753
+ taskMap[taskID].started = true;
2754
+ var task = taskMap[taskID].task;
2755
+ if (task.dependencies) for (var i = 0; i < task.dependencies.length; i++) {
2756
+ var successVal = topologicalOrderingHelper(task.dependencies[i], taskMap, sortedTaskList);
2757
+ if (!successVal) return false;
2758
+ }
2759
+ taskMap[taskID].finished = true;
2760
+ sortedTaskList.push(taskID);
2761
+ return true;
2762
+ }
2763
+
2743
2764
  function getCriticalPaths(leafTasks) {
2744
- var _leafTasks$reduce = leafTasks.reduce(function (_ref2, leafTask) {
2745
- var primaryPath = _ref2[0],
2746
- secondaryPath = _ref2[1],
2747
- primaryDuration = _ref2[2],
2748
- secondaryDuration = _ref2[3];
2749
- var newPath = criticalPath(leafTask, leafTasks);
2750
- var newDuration = computeDuration(newPath);
2751
- if (newDuration <= secondaryDuration) return [primaryPath, secondaryPath, primaryDuration, secondaryDuration];
2752
-
2753
- if (newDuration > primaryDuration) {
2754
- var _primaryPath$;
2755
-
2756
- if (((_primaryPath$ = primaryPath[0]) === null || _primaryPath$ === void 0 ? void 0 : _primaryPath$.id) !== newPath[0].id) return [newPath, primaryPath, newDuration, primaryDuration];else return [newPath, secondaryPath, newDuration, secondaryDuration];
2757
- } else {
2758
- var _primaryPath$2;
2765
+ var taskMap = {};
2759
2766
 
2760
- if (((_primaryPath$2 = primaryPath[0]) === null || _primaryPath$2 === void 0 ? void 0 : _primaryPath$2.id) !== newPath[0].id) return [primaryPath, newPath, primaryDuration, newDuration];else return [primaryPath, secondaryPath, primaryDuration, secondaryDuration];
2767
+ for (var i = 0; i < leafTasks.length; i++) {
2768
+ taskMap[leafTasks[i].id] = {
2769
+ task: leafTasks[i]
2770
+ };
2771
+ }
2772
+
2773
+ for (var _i = 0; _i < leafTasks.length; _i++) {
2774
+ taskMap[leafTasks[_i].id].dependents = [];
2775
+ }
2776
+
2777
+ for (var _i2 = 0; _i2 < leafTasks.length; _i2++) {
2778
+ var task = leafTasks[_i2];
2779
+ if (task.dependencies) for (var j = 0; j < task.dependencies.length; j++) {
2780
+ taskMap[task.dependencies[j]].dependents.push(task.id);
2761
2781
  }
2762
- }, [[], [], 0, 0]),
2763
- primaryPath = _leafTasks$reduce[0],
2764
- secondaryPath = _leafTasks$reduce[1];
2782
+ }
2765
2783
 
2766
- return [primaryPath, secondaryPath];
2767
- }
2784
+ var sortedTaskList = [];
2768
2785
 
2769
- function computeDuration(path) {
2770
- return path.length ? path[path.length - 1].end.getTime() - path[0].start.getTime() : 0;
2771
- }
2786
+ for (var _i3 = 0; _i3 < leafTasks.length; _i3++) {
2787
+ var successVal = topologicalOrderingHelper(leafTasks[_i3].id, taskMap, sortedTaskList);
2788
+ if (!successVal) return [[], []];
2789
+ }
2790
+
2791
+ for (var _i4 = sortedTaskList.length - 1; _i4 >= 0; _i4--) {
2792
+ computeCriticalPath(sortedTaskList[_i4], taskMap);
2793
+ }
2794
+
2795
+ var primaryLeaf;
2796
+ var primaryDuration = 0;
2772
2797
 
2773
- function criticalPath(task, tasks) {
2774
- var _task$dependencies;
2798
+ for (var _i5 = 0; _i5 < sortedTaskList.length; _i5++) {
2799
+ var newDuration = taskMap[sortedTaskList[_i5]].end - leafTasks[_i5].start.getTime();
2775
2800
 
2776
- if (!task) {
2777
- return [];
2801
+ if (primaryDuration < newDuration) {
2802
+ primaryLeaf = sortedTaskList[_i5];
2803
+ primaryDuration = newDuration;
2804
+ }
2778
2805
  }
2779
2806
 
2780
- if (!task.dependencies) return [task];
2807
+ var primaryPath = [];
2781
2808
 
2782
- var _task$dependencies$re = (_task$dependencies = task.dependencies) === null || _task$dependencies === void 0 ? void 0 : _task$dependencies.reduce(function (_ref3, dependencyTaskId) {
2783
- var longestPath = _ref3[0],
2784
- longestDuration = _ref3[1];
2785
- var dependencyTask = tasks.find(function (otherTask) {
2786
- return otherTask.id === dependencyTaskId;
2787
- });
2788
- var dependencyPath = criticalPath(dependencyTask, tasks);
2789
- var dependencyDuration = computeDuration(dependencyPath);
2790
- if (dependencyDuration > longestDuration) return [dependencyPath, dependencyDuration];else return [longestPath, longestDuration];
2791
- }, [[], 0]),
2792
- longestPath = _task$dependencies$re[0];
2809
+ while (primaryLeaf) {
2810
+ taskMap[primaryLeaf].excluded = true;
2811
+ primaryPath.push(taskMap[primaryLeaf].task);
2812
+ primaryLeaf = taskMap[primaryLeaf].next;
2813
+ }
2814
+
2815
+ var secondaryLeaf;
2816
+ var secondaryDuration = 0;
2817
+
2818
+ for (var _i6 = 0; _i6 < sortedTaskList.length; _i6++) {
2819
+ if (taskMap[sortedTaskList[_i6]].excluded) continue;
2820
+
2821
+ var _newDuration = taskMap[sortedTaskList[_i6]].end - leafTasks[_i6].start.getTime();
2793
2822
 
2794
- return [].concat(longestPath, [task]);
2823
+ if (secondaryDuration < _newDuration) {
2824
+ secondaryLeaf = sortedTaskList[_i6];
2825
+ secondaryDuration = _newDuration;
2826
+ }
2827
+ }
2828
+
2829
+ var secondaryPath = [];
2830
+
2831
+ while (secondaryLeaf) {
2832
+ secondaryPath.push(taskMap[secondaryLeaf].task);
2833
+ secondaryLeaf = taskMap[secondaryLeaf].next;
2834
+ }
2835
+
2836
+ return [primaryPath, secondaryPath];
2837
+ }
2838
+
2839
+ function computeCriticalPath(taskID, taskMap) {
2840
+ var task = taskMap[taskID].task;
2841
+ var dependents = taskMap[taskID].dependents;
2842
+ taskMap[taskID].end = task.end.getTime();
2843
+
2844
+ for (var j = 0; j < dependents.length; j++) {
2845
+ var newDependentEnd = taskMap[dependents[j]].end;
2846
+
2847
+ if (newDependentEnd > taskMap[taskID].end) {
2848
+ taskMap[taskID].next = dependents[j];
2849
+ taskMap[taskID].end = newDependentEnd;
2850
+ }
2851
+ }
2852
+ }
2853
+
2854
+ function uncolorAll(tasks) {
2855
+ tasks.forEach(function (task) {
2856
+ if (task.styles) delete task.styles.criticalPathColor;
2857
+ delete task.criticalPathArrows;
2858
+ });
2795
2859
  }
2796
2860
 
2797
2861
  function colorPath(path, color, tasks) {
2798
2862
  for (var i = 0; i < path.length; i++) {
2799
- for (var j = 0; j < tasks.length; j++) {
2800
- if (path[i].id.startsWith(tasks[j].id + ".") || path[i].id === tasks[j].id) {
2801
- var _tasks$j$styles;
2863
+ var longestIDLength = 0;
2864
+ var longestTask = void 0;
2802
2865
 
2803
- var _styles = (_tasks$j$styles = tasks[j].styles) != null ? _tasks$j$styles : {};
2866
+ for (var j = 0; j < tasks.length; j++) {
2867
+ if (path[i].id === tasks[j].id) {
2868
+ longestTask = tasks[j];
2869
+ break;
2870
+ }
2804
2871
 
2805
- _styles.criticalPathColor = color;
2806
- tasks[j].styles = _styles;
2872
+ if (path[i].id.startsWith(tasks[j].id + ".") && tasks[j].id.length > longestIDLength) {
2873
+ longestIDLength = tasks[j].id.length;
2874
+ longestTask = tasks[j];
2807
2875
  }
2808
2876
  }
2877
+
2878
+ if (longestTask) {
2879
+ var _longestTask$styles;
2880
+
2881
+ console.log("Colored " + longestTask.id + " " + color);
2882
+
2883
+ var _styles = (_longestTask$styles = longestTask.styles) != null ? _longestTask$styles : {};
2884
+
2885
+ _styles.criticalPathColor = color;
2886
+ longestTask.styles = _styles;
2887
+ }
2809
2888
  }
2810
2889
 
2811
- var _loop = function _loop(_i) {
2812
- var arrows = path[_i].criticalPathArrows;
2890
+ var _loop = function _loop(_i7) {
2891
+ var arrows = path[_i7].criticalPathArrows;
2813
2892
  if (!arrows) arrows = [];
2814
2893
  var arrow = arrows.find(function (arrow) {
2815
- return arrow.taskId === path[_i + 1].id;
2894
+ return arrow.taskId === path[_i7 + 1].id;
2816
2895
  });
2817
2896
  if (arrow) arrow.arrowColor = color;else arrows.push({
2818
- taskId: path[_i + 1].id,
2897
+ taskId: path[_i7 + 1].id,
2819
2898
  arrowColor: color
2820
2899
  });
2821
- path[_i].criticalPathArrows = arrows;
2900
+ path[_i7].criticalPathArrows = arrows;
2822
2901
  };
2823
2902
 
2824
- for (var _i = 0; _i + 1 < path.length; _i++) {
2825
- _loop(_i);
2903
+ for (var _i7 = 0; _i7 + 1 < path.length; _i7++) {
2904
+ _loop(_i7);
2826
2905
  }
2827
2906
  }
2828
2907