This commit is contained in:
Alexander Wang 2022-12-25 17:43:43 -08:00
parent ed8474aaba
commit 849012b9fd
No known key found for this signature in database
GPG key ID: D89FA31966BDBECE
2 changed files with 8 additions and 16 deletions

View file

@ -1191,19 +1191,6 @@ var StyleKeywords = map[string]struct{}{
// TODO maybe autofmt should allow other values, and transform them to conform
// e.g. left-center becomes center-left
var NearConstants = map[string]struct{}{
"top-left": {},
"top-center": {},
"top-right": {},
"center-left": {},
"center-right": {},
"bottom-left": {},
"bottom-center": {},
"bottom-right": {},
}
var NearConstantsArray = []string{
"top-left",
"top-center",
@ -1216,6 +1203,7 @@ var NearConstantsArray = []string{
"bottom-center",
"bottom-right",
}
var NearConstants map[string]struct{}
func init() {
for k, v := range StyleKeywords {
@ -1224,4 +1212,8 @@ func init() {
for k, v := range ReservedKeywordHolders {
ReservedKeywords[k] = v
}
NearConstants = make(map[string]struct{}, len(NearConstantsArray))
for _, k := range NearConstantsArray {
NearConstants[k] = struct{}{}
}
}

View file

@ -55,7 +55,7 @@ func Layout(ctx context.Context, g *d2graph.Graph, constantNears []*d2graph.Obje
return nil
}
// position returns the position of obj, taking into consideration its near value and the diagram
// place returns the position of obj, taking into consideration its near value and the diagram
func place(obj *d2graph.Object) (float64, float64) {
tl, br := boundingBox(obj.Graph)
w := br.X - tl.X
@ -79,10 +79,10 @@ func place(obj *d2graph.Object) (float64, float64) {
return br.X + pad, br.Y + pad
}
return 0, 0
}
// WithoutConstantNears removes
// 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) {
for i := 0; i < len(g.Objects); i++ {
obj := g.Objects[i]