@@ -2,9 +2,8 @@ import { ViewDevice } from "../view-devices";
22import { Edge , EdgeEdges } from "./../edge" ;
33import { DataGraph , DeviceId , DataNode , RemovedNodeData } from "./datagraph" ;
44import { Viewport } from "../../graphics/viewport" ;
5- import { Layer , layerIncluded } from "../layer" ;
5+ import { Layer } from "../layer" ;
66import { createViewDevice } from "../view-devices/utils" ;
7- import { layerFromType } from "../view-devices/vDevice" ;
87import { IpAddress } from "../../packets/ip" ;
98import { GlobalContext } from "../../context" ;
109import { Graph } from "./graph" ;
@@ -36,17 +35,14 @@ export class ViewGraph {
3635 const allConnections = new Map < string , EdgePair > ( ) ;
3736
3837 for ( const [ deviceId , device ] of this . datagraph . getDevices ( ) ) {
39- if ( layerIncluded ( layerFromType ( device . getType ( ) ) , this . layer ) ) {
40- this . addDevice ( deviceId , device . getDataNode ( ) ) ;
41- layerDFS (
42- this . datagraph ,
43- this . layer ,
44- deviceId ,
45- deviceId ,
46- new Set ( [ deviceId ] ) ,
47- allConnections ,
48- ) ;
49- }
38+ this . addDevice ( deviceId , device . getDataNode ( ) ) ;
39+ layerDFS (
40+ this . datagraph ,
41+ deviceId ,
42+ deviceId ,
43+ new Set ( [ deviceId ] ) ,
44+ allConnections ,
45+ ) ;
5046 }
5147 console . debug ( allConnections ) ;
5248 this . addConnections ( allConnections ) ;
@@ -60,7 +56,6 @@ export class ViewGraph {
6056 const connections = new Map < string , EdgePair > ( ) ;
6157 layerDFS (
6258 this . datagraph ,
63- this . layer ,
6459 deviceId ,
6560 deviceId ,
6661 new Set ( [ deviceId ] ) ,
@@ -220,9 +215,13 @@ export class ViewGraph {
220215 return Array . from ( this . graph . getAllVertices ( ) ) . map ( ( [ , device ] ) => device ) ;
221216 }
222217
223- // Returns an array of devices’ ids
224- getDeviceIds ( ) : DeviceId [ ] {
225- return Array . from ( this . graph . getAllVertices ( ) ) . map ( ( [ id ] ) => id ) ;
218+ /**
219+ * Returns all devices in the layer of the viewgraph
220+ */
221+ getLayerDeviceIds ( ) : DeviceId [ ] {
222+ return Array . from ( this . graph . getAllVertices ( ) )
223+ . filter ( ( [ , { visible } ] ) => visible )
224+ . map ( ( [ id ] ) => id ) ;
226225 }
227226
228227 // Get the number of devices in the graph
@@ -396,38 +395,10 @@ export class ViewGraph {
396395 }
397396 this . graph . clear ( ) ;
398397 }
399-
400- // Make all edges transparent except for the ones connected to the device
401- transparentEdgesForDevice ( id : DeviceId ) {
402- for ( const [ , , edge ] of this . graph . getAllEdges ( ) ) {
403- if ( edge . connectedNodes . n1 !== id && edge . connectedNodes . n2 !== id ) {
404- edge . becomeTransparent ( ) ;
405- }
406- }
407- }
408-
409- // Make all edges transparent except for the edge between the two devices
410- transparentEdgesForEdge ( n1 : DeviceId , n2 : DeviceId ) {
411- for ( const [ , , edge ] of this . graph . getAllEdges ( ) ) {
412- if (
413- ( edge . connectedNodes . n1 !== n1 || edge . connectedNodes . n2 !== n2 ) &&
414- ( edge . connectedNodes . n1 !== n2 || edge . connectedNodes . n2 !== n1 )
415- ) {
416- edge . becomeTransparent ( ) ;
417- }
418- }
419- }
420-
421- untransparentEdges ( ) {
422- for ( const [ , , edge ] of this . graph . getAllEdges ( ) ) {
423- edge . becomeOpaque ( ) ;
424- }
425- }
426398}
427399
428400function layerDFS (
429401 datagraph : DataGraph ,
430- layer : Layer ,
431402 s : DeviceId , // source node
432403 v : DeviceId ,
433404 visited : Set < DeviceId > ,
@@ -437,18 +408,12 @@ function layerDFS(
437408 if ( visited . has ( w ) ) {
438409 return ;
439410 }
440- const adjacent = datagraph . getDevice ( w ) ;
441411 // mark node as visited
442412 visited . add ( w ) ;
443413
444- if ( layerIncluded ( layerFromType ( adjacent . getType ( ) ) , layer ) ) {
445- // NOTE: we use strings because according to JavaScript, [1, 2] !== [1, 2]
446- const edgePair : EdgePair = [ w , s ] ;
447- edgePair . sort ( ) ;
448- connections . set ( edgePair . toString ( ) , edgePair ) ;
449- } else {
450- // continue with recursive search
451- layerDFS ( datagraph , layer , s , w , visited , connections ) ;
452- }
414+ // NOTE: we use strings because according to JavaScript, [1, 2] !== [1, 2]
415+ const edgePair : EdgePair = [ w , s ] ;
416+ edgePair . sort ( ) ;
417+ connections . set ( edgePair . toString ( ) , edgePair ) ;
453418 } ) ;
454419}
0 commit comments