Comments (4)
You could use onNodesChange
for this. Whenever nodes change their dimensions, a change of type "dimensions" gets fired:
const onNodesChange = useCallback((changes) => {
setNodes((nds) => {
const nextNodes = applyNodeChanges(changes, nds);
if (changes.some((change) => change.type === 'dimension')) {
// layout nodes
}
return nextNodes;
});
}, []);
from xyflow.
Thank you for the super fast answer!
Unfortunately the div inside the node is being changed, but I do not get any changes (except for selected change).
I also do not understand how to trigger the layout change.
Thanks again!
from xyflow.
You don't have to do anything. React Flow adds a resize observer to every node and should send the changes automatically. It's fine to resize an inner div, but it's important that the outer node doesn't have a fixed width or height and also changes it's size based on the content.
Are you using v11 or v12? Could you send a codesandbox or repo we could check out?
from xyflow.
Thank you, I think I understand what is happening.
I am using dagre to position the nodes and edges, and this indeed has a fixed height and width as per the example from the docs:
const dagreGraph = new dagre.graphlib.Graph()
dagreGraph.setDefaultEdgeLabel(() => ({}))
const nodeWidth = 250
const nodeHeight = 60
const getLayoutedElements = (nodes: any, edges: any, direction = 'TB') => {
dagreGraph.setGraph({ rankdir: direction })
nodes.forEach((node: any) => {
dagreGraph.setNode(node.id, { width: nodeWidth, height: nodeHeight })
})
edges.forEach((edge: any) => {
dagreGraph.setEdge(edge.source, edge.target)
})
dagre.layout(dagreGraph)
nodes.forEach((node: any) => {
const nodeWithPosition = dagreGraph.node(node.id)
node.targetPosition = 'top'
node.sourcePosition = 'bottom'
node.position = {
x: nodeWithPosition.x - nodeWidth / 2,
y: nodeWithPosition.y - nodeHeight / 2,
}
return node
})
return { nodes, edges }
}
Is it possible to let dagre "decide" about the height and width of the nodes instead of hardcoding them?
Thanks! :)
from xyflow.
Related Issues (20)
- Rotatable parent node HOT 5
- Resizing rotated node HOT 2
- Adding multiple Buttons in on the node and Multiple trees in same react flow canvas
- SvelteFlow `on:nodedrag`, `on:nodedragstart`, and `on:nodedragstop` not emitted when multiple nodes selected HOT 3
- [Svelte Flow] connectingto doesn't behave the same as connecting used to HOT 4
- Excalidraw's canvas not usable with ReactFlow component HOT 2
- Check if we can use static width/height for the computed values as well HOT 1
- Multi Select functionality using shift key not working properly
- React Flow v12: Cancel Connection does not work anymore HOT 1
- Update all example apps to v12
- Intersection helpers: used pass node values HOT 2
- `React.forwardRef` type definition is broken in `@xyflow/react: 12.0.0-next.11` HOT 2
- Reactflow holding Shift key acts werid and doesn't get released when we open context menu(browser's) HOT 2
- Support JSON Canvas HOT 1
- [Svelte Flow] contenteditable span/div are not editable HOT 2
- Node height dynamic HOT 2
- Unexpected connection behaviour when using a updateNodeInternals HOT 2
- GetConnectedNodes HOT 1
- Incorrect copy-paste example key handlers HOT 1
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 xyflow.