graph

package
v0.8.3 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 17 Imported by: 1 module, 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 graph holds the model of a diagram, a graph of nodes, edges and clusters, and its layered layout (D18, D31). The packages dot and mermaid below it read a source into a graph, and Compile writes a graph as a Vega spec that draws with the transform zuzu.layered.

Index

Constants

View Source
const (
	StyleNode         = theme.StyleNode
	StyleNodeMuted    = theme.StyleNodeMuted
	StyleNodeLabel    = theme.StyleNodeLabel
	StyleEdge         = theme.StyleEdge
	StyleArrow        = theme.StyleArrow
	StyleArrowOpen    = theme.StyleArrowOpen
	StyleEdgeLabel    = theme.StyleEdgeLabel
	StyleEdgeLabelBox = theme.StyleEdgeLabelBox
	StyleCluster      = theme.StyleCluster
	StyleClusterTitle = theme.StyleClusterTitle
	StyleIcon         = theme.StyleIcon
	StyleIconStroke   = theme.StyleIconStroke
	StyleGuide        = theme.StyleGuide
	StyleBand         = theme.StyleBand
)

The styles of the marks of a diagram, which the config of a theme gives (D14, D31).

View Source
const (
	EngineLayered = "layered"
	EngineDagre   = "dagre"
	EngineELK     = "elk"
)

The names of the built in engines, and of the engine of ELK, which the module github.com/xo/zuzu/elk gives. The engine of ELK lays out the layout elk and each layout whose name starts with elk., such as elk.stress (D45).

View Source
const (
	TB = "TB"
	BT = "BT"
	LR = "LR"
	RL = "RL"
)

The directions of a layout: the ranks go from the top to the bottom, from the bottom to the top, from the left to the right, or from the right to the left.

View Source
const ArrowSymbolSize = theme.ArrowLength * theme.ArrowLength

ArrowSymbolSize is the size of the symbol of an arrowhead at an arrowsize of 1. ArrowPaths draws the shape normal 2 long in a symbol of size 4, so that the shape is the square root of the size long, and this size makes it theme.ArrowLength long (docs/STYLE.md).

View Source
const BoldWeight = "600"

BoldWeight is the weight of a bold line of a field, the weight of the title of a cluster.

View Source
const ClusterPackage = "package"

ClusterPackage is the shape of a cluster that draws as a package of UML: a panel with a tab at its top left that holds the title (D32).

View Source
const ClusterState = "state"

ClusterState is the shape of a cluster that draws as a composite state of a state diagram: a panel with a band across its top that holds the title, in a stronger tint of its color, with a line under the band.

View Source
const ConfigLayout = "zuzu.layout"

ConfigLayout is the key of the config of a spec that names the layout of its graphs, such as dagre or elk.stress (D44, D45). The built in engines are layered and dagre. A layout of ELK, elk or a name that starts with elk., lays out with the engine named elk that the caller makes available with zuzu.WithLayoutEngine, and without it is a hint that the transform of the spec draws. A graph of Mermaid fills it: elk for a kind whose default layout is ELK when the diagram sets no layout, and else the layout that the diagram sets, such as dagre. The layout that the caller forces with zuzu.WithLayout wins over it.

View Source
const DOTCylinder = "dot-cylinder"

DOTCylinder is the shape of a cylinder of DOT. Graphviz draws a cylinder in the box of any other node, with its ends inside the box, so the cylinder takes the size of a box. Mermaid makes a cylinder taller than its label by its ends, as the shape cylinder does. The reader of DOT gives this name to the shape cylinder.

Variables

This section is empty.

Functions

func ArrowOf

func ArrowOf(kind string) bool

ArrowOf reports whether zuzu draws a kind of arrowhead: a name of the arrowType of Graphviz, or circle, cross or circleplus of Mermaid. An empty kind is normal.

func ArrowPaths added in v0.3.0

func ArrowPaths(kind string) (string, string)

ArrowPaths returns the paths of an arrowhead of a kind, for a symbol of Vega that points along x to its tip at 0, 0, scaled by the size of the symbol. A shape of normal is 2 long, and each shape of the name follows the one before it back along the edge. The first path holds the shapes that are filled with the color of the edge. The second holds the open shapes, which are filled with the background, and the shapes that are only lines, such as crow and tee. A kind that is not an arrowhead draws as normal, and none draws nothing.

func Color added in v0.2.0

func Color(v string) (string, bool)

