Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do you set a default layout? #14

Closed
sroussey opened this issue Jan 26, 2024 · 7 comments
Closed

How do you set a default layout? #14

sroussey opened this issue Jan 26, 2024 · 7 comments

Comments

@sroussey
Copy link
Contributor

I've tried issuing the layout at various points, but i always run it too early as the nodes don't have a height yet.

Basically, I have altered the InputGroups story:

  1. Removed position information from the nodes
  2. Tried calling Dagre layout using useEffect and similar. The idea being to set a default layout if the nodes don't have positions.
@clarkmcc
Copy link
Owner

I see. My first reaction is that the layout method is probably not what you're looking for. It sounds like we should just pass the nodes through the layout engine if positions are missing before handing them off to ReactFlow. I haven't vetted the idea fully or determined what the API for this would look like, but conceptually would this solve your problem?

@sroussey
Copy link
Contributor Author

Problem is... you don't have height and width of the nodes yet, so it is difficult to layout.

@clarkmcc
Copy link
Owner

clarkmcc commented Jan 26, 2024

Got it. Then I think we can take advantage of useNodesInitialized to apply the default layout at the right time. This hook should let us hook into the process the moment the nodes dimensions are calculated.

It seems like if we apply a default layout, we'd want to apply it regardless of whether the nodes have positions or not. What if all but one node has a position? The layout engine doesn't let us have some fixed position nodes and then layout the rest around them (at least not as it is designed today).

Do you have any thoughts or opinions on the API for configuring a default layout? If not, I can take a stab at something that makes sense to me and you can take a look after that, or I'm also happy to accept a PR.

@sroussey
Copy link
Contributor Author

Not familiar enough yet. Maybe an option to give to the editor: <NodeGraphEditor defaultLayout={LayoutEngine.Dagre} ...>

@sroussey
Copy link
Contributor Author

I have a version working, though I just send the layout function itself instead LayoutEngine.Dagre

@clarkmcc
Copy link
Owner

Okay I'll take a stab at something. Send me what you did if you'd like and I'll see if it gets any juices flowing.

@sroussey
Copy link
Contributor Author

#15

This one is using your Enum for the layout.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants