@@ -7,7 +7,7 @@ import { timer } from "../timer";
7
7
import { NODE } from "../node" ;
8
8
import { progress } from "./progress" ;
9
9
import { View } from "./view" ;
10
- import type { Core , Collection , NodeCollection , EdgeCollection , NodeSingular } from "cytoscape" ;
10
+ import type { Core , Collection , NodeCollection , EdgeCollection , NodeSingular , EdgeSingular } from "cytoscape" ;
11
11
import cytoscape from "cytoscape" ; //eslint-disable-line no-duplicate-imports
12
12
import type { Menu } from "./menu" ;
13
13
import log from "loglevel" ;
@@ -318,7 +318,8 @@ export class Graph {
318
318
return this . getElementsByIds ( nodes . map ( ( node ) => node . id ( ) ) ) as unknown as NodeCollection ;
319
319
}
320
320
321
- /** @param ids - iterable of cytoscape ids
321
+ /** Get a collection of nodes/edges using a list of their IDs. Works only in this graph.
322
+ * @param ids - iterable of cytoscape ids
322
323
* @returns cytoscape collection of elements with those ids */
323
324
getElementsByIds ( ids : Iterable < string > ) : Collection {
324
325
const own = this . cy . collection ( ) ;
@@ -328,6 +329,32 @@ export class Graph {
328
329
}
329
330
return own ;
330
331
}
332
+ /** Get a collection of nodes/edges using a list of their IDs.
333
+ * If not existant in this graph, then all others are scanned.
334
+ * @param ids - iterable of cytoscape ids
335
+ * @returns cytoscape collection of elements with those ids */
336
+ getElementsByAllMeansNecessary ( ids : Iterable < string > ) : Collection {
337
+ const own = this . cy . collection ( ) ;
338
+ for ( const id of ids ) {
339
+ let ele = this . cy . getElementById ( id ) ;
340
+ if ( ele . length === 0 ) {
341
+ // get out the big guns
342
+ // search every view for this id
343
+ for ( const view of View . views ( ) ) {
344
+ ele = view . state . cy . getElementById ( id ) ;
345
+ // if the query does not return an empty collection, we found the element
346
+ if ( ele . length !== 0 ) {
347
+ console . debug ( "Found!" ) ;
348
+ // add it to our graph!
349
+ this . cy . add ( ele ) ;
350
+ break ;
351
+ }
352
+ }
353
+ }
354
+ own . merge ( ele ) ;
355
+ }
356
+ return own ;
357
+ }
331
358
/** Returns the start node for all path operations
332
359
@returns the start node for all path operations, or null if none exists. */
333
360
getSource ( ) : NodeSingular | null {
0 commit comments