package p4nodes
import (
basegraph "github.com/d2lang/elk-go/internal/graph"
"github.com/d2lang/elk-go/internal/layered"
)
type SimpleNodePlacer struct {}
func (*SimpleNodePlacer ) ProcessorConfiguration (
arena *layered .LGraphArena ,
graphID layered .LGraphID ,
) layered .ProcessorConfiguration {
var configuration layered .ProcessorConfiguration
if basegraph .Get (&arena .Graph (graphID ).Properties , layered .GraphProperties )&layered .GraphPropertyExternalPorts != 0 {
configuration .AddBefore (layered .PhaseEdgeRouting , layered .HierarchicalPortPositionProcessor )
}
return configuration
}
func (*SimpleNodePlacer ) Process (arena *layered .LGraphArena , graphID layered .LGraphID ) error {
maximumHeight := 0.0
for _ , layerID := range arena .Graph (graphID ).Layers {
layer := arena .Layer (layerID )
layer .Size .Y = 0
var previous *layered .LNodeID
for _ , nodeID := range layer .Nodes {
node := arena .Node (nodeID )
if previous != nil {
layer .Size .Y += layered .VerticalSpacing (arena , nodeID , *previous )
}
layer .Size .Y += node .Margin .Top + node .Size .Y + node .Margin .Bottom
copyID := nodeID
previous = ©ID
}
if layer .Size .Y > maximumHeight {
maximumHeight = layer .Size .Y
}
}
for _ , layerID := range arena .Graph (graphID ).Layers {
layer := arena .Layer (layerID )
position := (maximumHeight - layer .Size .Y ) / 2
var previous *layered .LNodeID
for _ , nodeID := range layer .Nodes {
node := arena .Node (nodeID )
if previous != nil {
position += layered .VerticalSpacing (arena , nodeID , *previous )
}
position += node .Margin .Top
node .Position .Y = position
position += node .Size .Y + node .Margin .Bottom
copyID := nodeID
previous = ©ID
}
}
return nil
}
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 .