gantt-lib 0.145.0 → 0.145.2

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.mjs CHANGED
@@ -733,6 +733,29 @@ var ACTIVITY_LANES_PADDING = 2;
733
733
  var DAY_MS2 = 24 * 60 * 60 * 1e3;
734
734
  function packIntervals(intervals) {
735
735
  const sorted = [...intervals].sort((a, b) => a.start - b.start);
736
+ if (intervals.some((item) => item.laneGroup !== void 0)) {
737
+ const groups = /* @__PURE__ */ new Map();
738
+ for (const item of intervals) {
739
+ const key = item.laneGroup ?? item;
740
+ const group = groups.get(key) ?? [];
741
+ group.push(item);
742
+ groups.set(key, group);
743
+ }
744
+ const lanes = [];
745
+ const assigned = /* @__PURE__ */ new Map();
746
+ for (const group of groups.values()) {
747
+ const compatible = lanes.findIndex((lane) => group.every((item) => !lane.some((other) => item.start < other.end && other.start < item.end)));
748
+ const preferred = compatible < 0 ? lanes.length : compatible;
749
+ for (const item of [...group].sort((a, b) => a.start - b.start)) {
750
+ const free = (lane2) => !lanes[lane2]?.some((other) => item.start < other.end && other.start < item.end);
751
+ let lane = free(preferred) ? preferred : lanes.findIndex((_, index) => free(index));
752
+ if (lane < 0) lane = lanes.length;
753
+ (lanes[lane] ?? (lanes[lane] = [])).push(item);
754
+ assigned.set(item, lane);
755
+ }
756
+ }
757
+ return sorted.map((item) => ({ ...item, lane: assigned.get(item) }));
758
+ }
736
759
  const laneEnds = [];
737
760
  return sorted.map((item) => {
738
761
  let lane = 0;
@@ -751,6 +774,7 @@ function computeActivityLanes(activities, monthStart, dayWidth) {
751
774
  const bar = calculateTaskBar(parseUTCDate(activity.startDate), parseUTCDate(activity.endDate), monthStart, dayWidth);
752
775
  return {
753
776
  id: activity.id,
777
+ laneGroup: activity.laneGroup,
754
778
  name: activity.name,
755
779
  color: activity.color,
756
780
  lag: activity.lag,
@@ -2046,8 +2070,8 @@ function recalculateProjectSchedule(snapshot, options) {
2046
2070
  }
2047
2071
  }
2048
2072
  const queue = snapshot.filter((task) => (indegree.get(task.id) ?? 0) === 0).map((task) => task.id);
2049
- while (queue.length > 0) {
2050
- const currentId = queue.shift();
2073
+ for (let queueIndex = 0; queueIndex < queue.length; queueIndex++) {
2074
+ const currentId = queue[queueIndex];
2051
2075
  for (const successorId of successorIdsByTask.get(currentId) ?? []) {
2052
2076
  const nextIndegree = (indegree.get(successorId) ?? 0) - 1;
2053
2077
  indegree.set(successorId, nextIndegree);
@@ -2098,7 +2122,13 @@ function recalculateProjectSchedule(snapshot, options) {
2098
2122
  queue.push(successorId);
2099
2123
  }
2100
2124
  }
2101
- const parentsByDepth = snapshot.filter((task) => isTaskParent(task.id, snapshot)).map((task) => {
2125
+ const childrenByParent = /* @__PURE__ */ new Map();
2126
+ for (const task of snapshot) if (task.parentId) {
2127
+ const children = childrenByParent.get(task.parentId) ?? [];
2128
+ children.push(task.id);
2129
+ childrenByParent.set(task.parentId, children);
2130
+ }
2131
+ const parentsByDepth = snapshot.filter((task) => childrenByParent.has(task.id)).map((task) => {
2102
2132
  let depth = 0;
2103
2133
  let current = task.parentId ? workingMap.get(task.parentId) : void 0;
2104
2134
  while (current) {
@@ -2107,17 +2137,21 @@ function recalculateProjectSchedule(snapshot, options) {
2107
2137
  }
2108
2138
  return { taskId: task.id, depth };
2109
2139
  }).sort((left, right) => right.depth - left.depth);
2110
- const workingTasks = () => Array.from(workingMap.values());
2111
2140
  for (const { taskId } of parentsByDepth) {
2112
2141
  const parent = workingMap.get(taskId);
2113
2142
  if (!parent || parent.locked) {
2114
2143
  continue;
2115
2144
  }
2116
- const { startDate, endDate } = computeParentDates(taskId, workingTasks());
2145
+ let startTime = Infinity, endTime = -Infinity;
2146
+ for (const childId of childrenByParent.get(taskId)) {
2147
+ const child = workingMap.get(childId);
2148
+ startTime = Math.min(startTime, new Date(child.startDate).getTime());
2149
+ endTime = Math.max(endTime, new Date(child.endDate).getTime());
2150
+ }
2117
2151
  workingMap.set(taskId, {
2118
2152
  ...parent,
2119
- startDate: toIsoDate(startDate),
2120
- endDate: toIsoDate(endDate)
2153
+ startDate: toIsoDate(new Date(startTime)),
2154
+ endDate: toIsoDate(new Date(endTime))
2121
2155
  });
2122
2156
  }
2123
2157
  return createChangedResult(snapshot, Array.from(workingMap.values()));