diff --git a/d2compiler/compile.go b/d2compiler/compile.go index 34cb7567f..0af1f26b6 100644 --- a/d2compiler/compile.go +++ b/d2compiler/compile.go @@ -763,10 +763,10 @@ func (c *compiler) validateNear(g *d2graph.Graph) { var isSrcNearConst, isDstNearConst bool - if srcNearContainer != nil { + if srcNearContainer != nil && srcNearContainer != edge.Src { _, isSrcNearConst = d2graph.NearConstants[d2graph.Key(srcNearContainer.Attributes.NearKey)[0]] } - if dstNearContainer != nil { + if dstNearContainer != nil && dstNearContainer != edge.Dst { _, isDstNearConst = d2graph.NearConstants[d2graph.Key(dstNearContainer.Attributes.NearKey)[0]] } diff --git a/d2graph/d2graph.go b/d2graph/d2graph.go index 0f3df5683..5f966ddfc 100644 --- a/d2graph/d2graph.go +++ b/d2graph/d2graph.go @@ -969,13 +969,11 @@ func (obj *Object) GetDefaultSize(mtexts []*d2target.MText, ruler *textmeasure.R } func (obj *Object) OuterNearContainer() *Object { - temp := obj - for temp != nil { - // find outer near container that isn't itself - if temp.Attributes.NearKey != nil && temp != obj { - return temp + for obj != nil { + if obj.Attributes.NearKey != nil { + return obj } - temp = temp.Parent + obj = obj.Parent } return nil }