package components
import (
"github.com/d2lang/elk-go/internal/geometry"
basegraph "github.com/d2lang/elk-go/internal/graph"
"github.com/d2lang/elk-go/internal/layered"
)
type graphPlacer interface {
combine(*layered .LGraphArena , []layered .LGraphID , layered .LGraphID ) error
}
func moveGraphs(
arena *layered .LGraphArena ,
destination layered .LGraphID ,
sources []layered .LGraphID ,
offset geometry .Point ,
) {
for _ , source := range sources {
moveGraph (arena , destination , source , offset )
}
}
func moveGraph(
arena *layered .LGraphArena ,
destination , source layered .LGraphID ,
offset geometry .Point ,
) {
sourceGraph := arena .Graph (source )
graphOffset := sourceGraph .Offset .Add (offset )
for _ , nodeID := range sourceGraph .LayerlessNodes {
offsetNodeAndOutgoingEdges (arena , nodeID , graphOffset )
arena .Graph (destination ).LayerlessNodes = append (
arena .Graph (destination ).LayerlessNodes , nodeID )
arena .Node (nodeID ).Graph = destination
}
}
func offsetGraph(arena *layered .LGraphArena , graphID layered .LGraphID , offset geometry .Point ) {
for _ , nodeID := range arena .Graph (graphID ).LayerlessNodes {
offsetNodeAndOutgoingEdges (arena , nodeID , offset )
}
}
func offsetNodeAndOutgoingEdges(
arena *layered .LGraphArena ,
nodeID layered .LNodeID ,
offset geometry .Point ,
) {
node := arena .Node (nodeID )
node .Position = node .Position .Add (offset )
for _ , portID := range node .Ports {
for _ , edgeID := range arena .Port (portID ).OutgoingEdges {
edge := arena .Edge (edgeID )
edge .BendPoints = edge .BendPoints .Offset (offset )
if junctionPoints , found := basegraph .TryGet (
&edge .Properties , layered .JunctionPoints ,
); found {
basegraph .Set (&edge .Properties , layered .JunctionPoints ,
junctionPoints .Offset (offset ))
}
for _ , labelID := range edge .Labels {
label := arena .Label (labelID )
label .Position = label .Position .Add (offset )
}
}
}
}
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 .