Skip to content

Commit 7c6df47

Browse files
committed
Remove unecessary reactive property; further tidy
1 parent 7cbe49f commit 7c6df47

File tree

1 file changed

+125
-139
lines changed

1 file changed

+125
-139
lines changed

src/views/Graph.vue

Lines changed: 125 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,6 @@ export default {
396396
// true if page is loading for the first time and nodeDimensions are yet to be calculated
397397
initialLoad: true,
398398
cycleArrayStore: [],
399-
edgeTemplate: {},
400399
}
401400
},
402401
@@ -844,11 +843,7 @@ export default {
844843
checkForEdgeBySource (sourceName, cyclePoint, edges) {
845844
const edgePath = this.workflowIDs[0]
846845
const edgeSearchTerm = `${edgePath}//${cyclePoint}/${sourceName}`
847-
848-
const edgeSearch = edges.filter((edge) => {
849-
return edge.node.source === edgeSearchTerm
850-
})
851-
return edgeSearch
846+
return edges.filter((edge) => edge.node.source === edgeSearchTerm)
852847
},
853848
854849
/**
@@ -861,11 +856,7 @@ export default {
861856
checkForEdgeByTarget (targetName, cyclePoint, edges) {
862857
const edgePath = this.workflowIDs[0]
863858
const edgeSearchTerm = `${edgePath}//${cyclePoint}/${targetName}`
864-
865-
const edgeSearch = edges.filter((edge) => {
866-
return edge.node.target === edgeSearchTerm
867-
})
868-
return edgeSearch
859+
return edges.filter((edge) => edge.node.target === edgeSearchTerm)
869860
},
870861
871862
/**
@@ -1335,92 +1326,89 @@ export default {
13351326
// ...loop through collapsed families...
13361327
for (const family of this.collapseFamily) {
13371328
// ...get the node from the index...
1338-
const indexSearch = Object.values(this.cylcTree.$index).find((node) => {
1339-
return node.name === family && node.tokens.cycle === cycle
1340-
})
1329+
const indexSearch = Object.values(this.cylcTree.$index).find(
1330+
(node) => node.name === family && node.tokens.cycle === cycle
1331+
)
1332+
if (!indexSearch) continue
13411333
// ...now we have a node - we have to understand all its relations in the graph...
1342-
if (indexSearch) {
1343-
// ---------------REMOVE NODES BASED ON FAMILY------------
1344-
// must do this before removing nodes and edges based on cycle as
1345-
// cycle collapsing takes priority of families
1346-
// ...this node is collapsed so need to remove any of its children
1347-
// (nodes and edges) from the graph if it has any...
1348-
for (const config of this.allChildrenLookUp[indexSearch.id]) {
1349-
if (config.name !== indexSearch.name) {
1350-
// REMOVE NODES
1351-
nodes = this.removeNode(config.name, cycle, nodes)
1352-
// REMOVE EDGES
1353-
// if there is an edge with a source or target it needs removing
1354-
const edgeCheckSource = this.checkForEdgeBySource(config.name, cycle, edges)
1355-
const edgeCheckTarget = this.checkForEdgeByTarget(config.name, cycle, edges)
1356-
1357-
if (edgeCheckSource.length) {
1358-
[edges, removedEdges] = this.removeEdgeBySource(edgeCheckSource, edges, removedEdges, config, cycle)
1359-
}
1360-
if (edgeCheckTarget.length) {
1361-
[edges, removedEdges] = this.removeEdgeByTarget(edgeCheckTarget, edges, removedEdges)
1362-
}
1334+
// ---------------REMOVE NODES BASED ON FAMILY------------
1335+
// must do this before removing nodes and edges based on cycle as
1336+
// cycle collapsing takes priority of families
1337+
// ...this node is collapsed so need to remove any of its children
1338+
// (nodes and edges) from the graph if it has any...
1339+
for (const config of this.allChildrenLookUp[indexSearch.id]) {
1340+
if (config.name !== indexSearch.name) {
1341+
// REMOVE NODES
1342+
nodes = this.removeNode(config.name, cycle, nodes)
1343+
// REMOVE EDGES
1344+
// if there is an edge with a source or target it needs removing
1345+
const edgeCheckSource = this.checkForEdgeBySource(config.name, cycle, edges)
1346+
const edgeCheckTarget = this.checkForEdgeByTarget(config.name, cycle, edges)
1347+
1348+
if (edgeCheckSource.length) {
1349+
[edges, removedEdges] = this.removeEdgeBySource(edgeCheckSource, edges, removedEdges, config, cycle)
13631350
}
1364-
}
1365-
// ...now we have removed any parts of child nodes that shouldnt be there we can add nodes and edges that should be...
1366-
// ---------------ADD NODES BASED ON FAMILY------------
1367-
if (!this.collapseCycle.includes(cycle)) { // cycle collapsing takes priority over family collapsing
1368-
if (!this.isNodeCollapsedByFamily(indexSearch.node.firstParent.name)) {
1369-
nodes.push(indexSearch)
1351+
if (edgeCheckTarget.length) {
1352+
[edges, removedEdges] = this.removeEdgeByTarget(edgeCheckTarget, edges, removedEdges)
13701353
}
13711354
}
1355+
}
1356+
// ...now we have removed any parts of child nodes that shouldnt be there we can add nodes and edges that should be...
1357+
// ---------------ADD NODES BASED ON FAMILY------------
1358+
if (!this.collapseCycle.includes(cycle)) { // cycle collapsing takes priority over family collapsing
1359+
if (!this.isNodeCollapsedByFamily(indexSearch.node.firstParent.name)) {
1360+
nodes.push(indexSearch)
1361+
}
1362+
}
1363+
1364+
// ...this node is collapsed so need to remove any of its children (nodes and edges) from the graph if it has any...
1365+
for (const config of this.allChildrenLookUp[indexSearch.id]) {
1366+
for (const edge of this.checkForEdgeBySource(config.name, cycle, removedEdges)) {
1367+
const sourceCycle = this.cylcTree.$index[edge.node.source].tokens.cycle
1368+
const targetName = this.cylcTree.$index[edge.node.target].name
1369+
const targetCycle = this.cylcTree.$index[edge.node.target].tokens.cycle
1370+
const sourceFamilyName = this.cylcTree.$index[edge.node.source].node.firstParent.name
1371+
const targetFamilyName = this.cylcTree.$index[edge.node.target].node.firstParent.name
1372+
1373+
if (!this.collapseCycle.includes(sourceCycle)) {
1374+
const familyData = this.edgeHasCollapsedSourceFamilyOnly(targetFamilyName, sourceFamilyName)
1375+
if (familyData) {
1376+
edges.push(
1377+
this.createEdge('noCollapsed', familyData.source, targetName, sourceCycle, targetCycle)
1378+
)
1379+
}
13721380
1373-
// ...this node is collapsed so need to remove any of its children (nodes and edges) from the graph if it has any...
1374-
for (const config of this.allChildrenLookUp[indexSearch.id]) {
1375-
const edgeCheckSource = this.checkForEdgeBySource(config.name, cycle, removedEdges)
1376-
if (edgeCheckSource) {
1377-
for (const edge of edgeCheckSource) {
1378-
const sourceCycle = this.cylcTree.$index[edge.node.source].tokens.cycle
1379-
const targetName = this.cylcTree.$index[edge.node.target].name
1380-
const targetCycle = this.cylcTree.$index[edge.node.target].tokens.cycle
1381-
const sourceFamilyName = this.cylcTree.$index[edge.node.source].node.firstParent.name
1382-
const targetFamilyName = this.cylcTree.$index[edge.node.target].node.firstParent.name
1383-
1384-
if (!this.collapseCycle.includes(sourceCycle)) {
1385-
const familyData = this.edgeHasCollapsedSourceFamilyOnly(targetFamilyName, sourceFamilyName)
1386-
if (familyData) {
1387-
this.edgeTemplate = this.createEdge('noCollapsed', familyData.source, targetName, sourceCycle, targetCycle)
1388-
edges.push(this.edgeTemplate)
1389-
}
1390-
1391-
if (!this.collapseCycle.includes(targetCycle)) {
1392-
const familyData = this.edgeHasCollapsedTargetandSourceFamily(targetFamilyName, sourceFamilyName)
1393-
if (familyData && (familyData.source !== familyData.target || sourceCycle !== targetCycle)) {
1394-
this.edgeTemplate = this.createEdge('noCollapsed', familyData.source, familyData.target, sourceCycle, targetCycle)
1395-
edges.push(this.edgeTemplate)
1396-
}
1397-
}
1381+
if (!this.collapseCycle.includes(targetCycle)) {
1382+
const familyData = this.edgeHasCollapsedTargetandSourceFamily(targetFamilyName, sourceFamilyName)
1383+
if (familyData && (familyData.source !== familyData.target || sourceCycle !== targetCycle)) {
1384+
edges.push(
1385+
this.createEdge('noCollapsed', familyData.source, familyData.target, sourceCycle, targetCycle)
1386+
)
13981387
}
13991388
}
14001389
}
1401-
const edgeCheckTarget = this.checkForEdgeByTarget(config.name, cycle, removedEdges)
1402-
if (edgeCheckTarget) {
1403-
for (const edge of edgeCheckTarget) {
1404-
const sourceName = this.cylcTree.$index[edge.node.source].name
1405-
const sourceCycle = this.cylcTree.$index[edge.node.source].tokens.cycle
1406-
const targetCycle = this.cylcTree.$index[edge.node.target].tokens.cycle
1407-
const sourceFamilyName = this.cylcTree.$index[edge.node.source].node.firstParent.name
1408-
const targetFamilyName = this.cylcTree.$index[edge.node.target].node.firstParent.name
1409-
1410-
if (!this.collapseCycle.includes(targetCycle)) {
1411-
const familyData = this.edgeHasCollapsedTargetFamilyOnly(targetFamilyName, sourceFamilyName)
1412-
if (familyData) {
1413-
this.edgeTemplate = this.createEdge('noCollapsed', sourceName, familyData.target, sourceCycle, targetCycle)
1414-
edges.push(this.edgeTemplate)
1415-
}
1416-
1417-
if (!this.collapseCycle.includes(sourceCycle)) {
1418-
const familyData = this.edgeHasCollapsedTargetandSourceFamily(targetFamilyName, sourceFamilyName)
1419-
if (familyData && (familyData.source !== familyData.target || sourceCycle !== targetCycle)) {
1420-
this.edgeTemplate = this.createEdge('noCollapsed', familyData.source, familyData.target, sourceCycle, targetCycle)
1421-
edges.push(this.edgeTemplate)
1422-
}
1423-
}
1390+
}
1391+
for (const edge of this.checkForEdgeByTarget(config.name, cycle, removedEdges)) {
1392+
const sourceName = this.cylcTree.$index[edge.node.source].name
1393+
const sourceCycle = this.cylcTree.$index[edge.node.source].tokens.cycle
1394+
const targetCycle = this.cylcTree.$index[edge.node.target].tokens.cycle
1395+
const sourceFamilyName = this.cylcTree.$index[edge.node.source].node.firstParent.name
1396+
const targetFamilyName = this.cylcTree.$index[edge.node.target].node.firstParent.name
1397+
1398+
if (!this.collapseCycle.includes(targetCycle)) {
1399+
const familyData = this.edgeHasCollapsedTargetFamilyOnly(targetFamilyName, sourceFamilyName)
1400+
if (familyData) {
1401+
edges.push(
1402+
this.createEdge('noCollapsed', sourceName, familyData.target, sourceCycle, targetCycle)
1403+
)
1404+
}
1405+
1406+
if (!this.collapseCycle.includes(sourceCycle)) {
1407+
const familyData = this.edgeHasCollapsedTargetandSourceFamily(targetFamilyName, sourceFamilyName)
1408+
if (familyData && (familyData.source !== familyData.target || sourceCycle !== targetCycle)) {
1409+
edges.push(
1410+
this.createEdge('noCollapsed', familyData.source, familyData.target, sourceCycle, targetCycle)
1411+
)
14241412
}
14251413
}
14261414
}
@@ -1455,61 +1443,59 @@ export default {
14551443
// next bit starts here
14561444
// ---------------ADD EDGES BASED ON CYCLE POINT------------
14571445
for (const config of this.allChildrenLookUp[indexSearch.id]) {
1458-
const edgeCheckSource = this.checkForEdgeBySource(config.name, cycle, removedEdges)
1459-
if (edgeCheckSource) {
1460-
for (const edge of edgeCheckSource) {
1461-
const sourceCycle = this.cylcTree.$index[edge.node.source].tokens.cycle
1462-
const targetName = this.cylcTree.$index[edge.node.target].name
1463-
const targetCycle = this.cylcTree.$index[edge.node.target].tokens.cycle
1464-
const targetFamilyName = this.cylcTree.$index[edge.node.target].node.firstParent.name
1465-
1466-
if (targetCycle !== sourceCycle) {
1467-
// edge has collapsed source cycle only
1468-
if (!this.collapseCycle.includes(targetCycle) && this.collapseCycle.includes(sourceCycle)) {
1469-
if (this.isNodeCollapsedByFamily(targetFamilyName)) {
1470-
this.edgeTemplate = this.createEdge('collapsedSource', sourceCycle, this.isNodeCollapsedByFamily(targetFamilyName), sourceCycle, targetCycle)
1471-
edges.push(this.edgeTemplate)
1472-
} else {
1473-
this.edgeTemplate = this.createEdge('collapsedSource', sourceCycle, targetName, sourceCycle, targetCycle)
1474-
edges.push(this.edgeTemplate)
1475-
}
1476-
}
1477-
1478-
// edge has collapsed target and source cycle
1479-
if (this.collapseCycle.includes(targetCycle) && this.collapseCycle.includes(sourceCycle)) {
1480-
this.edgeTemplate = this.createEdge('collapsedSourceAndTarget', sourceCycle, targetCycle, sourceCycle, targetCycle)
1481-
edges.push(this.edgeTemplate)
1482-
}
1446+
for (const edge of this.checkForEdgeBySource(config.name, cycle, removedEdges)) {
1447+
const sourceCycle = this.cylcTree.$index[edge.node.source].tokens.cycle
1448+
const targetName = this.cylcTree.$index[edge.node.target].name
1449+
const targetCycle = this.cylcTree.$index[edge.node.target].tokens.cycle
1450+
const targetFamilyName = this.cylcTree.$index[edge.node.target].node.firstParent.name
1451+
1452+
if (sourceCycle === targetCycle) continue
1453+
// edge has collapsed source cycle only
1454+
if (!this.collapseCycle.includes(targetCycle) && this.collapseCycle.includes(sourceCycle)) {
1455+
if (this.isNodeCollapsedByFamily(targetFamilyName)) {
1456+
edges.push(
1457+
this.createEdge('collapsedSource', sourceCycle, this.isNodeCollapsedByFamily(targetFamilyName), sourceCycle, targetCycle)
1458+
)
1459+
} else {
1460+
edges.push(
1461+
this.createEdge('collapsedSource', sourceCycle, targetName, sourceCycle, targetCycle)
1462+
)
14831463
}
14841464
}
1485-
}
1486-
const edgeCheckTarget = this.checkForEdgeByTarget(config.name, cycle, removedEdges)
1487-
if (edgeCheckTarget) {
1488-
for (const edge of edgeCheckTarget) {
1489-
const sourceName = this.cylcTree.$index[edge.node.source].name
1490-
const sourceCycle = this.cylcTree.$index[edge.node.source].tokens.cycle
1491-
const targetCycle = this.cylcTree.$index[edge.node.target].tokens.cycle
1492-
const sourceFamilyName = this.cylcTree.$index[edge.node.source].node.firstParent.name
1493-
1494-
if (targetCycle !== sourceCycle) {
1495-
// edge has collapsed target cycle only
1496-
if (this.collapseCycle.includes(targetCycle) && !this.collapseCycle.includes(sourceCycle)) {
1497-
if (this.isNodeCollapsedByFamily(sourceFamilyName)) {
1498-
this.edgeTemplate = this.createEdge('collapsedTarget', this.isNodeCollapsedByFamily(sourceFamilyName), targetCycle, sourceCycle, targetCycle)
1499-
edges.push(this.edgeTemplate)
1500-
} else {
1501-
this.edgeTemplate = this.createEdge('collapsedTarget', sourceName, targetCycle, sourceCycle, targetCycle)
1502-
edges.push(this.edgeTemplate)
1503-
}
1504-
}
15051465
1506-
// edge has collapsed target and source cycle
1507-
if (this.collapseCycle.includes(targetCycle) && this.collapseCycle.includes(sourceCycle)) {
1508-
this.edgeTemplate = this.createEdge('collapsedSourceAndTarget', sourceCycle, targetCycle, sourceCycle, targetCycle)
1509-
edges.push(this.edgeTemplate)
1510-
}
1466+
// edge has collapsed target and source cycle
1467+
if (this.collapseCycle.includes(targetCycle) && this.collapseCycle.includes(sourceCycle)) {
1468+
edges.push(
1469+
this.createEdge('collapsedSourceAndTarget', sourceCycle, targetCycle, sourceCycle, targetCycle)
1470+
)
1471+
}
1472+
}
1473+
for (const edge of this.checkForEdgeByTarget(config.name, cycle, removedEdges)) {
1474+
const sourceName = this.cylcTree.$index[edge.node.source].name
1475+
const sourceCycle = this.cylcTree.$index[edge.node.source].tokens.cycle
1476+
const targetCycle = this.cylcTree.$index[edge.node.target].tokens.cycle
1477+
const sourceFamilyName = this.cylcTree.$index[edge.node.source].node.firstParent.name
1478+
1479+
if (sourceCycle === targetCycle) continue
1480+
// edge has collapsed target cycle only
1481+
if (this.collapseCycle.includes(targetCycle) && !this.collapseCycle.includes(sourceCycle)) {
1482+
if (this.isNodeCollapsedByFamily(sourceFamilyName)) {
1483+
edges.push(
1484+
this.createEdge('collapsedTarget', this.isNodeCollapsedByFamily(sourceFamilyName), targetCycle, sourceCycle, targetCycle)
1485+
)
1486+
} else {
1487+
edges.push(
1488+
this.createEdge('collapsedTarget', sourceName, targetCycle, sourceCycle, targetCycle)
1489+
)
15111490
}
15121491
}
1492+
1493+
// edge has collapsed target and source cycle
1494+
if (this.collapseCycle.includes(targetCycle) && this.collapseCycle.includes(sourceCycle)) {
1495+
edges.push(
1496+
this.createEdge('collapsedSourceAndTarget', sourceCycle, targetCycle, sourceCycle, targetCycle)
1497+
)
1498+
}
15131499
}
15141500
}
15151501
}

0 commit comments

Comments
 (0)