d2 icon indicating copy to clipboard operation
d2 copied to clipboard

option to add bridges/arcs to crossings/intersections

Open alixander opened this issue 1 year ago • 8 comments

Screenshot 2024-05-03 at 9 15 45 AM

can be a configuration for those who want it. should be relatively simple to add

alixander avatar May 03 '24 15:05 alixander

@alixander Hello ! I am interested in this issue. If it's okay, can I solve it?

H0onnn avatar May 06 '24 13:05 H0onnn

@H0onnn Yes certainly!

Some pointers:

  1. I would add intersection-bridge as a boolean to d2-configs: https://github.com/terrastruct/d2/blob/7269d3000feeb8745f3952edb2edea3048742590/d2compiler/compile.go#L1394
  2. Add a visual e2e test that has a crossing to https://github.com/terrastruct/d2/blob/master/e2etests/testdata/txtar.txt . Grid diagrams are one way to trigger it: https://play.d2lang.com/?script=Si_KTNFNzs8pzc0rtlIw4krkSuJK5krh4kpU0LVTSOFKBlFJXIAAAAD__w%3D%3D& . After you add this test, you can keep running TA=1 ./ci/test.sh ./e2etests -run TestE2E/txtar/your-test-name -v to see changes and keep opening the new svg to see what it looks like.
  3. When the diagram is being exported, add logic to add a bridge: true field to connections which should have a bridge rendered: https://github.com/terrastruct/d2/blob/master/d2exporter/export.go . Note that this function which detects intersections may be useful: https://github.com/terrastruct/d2/blob/7269d3000feeb8745f3952edb2edea3048742590/lib/geo/segment.go#L41 .
  4. When you render connections, for those that have a bridge: true field, you'll want to actually draw the little bridge at the intersection. This will probably be the hardest part, since you'll have to calculate svg paths. https://github.com/terrastruct/d2/blob/7269d3000feeb8745f3952edb2edea3048742590/d2renderers/d2svg/d2svg.go#L497

Here to answer any questions as you go. If you decide you're no longer interested (no worries), just un-assign yourself.

alixander avatar May 06 '24 23:05 alixander

A test with orthogonal edges: https://play.d2lang.com/?script=XMxBCoMwEIXh_TvFw6VgELopWfQu0YzOQKjFBESKdy9Nu8pq5n2Lf04hZ8meb5BqMcrz95MpTJI8u66uXM4kbnuF2crpOYK8cGHdLQ77dmTPGxBc7fl_CRPmRiKkkQVrIwprBL07LBb1vI_onYqtWurAxOFBRfyeBZ8AAAD__w%3D%3D&

Probably worth adding both to make sure the arc looks good both diagonally and orthogonally

alixander avatar May 06 '24 23:05 alixander

Thank you for your kind response ! I will keep this in mind as I proceed with the work.

H0onnn avatar May 07 '24 03:05 H0onnn

Hi @H0onnn just checking in to see if you're still pursuing this

alixander avatar May 23 '24 18:05 alixander

@alixander Sorry, I'm not good at it :(

H0onnn avatar May 27 '24 00:05 H0onnn

Hey @alixander , interested in working on this, added the test in txtar.txt which generated svg in testdata/txtar. Added the boolean value in Config and changed compileConfig. If its not urgent, can i work on this ?

briheet avatar May 27 '24 11:05 briheet

@H0onnn No worries, thanks for trying!

@briheet Go for it!

alixander avatar May 27 '24 21:05 alixander

Image

i quite like just an empty gap too

alixander avatar Mar 27 '25 18:03 alixander

I'm inclined to just make the empty gap the default. Will see what comes up

alixander avatar Mar 28 '25 15:03 alixander

is here what happens when you show up with a big 'elk'.

Image Image

https://play.d2lang.com/?script=hMnNqsIwEMXx_XmKofsMly4umIXvcmYaS7Gk4EdBQt5d1E1Rg7vf_5yVp3Pshl7WP_3XXScFIkMffMmHaYzPFJl5W66XkPI45RQlzUeIVFQALCAM_ggr27TNUwGqh70plU3y62ovWpP-QW_SfpFvNHXgHgAA__8%3D&layout=elk&

bo-ku-ra avatar Mar 28 '25 23:03 bo-ku-ra

how about the idea of using opacity? Image

Image

bo-ku-ra avatar Mar 29 '25 00:03 bo-ku-ra