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

Is it possible to combine multiple subnodes into a fat node? #32

Closed
waterlens opened this issue May 12, 2024 · 2 comments
Closed

Is it possible to combine multiple subnodes into a fat node? #32

waterlens opened this issue May 12, 2024 · 2 comments

Comments

@waterlens
Copy link

I'm trying to draw a diagram similar to this one:
image
My plan is to regard it as separate 4 nodes which are close enough together.
However, I found it hard to specify the distance between nodes in fletcher because I cannot directly get the size of a node.
And I don't know if I can let all nodes share the same height automatically.
Is it possible to add support to such a diagram, through a new concept of fat nodes and subnodes in fletcher?

Currently, I can get a scribbled diagram using fletcher,
image
with this code:

#import "@preview/fletcher:0.4.4" as fletcher: diagram, node, edge, draw

#let debug = if false { 2 } else { 0 }

#let nodeshape(node, extrude, fradius: x => x + 3pt) = {
	let (w, h) = node.size.map(i => i/2 + extrude)
	draw.rect(
		(-w, -h), (+w, +h),
		radius: fradius(extrude),
	)
}

#let lnodeshape = nodeshape.with(fradius: extrude => (north-west: extrude + 3pt, south-west: extrude + 3pt))
#let mnodeshape = nodeshape.with(fradius: extrude => 0pt)
#let rnodeshape = nodeshape.with(fradius: extrude => (north-east: extrude + 3pt, south-east: extrude + 3pt))

#let mydiagram = diagram.with(
  debug: debug,
  spacing: (10mm, 5mm),
  node-stroke: 1pt,
  edge-stroke: 1pt,
  mark-scale: 60%
)

#let node0 = node((0, 0), `Left`, shape: lnodeshape)
#let node1 = node((0.63, 0), `Right`, shape: rnodeshape)

#mydiagram(
  node0,
  node1,
)
@Jollywatt
Copy link
Owner

Jollywatt commented May 12, 2024

You could try making the composite node one node with a table as content. This solution still requires you to manually position edges, but that's easier than manually joining nodes.

#import "@preview/fletcher:0.4.4" as fletcher: diagram, node, edge, draw

#let label = table(
  columns: (12mm, 4mm, 4mm, 4mm),
  `Node`, none, `4`, none,
  stroke: (x, y) => if 0 < x and x < 3 { (x: 1pt) },
)

#diagram(
  node-stroke: 1pt,
  edge-stroke: 1pt,
  mark-scale: 50%,
  node((0,0), label, inset: 0pt, corner-radius: 3pt),
  edge((0.09,0), (0,1), "*-straight", snap-to: ((99,99), auto)),
  edge((0.41,0), (1,1), "*-straight", snap-to: ((99,99), auto)),
  node((0,1), `Subnode`),
)

I've used snap-to to prevent the edges from snapping to the composite node. (Surprisingly, passing none to snap-to doesn'y work — I'll fix that — so I gave it coordinates of a nonexistent node instead.)

It would be really cool to support something like pinit for doing something like this more automatically, though.

@Jollywatt
Copy link
Owner

@waterlens I'm going to assume that the table-in-a-node trick worked fine, so that we don't need to add a new kind of 'fat' node or 'subnode' :)

@Jollywatt Jollywatt closed this as not planned Won't fix, can't repro, duplicate, stale May 22, 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

2 participants