check shape type

This commit is contained in:
Gavin Nishizawa 2023-06-08 14:00:32 -07:00
parent f9a55e6acd
commit fe52f1a659
No known key found for this signature in database
GPG key ID: AE3B177777CE55CD

View file

@ -494,7 +494,11 @@ func Layout(ctx context.Context, g *d2graph.Graph, opts *ConfigurableOpts) (err
// if an edge runs into an outside label, stop the edge at the label instead
overlapsOutsideLabel := false
if edge.Src.Label.Value != "" && !srcShape.Is(shape.TEXT_TYPE) {
switch srcShape.GetType() {
case shape.TEXT_TYPE, shape.TABLE_TYPE, shape.CLASS_TYPE, shape.CODE_TYPE:
// labels aren't actually labels
default:
if edge.Src.Label.Value != "" {
// assumes LabelPosition, LabelWidth, LabelHeight are all set if there is a label
labelPosition := label.Position(*edge.Src.LabelPosition)
if labelPosition.IsOutside() {
@ -520,13 +524,18 @@ func Layout(ctx context.Context, g *d2graph.Graph, opts *ConfigurableOpts) (err
}
}
}
}
if !overlapsOutsideLabel {
// trace the edge to the specific shape's border
points[startIndex] = shape.TraceToShapeBorder(srcShape, start, points[startIndex+1])
}
overlapsOutsideLabel = false
if edge.Dst.Label.Value != "" && !dstShape.Is(shape.TEXT_TYPE) {
switch dstShape.GetType() {
case shape.TEXT_TYPE, shape.TABLE_TYPE, shape.CLASS_TYPE, shape.CODE_TYPE:
// labels aren't actually labels
default:
if edge.Dst.Label.Value != "" {
// assumes LabelPosition, LabelWidth, LabelHeight are all set if there is a label
labelPosition := label.Position(*edge.Dst.LabelPosition)
if labelPosition.IsOutside() {
@ -552,6 +561,7 @@ func Layout(ctx context.Context, g *d2graph.Graph, opts *ConfigurableOpts) (err
}
}
}
}
if !overlapsOutsideLabel {
points[endIndex] = shape.TraceToShapeBorder(dstShape, end, points[endIndex-1])
}