Git Product home page Git Product logo

Comments (7)

vasturiano avatar vasturiano commented on June 11, 2024

@daniel301r the force directed engine only runs its computation (which sets the nodes' coordinates) after the objects are generated. Therefore, the first time the nodeThreeObject method is ran there are still no coordinates assigned.

What you can do is set an async call for the next available frame, and likely you'll have the initial nodes positions by then. Something like:

nodeThreeObject={(node) => {
  setTimeout(() => console.log(node));
  ...
}}

from react-force-graph.

daniel301r avatar daniel301r commented on June 11, 2024

Thanks so much @vasturiano for your quick response.

I am actually trying to get the position of the nodes after the engine has run. Is there a way to do this?

For context, I have a main graph and the users are able to click on a node which will then generate a completely new graph. Depending on which node they click on in the main graph, I would like to be able to focus on different node in the new graph so knowing the final position of the nodes on the new graph would be very helpful.

from react-force-graph.

vasturiano avatar vasturiano commented on June 11, 2024

In that case, why not extract the nodes' coordinates at the time of the click (within onNodeClick)? They should be available by then.

from react-force-graph.

daniel301r avatar daniel301r commented on June 11, 2024

I can't use the coordinates of the node that was clicked on because when the user clicks on a node, it generates a new graph so the previous graph's node positions are not relevant. Is there a way to get the position of the nodes on a graph after the engine has run?

from react-force-graph.

vasturiano avatar vasturiano commented on June 11, 2024

You can get the position of the nodes at any time by looking for the x,y,z attributes in your nodes data structure.

from react-force-graph.

daniel301r avatar daniel301r commented on June 11, 2024

Thanks for the quick response again.

I'm not setting the position of the nodes manually when I create the nodes data structure. Is there a way to access the positions that have been assigned by the engine after it has run? Or am I missing something?

from react-force-graph.

vasturiano avatar vasturiano commented on June 11, 2024

The engine assigns those attributes on the data object for you automatically. In fact, that is the sole way it maintains state of the nodes positions.

from react-force-graph.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.