trace to outside labels
This commit is contained in:
parent
64f63d2201
commit
35fd624ead
1 changed files with 24 additions and 22 deletions
|
|
@ -495,14 +495,15 @@ func Layout(ctx context.Context, g *d2graph.Graph, opts *ConfigurableOpts) (err
|
|||
// trace the edge to the specific shape's border
|
||||
points[startIndex] = shape.TraceToShapeBorder(srcShape, start, points[startIndex+1])
|
||||
|
||||
// if an edge to a container runs into its label, stop the edge at the label instead
|
||||
overlapsContainerLabel := false
|
||||
if edge.Dst.IsContainer() && edge.Dst.Label.Value != "" && !dstShape.Is(shape.TEXT_TYPE) {
|
||||
// if an edge runs into an outside label, stop the edge at the label instead
|
||||
overlapsOutsideLabel := false
|
||||
if edge.Dst.Label.Value != "" && !dstShape.Is(shape.TEXT_TYPE) {
|
||||
// assumes LabelPosition, LabelWidth, LabelHeight are all set if there is a label
|
||||
labelPosition := label.Position(*edge.Dst.LabelPosition)
|
||||
if labelPosition.IsOutside() {
|
||||
labelWidth := float64(edge.Dst.LabelDimensions.Width)
|
||||
labelHeight := float64(edge.Dst.LabelDimensions.Height)
|
||||
labelTL := label.Position(*edge.Dst.LabelPosition).
|
||||
GetPointOnBox(edge.Dst.Box, label.PADDING, labelWidth, labelHeight)
|
||||
labelTL := labelPosition.GetPointOnBox(edge.Dst.Box, label.PADDING, labelWidth, labelHeight)
|
||||
|
||||
endingSegment := geo.Segment{Start: points[endIndex-1], End: points[endIndex]}
|
||||
labelBox := geo.NewBox(labelTL, labelWidth, labelHeight)
|
||||
|
|
@ -510,7 +511,7 @@ func Layout(ctx context.Context, g *d2graph.Graph, opts *ConfigurableOpts) (err
|
|||
labelBox.TopLeft.X -= label.PADDING
|
||||
labelBox.Width += 2 * label.PADDING
|
||||
if intersections := labelBox.Intersections(endingSegment); len(intersections) > 0 {
|
||||
overlapsContainerLabel = true
|
||||
overlapsOutsideLabel = true
|
||||
// move ending segment to label intersection point
|
||||
points[endIndex] = intersections[0]
|
||||
endingSegment.End = intersections[0]
|
||||
|
|
@ -521,7 +522,8 @@ func Layout(ctx context.Context, g *d2graph.Graph, opts *ConfigurableOpts) (err
|
|||
}
|
||||
}
|
||||
}
|
||||
if !overlapsContainerLabel {
|
||||
}
|
||||
if !overlapsOutsideLabel {
|
||||
points[endIndex] = shape.TraceToShapeBorder(dstShape, end, points[endIndex-1])
|
||||
}
|
||||
points = points[startIndex : endIndex+1]
|
||||
|
|
|
|||
Loading…
Reference in a new issue