Help us shape the future of Go! Take the 2026 Go Developer Survey

c4

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package c4 parses Mermaid's C4 diagrams and lays them out, as Pele's src/diagrams/c4 does: a lexer and a parser that read what Mermaid's c4Diagram.jison reads, the model they build (C4Db), the grid of shapes and boundaries Mermaid lays them out in (layout.ts), the routes of the relations between them (route.ts), and Layout, which draws them as a scene (render.ts).

Index

Constants

View Source
const (
	RoleTitle         scene.Role = "c4.title"
	RoleBoundary      scene.Role = "c4.boundary"
	RoleDeployment    scene.Role = "c4.deployment"
	RoleBoundaryLabel scene.Role = "c4.boundary-label"
	RoleBoundaryType  scene.Role = "c4.boundary-type"
	RoleBoundaryDescr scene.Role = "c4.boundary-descr"
	RoleRel           scene.Role = "c4.rel"
	RoleElement       scene.Role = "c4.element"
	RoleElementType   scene.Role = "c4.element-type"
	RoleElementTechn  scene.Role = "c4.element-techn"
	RoleElementDescr  scene.Role = "c4.element-descr"
	RoleRelLabel      scene.Role = "c4.rel-label"
	RoleRelTechn      scene.Role = "c4.rel-techn"
)

The roles of the items of a C4 diagram.

Variables

This section is empty.

Functions

func Layout

func Layout(db *DB, _ diagram.Config, o *layout.Options) (*scene.Scene, error)

Layout lays out a parsed C4 diagram as a scene, as Pele's renderC4 draws it: on Mermaid's grid with room to spare, and, when that does not fit o.MaxWidth, tightly, with the gap between columns that leaves the fewest relations without a lane of their own. A relation between things the diagram does not have is an error, a *diagram.Error.

Types

type Boundary

type Boundary struct {
	Element
	// NodeType is set on deployment nodes: node, nodeL or nodeR.
	NodeType string
}

Boundary is a boundary or a deployment node, Pele's C4Boundary.

type DB

type DB struct {
	// C4Type is the header keyword: C4Context, C4Container, C4Component, C4Dynamic or
	// C4Deployment.
	C4Type string
	// Title is the title, when HasTitle.
	Title    string
	HasTitle bool
	// AccTitle is never set: the grammar hands accTitle to the title.
	AccTitle string
	// AccDescr is the accessible description, when HasAccDescr.
	AccDescr    string
	HasAccDescr bool
	Shapes      []*Shape
	// The first boundary is the unnamed one that holds everything at the top level.
	Boundaries []*Boundary
	Rels       []*Rel
	// ShapeInRow and BoundaryInRow are as parseInt reads them, which may be past any int.
	ShapeInRow, BoundaryInRow float64
	// contains filtered or unexported fields
}

DB is a parsed C4 diagram, Pele's C4Db, and the builder the parser calls.

func Parse

func Parse(source, title string) (*DB, error)

Parse parses a C4 diagram's text, as the parse of Pele's C4 diagram does: source is what diagram.Prepared.Source gives, and title the title its front matter gives, "" for none. An error is a *diagram.Error.

func ParsePrepared

func ParsePrepared(p *diagram.Prepared) (*DB, error)

ParsePrepared parses a prepared C4 diagram. It is limu's own: it hands Parse the source and the title that Pele's caller hands the parse of its C4 diagram.

type Element

type Element struct {
	Alias, Label string
	// A named argument written where the alias or the label belongs. It is applied to the
	// field it names.
	AliasAttr, LabelAttr *Named
	Parent               *Boundary

	Type, Descr, Techn, Sprite, Tags, Link     string
	BgColor, FontColor, BorderColor            string
	Shadowing, Shape, LegendText, LegendSprite string
	// Extra holds the named arguments that set no known field, in the order they were first
	// given; a later one of the same key replaces the value.
	Extra []Named
	// contains filtered or unexported fields
}

Element is what shapes and boundaries share, Pele's C4Element. A field Pele leaves undefined is empty, and Defined tells it from one set to "".

func (*Element) Defined

func (e *Element) Defined(field string) bool

Defined reports whether the field of the name Pele gives it, as "descr", is defined. Pele has no such method: its fields are left undefined, and this reads what that tells.

type Named

type Named struct{ Key, Value string }

Named is a `$key="value"` argument, Pele's C4Named.

type Rel

type Rel struct {
	Type, From, To, Label       string
	FromAttr, ToAttr, LabelAttr *Named

	Techn, Descr, Sprite, Tags, Link, TextColor, LineColor string
	// OffsetX and OffsetY are as parseInt reads them, NaN among them.
	OffsetX, OffsetY float64
	Extra            []Named
	// contains filtered or unexported fields
}

Rel is a relation, Pele's C4Rel.

func (*Rel) Defined

func (r *Rel) Defined(field string) bool

Defined reports whether the field of the name Pele gives it, as "techn", is defined, as Element's Defined does for a relation.

type Shape

type Shape struct {
	Element
	// Kind is Mermaid's typeC4Shape: person, external_system_db, container_queue and so on.
	Kind string
}

Shape is a person, a system, a container or a component, Pele's C4Shape.

Jump to

Keyboard shortcuts

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