Skip to content

Conversation

joeyballentine
Copy link
Member

@joeyballentine joeyballentine commented Feb 5, 2024

image

The implementation actually ended up being quite simple. I added a new node type that is secretly just a passthrough node with special styling. This node type is not manually connectable but rather is entirely controlled by us managing the edges going between it and the actual nodes.

This means that everything just works with it. There's a tad bit of jankiness with the node-merge (hold alt and connect) feature since these lines aren't bezier -- but I would prefer to just fix that in a separate PR as it works well enough still.

The breakpoints can be added or removed via context menu:
image
image

When a breakpoint is removed, an edge fills its place. When a breakpoint is added, it creates two new edges.

If an edge is deleted, all edges and breakpoints along what visually appears as the single edge will be removed. The way I made this happen was I jut made the BreakPoint component handle deleting itself if at any point in time its missing an edge, as a breakpoint can't just exist on its own. Perhaps in the future we could make it so breakpoints can be on their own, but I think this is good enough for a V1, and it can be improved upon later.

Oh yeah, and since they're just nodes, it works with the auto-layout feature as well.

image

Fast follows:

  • Improving the alt-drag-to-connect feature with this
  • Making the edges out and in to actual nodes be half-bezier (if that's even possible)

Longer-term followups

  • allowing breakpoints to stand on their own and be connectable from them

Closes #2420

@RunDevelopment
Copy link
Member

Very cool. It's very clever to use pass through nodes. I haven't look at the code too deeply yet, so I'll start with bugs and suggestions:

  1. Added and removing breakpoints is a pain. I would suggest that Alt+Click (or Ctrl+Click or similar) on an edge adds a breakpoint there. Double-clicking on a breakpoint could remove it, just like double-clicking an edge removes it.
  2. Using straight lines looks kinda bad compared to our smooth edges.
  3. The hit box for breakpoints is small and inconsistent. It's sometimes very difficult to select breakpoints because their hitbox is under the hitbox of connected edges. So I would suggest increasing the size of the hitbox of breakpoints and keeping breakpoints above connected edges at all times.
  4. When the size of a breakpoint increases on hover, the center of the breakpoint slightly shifts, which causes connected edges to move slightly.

@joeyballentine
Copy link
Member Author

I would suggest that Alt+Click (or Ctrl+Click or similar)

Sure, we should just still leave the context menu though so this doesn't become a feature nobody is ever aware of like the Alt drag one

Using straight lines looks kinda bad compared to our smooth edges.

You should have seen it with the smooth edges, it looked a whole lot worse. I think the ideal thing would be for it to be curved coming in and out of the handles still, but straight to and a from breakpoints. I'm just not sure how to make it so that an edge is half bezier half straight

keeping breakpoints above connected edges at all times.

Honestly this is just kinda an issue with react flow that I have no idea how to solve without re-implementong that complex custom sorting algo we had, and even then we still had this exact issue where edges would be over the nodes

the center of the breakpoint slightly shifts,

I'll try to fix this 👍

@RunDevelopment
Copy link
Member

Sure, we should just still leave the context menu

Definetly. On that note: we should probably show the short cuts for options in our context menus.

Honestly this is just kinda an issue with react flow that I have no idea how to solve without re-implementong that complex custom sorting algo we had, and even then we still had this exact issue where edges would be over the nodes

Edges over breakpoints is a huge issue though. Two unfortunately positioned edges can cover almost the entire hitbox of a breakpoint, making it almost unusable. We need a solution for this.

@joeyballentine
Copy link
Member Author

We need a solution for this.

In my opinion to fix this we need to PR react flow and adjust the default sorting logic so that edges don't ever get hoisted over the nodes they're connecting to. Like clamp them at the node's zIndex - 1 max.

That doesn't fix the issue of overlapping separate edges, but that's an entirely different problem that I don't actually think is solvable personally

@joeyballentine
Copy link
Member Author

I believe I have fixed all of your concerns. Please try it out again and let me know if there's anything else I should change

@RunDevelopment
Copy link
Member

RunDevelopment commented Feb 6, 2024

Thank you Joey! I really like the half-smooth edges.

About the overlapping hitboxes, I think we could largely fix this by making edges not go into break points as much. They currently go into the center of the break point. If we make edges stop at the perimeter of our breakpoints, then we can minimize the hitbox overlap. (First image is a screenshot, second image visualizes the hitbox of the selected edge.)

image image

I also found 2 other minor things:

  1. Breakpoints aren't well-aligned with the grid when snapped to it. It seems like they are aligned to the top-left corner of the breakpoint instead of the center. This causes them to be weirdly off-grid (see screenshot above). I think breakpoints should be snapped such that they land right on top of these little dots in the background.
  2. Straight lines aren't centered correctly in the X direction.
    image

@joeyballentine
Copy link
Member Author

Fixed both things
image
image

It still overlaps a tiny amount, but it doesnt seem to interfere with use.

@RunDevelopment
Copy link
Member

Very nice!

The only remaining issue is the weird alignment of breakpoints when snapped to grid.

@joeyballentine
Copy link
Member Author

I think I'd be able to make it so breakpoints are snapped at their position minus their radius, but I fear that that will cause some compounding issue where each render will just offset them more and more...

As for being "weirdly off grid", snapping to grid does not guarantee that the dots in the background align with the nodes at all. Never has, unless you pick a specific value that happens to line up with the dots.

@RunDevelopment
Copy link
Member

I fear that that will cause some compounding issue where each render will just offset them more and more...

This shouldn't be an issue.

Never has, unless you pick a specific value that happens to line up with the dots.

That's why I changed the default snap to grid amount to 16 in #1445. This ensures that things line up with the grid. So things line up by default.

@joeyballentine
Copy link
Member Author

Ok, I will try to align those to center

@joeyballentine
Copy link
Member Author

image

@joeyballentine joeyballentine merged commit 80b79bf into main Feb 11, 2024
@joeyballentine joeyballentine deleted the breakpoints branch February 11, 2024 23:07
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

Successfully merging this pull request may close these issues.

Reroute edges for organizing nodes
2 participants