@@ -8,6 +8,12 @@ import { Graph3DPluginSettings, GraphNode, GraphLink, NodeShape, NodeType, Filte
88
99export const VIEW_TYPE_3D_GRAPH = "3d-graph-view" ;
1010
11+ // Define a more specific type for links once they are processed by the graph engine
12+ interface ProcessedGraphLink {
13+ source : GraphNode ;
14+ target : GraphNode ;
15+ }
16+
1117export class Graph3DView extends ItemView {
1218 private graph : any ;
1319 private plugin : Graph3DPlugin ;
@@ -434,8 +440,8 @@ export class Graph3DView extends ItemView {
434440
435441 if ( this . pressedKeys . has ( 'w' ) ) moveVector . add ( direction ) ;
436442 if ( this . pressedKeys . has ( 's' ) ) moveVector . sub ( direction ) ;
437- if ( this . pressedKeys . has ( 'a' ) ) moveVector . sub ( right ) ; // Corrected from add
438- if ( this . pressedKeys . has ( 'd' ) ) moveVector . add ( right ) ; // Corrected from sub
443+ if ( this . pressedKeys . has ( 'a' ) ) moveVector . sub ( right ) ;
444+ if ( this . pressedKeys . has ( 'd' ) ) moveVector . add ( right ) ;
439445
440446 if ( moveVector . lengthSq ( ) > 0 ) {
441447 moveVector . normalize ( ) . multiplyScalar ( moveSpeed ) ;
@@ -468,7 +474,7 @@ export class Graph3DView extends ItemView {
468474 this . graph = Graph ( ) ( this . graphContainer )
469475 . onNodeClick ( ( node : GraphNode , event : MouseEvent ) => this . handleNodeClick ( node , event ) )
470476 . onNodeHover ( ( node : GraphNode | null ) => this . handleNodeHover ( node ) )
471- . linkCurvature ( link => this . getLinkCurvature ( link ) )
477+ . linkCurvature ( ( link : ProcessedGraphLink ) => this . getLinkCurvature ( link ) )
472478 . onEngineTick ( ( ) => {
473479 const now = performance . now ( ) ;
474480 if ( now - this . lastLabelUpdateTime > this . LABEL_UPDATE_INTERVAL ) {
@@ -915,15 +921,12 @@ export class Graph3DView extends ItemView {
915921
916922 const allLinks = this . graph . graphData ( ) . links ;
917923
918- allLinks . forEach ( ( link : GraphLink ) => {
919- const sourceId = typeof link . source === 'object' ? ( link . source as GraphNode ) . id : link . source ;
920- const targetId = typeof link . target === 'object' ? ( link . target as GraphNode ) . id : link . target ;
921-
922- if ( sourceId === node . id ) {
923- this . highlightedNodes . add ( targetId ) ;
924+ allLinks . forEach ( ( link : ProcessedGraphLink ) => {
925+ if ( link . source . id === node . id ) {
926+ this . highlightedNodes . add ( link . target . id ) ;
924927 this . highlightedLinks . add ( link ) ;
925- } else if ( targetId === node . id ) {
926- this . highlightedNodes . add ( sourceId ) ;
928+ } else if ( link . target . id === node . id ) {
929+ this . highlightedNodes . add ( link . source . id ) ;
927930 this . highlightedLinks . add ( link ) ;
928931 }
929932 } ) ;
@@ -948,7 +951,7 @@ export class Graph3DView extends ItemView {
948951
949952 if ( node ) {
950953 this . highlightedNodes . add ( node . id ) ;
951- this . graph . graphData ( ) . links . forEach ( ( link : any ) => {
954+ this . graph . graphData ( ) . links . forEach ( ( link : ProcessedGraphLink ) => {
952955 if ( link . source . id === node . id || link . target . id === node . id ) {
953956 this . highlightedLinks . add ( link ) ;
954957 }
@@ -958,9 +961,9 @@ export class Graph3DView extends ItemView {
958961 this . updateDisplay ( ) ;
959962 }
960963
961- private getLinkCurvature ( link : any ) {
964+ private getLinkCurvature ( link : ProcessedGraphLink ) {
962965 const allLinks = this . graph . graphData ( ) . links ;
963- const hasReciprocal = allLinks . some ( ( l : any ) => l . source . id === link . target . id && l . target . id === link . source . id ) ;
966+ const hasReciprocal = allLinks . some ( ( l : ProcessedGraphLink ) => l . source . id === link . target . id && l . target . id === link . source . id ) ;
964967 if ( hasReciprocal ) {
965968 return link . source . id > link . target . id ? 0.2 : - 0.2 ;
966969 }
0 commit comments