Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search for node by node.id then can focus camera on that node #519

Open
EncompassingResidential opened this issue May 26, 2024 · 0 comments

Comments

@EncompassingResidential
Copy link

EncompassingResidential commented May 26, 2024

Is your feature request related to a problem? Please describe.

Hi Vasco Asturiano,

Not a problem, new feature.

Murphy's law, not 3 minutes after I created this issue I find this one:
#470

Which I think is what I want... let me test...

Yes Yes Rush Rush that worked. Phew. Glad you answered Issue 470 !

Describe the solution you'd like

I label all my nodes.
I want to focus on a node with a specific label.
I have buttons, such as a music band "Rush (band)" Button.

  • When "Rush (band)" button is pushed,
    • I want to search the the graph's nodes for the node labeled "Rush (band)"
    • Then I'll use the cameraPosition() to focus on the "Rush (band)" node

Describe alternatives you've considered

Now showing correct answer:

  const focusOnNode = (searchString) => {
    const myGraphData = fgRef.current.graphData();
    const node = myGraphData.nodes.find(n => n.id === searchString);

    if (node) {
      const distance = 40; // Distance from the node to position the camera
      const distRatio = 1 + distance / Math.hypot(node.x, node.y, node.z);

      fgRef.current.cameraPosition(
        { x: node.x * distRatio, y: node.y * distRatio, z: node.z * distRatio }, // new position
        node, // lookAt target
        3000 // ms transition duration
      );
    }
  };

  useEffect(() => {
    if (focusNodeId) {
      focusOnNode(focusNodeId);
    }
  }, [focusNodeId]);

Additional context

https://bandtree.fly.dev

Rush band and Geddy Lee buttons

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant