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