fix: ignore objects inside near container when calc boundingBox
This commit is contained in:
parent
17c4851618
commit
df19311f9b
2 changed files with 10 additions and 8 deletions
|
|
@ -90,11 +90,12 @@ type Object struct {
|
||||||
LabelDimensions d2target.TextDimensions `json:"label_dimensions"`
|
LabelDimensions d2target.TextDimensions `json:"label_dimensions"`
|
||||||
References []Reference `json:"references,omitempty"`
|
References []Reference `json:"references,omitempty"`
|
||||||
|
|
||||||
*geo.Box `json:"box,omitempty"`
|
*geo.Box `json:"box,omitempty"`
|
||||||
LabelPosition *string `json:"labelPosition,omitempty"`
|
LabelPosition *string `json:"labelPosition,omitempty"`
|
||||||
LabelWidth *int `json:"labelWidth,omitempty"`
|
LabelWidth *int `json:"labelWidth,omitempty"`
|
||||||
LabelHeight *int `json:"labelHeight,omitempty"`
|
LabelHeight *int `json:"labelHeight,omitempty"`
|
||||||
IconPosition *string `json:"iconPosition,omitempty"`
|
IconPosition *string `json:"iconPosition,omitempty"`
|
||||||
|
IsInsideNearContainer bool `json:"isInsideNearContainer,omitempty"`
|
||||||
|
|
||||||
Class *d2target.Class `json:"class,omitempty"`
|
Class *d2target.Class `json:"class,omitempty"`
|
||||||
SQLTable *d2target.SQLTable `json:"sql_table,omitempty"`
|
SQLTable *d2target.SQLTable `json:"sql_table,omitempty"`
|
||||||
|
|
|
||||||
|
|
@ -128,9 +128,6 @@ func place(obj *d2graph.Object) (float64, float64) {
|
||||||
func calcLabelDimension(obj *d2graph.Object, x float64, y float64) (float64, float64) {
|
func calcLabelDimension(obj *d2graph.Object, x float64, y float64) (float64, float64) {
|
||||||
var position string
|
var position string
|
||||||
if obj.LabelPosition != nil {
|
if obj.LabelPosition != nil {
|
||||||
if strings.Contains(*obj.LabelPosition, "INSIDE") {
|
|
||||||
return x, y
|
|
||||||
}
|
|
||||||
if strings.Contains(*obj.LabelPosition, "_TOP_") {
|
if strings.Contains(*obj.LabelPosition, "_TOP_") {
|
||||||
position = "TOP"
|
position = "TOP"
|
||||||
} else if strings.Contains(*obj.LabelPosition, "_LEFT_") {
|
} else if strings.Contains(*obj.LabelPosition, "_LEFT_") {
|
||||||
|
|
@ -211,6 +208,7 @@ func pluckOutNearObjectAndEdges(g *d2graph.Graph, obj *d2graph.Object) (descenda
|
||||||
if temp.AbsID() == obj.AbsID() {
|
if temp.AbsID() == obj.AbsID() {
|
||||||
descendantsObjects = append(descendantsObjects, obj)
|
descendantsObjects = append(descendantsObjects, obj)
|
||||||
g.Objects = append(g.Objects[:i], g.Objects[i+1:]...)
|
g.Objects = append(g.Objects[:i], g.Objects[i+1:]...)
|
||||||
|
obj.IsInsideNearContainer = true
|
||||||
for _, child := range obj.ChildrenArray {
|
for _, child := range obj.ChildrenArray {
|
||||||
subObjects, subEdges := pluckOutNearObjectAndEdges(g, child)
|
subObjects, subEdges := pluckOutNearObjectAndEdges(g, child)
|
||||||
descendantsObjects = append(descendantsObjects, subObjects...)
|
descendantsObjects = append(descendantsObjects, subObjects...)
|
||||||
|
|
@ -248,6 +246,9 @@ func boundingBox(g *d2graph.Graph) (tl, br *geo.Point) {
|
||||||
y2 = math.Max(y2, obj.TopLeft.Y+obj.Height)
|
y2 = math.Max(y2, obj.TopLeft.Y+obj.Height)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if obj.IsInsideNearContainer {
|
||||||
|
continue
|
||||||
|
}
|
||||||
x1 = math.Min(x1, obj.TopLeft.X)
|
x1 = math.Min(x1, obj.TopLeft.X)
|
||||||
y1 = math.Min(y1, obj.TopLeft.Y)
|
y1 = math.Min(y1, obj.TopLeft.Y)
|
||||||
x2 = math.Max(x2, obj.TopLeft.X+obj.Width)
|
x2 = math.Max(x2, obj.TopLeft.X+obj.Width)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue