@@ -15,16 +15,16 @@ import (
15
15
const pad = 20
16
16
17
17
// 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 {
20
20
return nil
21
21
}
22
22
23
23
// Imagine the graph has two long texts, one at top center and one at top left.
24
24
// Top left should go left enough to not collide with center.
25
25
// So place the center ones first, then the later ones will consider them for bounding box
26
26
for _ , processCenters := range []bool {true , false } {
27
- for _ , obj := range constantNears {
27
+ for obj := range constantNearGraphs {
28
28
if processCenters == strings .Contains (d2graph .Key (obj .Attributes .NearKey )[0 ], "-center" ) {
29
29
preX , preY := obj .TopLeft .X , obj .TopLeft .Y
30
30
obj .TopLeft = geo .NewPoint (place (obj ))
@@ -54,7 +54,7 @@ func Layout(ctx context.Context, g *d2graph.Graph, constantNears []*d2graph.Obje
54
54
g .Edges = append (g .Edges , subEdges ... )
55
55
}
56
56
}
57
- for _ , obj := range constantNears {
57
+ for obj := range constantNearGraphs {
58
58
if processCenters == strings .Contains (d2graph .Key (obj .Attributes .NearKey )[0 ], "-center" ) {
59
59
// The z-index for constant nears does not matter, as it will not collide
60
60
g .Objects = append (g .Objects , obj )
@@ -144,7 +144,7 @@ func calcLabelDimension(obj *d2graph.Object, x float64, y float64) (float64, flo
144
144
145
145
// WithoutConstantNears plucks out the graph objects which have "near" set to a constant value
146
146
// 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 ) {
148
148
constantNearGraphs = make (map [* d2graph.Object ]* d2graph.Graph )
149
149
150
150
for i := 0 ; i < len (g .Objects ); i ++ {
@@ -168,7 +168,6 @@ func WithoutConstantNears(ctx context.Context, g *d2graph.Graph) (nears []*d2gra
168
168
169
169
constantNearGraphs [obj ] = tempGraph
170
170
171
- nears = append (nears , obj )
172
171
i --
173
172
delete (obj .Parent .Children , strings .ToLower (obj .ID ))
174
173
for i := 0 ; i < len (obj .Parent .ChildrenArray ); i ++ {
@@ -179,7 +178,7 @@ func WithoutConstantNears(ctx context.Context, g *d2graph.Graph) (nears []*d2gra
179
178
}
180
179
}
181
180
}
182
- return nears , constantNearGraphs
181
+ return constantNearGraphs
183
182
}
184
183
185
184
func pluckOutNearObjectAndEdges (g * d2graph.Graph , obj * d2graph.Object ) (descendantsObjects []* d2graph.Object , edges []* d2graph.Edge ) {
0 commit comments