Comments (7)
@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.
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.
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.
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.
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.
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.
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)
- How to modify the canvas in 3d graph (canvas touchAction = "auto!important") HOT 1
- Performance issues with 80k+ edges
- A problem with pReact and react-kapsule script in a production environment HOT 3
- Centering on a node when more nodes are added as children to that node. HOT 1
- Three Js Dependency issue HOT 1
- dag mode + custom node shapes
- Links are not updating correctly HOT 4
- When nodeThreeObject is used, three-spritetext gives an error HOT 1
- Add a minimap to visualize one's locatin in huge graphs HOT 2
- graphRef.current.cameraPosition undefined
- Attempting to implement instancing for edges + nodes HOT 1
- Problem integrating react-force-graph-2d in a react with TypeScript project HOT 1
- Cannot use import statement outside a module for react-kapsule from react-force-graph-2d HOT 4
- How to implement cluster area with nodes inside?
- Expanded nodes by default when rendering HOT 4
- Attempted import error: 'AmbientLight' is not exported from 'three'. HOT 1
- "Highlights" example not working for me HOT 4
- Unable to Display Node Text in Stage Environment? HOT 1
- DOMException on CustomElementRegistry when using multiple modules HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-force-graph.