shift edges with grid
This commit is contained in:
parent
c0c66ad36e
commit
c9a6e65c6b
4 changed files with 25 additions and 4 deletions
|
|
@ -1169,6 +1169,13 @@ func (e *Edge) Text() *d2target.MText {
|
|||
}
|
||||
}
|
||||
|
||||
func (e *Edge) Move(dx, dy float64) {
|
||||
for _, p := range e.Route {
|
||||
p.X += dx
|
||||
p.Y += dy
|
||||
}
|
||||
}
|
||||
|
||||
func (e *Edge) AbsID() string {
|
||||
srcIDA := e.Src.AbsIDArray()
|
||||
dstIDA := e.Dst.AbsIDArray()
|
||||
|
|
|
|||
|
|
@ -81,7 +81,12 @@ func pluckObjAndEdges(g *Graph, obj *Object) (descendantsObjects []*Object, edge
|
|||
|
||||
func (g *Graph) InjectNestedGraph(tempGraph *Graph, parent *Object) {
|
||||
obj := tempGraph.Root.ChildrenArray[0]
|
||||
obj.MoveWithDescendantsTo(0, 0)
|
||||
dx := 0 - obj.TopLeft.X
|
||||
dy := 0 - obj.TopLeft.Y
|
||||
obj.MoveWithDescendants(dx, dy)
|
||||
for _, e := range tempGraph.Edges {
|
||||
e.Move(dx, dy)
|
||||
}
|
||||
obj.Parent = parent
|
||||
for _, obj := range tempGraph.Objects {
|
||||
obj.Graph = g
|
||||
|
|
|
|||
|
|
@ -108,6 +108,9 @@ func (gd *gridDiagram) shift(dx, dy float64) {
|
|||
for _, obj := range gd.objects {
|
||||
obj.MoveWithDescendants(dx, dy)
|
||||
}
|
||||
for _, e := range gd.edges {
|
||||
e.Move(dx, dy)
|
||||
}
|
||||
}
|
||||
|
||||
func (gd *gridDiagram) cleanup(obj *d2graph.Object, graph *d2graph.Graph) {
|
||||
|
|
|
|||
|
|
@ -212,16 +212,22 @@ func withoutGridDiagrams(ctx context.Context, g *d2graph.Graph, layout d2graph.L
|
|||
// simple straight line edge routing between grid objects
|
||||
for i, e := range g.Edges {
|
||||
edgeOrder[e.AbsID()] = i
|
||||
if e.Dst.Parent.ClosestGridDiagram() != obj {
|
||||
if !e.Src.Parent.IsDescendantOf(obj) && !e.Dst.Parent.IsDescendantOf(obj) {
|
||||
continue
|
||||
}
|
||||
// if edge is within grid, remove it from outer layout
|
||||
gd.edges = append(gd.edges, e)
|
||||
edgeToRemove[e] = struct{}{}
|
||||
|
||||
if e.Src.Parent != obj || e.Dst.Parent != obj {
|
||||
continue
|
||||
}
|
||||
// if edge is grid child, use simple routing
|
||||
e.Route = []*geo.Point{e.Src.Center(), e.Dst.Center()}
|
||||
e.TraceToShape(e.Route, 0, 1)
|
||||
if e.Label.Value != "" {
|
||||
e.LabelPosition = go2.Pointer(string(label.InsideMiddleCenter))
|
||||
}
|
||||
gd.edges = append(gd.edges, e)
|
||||
edgeToRemove[e] = struct{}{}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
|||
Loading…
Reference in a new issue