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

Examples are not beginner friendly #318

Open
Microwave-WYB opened this issue Aug 22, 2022 · 4 comments
Open

Examples are not beginner friendly #318

Microwave-WYB opened this issue Aug 22, 2022 · 4 comments
Assignees

Comments

@Microwave-WYB
Copy link

Describe the Bug

The demo code on https://reactflow.dev/docs/examples/overview/ does not run correctly on the latest version because of the missing width and height

Your Example Website or App

No response

Steps to Reproduce the Bug or Issue

  1. Initialize project with npm init react-app <app_name>
  2. Copy the code for App.js and initial-elements.js from https://reactflow.dev/docs/examples/overview/
  3. npm start

Expected behavior

What's shown in the feature overview

Screenshots or Videos

image
The app worked after adding the height
image

Platform

  • OS: Linux
  • Browser: Chrome/Firefox
  • Version: Chrome 103.0.5060.53 , Firefox 103.0.2

Additional context

No response

@moklick
Copy link
Member

moklick commented Aug 22, 2022

Screenshot 2022-08-22 at 13 54 05

There is a little button "Open in Codesandbox" in the bottom right corner that shows the whole code of that example: https://codesandbox.io/s/zbu68r?file=/App.js&from-sandpack=true. But you have a good point here. It's not very beginner friendly. We will keep this open for now.

@moklick moklick self-assigned this Aug 22, 2022
@moklick moklick changed the title Outdated Feature Overview Demo Examples are not beginner friendly Aug 24, 2022
@raarts
Copy link

raarts commented Sep 8, 2022

Adding to this: a page on coordinates (both pixel as well as react-flow) and width/height and how to retrieve them.
Both when inside a custom node as well a in a ReactFlow handler. I have spent a lot of time already with react-flow, and this keeps stopping me in my tracks.

(latest hurdles for me:

  • inside a custom node draghandler the mouse coordinates are easy to get, but getting the reactflow outer bounds is hard from there, even though width+height are in the store.
  • getting the coordinates of the custom node or width/height in pixels is challenging too).

A page dedicated to this subject with code examples would be very helpful for beginners.

Another possible help page might be on strategies for handling dynamic re-layouting (for example while an textarea field inside a custom node is edited, growing and growing to overlap other nodes).

Both typescript and plain JS code for all examples would also be great I think.

@bcakmakoglu
Copy link
Contributor

@raarts FYI: Custom Nodes receive xPos and yPos as props so you should be able to fetch the coordinates from there pretty easily :)

// props that get passed to a custom node
export interface NodeProps<T = any> {
  id: string;
  type: string;
  data: T;
  selected: boolean;
  isConnectable: boolean;
  xPos: number;
  yPos: number;
  dragging: boolean;
  zIndex: number;
  targetPosition?: Position;
  sourcePosition?: Position;
  dragHandle?: string;
}

@raarts
Copy link

raarts commented Sep 12, 2022

@bcakmakoglu Yes, I know, but I needed it in browser pixels so I gathered I needed something like a reverse project() function. There isn't one, so I ended up just copying it out of the reactflow sourcecode, and reverse it myself.

@moklick moklick transferred this issue from xyflow/xyflow Jan 16, 2024
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

4 participants