fix: cr, delete redundant variable
This commit is contained in:
parent
4e4959f39b
commit
ebab91b043
2 changed files with 9 additions and 13 deletions
|
|
@ -15,7 +15,7 @@ import (
|
|||
const pad = 20
|
||||
|
||||
// Layout finds the shapes which are assigned constant near keywords and places them.
|
||||
func Layout(ctx context.Context, g *d2graph.Graph, constantNearGraphs map[*d2graph.Object]*d2graph.Graph) error {
|
||||
func Layout(ctx context.Context, g *d2graph.Graph, constantNearGraphs []*d2graph.Graph) error {
|
||||
if len(constantNearGraphs) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
|
@ -24,17 +24,13 @@ func Layout(ctx context.Context, g *d2graph.Graph, constantNearGraphs map[*d2gra
|
|||
// Top left should go left enough to not collide with center.
|
||||
// So place the center ones first, then the later ones will consider them for bounding box
|
||||
for _, processCenters := range []bool{true, false} {
|
||||
for obj := range constantNearGraphs {
|
||||
for _, tempGraph := range constantNearGraphs {
|
||||
obj := tempGraph.Root.ChildrenArray[0]
|
||||
if processCenters == strings.Contains(d2graph.Key(obj.Attributes.NearKey)[0], "-center") {
|
||||
preX, preY := obj.TopLeft.X, obj.TopLeft.Y
|
||||
obj.TopLeft = geo.NewPoint(place(obj))
|
||||
dx, dy := obj.TopLeft.X-preX, obj.TopLeft.Y-preY
|
||||
|
||||
tempGraph := constantNearGraphs[obj]
|
||||
if tempGraph == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
subObjects, subEdges := tempGraph.Objects, tempGraph.Edges
|
||||
for _, subObject := range subObjects {
|
||||
// `obj` already been replaced above by `place(obj)`
|
||||
|
|
@ -54,7 +50,8 @@ func Layout(ctx context.Context, g *d2graph.Graph, constantNearGraphs map[*d2gra
|
|||
g.Edges = append(g.Edges, subEdges...)
|
||||
}
|
||||
}
|
||||
for obj := range constantNearGraphs {
|
||||
for _, tempGraph := range constantNearGraphs {
|
||||
obj := tempGraph.Root.ChildrenArray[0]
|
||||
if processCenters == strings.Contains(d2graph.Key(obj.Attributes.NearKey)[0], "-center") {
|
||||
// The z-index for constant nears does not matter, as it will not collide
|
||||
g.Objects = append(g.Objects, obj)
|
||||
|
|
@ -144,9 +141,7 @@ func calcLabelDimension(obj *d2graph.Object, x float64, y float64) (float64, flo
|
|||
|
||||
// WithoutConstantNears plucks out the graph objects which have "near" set to a constant value
|
||||
// This is to be called before layout engines so they don't take part in regular positioning
|
||||
func WithoutConstantNears(ctx context.Context, g *d2graph.Graph) (constantNearGraphs map[*d2graph.Object]*d2graph.Graph) {
|
||||
constantNearGraphs = make(map[*d2graph.Object]*d2graph.Graph)
|
||||
|
||||
func WithoutConstantNears(ctx context.Context, g *d2graph.Graph) (constantNearGraphs []*d2graph.Graph) {
|
||||
for i := 0; i < len(g.Objects); i++ {
|
||||
obj := g.Objects[i]
|
||||
if obj.Attributes.NearKey == nil {
|
||||
|
|
@ -166,7 +161,7 @@ func WithoutConstantNears(ctx context.Context, g *d2graph.Graph) (constantNearGr
|
|||
tempGraph.Objects = descendantObjects
|
||||
tempGraph.Edges = edges
|
||||
|
||||
constantNearGraphs[obj] = tempGraph
|
||||
constantNearGraphs = append(constantNearGraphs, tempGraph)
|
||||
|
||||
i--
|
||||
delete(obj.Parent.Children, strings.ToLower(obj.ID))
|
||||
|
|
|
|||
|
|
@ -71,11 +71,12 @@ func compile(ctx context.Context, g *d2graph.Graph, opts *CompileOptions) (*d2ta
|
|||
constantNearGraphs := d2near.WithoutConstantNears(ctx, g)
|
||||
|
||||
// run core layout for constantNears
|
||||
for nearObject, tempGraph := range constantNearGraphs {
|
||||
for _, tempGraph := range constantNearGraphs {
|
||||
if tempGraph == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
nearObject := tempGraph.Root.ChildrenArray[0]
|
||||
nearObject.Parent = tempGraph.Root
|
||||
if err = coreLayout(ctx, tempGraph); err != nil {
|
||||
return nil, err
|
||||
|
|
|
|||
Loading…
Reference in a new issue