layout

package
v0.13.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package layout places the nodes of a drawing with Graphviz's layered engine: a positions-only graph is laid out by `dot` and the boxes it settles on are read back, for the caller to route edges over and draw.

Index

Constants

View Source
const EnvVar = "OPENSYSML_DOT"

EnvVar names the dot executable to lay out with, ahead of the one on PATH.

View Source
const Points = 72.0

Points is Graphviz's points to the inch, the pixel scale the DOT and draw.io forms position with.

View Source
const Tool = "dot"

Tool is the Graphviz executable the layered layout runs.

Variables

View Source
var ErrUnavailable = errors.New("a WebAssembly build cannot start external processes")

ErrUnavailable is why no layout runs on a host that starts no process: every Go WebAssembly target.

Functions

func Locate

func Locate() (string, error)

Locate is the absolute path of the dot to run: the one EnvVar names, else the one on PATH. On a host that starts no process the error is ErrUnavailable.

func Place

func Place(path string, g Graph) (map[string]Box, error)

Place lays g out with the dot at path and returns a box for every node, containers included, in pixels from the drawing's top-left corner.

func Version

func Version(path string) (string, error)

Version is the Graphviz version the dot at path reports with -V, "16.1.0" say.

Types

type Box

type Box struct {
	X, Y, Width, Height float64
}

Box is a placed node: its top-left corner and size in pixels, y down.

type Edge

type Edge struct {
	From, To string
}

Edge joins two nodes by ID, either of which may be a container.

type Error

type Error struct {
	Path   string
	Err    error
	Stderr string
}

Error is a dot run that failed: the process, or its answer.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

type Graph

type Graph struct {
	// Direction is the rank direction, Graphviz's rankdir: TB, LR, RL or BT;
	// empty leaves dot's top-to-bottom.
	Direction string
	// Nodes are the drawing's roots; a node with children is a container.
	Nodes []Node
	// Edges are the edges laid out; an end naming no node is skipped.
	Edges []Edge
	// Gap is the room left between neighbouring nodes and ranks, in pixels.
	Gap float64
	// Pad is the room a container keeps between its border and its members.
	Pad float64
}

Graph is a drawing to lay out: its nodes, nested where the drawing nests them, and the edges whose ends the layering keeps near each other.

type Node

type Node struct {
	ID            string
	Width, Height float64
	Children      []Node
}

Node is one box to place. A leaf is placed at Width by Height; a container keeps a header Width by Height above its members and grows round them.

type NotFoundError

type NotFoundError struct {
	// Override is what EnvVar named, empty when it names nothing.
	Override string
}

NotFoundError is a dot that is nowhere to be found: not at the override, when one is set, else not on PATH.

func (*NotFoundError) Error

func (e *NotFoundError) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL