Progress on dependency updates
This commit is contained in:
@@ -1,4 +1,10 @@
|
||||
export default function assignDependencyGroups(graph) {
|
||||
import { union } from "lodash";
|
||||
|
||||
export function assignDependencyGroups(graph) {
|
||||
console.log('assigning dep group ids');
|
||||
graph.forEachLink(function (link) {
|
||||
console.dir(link);
|
||||
});
|
||||
// Iterate through all the nodes
|
||||
graph.forEachNode(node => {
|
||||
if (node._depGroupVisited) {
|
||||
@@ -13,22 +19,20 @@ export default function assignDependencyGroups(graph) {
|
||||
while (stack.length) {
|
||||
top = stack.pop();
|
||||
if (top._depGroupVisited) continue;
|
||||
if (
|
||||
(lowestOrderId === undefined && top.data?._id) ||
|
||||
(top.data?._id && top.data?.order < lowestOrder)
|
||||
) {
|
||||
lowestOrderId = top.data?._id;
|
||||
lowestOrder = top.data?.order;
|
||||
}
|
||||
if (top.data?._id) {
|
||||
group.push(top)
|
||||
if (top.data?._id && (
|
||||
lowestOrderId === undefined ||
|
||||
top.data?.order < lowestOrder
|
||||
)) {
|
||||
lowestOrderId = top.data._id;
|
||||
lowestOrder = top.data.order;
|
||||
}
|
||||
group.push(top)
|
||||
top._depGroupVisited = true;
|
||||
graph.forEachLinkedNode(top.id, linkedNode => stack.push(linkedNode));
|
||||
}
|
||||
// Assign group id
|
||||
group.forEach(node => {
|
||||
if (!lowestOrderId) return;
|
||||
if (!node.data?._id) return;
|
||||
if (group.length > 1) {
|
||||
node.data.depGroupId = lowestOrderId;
|
||||
} else {
|
||||
@@ -36,4 +40,34 @@ export default function assignDependencyGroups(graph) {
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export default function assignDependencyGroups2(graph) {
|
||||
const groups = new Set();
|
||||
graph.forEachLink(function (link) {
|
||||
const from = graph.getNode(link.fromId);
|
||||
const to = graph.getNode(link.toId);
|
||||
let depGroup;
|
||||
if (from._depGroup) {
|
||||
depGroup = from._depGroup;
|
||||
groups.delete(to._depGroup);
|
||||
} else if (to._depGroup) {
|
||||
depGroup = to._depGroup;
|
||||
} else {
|
||||
depGroup = {};
|
||||
groups.add(depGroup);
|
||||
}
|
||||
depGroup.nodes = union(from._depGroup?.nodes, to._depGroup?.nodes, [from, to])
|
||||
from._depGroup = depGroup;
|
||||
to._depGroup = depGroup;
|
||||
});
|
||||
groups.forEach(g => {
|
||||
if (!g.nodes.length) return;
|
||||
const rootId = g.nodes[0].id;
|
||||
g.nodes.forEach(n => {
|
||||
if (!n.data?._id) return;
|
||||
n.data.depGroupId = rootId;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user