@@ -96,6 +96,7 @@ const graph = ForceGraph();
96
96
const gui = initGUI ( ) ;
97
97
98
98
function update ( patch ) {
99
+ const startTime = performance . now ( ) ;
99
100
// Apply the patch function to the model..
100
101
patch ( model ) ;
101
102
// ..then compute the derived state
@@ -121,6 +122,7 @@ function update(patch) {
121
122
model . focusLinks = focusLinks ;
122
123
123
124
gui . update ( model ) ;
125
+ console . log ( `Updated model in ${ performance . now ( ) - startTime } ms` ) ;
124
126
}
125
127
126
128
const Actions = {
@@ -386,8 +388,8 @@ function getLinkColor(link, model) {
386
388
switch ( getLinkState ( link , model ) ) {
387
389
case 'regular' :
388
390
if (
389
- model . graph . nodeInfo [ link . source . id ] . type === 'tag' &&
390
- model . graph . nodeInfo [ link . target . id ] . type === 'tag'
391
+ model . graph . nodeInfo [ getLinkNodeId ( link . source ) ] . type === 'tag' &&
392
+ model . graph . nodeInfo [ getLinkNodeId ( link . target ) ] . type === 'tag'
391
393
) {
392
394
return getNodeTypeColor ( 'tag' , model ) ;
393
395
}
@@ -401,6 +403,16 @@ function getLinkColor(link, model) {
401
403
}
402
404
}
403
405
406
+ /**
407
+ * Helper function to safely get node ID from a link's source or target
408
+ * Handles both when the link endpoint is a string ID or a full node object
409
+ * @param {string|Object } endpoint - Either a node ID string or a node object
410
+ * @returns {string } The node ID
411
+ */
412
+ function getLinkNodeId ( endpoint ) {
413
+ return typeof endpoint === 'object' ? endpoint . id : endpoint ;
414
+ }
415
+
404
416
function getNodeState ( nodeId , model ) {
405
417
return model . selectedNodes . has ( nodeId ) || model . hoverNode === nodeId
406
418
? 'highlighted'
@@ -416,7 +428,8 @@ function getLinkState(link, model) {
416
428
? 'regular'
417
429
: Array . from ( model . focusLinks ) . some (
418
430
fLink =>
419
- fLink . source === link . source . id && fLink . target === link . target . id
431
+ getLinkNodeId ( fLink . source ) === getLinkNodeId ( link . source ) &&
432
+ getLinkNodeId ( fLink . target ) === getLinkNodeId ( link . target )
420
433
)
421
434
? 'highlighted'
422
435
: 'lessened' ;
0 commit comments