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

wip: Consider arrowhead for label position #1192

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

donglixiaoche
Copy link
Contributor

#793

consider testcase arrowhead_labels, before this pr, the result svg will be
image
because we didn't consider arrowhead for labelPosition, the position will be a little be downward along the rendering path

after this pr, srcAdj, dstAdj, srcArrowhead, dstArrowhead will have an effect on labelPostion
image

@donglixiaoche
Copy link
Contributor Author

donglixiaoche commented Apr 13, 2023

@alixander the logic of this pr focus on connection.GetLabelTopLeft

previously, we got labelTL base on connection.Route, but the real rendering path of connection may diff a little bit with connection.Route, due to the exist of stroke-width(of both edge and shape). and for now, connection.LabelPosition will always be INSIDE_MIDDLE_CENTER (am i right? do i miss something?) , so stroke-width won't effect the way we calc labelPosition

in this pr, we need to consider stroke-width and arrowhead for labelPosition, i think there may be two ways doing this:

  1. construct the real rendering route before we calc the labelPosition (give this up, more complicated than i thought)
  2. calc the real length we need walk through along connection.Route (currently used)

what do you think?

@alixander
Copy link
Collaborator

connection.LabelPosition will always be INSIDE_MIDDLE_CENTER (am i right? do i miss something?)

no, only for dagre and elk. TALA places it anywhere along the connection.

e.g. notice "turn into target" is closer to the destination

https://play.d2lang.com/?script=fJIxjoQwDEV7n-JfYCm2TLHNVnsMlA0QDSSRk4xAA3cfOSESEtJUfPnZ_l841oWcFP7kgxcBUbMNSWH__yYAWPH1g42AnQDt3WDHqPBbROZeXkaZA9JkFlPUoCAnLHruN5-rjA-T9ETAQQdRce6qnXiEnqPhs3wadWWnULMGz-nGB2HaL8HON1adPzTUPNLARn6QYaKa4jqkmqJWueZRSJkdrEse9UjU0HWxOhW1gsD4HOkdAAD__w%3D%3D&layout=tala&sketch=1&theme=302&

@donglixiaoche
Copy link
Contributor Author

donglixiaoche commented Apr 14, 2023

ohh, i see. don't know how TALA is integrated. i used to assume all my work is for dagre and elk engine. so i'd better to try construct target route and calc labelPosition base on that right? ( in my opinion, just add some adjustment should be ok)

and i want to ask is there any chance the rendering path may longer than the real route? now i see all the adjustment make it shorter

@alixander
Copy link
Collaborator

yeah actually i don't think you'd need to do anything for TALA. will take a look at this PR shortly


srcAdjDistance := geo.EuclideanDistance(srcAdj.X, srcAdj.Y, 0, 0) + srcArrowWidth
dstAdjDistance := geo.EuclideanDistance(dstAdj.X, dstAdj.Y, 0, 0) + dstArrowWidth
labelTL = connection.GetLabelTopLeft(srcAdjDistance, dstAdjDistance)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of updating GetLabelTopLeft, and GetPointOnRoute, I think it might be better to temporarily move the route start and end points to begin after the arrowheads (e.g. connection.Route[0].X += srcAdj.X) and then revert this after getting the label position on the route between arrowheads. This avoids the extra complexity in the GetPointOnRoute funcs.

Copy link
Contributor Author

@donglixiaoche donglixiaoche Apr 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to temporarily construct the route, we can't just add a start and end point to original route, but also we need to remove the extra points before and after, can this be done by calcing the distance along the route? what if the connection is a curve?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant just you could modify the first and last points in the route to start after the arrowheads. Similar to how we adjust them here to account for the arrowhead+shape stroke widths:

path = append(path, fmt.Sprintf("M %f %f",
route[0].X+srcAdj.X,
route[0].Y+srcAdj.Y,
))

after computing the label position on the adjusted route, apply the -adjustments to get the original back going forwards

you can compute the adjustment similar to this:

v := geo.NewVector(end.X-start.X, end.Y-start.Y)
return v.Unit().Multiply(-distance).ToPoint()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if there are multiple points between original point and new point? if so there would still be issue

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's true but there shouldn't be multiple points within the length of the arrowhead. It will be more robust to account for that though in case it does come up.

@alixander
Copy link
Collaborator

also @donglixiaoche just a heads up that @gavin-ts is working on a cousin issue of this, which is adjusting arrowhead labels (different from yours, but related). might be worth taking a look at his to see potential merge conflicts that i think will arise: #1207

@donglixiaoche
Copy link
Contributor Author

also @donglixiaoche just a heads up that @gavin-ts is working on a cousin issue of this, which is adjusting arrowhead labels (different from yours, but related). might be worth taking a look at his to see potential merge conflicts that i think will arise: #1207

copy, will try to figure out the a proper way to do it

@alixander
Copy link
Collaborator

@donglixiaoche sorry for the many merge conflicts here. whenever you want to move this forward and resolve those, feel free to ping me to take another look

@donglixiaoche donglixiaoche changed the title Consider arrowhead for label position wip: Consider arrowhead for label position May 16, 2023
@donglixiaoche donglixiaoche marked this pull request as draft May 16, 2023 18:55
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

Successfully merging this pull request may close these issues.

3 participants