@@ -350,6 +350,19 @@ export function convertTree (map) {
350
350
}))
351
351
}
352
352
353
+ /**
354
+ * Get the nodes binned by cycle point
355
+ *
356
+ * @param {Node[]} nodes - The graph nodes
357
+ * @returns {{ [dateTime: string]: Object[] }=} mapping of cycle points to nodes
358
+ */
359
+ export function getCyclesToNodes (nodes ) {
360
+ return nodes .reduce ((x , y ) => {
361
+ (x[y .tokens .cycle ] || = []).push (y)
362
+ return x
363
+ }, {})
364
+ }
365
+
353
366
export default {
354
367
name: ' Graph' ,
355
368
@@ -451,7 +464,6 @@ export default {
451
464
// supports loading graph when component is mounted and autoRefresh is off.
452
465
// true if page is loading for the first time and nodeDimensions are yet to be calculated
453
466
initialLoad: true ,
454
- cycleArrayStore: [],
455
467
}
456
468
},
457
469
@@ -500,11 +512,11 @@ export default {
500
512
return this .allParentLookUp .size ? this .getTree () : [{ name: ' No families' , disabled: true }]
501
513
},
502
514
/**
503
- * Gets the array of cycles for use in vuetify toolbar drop down
504
- * @returns {String []} array containing nested structure of families
515
+ * Gets the array of cycles
516
+ * @returns {string []}
505
517
*/
506
- treeDropDownCycle () {
507
- return this .cycleArrayStore . map ((name ) => ({ name }))
518
+ cycles () {
519
+ return this .workflows [ 0 ] ? . children . map (({ tokens } ) => tokens . cycle ) || []
508
520
},
509
521
/**
510
522
* Object for looking up family ancestors
@@ -671,7 +683,7 @@ export default {
671
683
action: ' select-tree' ,
672
684
value: this .collapseCycle ,
673
685
key: ' collapseCycle' ,
674
- items: this .treeDropDownCycle ,
686
+ items: this .cycles . map (( name ) => ({ name })) ,
675
687
},
676
688
{
677
689
title: ' Collapse by family' ,
@@ -887,19 +899,6 @@ export default {
887
899
return ret
888
900
},
889
901
890
- /**
891
- * Get the nodes binned by cycle point
892
- *
893
- * @param {Node[]} nodes - The graph nodes
894
- * @returns {{ [dateTime: string]: Object[] }=} mapping of cycle points to nodes
895
- */
896
- getCycles (nodes ) {
897
- return nodes .reduce ((x , y ) => {
898
- (x[y .tokens .cycle ] || = []).push (y)
899
- return x
900
- }, {})
901
- },
902
-
903
902
/**
904
903
* Recursive function that adds a subgraph to the dot code
905
904
*
@@ -989,7 +988,7 @@ export default {
989
988
}
990
989
},
991
990
992
- getDotCode (nodeDimensions , nodes , edges , cycles ) {
991
+ getDotCode (nodeDimensions , nodes , edges , cyclesToNodes ) {
993
992
// return GraphViz dot code for the given nodes, edges and dimensions
994
993
const ret = [' digraph {' ]
995
994
let spacing = this .spacing
@@ -1034,8 +1033,7 @@ export default {
1034
1033
}
1035
1034
1036
1035
const graphSections = {}
1037
- for (const cycle of Object .keys (cycles)) {
1038
- const indexSearch = cycles[cycle]
1036
+ for (const [cycle , indexSearch ] of Object .entries (cyclesToNodes)) {
1039
1037
if (indexSearch .length && ! this .collapseCycle .includes (cycle)) {
1040
1038
for (const task of indexSearch) {
1041
1039
const section = graphSections[task .node .firstParent .id ] ?? = []
@@ -1162,7 +1160,7 @@ export default {
1162
1160
1163
1161
// ----------------------------------------
1164
1162
for (const family of this .collapseFamily ) {
1165
- for (const cycle of this .cycleArrayStore ) {
1163
+ for (const cycle of this .cycles ) {
1166
1164
// ...get the node from the index...
1167
1165
const famNode = this .cylcTree .$index [
1168
1166
this .workflows [0 ].tokens .clone ({ cycle, task: family }).id
@@ -1259,8 +1257,7 @@ export default {
1259
1257
return
1260
1258
}
1261
1259
1262
- const cycles = this .getCycles (nodes)
1263
- this .cycleArrayStore = this .workflows [0 ].children .map (child => child .tokens .cycle )
1260
+ const cyclesToNodes = getCyclesToNodes (nodes)
1264
1261
// compute the graph ID
1265
1262
const graphID = this .hashGraph (nodes, edges)
1266
1263
if (this .graphID === graphID) {
@@ -1305,7 +1302,7 @@ export default {
1305
1302
1306
1303
// layout the graph
1307
1304
try {
1308
- await this .layout (nodes, edges, nodeDimensions, cycles )
1305
+ await this .layout (nodes, edges, nodeDimensions, cyclesToNodes )
1309
1306
} catch (e) {
1310
1307
// something went wrong, allow the layout to retry later
1311
1308
this .graphID = null
@@ -1349,9 +1346,9 @@ export default {
1349
1346
* @param {Map<string, Edge>} edges
1350
1347
* @param {{ [id: string]: SVGRect }} nodeDimensions
1351
1348
*/
1352
- async layout (nodes , edges , nodeDimensions , cycles ) {
1349
+ async layout (nodes , edges , nodeDimensions , cyclesToNodes ) {
1353
1350
// generate the GraphViz dot code
1354
- const dotCode = this .getDotCode (nodeDimensions, nodes, edges, cycles )
1351
+ const dotCode = this .getDotCode (nodeDimensions, nodes, edges, cyclesToNodes )
1355
1352
1356
1353
// run the layout algorithm
1357
1354
const jsonString = (await this .graphviz ).layout (dotCode, ' json' )
0 commit comments