terrastruct / d2

D2 is a modern diagram scripting language that turns text to diagrams.
https://d2lang.com
Mozilla Public License 2.0
16.15k stars 400 forks source link

Can't create connection to container or objects with 'near' placement control set, results in "err: failed to compile: 153:3: cannot connect objects from within a container, that has near constant set, to objects outside that container" #1285

Open HariSekhon opened 1 year ago

HariSekhon commented 1 year ago

I've got a diagram of OpenTSDB on HBase and I've set near: bottom-center on the Hadoop/HBase cluster because it must be underneath the OpenTSDB cluster like so:

opentsdb_kubernetes_hbase

But I want to connect the OpenTSDB nodes to the HBase nodes, but any connection to the cluster or cluster nodes such as:

tsdb1 -> hadoop

results in this error:

err: failed to compile: 153:3: cannot connect objects from within a container, that has near constant set, to objects outside that container

If I comment out the near: bottom-center the the diagram comes out messed up with the Hadoop/HBase cluster being put out to the side (the very reason I came to D2 running away from Python diagrams module in the first place)

opentsdb_kubernetes_hbase

The full code is here in my Diagrams-as-Code github repo:

https://github.com/HariSekhon/Diagrams-as-Code/blob/master/opentsdb_kubernetes_hbase.d2

alixander commented 1 year ago

you can try the following together

  1. direction: down
  2. invisible connection between the two
  3. use ELK

(3) only because dagre's container-container connection isn't great and looks a little weird.

https://play.d2lang.com/?script=tJnfjpw2FMbveYojrXKXBcx_uIjUNEq3qtRVlfR6xILD0p0Bansmiap598oGsxg7hu2qV9mxv-_453PsMwxhLTviAv5xAESuCrgfcPf504f30Hdw976k2AHgOSqA9cNthTuGiQMg8lEAX5p_4tDuXLcCIn8enRcvgJEzdq6OM520cd0zxWT6E4AXsIBHxgZaeB7_RF2GCSkpI-eKuVV_8jCluGNteaRvgo9hnN-KCC69NA7AleM2bfftJRFrfHkTfBS2RZinjB7opTIHqtuyIeWJuqe243-cMBGh2lPjkemgUO8po16H2deePHn0UrlDJ4P3A-4YrR_U6K7XnsoGU09OLxyPDyXFUn6zwhGTbjmU1SN2e9LIOGL8cOyb_vC1ZY-HnlTlFPN1QQ5HfiRfHOqv82lou-ZWhCA94-1pDvJfMtx3A8Enry5ZyZecFl5kraz7fnhND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eI0ciOZIlR6pwpJIj3cORqhy6x8iRSo50yZEpHJnkyPZwZCqH7jFyZJIjW3LkCkcuOfI9HLnKoXuMHLnkyJcc_AF32cj8uZP5u1qZv-plusvczPy5m_kKzqqvPjfWfZ113Vr39tbn5qp0V6S2VzT3V7SrwaJVhzW4zDhzj0WBfKn7lIm3XMsXyOPLqem_iQrwnavzbwAAAP__&layout=elk&

HariSekhon commented 1 year ago

I had tried direction: down initially as one of the first things, but it didn't work, and nor does the invisible connection between the two, it's only ELK that makes it work when combined with both of the other two options.

I expect it's difficult to fix near and connections to work together?

That placement control given by near is such a key feature... as are connections... having to choose between the two or switch engines entirely seems like a pretty big limitation?

Thank you for the workaround though, I'll try that.

HariSekhon commented 1 year ago

So since raising this ticket, I switched all the icons to shape: image... which looked better, but when comined with --layout elk just now, results in the arrows not reaching the icons any more, look at the middle of this diagram, the two arrows around the OpenTSDB service go into thin air (probably because there would have been a big horizontal rectangle with a little icon in the middle without shape: image:

opentsdb_kubernetes_hbase

HariSekhon commented 1 year ago

This is the best I've been able to come up with by going back to the default dagre layout engine, using near placement control of the hadoop cluster and not using any connections between the tsdb objects or k8s container and the hadoop container, due to the original error message from this issue:

opentsdb_kubernetes_hbase

switchupcb commented 1 year ago

This issue could be fixed if the use of grid on the blank canvas is implemented (https://github.com/terrastruct/d2/issues/1145).

The user could specify:

# title, first node, kubernetes on prem, hadoop cluster on prem
grid-columns: 4

# prevent nodes from appearing on right or left side
grid-rows: 1

# Influence the diagram to declare nodes in a specific direction (from declaration order?)
direction: down

Documentation https://d2lang.com/tour/grid-diagrams/ https://d2lang.com/tour/layouts/#direction

HariSekhon commented 1 year ago

Hitting this issue with another diagram too:

https://github.com/terrastruct/d2/discussions/1416

HariSekhon commented 1 year ago

I think this placement control is a really big issue, it affects this one too:

https://github.com/terrastruct/d2/discussions/1300

AndreiPashkin commented 8 months ago

Very strange - this code doesn't work with v0.6.1 CLI, but does work in the Playground.

A: {
  near: top-center
  a
  b
}
B: {
  x
  y
}
A.a -> B.x

https://play.d2lang.com/?script=crRSqOZSUAA50UqhJL9ANzk1ryS1iEtBIZFLQSGJq5bLCaKigktBoZKrlstRL1FB107BSa-CCxAAAP__&

alixander commented 8 months ago

@AndreiPashkin oh Playground runs on latest master branch. I made an issue to note that in Playground so it's clear: https://github.com/terrastruct/d2-playground/issues/42

AndreiPashkin commented 8 months ago

@AndreiPashkin oh Playground runs on latest master branch. I made an issue to note that in Playground so it's clear: terrastruct/d2-playground#42

Okay, my sanity is restored.