shift whole edge down if horizontal between two non root nodes
This commit is contained in:
parent
357dda9815
commit
d7ad0f39a9
1 changed files with 22 additions and 22 deletions
|
|
@ -300,26 +300,9 @@ func Layout(ctx context.Context, g *d2graph.Graph, opts *ConfigurableOpts) (err
|
||||||
// If the edge is connected to two descendants that are about to be downshifted, their whole route gets downshifted
|
// If the edge is connected to two descendants that are about to be downshifted, their whole route gets downshifted
|
||||||
movedEdges := make(map[*d2graph.Edge]struct{})
|
movedEdges := make(map[*d2graph.Edge]struct{})
|
||||||
for _, e := range g.Edges {
|
for _, e := range g.Edges {
|
||||||
currSrc := e.Src
|
isSrcDesc := e.Src.IsDescendantOf(obj)
|
||||||
currDst := e.Dst
|
isDstDesc := e.Dst.IsDescendantOf(obj)
|
||||||
|
|
||||||
isSrcDesc := false
|
|
||||||
isDstDesc := false
|
|
||||||
|
|
||||||
for currSrc != nil {
|
|
||||||
if currSrc == obj {
|
|
||||||
isSrcDesc = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
currSrc = currSrc.Parent
|
|
||||||
}
|
|
||||||
for currDst != nil {
|
|
||||||
if currDst == obj {
|
|
||||||
isDstDesc = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
currDst = currDst.Parent
|
|
||||||
}
|
|
||||||
if isSrcDesc && isDstDesc {
|
if isSrcDesc && isDstDesc {
|
||||||
stepSize := subtract
|
stepSize := subtract
|
||||||
if e.Src != obj || e.Dst != obj {
|
if e.Src != obj || e.Dst != obj {
|
||||||
|
|
@ -364,6 +347,7 @@ func Layout(ctx context.Context, g *d2graph.Graph, opts *ConfigurableOpts) (err
|
||||||
if _, ok := movedEdges[e]; ok {
|
if _, ok := movedEdges[e]; ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
moveWholeEdge := false
|
||||||
if e.Src == curr {
|
if e.Src == curr {
|
||||||
// Don't move src points on side of container
|
// Don't move src points on side of container
|
||||||
if almostEqual(e.Route[0].X, obj.TopLeft.X) || almostEqual(e.Route[0].X, obj.TopLeft.X+obj.Width) {
|
if almostEqual(e.Route[0].X, obj.TopLeft.X) || almostEqual(e.Route[0].X, obj.TopLeft.X+obj.Width) {
|
||||||
|
|
@ -373,14 +357,30 @@ func Layout(ctx context.Context, g *d2graph.Graph, opts *ConfigurableOpts) (err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if shouldMove(e.Route[0]) {
|
if shouldMove(e.Route[0]) {
|
||||||
e.Route[0].Y += stepSize
|
if isHorizontal && e.Src.Parent != g.Root && e.Dst.Parent != g.Root {
|
||||||
|
moveWholeEdge = true
|
||||||
|
} else {
|
||||||
|
e.Route[0].Y += stepSize
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if e.Dst == curr {
|
if !moveWholeEdge && e.Dst == curr {
|
||||||
if shouldMove(e.Route[len(e.Route)-1]) {
|
if shouldMove(e.Route[len(e.Route)-1]) {
|
||||||
e.Route[len(e.Route)-1].Y += stepSize
|
if isHorizontal && e.Dst.Parent != g.Root && e.Src.Parent != g.Root {
|
||||||
|
moveWholeEdge = true
|
||||||
|
} else {
|
||||||
|
e.Route[len(e.Route)-1].Y += stepSize
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if moveWholeEdge {
|
||||||
|
for _, p := range e.Route {
|
||||||
|
p.Y += stepSize / 2.
|
||||||
|
}
|
||||||
|
movedEdges[e] = struct{}{}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
q = append(q, curr.ChildrenArray...)
|
q = append(q, curr.ChildrenArray...)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue