Skip to content

Commit ba4398a

Browse files
Merge pull request #2206 from MetRonnie/graph-fix
Graph view: Fix missing edge between collapsed cycles that contain collapsed families
2 parents ecb5060 + da0808d commit ba4398a

File tree

1 file changed

+45
-49
lines changed

1 file changed

+45
-49
lines changed

src/views/Graph.vue

Lines changed: 45 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,23 +1033,22 @@ export default {
10331033
}
10341034
10351035
const graphSections = {}
1036-
for (const [cycle, indexSearch] of Object.entries(cyclesToNodes)) {
1037-
if (indexSearch.length && !this.collapseCycle.includes(cycle)) {
1038-
for (const task of indexSearch) {
1036+
for (const [cycle, nodesInCycle] of Object.entries(cyclesToNodes)) {
1037+
if (nodesInCycle.length && !this.collapseCycle.includes(cycle)) {
1038+
for (const task of nodesInCycle) {
10391039
const section = graphSections[task.node.firstParent.id] ??= []
10401040
section.push(`${task.name} [title=${task.name}]`)
1041-
graphSections[task.node.firstParent.id] = section
10421041
}
10431042
if (this.groupCycle) {
10441043
const removedNodes = new Set()
1045-
for (const node of indexSearch) {
1044+
for (const node of nodesInCycle) {
10461045
if (this.collapseFamily.includes(node.name)) {
10471046
for (const child of this.allChildrenLookUp[node.id]) {
10481047
removedNodes.add(child.name)
10491048
}
10501049
}
10511050
}
1052-
const nodeFormattedArray = indexSearch.filter((a) => (
1051+
const nodeFormattedArray = nodesInCycle.filter((a) => (
10531052
// if its not in the list of families (unless its been collapsed)
10541053
(!this.allParentLookUp.has(a.name) || this.collapseFamily.includes(a.name)) &&
10551054
// the node has been removed/collapsed
@@ -1158,7 +1157,46 @@ export default {
11581157
})
11591158
const edges = this.getGraphEdges()
11601159
1161-
// ----------------------------------------
1160+
for (const cycle of this.collapseCycle) {
1161+
const cycleNode = this.cylcTree.$index[
1162+
this.workflows[0].tokens.clone({ cycle }).id
1163+
]
1164+
if (!cycleNode) continue
1165+
// ---------------REMOVE NODES BASED ON CYCLE POINT------------
1166+
// must do this before removing nodes/edges based on family as cycle collapsing takes priority over families
1167+
for (const { id } of this.allChildrenLookUp[cycleNode.id]) {
1168+
if (id !== cycleNode.id) {
1169+
// REMOVE NODES
1170+
nodes = nodes.filter((node) => node.id !== id)
1171+
// REMOVE EDGES
1172+
// if there is an edge with a source or target it needs removing
1173+
for (const edge of this.removeEdges(id, edges)) {
1174+
// ---------------ADD EDGES BASED ON CYCLE POINT------------
1175+
// prevent self-loop edges:
1176+
if (edge.source.cycle === edge.target.cycle) continue
1177+
1178+
const sourceName = this.collapseCycle.includes(edge.source.cycle)
1179+
? edge.source.cycle
1180+
: this.getCollapsedAncestor(edge.source.id) ?? edge.source.task
1181+
const targetName = this.collapseCycle.includes(edge.target.cycle)
1182+
? edge.target.cycle
1183+
: this.getCollapsedAncestor(edge.target.id) ?? edge.target.task
1184+
1185+
edges.set(
1186+
...this.createEdge({
1187+
sourceName,
1188+
sourceCycle: edge.source.cycle,
1189+
targetName,
1190+
targetCycle: edge.target.cycle,
1191+
})
1192+
)
1193+
}
1194+
}
1195+
}
1196+
// ---------------ADD NODES BASED ON CYCLE POINT------------
1197+
nodes.push(cycleNode)
1198+
}
1199+
11621200
for (const family of this.collapseFamily) {
11631201
for (const cycle of this.cycles) {
11641202
// ...get the node from the index...
@@ -1168,8 +1206,6 @@ export default {
11681206
if (!famNode) continue
11691207
// ...now we have a node - we have to understand all its relations in the graph...
11701208
// ---------------REMOVE NODES BASED ON FAMILY------------
1171-
// must do this before removing nodes and edges based on cycle as
1172-
// cycle collapsing takes priority of families
11731209
// ...this node is collapsed so need to remove any of its children
11741210
// (nodes and edges) from the graph if it has any...
11751211
for (const { id } of this.allChildrenLookUp[famNode.id]) {
@@ -1209,46 +1245,6 @@ export default {
12091245
}
12101246
}
12111247
}
1212-
for (const cycle of this.collapseCycle) {
1213-
const cycleNode = this.cylcTree.$index[
1214-
this.workflows[0].tokens.clone({ cycle }).id
1215-
]
1216-
if (!cycleNode) continue
1217-
// ---------------REMOVE NODES BASED ON CYCLE POINT------------
1218-
for (const { id } of this.allChildrenLookUp[cycleNode.id]) {
1219-
if (id !== cycleNode.id) {
1220-
// REMOVE NODES
1221-
nodes = nodes.filter((node) => node.id !== id)
1222-
// REMOVE EDGES
1223-
// if there is an edge with a source or target it needs removing
1224-
for (const edge of this.removeEdges(id, edges)) {
1225-
// ---------------ADD EDGES BASED ON CYCLE POINT------------
1226-
// prevent self-loop edges:
1227-
if (edge.source.cycle === edge.target.cycle) continue
1228-
1229-
const sourceName = this.collapseCycle.includes(edge.source.cycle)
1230-
? edge.source.cycle
1231-
: this.getCollapsedAncestor(edge.source.id) ?? edge.source.task
1232-
const targetName = this.collapseCycle.includes(edge.target.cycle)
1233-
? edge.target.cycle
1234-
: this.getCollapsedAncestor(edge.target.id) ?? edge.target.task
1235-
1236-
edges.set(
1237-
...this.createEdge({
1238-
sourceName,
1239-
sourceCycle: edge.source.cycle,
1240-
targetName,
1241-
targetCycle: edge.target.cycle,
1242-
})
1243-
)
1244-
}
1245-
}
1246-
}
1247-
// ---------------ADD NODES BASED ON CYCLE POINT------------
1248-
nodes.push(cycleNode)
1249-
}
1250-
1251-
// ----------------------------------------
12521248
12531249
if (!nodes || !nodes.length) {
12541250
// we can't graph this, reset and wait for something to draw

0 commit comments

Comments
 (0)