Comments (3)
@Jing1524 you can try setting the node's velocities (via v*
attributes) instead of their positions. This will probably get you closer to what you have in mind. And possibly it helps too to set d3VelocityDecay
and d3AlphaDecay
to 0
.
Take a look at this example.
react-force-graph/example/collision-detection/index.html
Lines 49 to 53 in 0fd8cac
from react-force-graph.
@vasturiano thank you so much for the quick response! will try it out! :)
from react-force-graph.
@vasturiano hey sorry to bother you again.
I just spend a few hours working on it again, but having a hard time to get it to work, feels like I'm missing something still,
i did manage to have the node keep moving, but the resulting movement is way too dramatic. I'm attaching my code and sandbox to show you the currently result. wondering if you could help.
here is the current result
Below useEffect is doing the heavy lift for the "floating" movement.
useEffect(() => {
graphData.nodes.forEach((node) => {
const initialColor = "#E4CDC6";
const targetColor = "#a7715f";
setNodeTransition((prev) => ({ ...prev, [node.id]: initialColor }));
setTimeout(() => {
animateColorTransition(node.id, initialColor, targetColor, 500); // Transition over 2 seconds
}, Math.random() * 5000 + 1000); // Random interval between 3s and 8s
});
graphData.nodes.forEach((node) => {
node.vx = Math.random() * 2 - 1;
node.vy = Math.random() * 2 - 1;
node.vz = Math.random() * 2 - 1;
});
const BOUNDING_BOX_SIZE = 10;
const enforceBoundingBox = () => {
graphData.nodes.forEach((node) => {
if (Math.abs(node.x) > BOUNDING_BOX_SIZE) node.vx *= -1;
if (Math.abs(node.y) > BOUNDING_BOX_SIZE) node.vy *= -1;
if (Math.abs(node.z) > BOUNDING_BOX_SIZE) node.vz *= -1;
});
};
const interval = setInterval(enforceBoundingBox, 1000);
return () => clearInterval(interval);
}, [graphData.nodes]);
return (
<ForceGraph3D
ref={forceGraphRef}
width={width}
height={height}
graphData={graphData}
backgroundColor="#ffffff"
showNavInfo={false}
nodeColor={(node) => nodeTransition[node.id] || "#E4CDC6"}
nodeOpacity={1}
linkColor={(d) => (d.type === "OK" ? "#E4CDC6" : "#E4CDC6")}
linkOpacity={0.75}
enableNavigationControls={false}
d3AlphaDecay={0}
d3VelocityDecay={0}
/>
)
from react-force-graph.
Related Issues (20)
- Cannot find name 'ChainableInstance'.ts in Latest Release HOT 1
- How to use useRef with Typescript? HOT 1
- It There a way to remove the bottom text of the graph?
- ReferenceError: self is not defined NextJS app router HOT 4
- Cannot add threejs object in the current ref scene
- BackgroundColor: white is not working propertly HOT 1
- Unable to get the dynamic position of the node HOT 2
- Is it possible to incorporate a lasso selection? HOT 2
- d3Force is not a function HOT 2
- 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
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.