gantt-lib 0.135.5 → 0.135.6

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
@@ -3039,19 +3039,37 @@ function normalizeHierarchyTasks(tasks) {
3039
3039
  const { startDate, endDate } = normalizeTaskDates(task.startDate, task.endDate);
3040
3040
  return { ...task, startDate, endDate };
3041
3041
  });
3042
- for (const task of [...orderedTasks].reverse()) {
3043
- if (!isTaskParent(task.id, orderedTasks)) continue;
3044
- const { startDate, endDate } = computeParentDates(task.id, orderedTasks);
3045
- const progress = computeParentProgress(task.id, orderedTasks);
3046
- const normalizedStartDate = startDate.toISOString().split("T")[0];
3047
- const normalizedEndDate = endDate.toISOString().split("T")[0];
3048
- const parentIndex = orderedTasks.findIndex((candidate) => candidate.id === task.id);
3049
- if (parentIndex === -1) continue;
3050
- orderedTasks[parentIndex] = {
3051
- ...orderedTasks[parentIndex],
3052
- startDate: normalizedStartDate,
3053
- endDate: normalizedEndDate,
3054
- progress
3042
+ const childrenByParent = /* @__PURE__ */ new Map();
3043
+ for (let index = 0; index < orderedTasks.length; index++) {
3044
+ const parentId = orderedTasks[index].parentId;
3045
+ if (!parentId) continue;
3046
+ const children = childrenByParent.get(parentId) ?? [];
3047
+ children.push(index);
3048
+ childrenByParent.set(parentId, children);
3049
+ }
3050
+ const DAY_MS6 = 24 * 60 * 60 * 1e3;
3051
+ for (let index = orderedTasks.length - 1; index >= 0; index--) {
3052
+ const children = childrenByParent.get(orderedTasks[index].id);
3053
+ if (!children?.length) continue;
3054
+ let minStart = Infinity;
3055
+ let maxEnd = -Infinity;
3056
+ let totalWeight = 0;
3057
+ let weightedProgress = 0;
3058
+ for (const childIndex of children) {
3059
+ const child = orderedTasks[childIndex];
3060
+ const start = new Date(child.startDate).getTime();
3061
+ const end = new Date(child.endDate).getTime();
3062
+ minStart = Math.min(minStart, start);
3063
+ maxEnd = Math.max(maxEnd, end);
3064
+ const duration = (end - start + DAY_MS6) / DAY_MS6;
3065
+ totalWeight += duration;
3066
+ weightedProgress += duration * (child.progress ?? 0);
3067
+ }
3068
+ orderedTasks[index] = {
3069
+ ...orderedTasks[index],
3070
+ startDate: new Date(minStart).toISOString().split("T")[0],
3071
+ endDate: new Date(maxEnd).toISOString().split("T")[0],
3072
+ progress: totalWeight === 0 ? 0 : Math.round(weightedProgress / totalWeight * 10) / 10
3055
3073
  };
3056
3074
  }
3057
3075
  return orderedTasks;
@@ -15096,9 +15114,8 @@ function TaskGanttChartInner(props, ref) {
15096
15114
  });
15097
15115
  }, []);
15098
15116
  const allParentIds = (0, import_react19.useMemo)(() => {
15099
- return new Set(
15100
- normalizedTasks.filter((t) => isTaskParent(t.id, normalizedTasks)).map((t) => t.id)
15101
- );
15117
+ const taskIds = new Set(normalizedTasks.map((task) => task.id));
15118
+ return new Set(normalizedTasks.map((task) => task.parentId).filter((parentId) => Boolean(parentId && taskIds.has(parentId))));
15102
15119
  }, [normalizedTasks]);
15103
15120
  const handleCollapseAll = (0, import_react19.useCallback)(() => {
15104
15121
  if (externalCollapsedParentIds) return;