@@ -288,15 +288,35 @@ export class Edge extends Graphics {
288288 this . on ( "mouseover" , ( ) => {
289289 const group = this . viewgraph . findConnectedEdges ( this ) ;
290290 group . forEach ( ( edge ) => {
291- edge . setupConnectedDevicesTooltips ( ) ;
291+ edge . handleConnectedDevicesTooltips (
292+ ( device : ViewDevice , iface : number ) => {
293+ if ( ! device ) {
294+ console . error (
295+ `Device ${ device . id } not found in viewgraph, cannot set device tooltip` ,
296+ ) ;
297+ return ;
298+ }
299+ if ( device . isVisible ( ) ) {
300+ device . setupToolTip ( iface ) ;
301+ }
302+ } ,
303+ ) ;
292304 edge . showTooltips ( ) ;
293305 edge . fixTooltipPositions ( ) ;
294306 } ) ;
295307 } ) ;
296308 this . on ( "mouseout" , ( ) => {
297309 const group = this . viewgraph . findConnectedEdges ( this ) ;
298310 group . forEach ( ( edge ) => {
299- edge . hideConnectedDevicesTooltips ( ) ;
311+ edge . handleConnectedDevicesTooltips ( ( device : ViewDevice ) => {
312+ if ( ! device ) {
313+ console . error (
314+ `Device ${ device . id } not found in viewgraph, cannot set device tooltip` ,
315+ ) ;
316+ return ;
317+ }
318+ device . hideToolTip ( ) ;
319+ } ) ;
300320 edge . hideTooltips ( ) ;
301321 } ) ;
302322 } ) ;
@@ -326,46 +346,28 @@ export class Edge extends Graphics {
326346 ) ;
327347 }
328348
329- private setupConnectedDevicesTooltips ( ) {
349+ handleConnectedDevicesTooltips (
350+ handleTooltip : ( device : ViewDevice , iface ?: number ) => void ,
351+ ) {
330352 const [ startId , startIface ] = [ this . data . from . id , this . data . from . iface ] ;
331353 const [ endId , endIface ] = [ this . data . to . id , this . data . to . iface ] ;
332354 const startDevice = this . viewgraph . getDevice ( startId ) ;
333355 const endDevice = this . viewgraph . getDevice ( endId ) ;
334356
335- const setTooltip = ( device : ViewDevice , iface : number ) => {
357+ const deviceFound = ( device : ViewDevice , id : DeviceId ) => {
336358 if ( ! device ) {
337359 console . error (
338- `Device ${ device . id } not found in viewgraph, cannot set device tooltip` ,
360+ `Device ${ id } not found in viewgraph, cannot set device tooltip` ,
339361 ) ;
340- return ;
341- }
342- if ( device . isVisible ( ) ) {
343- device . setupTooltip ( iface ) ;
362+ return false ;
344363 }
364+ return true ;
345365 } ;
346366
347- setTooltip ( startDevice , startIface ) ;
348- setTooltip ( endDevice , endIface ) ;
349- }
367+ if ( deviceFound ( startDevice , startId ) )
368+ handleTooltip ( startDevice , startIface ) ;
350369
351- private hideConnectedDevicesTooltips ( ) {
352- const startId = this . data . from . id ;
353- const endId = this . data . to . id ;
354- const startDevice = this . viewgraph . getDevice ( startId ) ;
355- const endDevice = this . viewgraph . getDevice ( endId ) ;
356-
357- const hideTooltip = ( device : ViewDevice ) => {
358- if ( ! device ) {
359- console . error (
360- `Device ${ device . id } not found in viewgraph, cannot set device tooltip` ,
361- ) ;
362- return ;
363- }
364- device . hideToolTip ( ) ;
365- } ;
366-
367- hideTooltip ( startDevice ) ;
368- hideTooltip ( endDevice ) ;
370+ if ( deviceFound ( endDevice , endId ) ) handleTooltip ( endDevice , endIface ) ;
369371 }
370372
371373 private fixTooltipPositions ( ) {
@@ -411,6 +413,9 @@ export class Edge extends Graphics {
411413 }
412414
413415 private removeTooltips ( ) {
416+ this . handleConnectedDevicesTooltips ( ( device : ViewDevice ) =>
417+ device . hideToolTip ( ) ,
418+ ) ;
414419 this . startTooltip = removeTooltip ( this , this . startTooltip ) ;
415420 this . endTooltip = removeTooltip ( this , this . endTooltip ) ;
416421 }
0 commit comments