package hierarchy
import (
"github.com/pancsta/d2/d2layouts/d2talalayout/internal/layoutgraph"
"github.com/pancsta/d2/d2layouts/d2talalayout/internal/nodeshape"
"github.com/pancsta/d2/lib/shape"
)
func Candidates (graph *layoutgraph .Graph ) map [*layoutgraph .Node ]struct {} {
candidates := make (map [*layoutgraph .Node ]struct {})
for _ , node := range graph .Nodes {
if _ , inTree := graph .NodeToTree [node ]; inTree {
continue
}
if graph .IsTreeSentinel (node ) || node .Sequence != nil || node .FixedTopLeft != nil {
continue
}
if isSimpleCandidate (graph , node ) {
candidates [node ] = struct {}{}
continue
}
if node .IsContainer () && shapeCanBeContainer (node .Shape ) && !node .AspectRatio1 () && isEligibleContainer (graph , node ) {
candidates [node ] = struct {}{}
}
}
return candidates
}
func isSimpleCandidate(graph *layoutgraph .Graph , node *layoutgraph .Node ) bool {
return !(node .IsContainer () || graph .IsTreeSentinel (node ) || node .IsClusterVessel () ||
graph .IsSequenceVessel (node ) || node .Cluster != nil )
}
func shapeCanBeContainer(candidate nodeshape .Shape ) bool {
switch candidate .GetType () {
case "" , shape .SQUARE_TYPE , shape .PACKAGE_TYPE , shape .STORED_DATA_TYPE , shape .QUEUE_TYPE , shape .STEP_TYPE :
return true
default :
return false
}
}
func isEligibleContainer(graph *layoutgraph .Graph , root *layoutgraph .Node ) bool {
for _ , child := range graph .Containers [root ] {
if child .FixedTopLeft != nil {
return false
}
if _ , inTree := graph .NodeToTree [child ]; inTree {
return false
}
if graph .IsTreeSentinel (child ) || child .Sequence != nil {
return false
}
if !child .IsContainer () && !isSimpleCandidate (graph , child ) {
return false
}
for _ , edge := range child .Edges {
if !isHierarchyStructuralEdge (edge ) {
continue
}
if child .Adjacent (edge ).IsDescendantOf (root ) {
return false
}
}
if child .IsContainer () && !isEligibleContainer (graph , child ) {
return false
}
}
return true
}
The pages are generated with Golds v0.8.7 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .