terrastruct / d2

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

Near keyword does not work #279

Closed pleshevskiy closed 1 year ago

pleshevskiy commented 1 year ago

Seems like near keyword in text block does not work. And we have to reorder block manually, but reordering doesn't work too in complex examples. See below.

Simple

If we want to render text near to a block or group

a; b; c; d;

foo: |txt
bar biz baz
| {
  near: b
}

Expected

[a] [b] [c] [d]
   ↑ or↑
   `foo`

Actual

image

Workaround

We can reorder the text block and now it works as expected without near keyword.

a; b;

foo: |txt
bar biz baz
|

c; d;

image

Complex

if we want to render text near to a connected block or group

a -> e; b -> f;

foo: |txt
bar biz baz
| {
  near: b
}

c -> g; d -> h;

Expected

   `foo`
   ↓ or↓
[a] [b] [c] [d]
 ↓   ↓   ↓   ↓
[e] [f] [g] [h]

Actual

image

Misc

Tested on d2 versions 0.0.13 and latest e6c7d066164040098d294c00779a2248c402c864

alixander commented 1 year ago

it does not, sorry for the lack of clarity. i have it in the next release of d2-docs to document that:

https://github.com/terrastruct/d2-docs/pull/15/files#diff-d23c28129c5e819c092f20bfcbf291203169d455eabed54a3498779040e06b20R123

we'll add support for it probably in the release after

murphyke commented 1 year ago

Also, it seems near only "works" with top-level shapes. Otherwise, it gives a "failed to recompile" error and a panic dump, for example:

dog.flea
comment: |md
    parasite
| {
    near: dog.flea
}
alixander commented 1 year ago

documented