1- import ForceGraph3D , { ForceGraph3DInstance } from "3d-force-graph" ;
1+ import ForceGraph3D from "3d-force-graph" ;
2+ import { Colors } from "design/theme" ;
23import React , { useEffect , useRef } from "react" ;
34import * as THREE from "three" ;
45import {
@@ -16,15 +17,18 @@ interface NodeObject {
1617 datatype : string [ ] ;
1718 support : string ;
1819 url : string ;
20+ datasets : number ;
1921}
2022
2123const NeuroJsonGraph : React . FC < { registry : Database [ ] } > = ( { registry } ) => {
2224 const graphRef = useRef < HTMLDivElement > ( null ) ;
2325
24- // Debug log for registry data
25- useEffect ( ( ) => {
26- console . log ( "From NeuroJsonGraph, registry:" , registry ) ;
27- } , [ registry ] ) ;
26+ // Function to determine color and size based on node size
27+ const size2colorAndSize = ( size : number ) => {
28+ if ( size > 32 ) return { color : Colors . primary . dark , size : 10 } ;
29+ if ( size > 3 ) return { color : Colors . primary . main , size : 7 } ;
30+ return { color : Colors . primary . light , size : 5 } ;
31+ } ;
2832
2933 useEffect ( ( ) => {
3034 // Ensure registry and graphRef are properly initialized
@@ -40,40 +44,61 @@ const NeuroJsonGraph: React.FC<{ registry: Database[] }> = ({ registry }) => {
4044
4145 // Prepare graph data
4246 const graphData = {
43- nodes : registry . map ( ( db ) => ( {
44- id : db . id ,
45- name : db . fullname || db . name ,
46- dbname : db . name ,
47- color : "rgba(255,255,255,1)" , // White color for nodes
48- datatype : db . datatype ,
49- support : db . support ,
50- url : db . url ,
51- } ) ) ,
52- links : [ ] , // Add links if needed
47+ nodes : registry . map ( ( db ) => {
48+ const { color, size } = size2colorAndSize ( db . datasets ) ;
49+ return {
50+ id : db . id ,
51+ name : db . fullname || db . name ,
52+ dbname : db . name ,
53+ color : color ,
54+ datatype : db . datatype ,
55+ support : db . support ,
56+ url : db . url ,
57+ datasets : db . datasets ,
58+ size : size ,
59+ } ;
60+ } ) ,
61+ links : registry . flatMap ( ( db , index ) => {
62+ const connections = [ ] ;
63+ const nextIndex = ( index + 1 ) % registry . length ;
64+ const { color } = size2colorAndSize ( db . datasets ) ;
65+ connections . push ( {
66+ source : db . id ,
67+ target : registry [ nextIndex ] . id ,
68+ color : color ,
69+ visible : true ,
70+ } ) ;
71+ return connections ;
72+ } ) ,
5373 } ;
5474
5575 // Initialize 3D Force Graph
56- const Graph : ForceGraph3DInstance = new ForceGraph3D ( graphRef . current )
76+ const Graph = new ForceGraph3D ( graphRef . current )
5777 . graphData ( graphData )
5878 . nodeRelSize ( 2 )
59- . nodeColor ( ( node ) => ( node as NodeObject ) . color || "rgba(255,255,255,1)" ) // White nodes
79+ . nodeColor ( ( node ) => ( node as NodeObject ) . color )
80+ . linkWidth ( 2 ) // Set the thickness of the links
6081 . backgroundColor ( "rgba(0,0,0,0)" ) // Transparent background
6182 . nodeLabel ( "name" )
6283 . nodeThreeObject ( ( node ) => {
6384 const castNode = node as NodeObject ;
6485
6586 // Create a 3D sphere for the node
66- const sphereGeometry = new THREE . SphereGeometry ( 5 , 16 , 16 ) ; // Radius 5
87+ const sphereGeometry = new THREE . SphereGeometry (
88+ ( castNode as any ) . size ,
89+ 16 ,
90+ 16
91+ ) ; // Dynamic radius
6792 const sphereMaterial = new THREE . MeshBasicMaterial ( {
68- color : "white" ,
93+ color : ( castNode as any ) . color ,
6994 } ) ;
7095 const sphere = new THREE . Mesh ( sphereGeometry , sphereMaterial ) ;
7196
7297 // Add label as CSS2DObject
7398 const label = new CSS2DObject ( document . createElement ( "div" ) ) ;
7499 label . element . textContent = castNode . dbname || "Unnamed" ;
75- label . element . style . color = "white" ;
76- label . element . style . fontSize = "10px " ;
100+ label . element . style . color = Colors . primary . main ;
101+ label . element . style . fontSize = "12px " ;
77102 label . element . style . pointerEvents = "none" ; // Prevent interaction
78103 label . position . set ( 0 , 10 , 0 ) ; // Position label above the node
79104 sphere . add ( label ) ;
@@ -86,7 +111,7 @@ const NeuroJsonGraph: React.FC<{ registry: Database[] }> = ({ registry }) => {
86111 labelRenderer . setSize ( window . innerWidth , window . innerHeight ) ;
87112 labelRenderer . domElement . style . position = "absolute" ;
88113 labelRenderer . domElement . style . top = "0px" ;
89- labelRenderer . domElement . style . pointerEvents = "none" ; // Prevent interaction
114+ labelRenderer . domElement . style . pointerEvents = "none" ;
90115 graphRef . current ?. appendChild ( labelRenderer . domElement ) ;
91116
92117 // Animate label rendering
0 commit comments