Skip to content

Commit 849b117

Browse files
committed
fix: cr, delete redundant return value
1 parent 040be1d commit 849b117

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

d2layouts/d2near/layout.go

+6-7
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ import (
1515
const pad = 20
1616

1717
// Layout finds the shapes which are assigned constant near keywords and places them.
18-
func Layout(ctx context.Context, g *d2graph.Graph, constantNears []*d2graph.Object, constantNearGraphs map[*d2graph.Object]*d2graph.Graph) error {
19-
if len(constantNears) == 0 {
18+
func Layout(ctx context.Context, g *d2graph.Graph, constantNearGraphs map[*d2graph.Object]*d2graph.Graph) error {
19+
if len(constantNearGraphs) == 0 {
2020
return nil
2121
}
2222

2323
// Imagine the graph has two long texts, one at top center and one at top left.
2424
// Top left should go left enough to not collide with center.
2525
// So place the center ones first, then the later ones will consider them for bounding box
2626
for _, processCenters := range []bool{true, false} {
27-
for _, obj := range constantNears {
27+
for obj := range constantNearGraphs {
2828
if processCenters == strings.Contains(d2graph.Key(obj.Attributes.NearKey)[0], "-center") {
2929
preX, preY := obj.TopLeft.X, obj.TopLeft.Y
3030
obj.TopLeft = geo.NewPoint(place(obj))
@@ -54,7 +54,7 @@ func Layout(ctx context.Context, g *d2graph.Graph, constantNears []*d2graph.Obje
5454
g.Edges = append(g.Edges, subEdges...)
5555
}
5656
}
57-
for _, obj := range constantNears {
57+
for obj := range constantNearGraphs {
5858
if processCenters == strings.Contains(d2graph.Key(obj.Attributes.NearKey)[0], "-center") {
5959
// The z-index for constant nears does not matter, as it will not collide
6060
g.Objects = append(g.Objects, obj)
@@ -144,7 +144,7 @@ func calcLabelDimension(obj *d2graph.Object, x float64, y float64) (float64, flo
144144

145145
// WithoutConstantNears plucks out the graph objects which have "near" set to a constant value
146146
// This is to be called before layout engines so they don't take part in regular positioning
147-
func WithoutConstantNears(ctx context.Context, g *d2graph.Graph) (nears []*d2graph.Object, constantNearGraphs map[*d2graph.Object]*d2graph.Graph) {
147+
func WithoutConstantNears(ctx context.Context, g *d2graph.Graph) (constantNearGraphs map[*d2graph.Object]*d2graph.Graph) {
148148
constantNearGraphs = make(map[*d2graph.Object]*d2graph.Graph)
149149

150150
for i := 0; i < len(g.Objects); i++ {
@@ -168,7 +168,6 @@ func WithoutConstantNears(ctx context.Context, g *d2graph.Graph) (nears []*d2gra
168168

169169
constantNearGraphs[obj] = tempGraph
170170

171-
nears = append(nears, obj)
172171
i--
173172
delete(obj.Parent.Children, strings.ToLower(obj.ID))
174173
for i := 0; i < len(obj.Parent.ChildrenArray); i++ {
@@ -179,7 +178,7 @@ func WithoutConstantNears(ctx context.Context, g *d2graph.Graph) (nears []*d2gra
179178
}
180179
}
181180
}
182-
return nears, constantNearGraphs
181+
return constantNearGraphs
183182
}
184183

185184
func pluckOutNearObjectAndEdges(g *d2graph.Graph, obj *d2graph.Object) (descendantsObjects []*d2graph.Object, edges []*d2graph.Edge) {

d2lib/d2.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func compile(ctx context.Context, g *d2graph.Graph, opts *CompileOptions) (*d2ta
6868
return nil, err
6969
}
7070

71-
constantNears, constantNearGraphs := d2near.WithoutConstantNears(ctx, g)
71+
constantNearGraphs := d2near.WithoutConstantNears(ctx, g)
7272

7373
// run core layout for constantNears
7474
for nearObject, tempGraph := range constantNearGraphs {
@@ -88,7 +88,7 @@ func compile(ctx context.Context, g *d2graph.Graph, opts *CompileOptions) (*d2ta
8888
return nil, err
8989
}
9090

91-
err = d2near.Layout(ctx, g, constantNears, constantNearGraphs)
91+
err = d2near.Layout(ctx, g, constantNearGraphs)
9292
if err != nil {
9393
return nil, err
9494
}

0 commit comments

Comments
 (0)