Proposal: label alignment
Current issues
- Semantics break when you have reverse direction. The code below, will output the label on the start (source) of the arrowhead, not the target. This happens because the code logic always sees the source as the left variable not the right.
bob <- alice: {
target-arrowhead: Lorem
}
- Semantics break on
<-->. There is nosourceortargetsemantically speaking - Semantics break on
--. There is nosourceortargetsemantically speaking
Proposal
Introduce a label keyword and a align keyword.
- label: The text that will be placed on the default spot/position unless told otherwise.
- align: Enum value of
left/right/middle. Whereleftis the left part of the equation (left variable),rightis the right variable and when it ismiddlethe text is placed on the middle part of the line.
Example
alice <-> bob: {
label: Lorem ipsum
align: right # the label is aligned on bob's side
}
ty for the clean issue and proposal!
i've added the bug tag for the issue reported where target is wrongly identified.
the label keyword already works. as for align, you'd run into the same problem. If alice and bob are vertically aligned, due to autolayout, what does align: right mean?
we should take target to mean the right-hand-side operand when the connections are bidirectional (-- or <->)
the label keyword already works. as for align, you'd run into the same problem. If alice and bob are vertically aligned, due to autolayout, what does align: right mean?
left and right are meant to be a reference to where Alice and Bob are positioned in the equation, not in the visual graphical space.
Example
alice -- bob
# alice is on the left
# bob is on the right
So essentially,
align: righthere would point tobobalign: leftwould point toalice
I'm also interested in being able to nudge/control the position of connection labels.
Two points:
- The title of this issue would be more clear if it mentioned "connection".
- I think the arrowhead and label considerations are separate issues.
@alixander Are there any mechanisms in d2 for coercing the position of a connection label? Sometimes even TALA does not make optimal label placement along connection lines. @exapsy's idea of specifying that a connection label should be closer to one of the two objects is interesting, although there are many other possible connection label position tweaks.
I notice that there is already label.near: someobj when applied to shapes. Maybe that should do something reasonable when applied to connections?
I'd also love to be able to put labels right at the head or tail of my edges. The left/right syntax is a great idea since it works for both directed and undirected edges. I hope this one is revisited some time soon!
Thanks, Darrick
Is there a way to put a label on the head and another label on the tail? E.g., "X 1 <--> * Y". EDIT: Found an example: https://d2lang.com/tour/connections/#arrowheads
align: righthere would point tobobalign: leftwould point toalice
Perhaps you can use keys instead: e.g., align: alice.