fix: cr, delete redundant return value

This commit is contained in:
donglixiaoche 2023-03-25 02:09:28 +08:00
parent e09a85e80b
commit 4e4959f39b
No known key found for this signature in database
GPG key ID: 3190E65EBAD6D6E2
2 changed files with 8 additions and 9 deletions

View file

@ -15,8 +15,8 @@ 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, constantNears []*d2graph.Object, constantNearGraphs map[*d2graph.Object]*d2graph.Graph) error {
if len(constantNears) == 0 {
func Layout(ctx context.Context, g *d2graph.Graph, constantNearGraphs map[*d2graph.Object]*d2graph.Graph) error {
if len(constantNearGraphs) == 0 {
return nil
}
@ -24,7 +24,7 @@ func Layout(ctx context.Context, g *d2graph.Graph, constantNears []*d2graph.Obje
// 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 constantNears {
for obj := range constantNearGraphs {
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))
@ -54,7 +54,7 @@ func Layout(ctx context.Context, g *d2graph.Graph, constantNears []*d2graph.Obje
g.Edges = append(g.Edges, subEdges...)
}
}
for _, obj := range constantNears {
for obj := range constantNearGraphs {
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,7 +144,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) (nears []*d2graph.Object, constantNearGraphs map[*d2graph.Object]*d2graph.Graph) {
func WithoutConstantNears(ctx context.Context, g *d2graph.Graph) (constantNearGraphs map[*d2graph.Object]*d2graph.Graph) {
constantNearGraphs = make(map[*d2graph.Object]*d2graph.Graph)
for i := 0; i < len(g.Objects); i++ {
@ -168,7 +168,6 @@ func WithoutConstantNears(ctx context.Context, g *d2graph.Graph) (nears []*d2gra
constantNearGraphs[obj] = tempGraph
nears = append(nears, obj)
i--
delete(obj.Parent.Children, strings.ToLower(obj.ID))
for i := 0; i < len(obj.Parent.ChildrenArray); i++ {
@ -179,7 +178,7 @@ func WithoutConstantNears(ctx context.Context, g *d2graph.Graph) (nears []*d2gra
}
}
}
return nears, constantNearGraphs
return constantNearGraphs
}
func pluckOutNearObjectAndEdges(g *d2graph.Graph, obj *d2graph.Object) (descendantsObjects []*d2graph.Object, edges []*d2graph.Edge) {

View file

@ -68,7 +68,7 @@ func compile(ctx context.Context, g *d2graph.Graph, opts *CompileOptions) (*d2ta
return nil, err
}
constantNears, constantNearGraphs := d2near.WithoutConstantNears(ctx, g)
constantNearGraphs := d2near.WithoutConstantNears(ctx, g)
// run core layout for constantNears
for nearObject, tempGraph := range constantNearGraphs {
@ -88,7 +88,7 @@ func compile(ctx context.Context, g *d2graph.Graph, opts *CompileOptions) (*d2ta
return nil, err
}
err = d2near.Layout(ctx, g, constantNears, constantNearGraphs)
err = d2near.Layout(ctx, g, constantNearGraphs)
if err != nil {
return nil, err
}