add check for nodes that need to move with edges even if they start behind the original node

This commit is contained in:
Gavin Nishizawa 2023-07-28 02:10:27 -07:00 committed by Alexander Wang
parent 120811e687
commit 189edf552a
No known key found for this signature in database
GPG key ID: D89FA31966BDBECE

View file

@ -856,6 +856,7 @@ func shiftUp(g *d2graph.Graph, start, distance float64, isHorizontal bool) {
func shiftReachableDown(g *d2graph.Graph, obj *d2graph.Object, start, distance float64, isHorizontal, isMargin bool) map[*d2graph.Object]struct{} { func shiftReachableDown(g *d2graph.Graph, obj *d2graph.Object, start, distance float64, isHorizontal, isMargin bool) map[*d2graph.Object]struct{} {
q := []*d2graph.Object{obj} q := []*d2graph.Object{obj}
needsMove := make(map[*d2graph.Object]struct{})
seen := make(map[*d2graph.Object]struct{}) seen := make(map[*d2graph.Object]struct{})
shifted := make(map[*d2graph.Object]struct{}) shifted := make(map[*d2graph.Object]struct{})
shiftedEdges := make(map[*d2graph.Edge]struct{}) shiftedEdges := make(map[*d2graph.Edge]struct{})
@ -915,23 +916,27 @@ func shiftReachableDown(g *d2graph.Graph, obj *d2graph.Object, start, distance f
} }
// skip other objects behind start // skip other objects behind start
if curr != obj { if curr != obj {
if isHorizontal { if _, in := needsMove[curr]; !in {
if curr.TopLeft.X < start { if isHorizontal {
continue if curr.TopLeft.X < start {
} continue
} else { }
if curr.TopLeft.Y < start { } else {
continue if curr.TopLeft.Y < start {
continue
}
} }
} }
} }
if isHorizontal { if isHorizontal {
shift := false _, shift := needsMove[curr]
if !isMargin { if !shift {
shift = start < curr.TopLeft.X if !isMargin {
} else { shift = start < curr.TopLeft.X
shift = start <= curr.TopLeft.X } else {
shift = start <= curr.TopLeft.X
}
} }
if shift { if shift {
@ -939,11 +944,13 @@ func shiftReachableDown(g *d2graph.Graph, obj *d2graph.Object, start, distance f
shifted[curr] = struct{}{} shifted[curr] = struct{}{}
} }
} else { } else {
shift := false _, shift := needsMove[curr]
if !isMargin { if !shift {
shift = start < curr.TopLeft.Y if !isMargin {
} else { shift = start < curr.TopLeft.Y
shift = start <= curr.TopLeft.Y } else {
shift = start <= curr.TopLeft.Y
}
} }
if shift { if shift {
curr.TopLeft.Y += distance curr.TopLeft.Y += distance
@ -977,6 +984,18 @@ func shiftReachableDown(g *d2graph.Graph, obj *d2graph.Object, start, distance f
shiftedEdges[e] = struct{}{} shiftedEdges[e] = struct{}{}
continue continue
} else if e.Src == curr { } else if e.Src == curr {
last := e.Route[len(e.Route)-1]
if isHorizontal {
if start <= last.X &&
e.Dst.TopLeft.X+e.Dst.Width < last.X+distance {
needsMove[e.Dst] = struct{}{}
}
} else {
if start <= last.Y &&
e.Dst.TopLeft.Y+e.Dst.Height < last.Y+distance {
needsMove[e.Dst] = struct{}{}
}
}
queue(e.Dst) queue(e.Dst)
if isHorizontal { if isHorizontal {
for _, p := range e.Route { for _, p := range e.Route {
@ -993,6 +1012,18 @@ func shiftReachableDown(g *d2graph.Graph, obj *d2graph.Object, start, distance f
} }
shiftedEdges[e] = struct{}{} shiftedEdges[e] = struct{}{}
} else if e.Dst == curr { } else if e.Dst == curr {
first := e.Route[0]
if isHorizontal {
if start <= first.X &&
e.Src.TopLeft.X+e.Src.Width < first.X+distance {
needsMove[e.Src] = struct{}{}
}
} else {
if start <= first.Y &&
e.Src.TopLeft.Y+e.Src.Height < first.Y+distance {
needsMove[e.Src] = struct{}{}
}
}
queue(e.Src) queue(e.Src)
if isHorizontal { if isHorizontal {
for _, p := range e.Route { for _, p := range e.Route {