cleanup
This commit is contained in:
parent
ed8474aaba
commit
849012b9fd
2 changed files with 8 additions and 16 deletions
|
|
@ -1191,19 +1191,6 @@ var StyleKeywords = map[string]struct{}{
|
||||||
|
|
||||||
// TODO maybe autofmt should allow other values, and transform them to conform
|
// TODO maybe autofmt should allow other values, and transform them to conform
|
||||||
// e.g. left-center becomes center-left
|
// 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{
|
var NearConstantsArray = []string{
|
||||||
"top-left",
|
"top-left",
|
||||||
"top-center",
|
"top-center",
|
||||||
|
|
@ -1216,6 +1203,7 @@ var NearConstantsArray = []string{
|
||||||
"bottom-center",
|
"bottom-center",
|
||||||
"bottom-right",
|
"bottom-right",
|
||||||
}
|
}
|
||||||
|
var NearConstants map[string]struct{}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
for k, v := range StyleKeywords {
|
for k, v := range StyleKeywords {
|
||||||
|
|
@ -1224,4 +1212,8 @@ func init() {
|
||||||
for k, v := range ReservedKeywordHolders {
|
for k, v := range ReservedKeywordHolders {
|
||||||
ReservedKeywords[k] = v
|
ReservedKeywords[k] = v
|
||||||
}
|
}
|
||||||
|
NearConstants = make(map[string]struct{}, len(NearConstantsArray))
|
||||||
|
for _, k := range NearConstantsArray {
|
||||||
|
NearConstants[k] = struct{}{}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ func Layout(ctx context.Context, g *d2graph.Graph, constantNears []*d2graph.Obje
|
||||||
return nil
|
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) {
|
func place(obj *d2graph.Object) (float64, float64) {
|
||||||
tl, br := boundingBox(obj.Graph)
|
tl, br := boundingBox(obj.Graph)
|
||||||
w := br.X - tl.X
|
w := br.X - tl.X
|
||||||
|
|
@ -79,10 +79,10 @@ func place(obj *d2graph.Object) (float64, float64) {
|
||||||
return br.X + pad, br.Y + pad
|
return br.X + pad, br.Y + pad
|
||||||
}
|
}
|
||||||
return 0, 0
|
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) {
|
func WithoutConstantNears(ctx context.Context, g *d2graph.Graph) (nears []*d2graph.Object) {
|
||||||
for i := 0; i < len(g.Objects); i++ {
|
for i := 0; i < len(g.Objects); i++ {
|
||||||
obj := g.Objects[i]
|
obj := g.Objects[i]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue