terrastruct / TALA

A diagram layout engine designed specifically for software architecture diagrams
https://terrastruct.com/tala
Other
202 stars 4 forks source link

vertical ordering of containers #32

Closed uliw closed 1 year ago

uliw commented 1 year ago

Is it possible to get the surface ocean container on top of the deep ocean container? The following code results in a good layout, but since the top and bottom are reversed, it could be more physical. Is there a way to get in the 'correct' order?

Atmosphere -> Surface Ocean.Nitrogen Fixation: N2
Surface Ocean.Nitrogen Fixation -> Surface Ocean.Photosynthesis: NH4
Surface Ocean.Photosynthesis -> Deep Ocean.Nitrification: Org. N
Deep Ocean.Nitrification -> Deep Ocean.Denitrification/Anammox: NH3
Deep Ocean.Denitrification/Anammox -> Atmosphere: N2
Deep Ocean.Nitrification -> Surface Ocean.Photosynthesis: NH3
gavin-ts commented 1 year ago

you can try adjusting with the direction keyword, here is the layout with direction:up:

https://play.d2lang.com/?script=gge2lUJpAReXY0lufnFBRmpRqoKunUJwaVFaYnKqgn9yamKenl9mSVF-emqegltmRSJEi58RFwE1mMYEZOSX5BdX5pVkpBZnFlsp-HmYcOFTATLBJTW1AMmGzLTMZKgL_IvS9RT8uHApQNPskpqHLKvvmJeYm5tfAXKEMRdhdSDTECEE9j4-iwn525gLEAAA__8%3D&layout=tala&

d2

uliw commented 1 year ago

thx!

uliw commented 1 year ago

Here a variation on this problem. There is probably no way to decide algorythmically whether the photosynthesis box should be on top or on the side of the nitrogen fixation box (except that this solution would use less space). When I was thinking of a layout grammar (for another project), I though of having syntax along the following lines:

Ocean.Surface.Nitrogen Fixation -> Ocean.Surface.Photosynthesis: NH4: right

i.e. each connection would have an optional direction keyword. Is that a feature that could be considered in the future?

direction: up

# Atmosphere -> Ocean.Surface.Nitrogen Fixation: N2
Ocean.Surface.Nitrogen Fixation -> Ocean.Surface.Photosynthesis: NH4

Ocean.Surface.Photosynthesis -> Ocean.Deep.Nitrification: Org. N
Ocean.Deep.Nitrification -> Ocean.Deep.Denitrification/Anammox: NH3
# Ocean.Deep.Denitrification/Anammox -> Atmosphere: N2
Ocean.Deep.Nitrification -> Ocean.Surface.Photosynthesis: NH3
alixander commented 1 year ago

oh this is very interesting. with direction per container, we can't actually force everything to be to that direction. You just may have cycles, so it's just a hint.

However, direction per edge we can force.

What if there's a cycle though? E.g.

a -> b: { direction: right }
b -> c: { direction: right }
c -> a: { direction: right }

It wouldn't be possible to enforce this. This kind of thing feels hard to detect algorithmically, since there's 4 values here (top, left, right, bottom).

I suppose TALA can just search to try to satisfy the constraints, and if it can't, it returns an error that a layout could not be found while trying to satisfy a direction constraint. The downside is that the error msg lacks clear action. We can say exactly which constraint caused the failure, but it could be that changing a constraint somewhere else fixes things.

In any case, I really like this and we've done like 80% of the work towards this already.

uliw commented 1 year ago

hmmh, the error could simply state the name of last element that fails (output the box in red?) The user can then try to untangle the chain. This is not too different from getting weird output if there are typos in one of the box names.

alixander commented 1 year ago

you can now specify it precisely with positions:

https://play.d2lang.com/?script=hJJNCsIwEIX3c4p3AatYV1kIhSKuUsEThDJts2hSkggV8e4yIlgV210gX95PZorU-zh0HBirPc6X0JiaUdVsXKZtCr5lh4MdjcxFQW9pgfmVOXU--Xh1qeNoo4I-7miOEIWSeZg42MbWrwRVaDNo-gd8PS7ZTW_XhTN970cJkdMyJ2rvH3rWnzNe6p3TZ3GFGwHJDwobAmTz5HSnRwAAAP__&layout=tala&

alixander commented 1 year ago

the direction per connection idea is still worth exploring through, i'll close this and move that here: https://github.com/terrastruct/TALA/issues/35