diff --git a/d2graph/d2graph.go b/d2graph/d2graph.go index 74d238b9c..ebeeb0816 100644 --- a/d2graph/d2graph.go +++ b/d2graph/d2graph.go @@ -90,12 +90,11 @@ type Object struct { LabelDimensions d2target.TextDimensions `json:"label_dimensions"` References []Reference `json:"references,omitempty"` - *geo.Box `json:"box,omitempty"` - LabelPosition *string `json:"labelPosition,omitempty"` - LabelWidth *int `json:"labelWidth,omitempty"` - LabelHeight *int `json:"labelHeight,omitempty"` - IconPosition *string `json:"iconPosition,omitempty"` - IsInsideNearContainer bool `json:"isInsideNearContainer,omitempty"` + *geo.Box `json:"box,omitempty"` + LabelPosition *string `json:"labelPosition,omitempty"` + LabelWidth *int `json:"labelWidth,omitempty"` + LabelHeight *int `json:"labelHeight,omitempty"` + IconPosition *string `json:"iconPosition,omitempty"` Class *d2target.Class `json:"class,omitempty"` SQLTable *d2target.SQLTable `json:"sql_table,omitempty"` @@ -969,6 +968,18 @@ func (obj *Object) GetDefaultSize(mtexts []*d2target.MText, ruler *textmeasure.R return &dims, nil } +func (obj *Object) IsInsideNearContainer() bool { + temp := obj + for temp != nil { + fmt.Println(temp.ID) + if temp.Attributes.NearKey != nil { + return true + } + temp = temp.Parent + } + return false +} + type Edge struct { Index int `json:"index"` diff --git a/d2layouts/d2near/layout.go b/d2layouts/d2near/layout.go index ad7fba3bd..a20e6bf3e 100644 --- a/d2layouts/d2near/layout.go +++ b/d2layouts/d2near/layout.go @@ -191,7 +191,6 @@ func pluckOutNearObjectAndEdges(g *d2graph.Graph, obj *d2graph.Object) (descenda if temp.AbsID() == obj.AbsID() { descendantsObjects = append(descendantsObjects, obj) g.Objects = append(g.Objects[:i], g.Objects[i+1:]...) - obj.IsInsideNearContainer = true for _, child := range obj.ChildrenArray { subObjects, subEdges := pluckOutNearObjectAndEdges(g, child) descendantsObjects = append(descendantsObjects, subObjects...) @@ -229,7 +228,7 @@ func boundingBox(g *d2graph.Graph) (tl, br *geo.Point) { y2 = math.Max(y2, obj.TopLeft.Y+obj.Height) } } else { - if obj.IsInsideNearContainer { + if obj.IsInsideNearContainer() { continue } x1 = math.Min(x1, obj.TopLeft.X)