Skip to content

Commit

Permalink
feat: remove extra tick subscribtion
Browse files Browse the repository at this point in the history
  • Loading branch information
Rassl committed Jan 7, 2025
1 parent 939e068 commit b9e5733
Showing 1 changed file with 1 addition and 84 deletions.
85 changes: 1 addition & 84 deletions src/components/Universe/Graph/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,89 +75,6 @@ export const Graph = () => {
return
}

simulation.on('tick', () => {
return

if (groupRef.current) {
const gr = groupRef.current.getObjectByName('simulation-3d-group__nodes') as Group
const grPoints = groupRef.current.getObjectByName('simulation-3d-group__node-points') as Group
const grConnections = groupRef.current.getObjectByName('simulation-3d-group__connections') as Group

if (gr) {
gr.children.forEach((mesh, index) => {
const simulationNode = simulation.nodes()[index]

if (simulationNode) {
mesh.position.set(simulationNode.x, simulationNode.y, simulationNode.z)
}
})
}

if (grPoints) {
grPoints.children[0].children.forEach((mesh, index) => {
const simulationNode = simulation.nodes()[index]

if (simulationNode) {
mesh.position.set(simulationNode.x, simulationNode.y, simulationNode.z)
}
})
}

if (simulation.alpha() > 1) {
return
}

if (grConnections) {
grConnections.children.forEach((g, i) => {
const r = g.children[0] // Assuming Line is the first child
const text = g.children[1] // Assuming Text is the second child

if (r instanceof Line2) {
// Ensure you have both Line and Text
const Line = r as Line2
const link = dataInitial?.links[i]

if (link) {
const sourceNode = simulation.nodes().find((n: NodeExtended) => n.ref_id === link.source)
const targetNode = simulation.nodes().find((n: NodeExtended) => n.ref_id === link.target)

if (!sourceNode || !targetNode) {
console.warn(`Missing source or target node for link: ${link?.ref_id}`)

return
}

const { x: sx, y: sy, z: sz } = sourceNode
const { x: tx, y: ty, z: tz } = targetNode

// Set positions for the link
linksPositionRef.current.set(link.ref_id, {
sx,
sy,
sz,
tx,
ty,
tz,
})

text.position.set((sx + tx) / 2, (sy + ty) / 2, (sz + tz) / 2)

const lineColor = normalizedSchemasByType[sourceNode.node_type]?.primary_color || 'white'

Line.geometry.setPositions([sx, sy, sz, tx, ty, tz])

const { material } = Line

material.color = new Color(lineColor)
material.transparent = true
material.opacity = 0.3
}
}
})
}
}
})

simulation.on('end', () => {
resetDataNew()

Expand All @@ -170,7 +87,7 @@ export const Graph = () => {
i.fz = i.z
})

if (groupRef.current) {
if (groupRef?.current) {
const gr = groupRef.current.getObjectByName('simulation-3d-group__nodes') as Group
const grPoints = groupRef.current.getObjectByName('simulation-3d-group__node-points') as Group
const grConnections = groupRef.current.getObjectByName('simulation-3d-group__connections') as Group
Expand Down

0 comments on commit b9e5733

Please sign in to comment.