Closed PanieriLorenzo closed 5 months ago
I managed to do it using the render function, but it's still a bit of a hassle. Essentially just made a bounding box and the nodes in said box transparent.
It's worth mentioning that you can get around this by dividing the coordinates by the node's span, so that in the quantum circuit example the y-coordinates are all -0.33, 0, +0.33 instead of -1, 0, +1. But that's kinda a hack.
Otherwise, I could maybe add:
fletcher.diagram
essentially the same as cetz.canvas
weight
attribute to nodes which adjusts its strength of influence on the grid layout, so that zero weight means the row/column sizes aren't affectedOpen to ideas:)
Seeing as my workaround is essentially what #5 describes, it sounds like a good idea :) I used cetz in the render function to draw a box around nodes with a certain color, then I made those same nodes invisible. Perhaps if it was easier to add some sort of arbitrary tag on nodes, they could be grouped by these tags?
Something like:
// ...
node((0,0), "foo", tag: "my-tag"),
node((0,1), "bar", tag: "my-tag"),
group(by: "my-tag", /* etc */),
// ...
Perhaps if it was easier to add some sort of arbitrary tag on nodes, they could be grouped by these tags?
You're in luck - version 0.4.3 introduced node names, which don't have to be unique. Of course, that only works if you weren't already giving them other names.
And I agree - since this kind of solution has come up twice now, I think it should be built in!
Here's an example:
that's perfect, makes it much more readable, thanks!
On the main branch, you can now do this:
#diagram(
node-stroke: .7pt,
edge-stroke: .7pt,
spacing: 10pt,
node((0,1), [volume]),
node((0,2), [gain]),
node((0,3), [fine]),
edge((0,1), "r", "->", snap-to: (auto, <bar>)),
edge((0,2), "r", "->", snap-to: (auto, <bar>)),
edge((0,3), "r", "->", snap-to: (auto, <bar>)),
// a node that encloses/spans multiple grid points,
node($Sigma$, enclose: ((1,1), (1,3)), inset: 10pt, name: <bar>),
edge((1,1), "r,u", "->", snap-to: (<bar>, auto)),
node((2,0), $ times $, radius: 8pt),
)
…to get this:
Future things to consider:
snap-to
, but that’s a tiny bit annoying.amazing thanks!
I would like to draw nodes that can span multiple grid cells. When I change the size of a node, it makes the cells bigger rather than spanning multiple cells. I get that this behavior makes sense in a lot of cases, but sometimes I wish I could override this behavior somehow.
My specific use-case is drawing block diagrams for DSP algorithms. I sometimes have blocks with a lot of inputs and would like to draw them as parallel arrows left-to-right, like parallel "lanes", entering into a single blocks spanning multiple "lanes".
The Typst package Quill can do something similar, but it's specifically for drawing quantum circuits, and doesn't really fit my use case. Here's a diagram similar to what I'm thinking of, from Quill's docs: