Documentation
¶
Overview ¶
Package layout provides grid-based layout and rendering algorithms.
This package is the Rendering Domain - a peer to the Application Domain in internal/domain/. While internal/domain/ contains business logic and entities (Diagram, Node, Edge), this package handles the computational details of arranging nodes on a grid and routing edges (paths).
Key types:
- Config: Grid/layout configuration (spacing, margins, dimensions)
- LayoutNode: A node positioned on the grid (distinct from domain.Node)
- LayoutPath: An edge's route through the grid (distinct from domain.Edge.Path)
- VertexMap: Grid vertex tracking for pathfinding
Layout algorithms:
- LayoutFlowSquare: Arrange nodes in a square grid pattern
- LayoutTopologicalSort: Single-row topological ordering
- LayoutTarjan: Multi-row layout using Tarjan's algorithm
- LayoutAbsolute: Use explicit positions from config
- LayoutRandomShortestSquare: Multiple attempts to minimize path length
Internal adapters (internal/adapters/) convert between the Application Domain (internal/domain/) and this Rendering Domain.
Index ¶
- func AbsoluteFromSVG(svg string, output OutputFunc) error
- func GetHeuristics() []string
- func GetLayoutOptions() []string
- func GetPathfindingAlgorithms() []string
- func PythagoreanDistance(from, to dijkstra.Point) int64
- type Arc
- type Arcs
- type Config
- type ConfigEdge
- type ConfigEdges
- type ConfigNode
- type ConfigNodes
- type ConfigPath
- type ConfigStyles
- type CreateFinder
- type Diagram
- type Layout
- func (l *Layout) Draw(canvas LayoutDrawer, spacing int)
- func (l *Layout) FindPath(from, to string) (*LayoutPath, error)
- func (l *Layout) InsideAny(x, y int) bool
- func (l *Layout) IsAnyPort(x, y int) bool
- func (l *Layout) LayoutHeight() int
- func (l *Layout) LayoutWidth() int
- func (l *Layout) ShowGrid(canvas LayoutDrawer, spacing int)
- type LayoutArrangementFunc
- type LayoutDrawer
- type LayoutNode
- func (n *LayoutNode) Draw(d LayoutDrawer, spacing, order int)
- func (n *LayoutNode) GetCentre() Point
- func (n *LayoutNode) GetPorts() Points
- func (n *LayoutNode) Height() int
- func (n *LayoutNode) IsInside(x, y int) bool
- func (n *LayoutNode) IsPort(x, y int) bool
- func (n *LayoutNode) Left() int
- func (n *LayoutNode) Top() int
- func (n *LayoutNode) Width() int
- type LayoutNodes
- type LayoutPath
- type LayoutPaths
- type OutputFunc
- type PathFinder
- type PathStrategy
- type Point
- type Points
- type Position
- type VertexMap
- func (v *VertexMap) CountAvailable(available bool) int
- func (v *VertexMap) Get(x, y int) bool
- func (vm VertexMap) GetArcs() Arcs
- func (v VertexMap) GetVertexPoints() Points
- func (v *VertexMap) Map(m VertexStateMapper)
- func (v *VertexMap) MapAnd(m VertexMapper)
- func (v *VertexMap) MapOr(m VertexMapper)
- func (v *VertexMap) MapSet(m VertexMapper)
- func (v *VertexMap) MapUnset(m VertexMapper)
- func (v *VertexMap) Set(x, y int, val bool)
- func (v VertexMap) String() string
- type VertexMapper
- type VertexStateMapper
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AbsoluteFromSVG ¶
func AbsoluteFromSVG(svg string, output OutputFunc) error
AbsoluteFromSVG parses a string of an SVG and turns it in to a Layli configuration with with absolute layout that can represent the same SVG
func GetHeuristics ¶ added in v0.0.16
func GetHeuristics() []string
GetHeuristics returns all available heuristic function names
NOTE: When adding a new heuristic, add it to: 1. internal/domain/diagram.go (PathfindingHeuristic constant) 2. internal/adapters/config/yaml_parser.go (validation map) 3. This function (so it's discoverable)
func GetLayoutOptions ¶ added in v0.0.16
func GetLayoutOptions() []string
GetLayoutOptions returns all available layout algorithm names
NOTE: When adding a new layout algorithm, remember to: 1. Add constant to internal/domain/diagram.go 2. Implement function in arrangements.go 3. Register in selectArrangement() in arrangements.go 4. Register in selectArranger() in internal/adapters/layout/engine.go 5. Add it to this function (so it's discoverable) See CONTRIBUTING_LAYOUTS.md for detailed steps.
func GetPathfindingAlgorithms ¶ added in v0.0.16
func GetPathfindingAlgorithms() []string
GetPathfindingAlgorithms returns all available pathfinding algorithm names
NOTE: When adding a new pathfinding algorithm, add it to: 1. internal/domain/diagram.go (PathfindingAlgorithm constant) 2. internal/adapters/config/yaml_parser.go (validation map) 3. This function (so it's discoverable)
func PythagoreanDistance ¶
Types ¶
type Config ¶
type Config struct {
Layout string `yaml:"layout,omitempty"`
LayoutAttempts int `yaml:"layout-attempts,omitempty"`
Path ConfigPath `yaml:"path,omitempty"`
Nodes ConfigNodes `yaml:"nodes"`
Edges ConfigEdges `yaml:"edges"`
Spacing int `yaml:"-"`
NodeWidth int `yaml:"width"`
NodeHeight int `yaml:"height"`
Border int `yaml:"border"`
Margin int `yaml:"margin"`
Styles ConfigStyles `yaml:"styles,omitempty"`
}
Config holds the layout configuration for a diagram.
Note: LayoutAttempts is overloaded and has different meanings depending on the layout algorithm: - For LayoutRandomShortestSquare: the number of random permutations to try - For other algorithms: available for custom use (e.g., grid columns) See CONTRIBUTING_LAYOUTS.md for details on using this field in new layouts.
type ConfigEdge ¶
type ConfigEdges ¶
type ConfigEdges []ConfigEdge
type ConfigNode ¶
type ConfigNodes ¶
type ConfigNodes []ConfigNode
func (ConfigNodes) ByID ¶
func (nodes ConfigNodes) ByID(id string) *ConfigNode
type ConfigPath ¶
type ConfigStyles ¶
type CreateFinder ¶
type CreateFinder func(start, end dijkstra.Point) PathFinder
type Layout ¶
type Layout struct {
Nodes LayoutNodes
Paths LayoutPaths
CreateFinder CreateFinder
// contains filtered or unexported fields
}
func NewLayout ¶
func NewLayout(nodes LayoutNodes, paths LayoutPaths, nodeWidth, nodeHeight, nodeMargin, layoutBorder, pathSpacing int) *Layout
NewLayout creates a Layout with the given configuration parameters.
func NewLayoutFromConfig ¶
func NewLayoutFromConfig(finder CreateFinder, c *Config) (*Layout, error)
func (*Layout) Draw ¶
func (l *Layout) Draw(canvas LayoutDrawer, spacing int)
func (*Layout) LayoutHeight ¶
LayoutHeight is the height in path units
func (*Layout) LayoutWidth ¶
LayoutWidth is the width in path units
func (*Layout) ShowGrid ¶
func (l *Layout) ShowGrid(canvas LayoutDrawer, spacing int)
type LayoutArrangementFunc ¶
type LayoutArrangementFunc func(c *Config) (LayoutNodes, error)
LayoutArrangementFunc returns a slice of nodes arranged according to the algorithm implemented
type LayoutDrawer ¶
type LayoutNode ¶
func NewLayoutNode ¶
func NewLayoutNode(id, contents string, left, top, width, height int, class, style string) LayoutNode
func (*LayoutNode) Draw ¶
func (n *LayoutNode) Draw(d LayoutDrawer, spacing, order int)
func (*LayoutNode) GetCentre ¶
func (n *LayoutNode) GetCentre() Point
func (*LayoutNode) GetPorts ¶
func (n *LayoutNode) GetPorts() Points
func (*LayoutNode) Height ¶
func (n *LayoutNode) Height() int
Height returns the height of the node in grid units.
func (*LayoutNode) IsInside ¶
func (n *LayoutNode) IsInside(x, y int) bool
func (*LayoutNode) IsPort ¶
func (n *LayoutNode) IsPort(x, y int) bool
func (*LayoutNode) Left ¶
func (n *LayoutNode) Left() int
Left returns the left position of the node in grid units.
func (*LayoutNode) Top ¶
func (n *LayoutNode) Top() int
Top returns the top position of the node in grid units.
func (*LayoutNode) Width ¶
func (n *LayoutNode) Width() int
Width returns the width of the node in grid units.
type LayoutNodes ¶
type LayoutNodes []LayoutNode
func LayoutAbsolute ¶
func LayoutAbsolute(c *Config) (LayoutNodes, error)
func LayoutFlowSquare ¶
func LayoutFlowSquare(c *Config) (LayoutNodes, error)
func LayoutRandomShortestSquare ¶
func LayoutRandomShortestSquare(config *Config) (LayoutNodes, error)
func LayoutTarjan ¶
func LayoutTarjan(config *Config) (LayoutNodes, error)
LayoutTarjan arranges nodes in multiple rows according to Tarhan's algorithm
func LayoutTopologicalSort ¶
func LayoutTopologicalSort(config *Config) (LayoutNodes, error)
LayoutTopologicalSort arranges nodes in a single row, sorted in topological order
func (LayoutNodes) ByID ¶
func (nodes LayoutNodes) ByID(id string) *LayoutNode
func (LayoutNodes) ConnectionDistances ¶
func (n LayoutNodes) ConnectionDistances(connections ConfigEdges) (float64, error)
func (LayoutNodes) String ¶
func (nodes LayoutNodes) String() string
type LayoutPath ¶
func (*LayoutPath) Draw ¶
func (p *LayoutPath) Draw(canvas LayoutDrawer, spacing, order int)
func (*LayoutPath) Length ¶
func (paths *LayoutPath) Length() float64
type LayoutPaths ¶
type LayoutPaths []LayoutPath
func (*LayoutPaths) Draw ¶
func (paths *LayoutPaths) Draw(canvas LayoutDrawer, spacing int)
func (LayoutPaths) Length ¶
func (paths LayoutPaths) Length() float64
type OutputFunc ¶
type PathFinder ¶
type PathStrategy ¶
type PathStrategy func(config Config, paths *LayoutPaths, find func(from, to string) (*LayoutPath, error)) error
type Point ¶
func (Point) Coordinates ¶
type VertexMap ¶
type VertexMap struct {
// contains filtered or unexported fields
}
func BuildVertexMap ¶
func NewVertexMap ¶
func (*VertexMap) CountAvailable ¶
func (VertexMap) GetVertexPoints ¶
func (*VertexMap) Map ¶
func (v *VertexMap) Map(m VertexStateMapper)
func (*VertexMap) MapAnd ¶
func (v *VertexMap) MapAnd(m VertexMapper)
func (*VertexMap) MapOr ¶
func (v *VertexMap) MapOr(m VertexMapper)
func (*VertexMap) MapSet ¶
func (v *VertexMap) MapSet(m VertexMapper)
func (*VertexMap) MapUnset ¶
func (v *VertexMap) MapUnset(m VertexMapper)