Color reads a color of DOT: a name of CSS or of the X11 scheme of Graphviz, #rrggbb, #rrggbbaa, hue, saturation and value from 0 to 1, or a color of a named scheme, as `/rdylgn11/1`, `/x11/salmon2` or `/svg/green`. A list of colors takes its first.

func ColorIn added in v0.4.0

func ColorIn(v, scheme string) (string, bool)

ColorIn reads a color of DOT in the color scheme that colorscheme names. In a scheme of ColorBrewer, such as blues9, a number is the color at that index from 1, and a name is a color of the default scheme, as in Graphviz. In the scheme svg, a name is a name of CSS. A color that names its scheme, as `/blues9/3`, takes that scheme. A name of the X11 scheme that CSS also has, such as green, keeps its color of CSS, except in the form `/x11/green`.

func ColorList added in v0.4.0

func ColorList(v string) ([]string, []float64, bool)

ColorList splits a list of colors of DOT, such as `a:b` or `a;0.3:b`, into its colors and their weights, with -1 for a color with no weight. It reports false for a weight that is not a number from 0 to 1.

func ColumnPath added in v0.3.0

func ColumnPath(xs []float64, top, bottom float64) string

ColumnPath returns the lines between the columns of a row of a record: a line from top to bottom at each x, around the center of the node.

func Compile

func Compile(g *Graph) (*vega.Spec, error)

Compile writes a graph as a Vega spec that draws it with the transform zuzu.layered: its clusters, its edges with their arrowheads and labels, and its nodes with their labels (D31).

func Contrast added in v0.2.0

func Contrast(fill string) string

Contrast returns a color of text that reads on a fill: the text of the light theme on a light fill, and that of the dark theme on a dark fill. The two hold in either mode. A fill of two colors, a gradient, reads as the mean of its colors, by their weights. It returns empty for a fill that is empty, unknown or mostly transparent.

func Crossings

func Crossings(l *Layout) int

Crossings counts the pairs of edges of a layout whose routes cross, by the lines through their points. Two edges that share an end do not count at that end.

func Finish added in v0.8.0

func Finish(in *LayoutInput, out *Layout)

Finish completes a layout that an engine made from the centers of its nodes, the boxes of its clusters, the points of its edges and the centers of the labels of its edges. An end of an edge at a node that does not lie on the outline of the shape of the node, such as an end on the box of a diamond or at the center of a node, moves along the line from the next point of the edge to where that line meets the outline. A loop keeps its ends. For each edge with two points or more, it then sets the place and the angle of each end from the first two and the last two points. It places the labels at the ends of the edges and the xlabels of the nodes and the edges, as zuzu.layered does. It then moves the layout so that it starts at 0, 0, sets its size, and writes the path of each edge with its curve. A loop, an edge from a node to itself, takes the path of a loop of zuzu.layered: a cubic curve from its first point to its last, which the two points between pull out.

An engine outside the package graph can call it after it sets the places, so that each engine draws the ends and the labels the same way.

func FollowedDirections added in v0.3.0

func FollowedDirections(g *Graph) map[string]string

FollowedDirections returns the ids of the clusters of a graph whose direction the layout does not keep, because an edge links a node inside the cluster to a node outside it. Each such cluster follows the direction of the layout that holds it, and the map gives that direction. A direction that is the same as the one it follows is not in the map.

func FontFace added in v0.6.0

func FontFace(name string) (weight, style string)

FontFace reads a weight and a style from the name of a font, such as Helvetica-Bold, Times-BoldItalic, "Arial Light" or Helvetica:bold, and returns them as Vega writes them. zuzu draws in IBM Plex Sans only, so the rest of the name changes nothing (D16, D32). The weight is empty when the name gives none, and a weight of semibold or more is BoldWeight, the heaviest weight that zuzu bundles. The style is italic for Italic and for Oblique, because the bundled font slants only as italic, and empty otherwise.

func Gradient added in v0.4.0

func Gradient(list string, angle float64, radial bool) (map[string]any, bool)

Gradient returns the gradient of a fill of two colors of DOT, as the object of Vega: a linear gradient at an angle in degrees, counterclockwise from the left to the right, or a radial gradient from the center, as style=radial of Graphviz draws it. A radial gradient with an angle moves its focus toward that angle. A weight on the first color, `a;0.3:b`, or on the second, `a:b;0.7`, makes a linear gradient a hard change at that fraction. A color after the second does not draw, as in Graphviz. It reports false for a list of one color or a color that does not read.

func HTMLGradients added in v0.4.0

func HTMLGradients(src string) (string, []HTMLGradient, []HTMLGradient)

HTMLGradients reads the attribute gradientangle and the style radial of each <table> and each <td> of a label of HTML, which the package html of okage does not read. It returns the source with them blanked out, so that each other part keeps its line and its column, and the gradients of the tables and of the cells, each in the order of the source. A gradientangle that is not a number stays in the source.

func HTMLInScheme added in v0.4.0

func HTMLInScheme(src, scheme string) string

HTMLInScheme writes each color of the attributes color and bgcolor of a label of HTML that reads in another way in a color scheme, such as 3 in the scheme blues9, with its scheme, as `/blues9/3`. A label of HTML takes the colorscheme of its node, edge, cluster or graph, as in Graphviz.

func NodeSize

func NodeSize(kind string, tw, th, pad float64) (float64, float64)

NodeSize returns the size of a node of a shape around a label of a size, with a padding.

func PaintKeys added in v0.6.0

func PaintKeys() []string

PaintKeys returns the keys of the paint of a node that a row can hold.

func Polygon added in v0.4.0

func Polygon(sides int, skew, distortion, orientation float64, regular bool) string

Polygon returns the name of the shape polygon of DOT with its sides, skew, distortion, orientation and regular. ShapeOf reads it. A polygon of fewer than 3 sides is an ellipse.

func RecordPath

func RecordPath(kind string, w, h float64, across bool, sizes []float64) string

RecordPath returns the path of a record: its box, of the shape rect or rounded, and a line between each two fields. The fields lie across the box when across is true, and down it otherwise, and sizes holds the size of each field on that axis.

func ShapeOf

func ShapeOf(name string) (string, bool)

ShapeOf returns the shape that draws a name of a shape, and false for a name that zuzu does not draw. An empty name is a rect. The name of a polygon is as Polygon writes it.

func ShapePath

func ShapePath(kind string, w, h float64) string

ShapePath returns the path of a node of a shape and a size, around 0, 0.

func StyleRow added in v0.6.0

func StyleRow(r map[string]any, st map[string]string)

StyleRow copies the paint of a style of a node into a row of a chart that lays itself out, with the names of Vega, as Compile does for a node: fill, fillOpacity, stroke, strokeWidth, strokeDash, and color as textColor. A solid fill with no color of text gets the color of text that reads on it.

func TextKeys added in v0.6.0

func TextKeys() []string

TextKeys returns the keys of the style of a label that a row can hold.

func TextOffset added in v0.5.0

func TextOffset(kind string, w, h float64) (float64, float64)

TextOffset returns how far right and down from the center of a node of a shape and a size the center of its label goes, so that the label sits in the middle of the body of the shape, where a reader looks for it: clear of the band at the top of a divided process, the band and the strip at the side of internal storage, the tab of a folder and the bar of a browser, on the front sheet of a stack of processes, below the top of a cylinder, a disk and a bucket, and left of the end of a cylinder on its side. A label goes up by half the band of a collapsed subgraph. Every other shape keeps its label in the middle.

func TextSignature added in v0.3.0

func TextSignature(r map[string]any) string

TextSignature writes the keys of the style of a label that a row sets into its field _text, and returns them. The transform zuzu.layered calls it for the rows of the fields of a record, whose fonts can differ from the font of their node.

func TintScale added in v0.8.0

func TintScale(name string, domain any) map[string]any

TintScale returns an ordinal scale, named name, that maps each value of domain to the solid tint of its color of the category scheme, in the order of the scheme. A node of a chart that takes a color by kind fills with it, and its outline takes the color itself (D55).

Types

type Cluster

type Cluster struct {
	ID, Label string
	// HTML is the source of a label of HTML of DOT for the title, or
	// empty. It draws in the place of Label.
	HTML string
	// Parent is the id of the cluster that holds this one, or empty.
	Parent string
	// Direction is the direction of the cluster, or empty for that of the
	// graph.
	Direction string
	Style     map[string]string
	// Href and Tooltip are the link and the tooltip of the cluster, or
	// empty (D32). Its box and its title take them.
	Href, Tooltip string
	// Category is the place of a color in the category scheme, as
	// Node.Category. The panel then draws as a node of that color draws: a
	// tint and an outline.
	Category int
	// Shape is the shape of the cluster: empty for a panel, or
	// ClusterPackage.
	Shape string
}

Cluster is a cluster of nodes, as a subgraph of DOT or Mermaid.

type ClusterPlace

type ClusterPlace struct {
	X, Y, Width, Height float64
	Depth               int
	TitleX, TitleY      float64
}

ClusterPlace is the box of a cluster, its depth from 0 for an outer one, and the place of the top left of its title.

type Edge

type Edge struct {
	ID             string
	Source, Target string
	// SourcePort and TargetPort name a field or a cell, a side such as e,
	// or both, as p:e.
	SourcePort, TargetPort string
	Label                  string
	// HTML is the source of a label of HTML of DOT, with no < and > around
	// it, or empty. It draws in the place of Label, and Label holds its
	// text.
	HTML string
	// HeadLabel and TailLabel are the labels at the head and at the tail of
	// the edge, such as the cardinality of an association, or empty. Each
	// sits beside the edge, near its end. XLabel is a label beside the
	// middle of the edge. These three take no space in the ranks.
	HeadLabel, TailLabel, XLabel string
	// HeadHTML, TailHTML and XHTML are the sources of labels of HTML that
	// draw in the place of HeadLabel, TailLabel and XLabel, or empty.
	HeadHTML, TailHTML, XHTML string
	// LabelStyle holds the paint of the head and the tail labels: color
	// and fontSize. A key that it does not set takes the one of Style.
	LabelStyle map[string]string
	// LabelDistance and LabelAngle fix the places of the head and the tail
	// labels, as labeldistance and labelangle of DOT do: the center of a
	// label is 10 times LabelDistance pixels from the end, at LabelAngle
	// degrees counterclockwise from the edge. When LabelDistance is 0, the
	// layout places them itself, beside the edge.
	LabelDistance, LabelAngle float64
	// MinLen is the least number of ranks that the edge spans, 1 by
	// default, and Weight how much a short edge counts, 1 when it is nil.
	// A Weight of 0 counts for nothing, as weight=0 of DOT does.
	MinLen int
	Weight *float64
	// NoConstraint takes the edge out of the ranks.
	NoConstraint bool
	// Head and Tail are the arrowheads at the ends: a name of the arrowType
	// of Graphviz, such as normal, vee, empty, odiamond, crowodot or
	// teetee, or circle, cross or circleplus of Mermaid. ArrowOf says
	// which names zuzu draws.
	Head, Tail string
	// ArrowSize scales the arrowheads, 1 for 0.
	ArrowSize float64
	// Style holds the paint of the edge, as Node.Style does.
	Style map[string]string
	// Curve is the interpolation of the route, or empty for basis.
	Curve string
	// Wrap is the width in pixels at which the label wraps, as Node.Wrap,
	// or 0 for a label that does not wrap.
	Wrap float64
	// Href and Tooltip are the link and the tooltip of the edge, or empty
	// (D32). Its line, its arrowheads and its labels take them.
	Href, Tooltip string
}

Edge is an edge of a graph.

type EdgePlace

type EdgePlace struct {
	Points                     [][2]float64
	Path                       string
	LabelX, LabelY             float64
	EndX, EndY, EndAngle       float64
	StartX, StartY, StartAngle float64
	HeadLabelX, HeadLabelY     float64
	TailLabelX, TailLabelY     float64
	XLabelX, XLabelY           float64
}

EdgePlace is the route of an edge: its points, its path of SVG, the place of its label, and the place and the angle in degrees of the end at its target and at its source. HeadLabelX, HeadLabelY, TailLabelX, TailLabelY, XLabelX and XLabelY are the centers of the labels at its head and its tail and of its xlabel.

type Engine added in v0.8.0

type Engine interface {
	// Name returns the name of the engine, such as layered or dagre. The
	// transform of the engine is zuzu. and the name, such as zuzu.dagre.
	Name() string
	// Lay lays out a graph.
	Lay(in LayoutInput) (*Layout, error)
}

Engine is a layout engine (D39 part 10). A graph goes in, as LayoutInput holds it: the nodes with their sizes, the clusters nested by their parents, the edges with the boxes of their labels and of the labels at their ends, the ports, the direction and the spaces. The places of the nodes and the clusters, the points of each edge and the places of its labels come out, as Layout holds them, in the order of the input.

An engine that does not lay out a part of the input as the input asks, such as a port, names that part in Layout.Unsupported. The transform that runs the engine reports each such part, so that zuzu never drops a part without a word (hard rule 4). An engine that does not lay out a graph at all returns an error.

An engine is safe for concurrent use. It keeps no state between two calls of Lay.

func BuiltinEngine added in v0.8.0

func BuiltinEngine(name string) Engine

BuiltinEngine returns the built in engine of a name, layered or dagre, or nil for another name.

func Dagre added in v0.8.0

func Dagre() Engine

Dagre returns the engine of zuzu.dagre: the layout of dagre 3.1.1, from the copy of dagro in internal/dagre, with the wrap of Mermaid 12.3 around it (D39 part 12, D44).

The wrap does what Mermaid does with dagre. A cluster with no edge across its border lays out on its own, as a graph of its own, in its own direction. A cluster with no direction then takes LayoutInput.ClusterDirection, or else LR inside a graph of TB, and TB inside a graph of any other direction, as Mermaid does for a subgraph of a flowchart when flowchart.inheritDir is false, its default. The graph of the cluster has the ranksep of the graph around it plus 25 pixels of Mermaid, and its box is a node of the graph around it. An edge to a cluster with an edge across its border goes to a node in the cluster, and its route stops at the box of the cluster. A loop goes through two small nodes, and draws on the side of its node where they lie. With LayoutInput.ReverseClusters, the sibling clusters set in the reverse of their order, as Mermaid sets the subgraphs of a flowchart.

The engine names in Layout.Unsupported the ports, the lanes, the groups of the same rank, the edges that take no part in the ranks, and a loop on a cluster, which dagre does not have. It lays out each such part as though the input did not ask for it. It gives no rank and no order.

func Layered added in v0.8.0

func Layered() Engine

Layered returns the engine of zuzu.layered, the layered layout of zuzu (D31). It lays out the whole of LayoutInput, and names nothing in Layout.Unsupported.

type Error

type Error string

Error is an error of the package graph.

const ErrGraph Error = "invalid graph"

ErrGraph is the error of a graph that does not lay out, such as an edge to a node that does not exist.

func (Error) Error

func (err Error) Error() string

Error satisfies the error interface.

type Field

type Field struct {
	Text, Port string
	// Cells are the cells of a row of a table, in the place of Text. The
	// cells of a column of a record line up, a line divides two columns,
	// and a column with no text in any row takes no space. A cell starts
	// at the left of its column.
	Cells []string
	// Align puts each line of the text at the left of the field, l, or at
	// its center, the default.
	Align string
	// Fonts holds the font of each line of the text, or of each cell of
	// a row of cells, or nil for the font of the node. A cell draws no
	// line under it.
	Fonts []Font
}

Field is a field of a record: its text and its port.

type Font added in v0.3.0

type Font struct {
	Bold, Italic, Underline bool
}

Font is the font of a line of a field: bold, italic, or with a line under it.

type Graph

type Graph struct {
	// Directed says whether an edge has a direction, as a digraph of DOT
	// does and a graph does not.
	Directed bool
	// Direction is TB, BT, LR or RL.
	Direction string
	// Title is the title of the diagram, or empty.
	Title string
	// TitleHTML is the source of a label of HTML of DOT for the title, with
	// no < and > around it, or empty. It draws in the place of Title, at
	// the top left of the diagram.
	TitleHTML string
	// TitleStyle holds the fontWeight and the fontStyle of Title, or nil.
	TitleStyle map[string]string
	Nodes      []*Node
	Edges      []*Edge
	Clusters   []*Cluster
	// RankSep and NodeSep are the space between the ranks and between the
	// nodes of a rank, or 0 for the defaults.
	RankSep, NodeSep float64
	// ClusterTitleTop and ClusterTitleBottom are the space above and below
	// the title of each cluster, 0 by default.
	ClusterTitleTop, ClusterTitleBottom float64
	// Padding is the space around the diagram, or nil for 8 pixels.
	Padding *float64
	// TitleOffset is the space between the title and the diagram, or nil
	// for the space of the title of a chart.
	TitleOffset *float64
	// Lanes lays the graph out in lanes, as LayoutInput.Lanes says, and
	// LaneEdges makes an edge between two lanes move its target to the next
	// rank, as LayoutInput.LaneEdges says.
	Lanes, LaneEdges bool
	// ClusterDirection is the direction of a cluster with no direction of
	// its own that lays out on its own in zuzu.dagre, as
	// LayoutInput.ClusterDirection says, or empty. A state diagram of
	// Mermaid gives TB.
	ClusterDirection string
	// ReverseClusters sets the sibling clusters in zuzu.dagre in the
	// reverse of their order, as LayoutInput.ReverseClusters says. The
	// reader of a flowchart of Mermaid sets it.
	ReverseClusters bool
	// BreakWords breaks a word that is wider than the wrap width of its
	// label between two letters, as the SVG labels of Mermaid do. Otherwise
	// the word stays whole on a line of its own, and the label is wider
	// than the wrap width, as the HTML labels of Mermaid are.
	BreakWords bool
	// Math draws the math of KaTeX in the labels, each text between two
	// $$, with the font of math of the render (D36). A label with math is
	// one row of its runs of text and of its formulas, with no wrap, and
	// each newline in it is a space, as Mermaid 12.3 draws it. Each line
	// of a field, such as a member of a class, is a label of its own.
	// MathSource holds the labels with math that draw their source as
	// text, because a formula in them does not lay out.
	Math       bool
	MathSource []string

	// Description is the text of the diagram for a screen reader, or
	// empty. Compile writes it as the description of the spec.
	Description string
	// Href and Tooltip are the link and the tooltip of the whole diagram,
	// or empty (D32).
	Href, Tooltip string
	// Background is a color of CSS that fills the page and is the
	// background of the theme, such as the bgcolor of a graph of DOT, or
	// empty (D37). Compile writes it in the config of the spec as
	// zuzu.background.
	Background string
}

Graph is a diagram: its nodes, its edges and its clusters, in the order of its source.

type HTMLGradient added in v0.4.0

type HTMLGradient struct {
	Angle  float64
	Radial bool
}

HTMLGradient is the gradient of a table or a cell of a label of HTML: its angle, and whether it is radial.

type Issues

type Issues struct {
	Strict bool
	Report vega.Report
	// contains filtered or unexported fields
}

Issues collects the parts of a source that zuzu does not draw: an error in the strict mode, and a line of the report in the loose mode (D26).

func (*Issues) Add

func (is *Issues) Add(path, format string, args ...any) error

Add records a part that zuzu does not draw, once for each message. In the strict mode it returns the issue as an error.

type Layout

type Layout struct {
	Width, Height float64
	Nodes         []NodePlace
	Edges         []EdgePlace
	Clusters      []ClusterPlace
	// Unsupported names each part of the input that the engine did not lay
	// out as the input asks, such as the port of an edge, in words that a
	// report shows, such as "the port of the edge a -> b, which the layout
	// leaves out". zuzu.layered names nothing.
	Unsupported []string
}

Layout is the result of Lay, and of the Lay of an Engine, with the places in the order of the input.

func Lay

func Lay(in LayoutInput) (*Layout, error)

Lay lays out a graph in ranks (D31). A cluster with a direction of its own, or a cluster that an edge names, lays out on its own when no edge links a node inside it to a node outside it, as in Mermaid. Its layout then takes the place of one node, of its size, in the layout that holds it. An edge to any other cluster ends at the box of the cluster: the layout takes it to the first node of the cluster, and the route stops at the box. A layout in lanes lays out as LayoutInput.Lanes says.

type LayoutCluster

type LayoutCluster struct {
	ID, Parent              string
	TitleWidth, TitleHeight float64
	// TitleTop is the space above the title, which TitleHeight holds.
	TitleTop float64
	// Direction is the direction of the ranks inside the cluster, TB, BT,
	// LR or RL, or empty for the direction of the layout that holds it.
	// The cluster keeps it only when no edge links a node inside the
	// cluster to a node outside it, as in Mermaid. Otherwise the cluster
	// follows the layout that holds it.
	Direction string
}

LayoutCluster is a cluster to lay out, with the size of its title.

type LayoutEdge

type LayoutEdge struct {
	// Source and Target are the ids of the ends: each a node, or else a
	// cluster. An edge to a cluster ends at the box of the cluster.
	Source, Target string
	// MinLen is 1 or more, and Weight is 1 when it is nil. A Weight of 0
	// counts for nothing in the ranks and in the places across them.
	MinLen int
	Weight *float64
	// NoConstraint takes the edge out of the ranks.
	NoConstraint bool
	// LabelWidth and LabelHeight are the size of the label of the edge, or
	// 0 for none.
	LabelWidth, LabelHeight float64
	// HeadLabelWidth, HeadLabelHeight, TailLabelWidth and TailLabelHeight
	// are the sizes of the labels at the ends of the edge, and XLabelWidth
	// and XLabelHeight the size of its xlabel, or 0 for none. These labels
	// take no space in the ranks.
	HeadLabelWidth, HeadLabelHeight float64
	TailLabelWidth, TailLabelHeight float64
	XLabelWidth, XLabelHeight       float64
	// LabelDistance and LabelAngle fix the places of the labels at the
	// ends, as Edge.LabelDistance and Edge.LabelAngle say, or the layout
	// places them beside the edge when LabelDistance is 0.
	LabelDistance, LabelAngle float64
	// Curve is the interpolation of the route: basis, the default, or
	// another curve of Vega, such as linear or step.
	Curve string
	// SourcePort and TargetPort are the places of the ports at the ends,
	// as x and y from the center of the node, or nil for none. An edge
	// leaves a port on the side of the node that faces its route.
	SourcePort, TargetPort []float64
	// SourceSide and TargetSide are the directions out of the node at a
	// port on a side, such as 1, 0 for the east side, or nil. An edge at
	// such a port ends on the port and leaves it in that direction.
	SourceSide, TargetSide []float64
}

LayoutEdge is an edge to lay out.

type LayoutInput

type LayoutInput struct {
	Nodes    []LayoutNode
	Edges    []LayoutEdge
	Clusters []LayoutCluster
	// Direction is TB, BT, LR or RL. Empty is TB.
	Direction string
	// RankSep, NodeSep and ClusterPadding are the space between the ranks,
	// between the nodes of a rank, and inside a cluster. 0 is 40, 24 and 12.
	RankSep, NodeSep, ClusterPadding float64
	// Lanes lays the graph out in lanes, as the swimlane layout of Mermaid
	// 12.3 does: each cluster at the top is a lane that runs along all the
	// ranks, the lanes lie side by side in the order of the input, and the
	// edges route at right angles. The nodes outside every cluster make a
	// lane before the others.
	Lanes bool
	// LaneEdges makes an edge between two lanes move its target to the
	// next rank in a layout in lanes, as the setting
	// swimlane.ignoreCrossLaneEdges false of Mermaid does.
	LaneEdges bool
	// ClusterDirection is the direction of a cluster with no direction of
	// its own that lays out on its own in zuzu.dagre, or empty. Empty gives
	// LR inside a graph of TB, and TB inside a graph of any other direction,
	// as Mermaid 12.3 does for a subgraph of a flowchart. Mermaid gives TB to
	// each composite state of a state diagram. zuzu.layered does not read
	// it.
	ClusterDirection string
	// ReverseClusters sets each list of sibling clusters in zuzu.dagre in
	// the reverse of the order of the input, as the wrap of dagre in
	// Mermaid 12.3 sets the subgraphs of a flowchart (D45 part 5). The
	// clusters still set from the outer to the inner. zuzu.layered does not
	// read it.
	ReverseClusters bool
	// Algorithm is the layout that the spec names in its config with
	// zuzu.layout, such as elk.stress, or empty. An engine with more than
	// one algorithm, such as one of ELK, reads it to choose one. zuzu.layered
	// and zuzu.dagre do not read it.
	Algorithm string
}

LayoutInput is what Lay lays out: nodes with their sizes, edges, clusters and the options.

type LayoutNode

type LayoutNode struct {
	ID string
	// Cluster is the id of the cluster that holds the node, or empty, and
	// Rank names a group of nodes of the same rank, or empty.
	Cluster, Rank string
	// Shape decides where an edge meets the node: ellipse, circle,
	// diamond, or else a rect.
	Shape         string
	Width, Height float64
	// XLabelWidth and XLabelHeight are the size of the xlabel of the node,
	// or 0 for none. The xlabel takes no space in the ranks.
	XLabelWidth, XLabelHeight float64
}

LayoutNode is a node to lay out.

type Media

type Media struct {
	// Icon names an icon, as pack:name, and Image the URL of an image.
	Icon, Image string
	// Path is a figure that zuzu draws in the place of an icon, such as
	// an actor of a use case diagram: the path data of SVG around 0, 0,
	// inside Width and Height. It takes the paint of its node.
	Path string
	// Form is the box around an icon: square, circle, rounded, or empty
	// for none.
	Form string
	// Pos puts the label above the icon, t, or below it, b, the default.
	Pos string
	// Width and Height are the size of the icon or the image, or 0 for the
	// default.
	Width, Height float64
	// Keep keeps the ratio of the width to the height of an image.
	Keep bool
	// Inline draws the icon before the label, inside the shape of the node,
	// as an icon in a label does.
	Inline bool
}

Media is the icon or the image of a node (D31).

type Node

type Node struct {
	ID string
	// Label is the text of the node. An empty label draws the id, except
	// on a node with a Width and a Height, or with NoLabel, which draws no
	// text.
	Label string
	// NoLabel draws no text for an empty Label, as label="" of DOT does.
	NoLabel bool
	// Shape names the shape of the node, such as rect or ellipse. The
	// shape polygon of DOT has the name that Polygon writes.
	Shape string
	// Cluster is the id of the cluster that holds the node, or empty.
	Cluster string
	// Rank names a group of nodes of the same rank, or empty.
	Rank string
	// Style holds the paint of the node: fill, stroke, color, strokeWidth,
	// strokeDash, strokeDashOffset, fontWeight, fontStyle and so on, with
	// the names of Vega. A fill of
	// two colors of DOT, such as a:b, sets gradient to the list of colors,
	// gradientAngle to its angle in degrees, and gradientType to radial
	// for a radial gradient. Fill then holds the first color.
	Style map[string]string
	// Media is the icon or the image of the node, or nil.
	Media *Media
	// Fields are the fields of a record, or nil.
	Fields []Field
	// Stack lays the fields of a record one under another in every
	// direction, as the title and the descriptions of a state of Mermaid.
	// Otherwise the fields lie across the ranks. A field of a stacked
	// record with no text and no cells is a thin empty band, as an empty
	// compartment of a class is.
	Stack bool
	// Note says that the node is a note of Mermaid, such as a note of a
	// state diagram, which draws in the color of a note of the theme, its
	// yellow, and not in the color of a node.
	Note bool
	// Solid says that the node fills with the color of its outline, not
	// with its tint, such as the start of a state diagram, a fork bar or a
	// junction point of a flowchart (D55).
	Solid bool
	// Runs are the parts of the label of a node in one font each, bold,
	// italic or plain, such as the runs of a string of markdown of
	// Mermaid, or nil for a label in one font. A run with the text "\n"
	// starts a new line. The layout wraps the runs and draws each in its
	// font, as a label of HTML.
	Runs []Run
	// HTML is the source of a label of HTML of DOT, with no < and > around
	// it, or empty. The package html of okage reads it and lays it out
	// (D31).
	HTML string
	// Margin is the space around a label of HTML, x and y, or nil for the
	// default of the shape.
	Margin []float64
	// XLabel is a label outside the node, at a corner of the node, and
	// XHTML the source of a label of HTML there, or empty. An xlabel takes
	// no space in the layout: it goes where it covers no node and no other
	// label, if it can.
	XLabel, XHTML string
	// Width and Height are the size of the node, or 0 to measure the label.
	Width, Height float64
	// MinWidth and MinHeight are the least size of the node, which grows to
	// fit its label, or 0 for none.
	MinWidth, MinHeight float64
	// MinLabelWidth is the least width of the box of the label, or 0 for
	// none. A narrower label takes the middle of a box of this width, and
	// the shape grows around the box, as Mermaid sizes a node with
	// minNodeWidth. A node with no label, a node with fields or HTML, and
	// a node with an icon or an image outside the line of its label do not
	// read it.
	MinLabelWidth float64
	// Wrap is the width in pixels at which the label wraps, or 0 for a
	// label that does not wrap. A line of the label that is wider breaks at
	// its spaces into lines that are not wider. The label of a node with
	// fields or HTML does not wrap.
	Wrap float64
	// Href is the link of the node and Tooltip its tooltip, or empty
	// (D32). Its shape and its labels take them.
	Href, Tooltip string
	// Category is the place of a color in the category scheme of the
	// theme, from 1, or 0 for none. The node then draws in that color, a
	// tint and an outline, and its figure too. A fill or a stroke of Style
	// wins over it. After the last color of the scheme, the colors start
	// again (D37).
	Category int
}

Node is a node of a graph.

type NodePlace

type NodePlace struct {
	X, Y, Width, Height float64
	Rank, Order         int
	// XLabelX and XLabelY are the center of the xlabel of the node.
	XLabelX, XLabelY float64
}

NodePlace is the place of a node: its center and its size, its rank and its order in the rank. A node in a cluster that lays out on its own has the rank and the order of the layout of that cluster. An engine that gives no rank and no order, such as the engine of zuzu.dagre, leaves them 0.

type Run added in v0.8.0

type Run struct {
	Text         string
	Bold, Italic bool
}

Run is a part of a label in one font: its text, and whether it is bold or italic.

Directories

Path Synopsis
Package dot reads the DOT language of Graphviz into a graph (D31).
Package dot reads the DOT language of Graphviz into a graph (D31).
Package mermaid reads diagrams of Mermaid 12.3.0 (D31): the flowchart, the swimlane diagram, the state diagram, the class diagram, the entity relationship diagram, the requirement diagram, the agentflow diagram and the use case diagram into a graph, and the charts into specs of Vega-Lite and Vega.
Package mermaid reads diagrams of Mermaid 12.3.0 (D31): the flowchart, the swimlane diagram, the state diagram, the class diagram, the entity relationship diagram, the requirement diagram, the agentflow diagram and the use case diagram into a graph, and the charts into specs of Vega-Lite and Vega.

Jump to

Keyboard shortcuts

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