breadboard-ai / breadboard

A library for prototyping generative AI applications.
Apache License 2.0
172 stars 23 forks source link

When a board with no visual properties is pasted into the visual editor, the default positioning is not used #2420

Open Mearman opened 3 months ago

Mearman commented 3 months ago

When pasting this board:

{
  "$schema": "https://raw.githubusercontent.com/breadboard-ai/breadboard/main/packages/schema/breadboard.schema.json",
  "nodes": [
    {
      "id": "input",
      "type": "input"
    },
    {
      "id": "output",
      "type": "output"
    }
  ],
  "edges": [
    {
      "from": "input",
      "to": "output",
      "in": "input",
      "out": "output"
    }
  ]
}

Default node positioning is not used and produces this image

After Reset layout is used CleanShot 2024-07-04 at 10 32 41

paullewis commented 3 months ago

This one isn't so obvious in terms of a fix. When you paste in nodes we have to make some assumptions about their layout, specifically that they should cursor-relative. As such we have to traverse the x & y coordinates of the pasted items and then choose the left-most, we then make set that node to be where the cursor is, and finally set all other node x & y coordinates to be relative to it.

Pasting in nodes without visual metadata is akin to posting {x: 0, y: 0}, which means what we're doing is somewhat Working As Intended. For graphs generated by the API we may want to run Dagre or something as part of the serialization process, but I don't think the right approach is to have the Editor do a layout pass because that would be very unpredictable.

paullewis commented 3 months ago

To clarify the last sentence, if you paste in a load of nodes then run layout, Dagre is likely to pick a "shape" for the graph you didn't necessarily anticipate. This is especially true if there are nodes already in place in the graph, and which you may not want to have moved.