({ data, width, height })
| 23 | width?: number; |
| 24 | height?: number; |
| 25 | }> = ({ data, width, height }) => { |
| 26 | const fgRef = useRef<any>(undefined); |
| 27 | |
| 28 | let angle = 0; |
| 29 | let cam: NodeJS.Timeout; |
| 30 | |
| 31 | const createCamMovement = () => { |
| 32 | cam = setInterval(() => { |
| 33 | // next available frame |
| 34 | requestAnimationFrame(() => { |
| 35 | const pos = fgRef.current.cameraPosition(); |
| 36 | // find the distance from the current camera position, taking into account the angle |
| 37 | const distance = pos.z ?? 1400; |
| 38 | |
| 39 | // const distance = fgRef.current?.distance; |
| 40 | fgRef.current?.cameraPosition({ |
| 41 | x: distance * Math.sin(angle), |
| 42 | y: distance * Math.cos(angle), |
| 43 | z: distance, |
| 44 | distance, |
| 45 | }); |
| 46 | angle += Math.PI / 5000; |
| 47 | }); |
| 48 | }, 10); |
| 49 | }; |
| 50 | |
| 51 | // Initialize the camera position |
| 52 | useEffect(() => { |
| 53 | fgRef.current?.cameraPosition({ z: 1400 }); |
| 54 | |
| 55 | createCamMovement(); |
| 56 | }, []); |
| 57 | |
| 58 | return ( |
| 59 | <ForceGraph3D |
| 60 | ref={fgRef} |
| 61 | width={width} |
| 62 | height={height} |
| 63 | graphData={data} |
| 64 | backgroundColor="#ffffff00" |
| 65 | extraRenderers={[new CSS3DRenderer()]} |
| 66 | nodeThreeObjectExtend={true} |
| 67 | linkAutoColorBy={(node: any) => node.source.type} |
| 68 | linkCurvature={0.1} |
| 69 | linkOpacity={1} |
| 70 | nodeThreeObject={(node: GraphNode) => { |
| 71 | const slug = node.id.split("-").slice(-1).join("-"); |
| 72 | const icon = iconOf(slug) ?? iconOf(node.icon); |
| 73 | |
| 74 | // const nodeEl = document.createElement("div"); |
| 75 | // nodeEl.innerHTML = 'icon?.svg ?? ""'; |
| 76 | // nodeEl.style.color = icon?.hex; |
| 77 | // nodeEl.className = "node-label"; |
| 78 | const nodeEl = document.createElement("div"); |
| 79 | nodeEl.style.width = "20px"; |
| 80 | nodeEl.style.height = "20px"; |
| 81 | nodeEl.style.borderRadius = "50%"; |
| 82 | console.log(nodeEl); |
nothing calls this directly
no test coverage detected