question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Layout example with dynamic width and height values

See original GitHub issue

Hello,

first of all, thank you for creating this library! This is by far the best library I’ve seen for creating interactive graphs. 😄

In the Layout-example (https://reactflow.dev/examples/layouting/) the widths and heights are hardcoded. The comment says that it is possible to access the real widths and heights using const nodes = useStoreState(state => state.nodes)

However, this only works in a child element of ReactFlow, where the nodes can be accessed (if I understood it correctly). I.e. it is not possible to access state.nodes before the graph has been created.

My question would be how exactly can we apply the real widths and heights to the nodes when generating the graph? 😅

I’ve read #5 and I have tried to apply the code provided by @mymywang but could not get it to work at all 😅

From my understanding, state.nodes would only be accessible in a scenario like this one:

<ReactFlow elements={TheseAreTheNodesWeWantToAccess}>
     <ComponentToAccessStateNodes/>
<ReactFlow/

and in ComponentToAccessStateNodes it is possible to access state.nodes and then iterate over every node and get the widths and height using node.__rf.width and node.__rf.height. But by that point, the graph already has been generated with the predefined widths and heights (which are in turn needed to generate the graph in the first place?).

I’m sorry if this is a trivial question but I really don’t seem to figure out how to do this. If someone could provide a minimal working example, that would be really kind.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
jayanthbondicommented, Aug 1, 2022

Hi @BorisGiba , @moklick In my use case, I’ll be dynamically adding or deleting the nodes. So without any user intervention, how will I be able to do auto adjust my layout?

1reaction
moklickcommented, Mar 28, 2021

Thanks for the example code. Looks very nice 👌

Read more comments on GitHub >

github_iconTop Results From Across the Web

Height equal to dynamic width (CSS fluid layout) [duplicate]
I know this is an old question, but I encountered a similar problem that I did solve only with CSS. Here is my...
Read more >
How to set height equal to the dynamic width (CSS fluid layout ...
To set height equal to the dynamic width in JavaScript, you can try to run the following code −. Example. <!DOCTYPE html> <html>...
Read more >
Exploring the Complexities of Width and Height in CSS
The width and height of parent-child combinations get even more interesting when we look at other properties, such as padding and margin ....
Read more >
Setting Height And Width On Images Is Important Again
To prevent layout shifts and improve performance scores, we need to always set width and height attributes on our images.
Read more >
Telerik Web Forms Responsive Layout and Dynamic Height
A responsive RadTileList must be able to use to entire viewport width because the layout of the control changes in correlation to the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found