I'm trying to write a block based editor (in the s...
# thinking-together
a
I'm trying to write a block based editor (in the style of unreal blueprints and its ilk), but I don't want to let users move nodes freely. I have an algorithm I'm fairly happy with to position the nodes, and now I need to draw edges between them. I'm fairly certain this is NP hard, but that circuit board designers deal with this a lot and have some pretty solid algorithms to do it - https://en.wikipedia.org/wiki/Routing_(electronic_design_automation). Is anyone aware of general purpose libraries that are able to do this?
i
What part of this is potentially NP Hard? Working out optimal routes for the wires? What sort of goals do you have in mind? Minimizing crossing? Minimizing distance? The constraints on physical PCBs are very different from the constraints on graphical interfaces.
Also — blueprints is what I'd call a "patcher" or "node-and-wire" editor. I'd use the term "block-based" to describe something like Scratch. Hopefully that helps your search.
Also — do you have any sketches or references for what you'd like the result to look like? I might be able to point to approaches people have used in the past.
a
My goal is to hybridize a few tried-and-true styles of visual programming. I'm starting simple with something in the ballpark of patch based or block based programming, although I'm not being very disciplined about fitting myself into an existing category. Attached is a mock up I've been using as reference material for the last few weeks. My plan is to draw the entire layout, then progressively replace variable references with arrows. I don't want the arrows to ever cross. The idea is to use a jump if two lines would ever have to cross, like you see with 'constant z' and 'ref z' (although its not a realistic example because you could easily draw a line to replace the ref).
❤️ 1
I think drawing any single arrow is easy (it should just be pathfinding), but drawing the arrows in aggregate can become hard or impossible as they begin to cut each other off. Potentially being able to re-order blocks to prevent wires from overlapping also introduces a feedback loop between drawing wires and laying out blocks that smells tricky. By allows 'ref's I always give myself an out, but I'd rather show as many arrows as possible, for clarity's sake.
i
Yeah, this sounds amenable to a progressive refinement / iterative approximation approach. You could even make it somewhat interactive, where the programmer can put edges roughly where they want them, and then the system can sort of tidy up the layout. Of course, with these sorts of approaches, you usually have to give up determinism, and naive implementations can be quite slow. You can probably do better than NP, though, since you can take advantage of spatial locality, just like collision detection systems in games.
(I'm personally of the total opposite opinion — that the programmer should have total manual control over the layout of their graph — so I don't have a good collection of references for ways that people have handled auto-layout. Others here might.)
a
I've been thinking of formatting like linting in a text based langauge, so what you're saying makes total sense to me. In addition to locality, I'm hoping good code hygiene will encourage fairly clean wires.
👍 1
My dream is to support pluggable editors so users can view each block in their program in a different way. So, you could have most of your code automatically laid out, but the inside of your loop manually laid out or in a text editor. The dream is that each library would provide an editor that made sense for its contents. So, if you make a spreadsheet library, you would provide an editor that lets you manipulate the content of the spreadsheet, and if you write a GUI library, you provide a wysiwig widget editor. I though this editor was a fun place to start, though.
🍰 1
Oh! I forgot to ask, what is it that you like about manually laying out patch based code? Do you have a particular example of an environment where that's a satisfying experience?
i
I'm used to graphics programs (2d and 3d), video editors, DAWs, and other environments where the arrangement of elements has an effect on the outcome. When it comes to code, I also prefer laying out my own code, rather than using a linter. I dislike the auto-layout feature of Max/MSP (though I think they could do a ton to improve their GUI regardless).
c
If you’re working in web frontend, https://github.com/projectstorm/react-diagrams may simplify things a bit for you
This is a pivot from your original ask, but there’s also a generic JS lib for making things that look like scratch, the insides may give you some ideas about “fill in the blanks” programming: https://developers.google.com/blockly
w
@Aleks when it comes to human-scale automatic things (like layout), the computational complexity is never as hard as the finesse of finding the aesthetically right thing to optimize.
🍰 1
g
@Aleks to add to @wtaysom’s point, id also love to see a more dynamic approach to node and wire diagrams: why not float the original declaration of z next to ref z when you’re hovering the cursor over it, for example. i think node and wire works great for getting started, but i’m often disappointed by tools that use it but go no further with affordances and basically recreate an architecture diagram on a dead (even if zoomable, pannable, infinite) whiteboard
👍 1