d2graph

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2026 License: MPL-2.0 Imports: 31 Imported by: 13 modules, 4 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

Index

Constants

View Source
const (
	// MaxGridDimension bounds each axis of an explicitly dimensioned grid. In
	// addition to layout work, this limits the coordinate span contributed by
	// empty cells before output-specific resource limits run.
	MaxGridDimension = 10_000
	// MaxGridCells bounds the capacity of an explicitly dimensioned grid. Grid
	// layout retains empty cells so that diagrams can add objects in later boards,
	// which makes rows*columns the relevant amount of user-controlled work even
	// when the current board contains few objects.
	MaxGridCells = 1_000_000
)
View Source
const DEFAULT_SHAPE_SIZE = 100.
View Source
const INNER_LABEL_PADDING int = 5
View Source
const MIN_SEGMENT_LEN = 10
View Source
const MIN_SHAPE_SIZE = 5

Variables

This section is empty.

Functions

func CompareSerializedEdge deprecated

func CompareSerializedEdge(edge, other *Edge) error

CompareSerializedEdge compares the portions of two edges preserved by SerializeGraph and DeserializeGraph.

Deprecated: CompareSerializedEdge is an incomplete, test-only assertion and will be removed after one compatibility release. Tests should compare the specific edge invariants they rely on.

func CompareSerializedGraph deprecated

func CompareSerializedGraph(g, other *Graph) error

CompareSerializedGraph compares the portions of two graphs preserved by SerializeGraph and DeserializeGraph.

Deprecated: CompareSerializedGraph is an incomplete, test-only assertion and will be removed after one compatibility release. Tests should serialize, deserialize, and compare the specific graph invariants they rely on.

func CompareSerializedObject deprecated

func CompareSerializedObject(obj, other *Object) error

CompareSerializedObject compares the portions of two objects preserved by SerializeGraph and DeserializeGraph.

Deprecated: CompareSerializedObject is an incomplete, test-only assertion and will be removed after one compatibility release. Tests should compare the specific object invariants they rely on.

func Convert

func Convert[T, Q any](from T, to *Q) error

func DeserializeGraph

func DeserializeGraph(bytes []byte, g *Graph) error

func GetTextDimensions

func GetTextDimensions(mtexts []*d2target.MText, ruler *textmeasure.Ruler, t *d2target.MText, fontFamily *d2fonts.FontFamily) *d2target.TextDimensions

func GetTextDimensionsWithMono

func GetTextDimensionsWithMono(mtexts []*d2target.MText, ruler *textmeasure.Ruler, t *d2target.MText, fontFamily *d2fonts.FontFamily, monoFontFamily *d2fonts.FontFamily) *d2target.TextDimensions

func GridCapacity added in v0.10.0

func GridCapacity(rows, columns int) (int, error)

GridCapacity returns rows*columns when both axes and their product are bounded. The division check keeps the multiplication from overflowing an int.

func Key

func Key(k *d2ast.KeyPath) []string

func ParseConnectionIconAnimation added in v0.10.1

func ParseConnectionIconAnimation(value string) (*d2target.ConnectionIconAnimation, error)

ParseConnectionIconAnimation interprets the edge icon's animated style. Other uses of style.animated retain their existing boolean grammar.

func SerializeGraph

func SerializeGraph(g *Graph) ([]byte, error)

Types

type Annotation added in v0.10.1

type Annotation struct {
	Label           Scalar                  `json:"label"`
	LabelDimensions d2target.TextDimensions `json:"labelDimensions"`
	// Shape is the mark. Unset, the renderer picks one that suits the target.
	Shape *Scalar `json:"shape,omitempty"`
	// Position is the side of the target the note sits on. Unset, the renderer
	// picks the side with the most room.
	Position *Scalar `json:"position,omitempty"`
	Stroke   *Scalar `json:"stroke,omitempty"`
	// FontColor colors the text alone. Unset, the text is written in the pen.
	FontColor *Scalar `json:"fontColor,omitempty"`
	// Group names the class or glob that gave the shape a lasso. Shapes with
	// the same group share one loop. Empty, the lasso holds this shape alone.
	Group string `json:"group,omitempty"`
	// Cues are the objects a board's caption links to, by absolute ID, in the
	// order the caption names them. Text is that caption as painted, with each
	// cue link replaced by emphasis.
	Cues []string `json:"cues,omitempty"`
	Text string   `json:"text,omitempty"`
}

Annotation is a mark and a short Markdown note that point at one object or connection. It takes no part in layout.

func (*Annotation) MText added in v0.10.1

func (a *Annotation) MText(fontSize int) *d2target.MText

MText returns the note as measurable Markdown at the given size.

func (*Annotation) Markdown added in v0.10.1

func (a *Annotation) Markdown() string

Markdown returns the text the annotation paints.

type Attributes

type Attributes struct {
	Sequence *SequenceOptions `json:"sequence,omitempty"`
	// SequenceOrder orders v2 timeline items at their import or spread occurrence.
	SequenceOrder []uint64 `json:"sequenceOrder,omitempty"`
	// SequenceDeclarationIndex identifies the reference that introduced this timeline item.
	SequenceDeclarationIndex int `json:"sequenceDeclarationIndex,omitempty"`

	Label           Scalar                  `json:"label"`
	LabelDimensions d2target.TextDimensions `json:"labelDimensions"`

	Style         Style                  `json:"style"`
	Icon          *url.URL               `json:"icon,omitempty"`
	IconStyle     Style                  `json:"iconStyle"`
	ImageFit      d2target.ImageFit      `json:"imageFit,omitempty"`
	ImagePosition d2target.ImagePosition `json:"imagePosition,omitempty"`
	Tooltip       *Scalar                `json:"tooltip,omitempty"`
	Link          *Scalar                `json:"link,omitempty"`
	// Annotation is drawn over the object for the length of its board. On a
	// board's root it is the board's caption.
	Annotation *Annotation `json:"annotation,omitempty"`

	WidthAttr  *Scalar `json:"width,omitempty"`
	HeightAttr *Scalar `json:"height,omitempty"`

	Top  *Scalar `json:"top,omitempty"`
	Left *Scalar `json:"left,omitempty"`

	// TODO consider separate Attributes struct for shape-specific and edge-specific
	// Shapes only
	NearKey  *d2ast.KeyPath `json:"near_key"`
	Language string         `json:"language,omitempty"`
	// TODO: default to ShapeRectangle instead of empty string
	Shape Scalar `json:"shape"`

	Direction  Scalar   `json:"direction"`
	Constraint []string `json:"constraint"`

	GridRows    *Scalar `json:"gridRows,omitempty"`
	GridColumns *Scalar `json:"gridColumns,omitempty"`
	// GridRowsFirst records declaration order in the merged map when both axes exist.
	GridRowsFirst *bool   `json:"gridRowsFirst,omitempty"`
	GridGap       *Scalar `json:"gridGap,omitempty"`
	VerticalGap   *Scalar `json:"verticalGap,omitempty"`
	HorizontalGap *Scalar `json:"horizontalGap,omitempty"`

	LabelPosition   *Scalar `json:"labelPosition,omitempty"`
	IconPosition    *Scalar `json:"iconPosition,omitempty"`
	TooltipPosition *Scalar `json:"tooltipPosition,omitempty"`

	// These names are attached to the rendered elements in SVG
	// so that users can target them however they like outside of D2
	Classes []string `json:"classes,omitempty"`
}

func (*Attributes) ApplyTextTransform

func (a *Attributes) ApplyTextTransform()

ApplyTextTransform will alter the `Label.Value` of the current object based on the specification of the `text-transform` styling option. This function has side-effects!

func (*Attributes) ToArrowhead

func (a *Attributes) ToArrowhead() d2target.Arrowhead

type ContainerLevel

type ContainerLevel int

func (ContainerLevel) LabelSize

func (l ContainerLevel) LabelSize() int

type Edge

type Edge struct {
	SequenceNumber int `json:"sequenceNumber,omitempty"`
	// SequenceNumberWidth reserves space beside a rich label for its plain-text ordinal.
	SequenceNumberWidth int `json:"sequenceNumberWidth,omitempty"`

	// SequenceKey is the v2 source address before participant hoisting and graph indexing.
	SequenceKey *d2ast.Key `json:"-"`
	// SequenceGraphOrder is the insertion order that assigns graph edge indexes,
	// before the diagram's edges are sorted by their source locations.
	SequenceGraphOrder int `json:"-"`

	IconShape *Scalar `json:"iconShape,omitempty"`
	Index     int     `json:"index"`

	SrcTableColumnIndex *int `json:"srcTableColumnIndex,omitempty"`
	DstTableColumnIndex *int `json:"dstTableColumnIndex,omitempty"`

	LabelPosition   *string  `json:"labelPosition,omitempty"`
	LabelPercentage *float64 `json:"labelPercentage,omitempty"`

	IsCurve bool         `json:"isCurve"`
	Route   []*geo.Point `json:"route,omitempty"`

	Src          *Object     `json:"-"`
	SrcArrow     bool        `json:"src_arrow"`
	SrcArrowhead *Attributes `json:"srcArrowhead,omitempty"`
	Dst          *Object     `json:"-"`
	// TODO alixander (Mon Sep 12 2022): deprecate SrcArrow and DstArrow and just use SrcArrowhead and DstArrowhead
	DstArrow     bool        `json:"dst_arrow"`
	DstArrowhead *Attributes `json:"dstArrowhead,omitempty"`

	References []EdgeReference `json:"references,omitempty"`
	Attributes `json:"attributes,omitempty"`

	ZIndex int `json:"zIndex"`
}

func (*Edge) AbsID

func (e *Edge) AbsID() string

AbsID returns the materialized source address for v2 messages. Other edges use "<common>(<src> <arrow> <dst>)[<index>]": the ID paths (AbsIDArray) of the endpoints joined with ".", without the leading IDs they share (compared with strings.EqualFold, spelled as in the source; each path keeps at least its last ID), which form <common>, each followed by ".".

func (*Edge) ArrowString

func (e *Edge) ArrowString() string

func (*Edge) Arrowheads added in v0.10.1

func (e *Edge) Arrowheads() (d2target.Arrowhead, d2target.Arrowhead)

Arrowheads returns the markers at the authored source and destination.

func (*Edge) ContainedBy

func (e *Edge) ContainedBy(obj *Object) bool

func (*Edge) EndpointStrokeWidths added in v0.10.1

func (e *Edge) EndpointStrokeWidths() (float64, float64)

EndpointStrokeWidths includes the subpixel width of tweened shapes.

func (*Edge) ExportIcon added in v0.10.1

func (e *Edge) ExportIcon(connection *d2target.Connection)

ExportIcon supplies the same artwork dimensions and positioning to label placement and rendering.

func (*Edge) GetAstEdge

func (e *Edge) GetAstEdge() *d2ast.Edge

func (*Edge) GetGroup

func (e *Edge) GetGroup() *Object

func (*Edge) GetStroke

func (e *Edge) GetStroke(dashGapSize interface{}) string

func (*Edge) HasIcon added in v0.10.1

func (e *Edge) HasIcon() bool

HasIcon includes native artwork and the default dot of an animated stream.

func (*Edge) IsEquivalent added in v0.8.2

func (e *Edge) IsEquivalent(src *Object, srcArrow bool, dst *Object, dstArrow bool) bool

IsEquivalent reports whether the given endpoints describe the same edge. Arrowheads are attached to endpoints, so reversing the endpoint order also reverses the arrow fields.

func (*Edge) Move

func (e *Edge) Move(dx, dy float64)

func (*Edge) ShiftEnd

func (edge *Edge) ShiftEnd(delta float64, isHorizontal bool)

ShiftEnd moves the ending point of the route by delta either horizontally or vertically if prior points are in line with the movement, they will be removed (unless it is the first point)

func (*Edge) ShiftStart

func (edge *Edge) ShiftStart(delta float64, isHorizontal bool)

ShiftStart moves the starting point of the route by delta either horizontally or vertically if subsequent points are in line with the movement, they will be removed (unless it is the last point) start end . ├────┼────┼───┼────┼───┤ before . ├──dx──► . ├──┼───┼────┼───┤ after

func (*Edge) SourceIndex added in v0.10.1

func (e *Edge) SourceIndex() int

SourceIndex gives the index within the address an author can use in D2. Graph indexing can span multiple sequence frames that share participants.

func (*Edge) Text

func (e *Edge) Text() *d2target.MText

func (*Edge) TraceToShape

func (edge *Edge) TraceToShape(points []*geo.Point, startIndex, endIndex int) (newStart, newEnd int)

type EdgeReference

type EdgeReference struct {
	IsVar bool        `json:"-"`
	Edge  *d2ast.Edge `json:"-"`

	MapKey          *d2ast.Key `json:"-"`
	MapKeyEdgeIndex int        `json:"map_key_edge_index"`
	Scope           *d2ast.Map `json:"-"`
	ScopeObj        *Object    `json:"-"`
	ScopeAST        *d2ast.Map `json:"-"`
}

type Graph

type Graph struct {
	FS     fs.FS  `json:"-"`
	Parent *Graph `json:"-"`
	Name   string `json:"name"`
	// BoardRange locates the board declaration in source, including dotted keys and imports.
	BoardRange d2ast.Range `json:"-"`
	// IsFolderOnly indicates a board or scenario itself makes no modifications from its
	// base. Folder only boards do not have a render and are used purely for organizing
	// the board tree.
	IsFolderOnly bool       `json:"isFolderOnly"`
	AST          *d2ast.Map `json:"ast"`
	// BaseAST is the AST of the original graph without inherited fields and edges
	BaseAST *d2ast.Map `json:"-"`

	Root    *Object   `json:"root"`
	Legend  *Legend   `json:"legend,omitempty"`
	Edges   []*Edge   `json:"edges"`
	Objects []*Object `json:"objects"`

	Layers    []*Graph `json:"layers,omitempty"`
	Scenarios []*Graph `json:"scenarios,omitempty"`
	Steps     []*Graph `json:"steps,omitempty"`

	// TweenFrames are the sampled incoming transition, in playback order. Each
	// frame belongs to this board and shares its navigation identity.
	TweenFrames     []*Graph `json:"-"`
	TweenDurationMS int      `json:"-"`

	Theme *d2themes.Theme `json:"theme,omitempty"`

	// Object.Level uses the location of a nested graph
	RootLevel int `json:"rootLevel,omitempty"`

	// IsPartialLayout marks a layout input whose surrounding objects or edges
	// were removed for a nested layout. RootLevel can still be zero when an
	// extraction includes its top-level container.
	IsPartialLayout bool `json:"isPartialLayout,omitempty"`

	// Data embedded from source configuration variables, including layout options.
	Data map[string]interface{} `json:"data,omitempty"`
}

func NewGraph

func NewGraph() *Graph

func (*Graph) ApplyTheme

func (g *Graph) ApplyTheme(themeID int64) error

ApplyTheme applies themes on the graph level This is different than on the render level, which only changes colors A theme applied on the graph level applies special rules that change the graph

func (*Graph) ExtractAsNestedGraph

func (g *Graph) ExtractAsNestedGraph(obj *Object) *Graph

remove obj and all descendants from graph, as a new Graph

func (*Graph) GetBoard

func (g *Graph) GetBoard(name string) *Graph

func (*Graph) IDA

func (g *Graph) IDA() []string

func (*Graph) InjectNestedGraph

func (g *Graph) InjectNestedGraph(tempGraph *Graph, parent *Object)

func (*Graph) IsWholeLayout added in v0.10.0

func (g *Graph) IsWholeLayout() bool

IsWholeLayout reports whether all surrounding objects and edges are present. Older serialized subgraphs record their nesting only in RootLevel.

func (*Graph) PrintString

func (g *Graph) PrintString() string

func (*Graph) RootBoard

func (g *Graph) RootBoard() *Graph

func (*Graph) SetDimensions

func (g *Graph) SetDimensions(mtexts []*d2target.MText, ruler *textmeasure.Ruler, fontFamily *d2fonts.FontFamily, monoFontFamily *d2fonts.FontFamily) error

func (*Graph) SortEdgesByAST

func (g *Graph) SortEdgesByAST()

func (*Graph) SortObjectsByAST

func (g *Graph) SortObjectsByAST()

func (*Graph) Texts

func (g *Graph) Texts() []*d2target.MText

type LayoutContinuation added in v0.10.0

type LayoutContinuation func(ctx context.Context, previous, current *Graph) (bool, error)

LayoutContinuation may refine a completed layout relative to its preceding board. It may change current geometry only and reports whether the boards share coordinates for playback. Both graphs are local to one compilation.

type LayoutGraph

type LayoutGraph func(context.Context, *Graph) error

type Legend

type Legend struct {
	Label   string    `json:"label,omitempty"`
	Objects []*Object `json:"objects,omitempty"`
	Edges   []*Edge   `json:"edges,omitempty"`
}

type Object

type Object struct {
	Graph  *Graph  `json:"-"`
	Parent *Object `json:"-"`

	// IDVal is the actual value of the ID whereas ID is the value in d2 syntax.
	// e.g. ID:    "yes'\""
	//      IDVal: yes'"
	//
	// ID allows joining on . naively and construct a valid D2 key path
	ID         string      `json:"id"`
	IDVal      string      `json:"id_val"`
	Map        *d2ast.Map  `json:"-"`
	References []Reference `json:"references,omitempty"`

	*geo.Box `json:"box,omitempty"`
	// MotionOffset is set by a layout that honored an interpolated pin.
	MotionOffset  *geo.Point `json:"motionOffset,omitempty"`
	LabelPosition *string    `json:"labelPosition,omitempty"`
	LabelFill     *Scalar    `json:"labelFill,omitempty"`
	IconPosition  *string    `json:"iconPosition,omitempty"`

	ContentAspectRatio *float64 `json:"contentAspectRatio,omitempty"`
	ELKLayerConstraint string   `json:"elkLayerConstraint,omitempty"`

	Class    *d2target.Class    `json:"class,omitempty"`
	SQLTable *d2target.SQLTable `json:"sql_table,omitempty"`

	Children      map[string]*Object `json:"-"`
	ChildrenArray []*Object          `json:"-"`

	Attributes `json:"attributes"`

	ZIndex int `json:"zIndex"`
	// contains filtered or unexported fields
}

TODO maybe rename to Shape

func ResolveUnderscoreKey

func ResolveUnderscoreKey(ida []string, obj *Object) (resolvedObj *Object, resolvedIDA []string, _ error)

TODO: remove once not used anywhere

func (*Object) AbsID

func (obj *Object) AbsID() string

func (*Object) AbsIDArray

func (obj *Object) AbsIDArray() []string

func (*Object) AppendReferences

func (obj *Object) AppendReferences(ida []string, ref Reference, unresolvedObj *Object)

func (*Object) ClosestGridCell

func (obj *Object) ClosestGridCell() *Object

func (*Object) ClosestGridDiagram

func (obj *Object) ClosestGridDiagram() *Object

func (*Object) Connect

func (obj *Object) Connect(srcID, dstID []d2ast.String, srcArrow, dstArrow bool, label string) (*Edge, error)

func (*Object) ContainedBy

func (o *Object) ContainedBy(obj *Object) bool

func (*Object) ContainsAnyEdge

func (obj *Object) ContainsAnyEdge(edges []*Edge) bool

func (*Object) ContainsAnyObject

func (obj *Object) ContainsAnyObject(objects []*Object) bool

func (*Object) EnsureChild

func (obj *Object) EnsureChild(ida []d2ast.String) *Object

EnsureChild grabs the child by ids or creates it if it does not exist including all intermediate nodes.

func (*Object) FindEdges

func (obj *Object) FindEdges(mk *d2ast.Key) ([]*Edge, bool)

TODO: remove edges []edge and scope each edge inside Object.

func (*Object) GetDefaultSize

func (obj *Object) GetDefaultSize(mtexts []*d2target.MText, ruler *textmeasure.Ruler, fontFamily *d2fonts.FontFamily, monoFontFamily *d2fonts.FontFamily, labelDims d2target.TextDimensions, withLabelPadding bool) (*d2target.TextDimensions, error)

func (*Object) GetFill

func (obj *Object) GetFill() string

func (*Object) GetIconTopLeft

func (obj *Object) GetIconTopLeft() *geo.Point

func (*Object) GetLabelSize

func (obj *Object) GetLabelSize(mtexts []*d2target.MText, ruler *textmeasure.Ruler, fontFamily *d2fonts.FontFamily, monoFontFamily *d2fonts.FontFamily) (*d2target.TextDimensions, error)

func (*Object) GetLabelTopLeft

func (obj *Object) GetLabelTopLeft() *geo.Point

func (*Object) GetMargin

func (obj *Object) GetMargin() geo.Spacing

func (*Object) GetModifierElementAdjustments

func (obj *Object) GetModifierElementAdjustments() (dx, dy float64)

GetModifierElementAdjustments returns width/height adjustments to account for shapes with 3d or multiple

func (*Object) GetStroke

func (obj *Object) GetStroke(dashGapSize interface{}) string

func (*Object) HasChild

func (obj *Object) HasChild(ids []string) (*Object, bool)

func (*Object) HasEdge

func (obj *Object) HasEdge(mk *d2ast.Key) (*Edge, bool)

func (*Object) HasIcon

func (obj *Object) HasIcon() bool

func (*Object) HasLabel

func (obj *Object) HasLabel() bool

func (*Object) HasLayoutFontSize added in v0.10.0

func (obj *Object) HasLayoutFontSize() bool

HasLayoutFontSize reports whether the current font was assigned by layout.

func (*Object) HasOutsideBottomLabel

func (obj *Object) HasOutsideBottomLabel() bool

func (*Object) Is3D

func (obj *Object) Is3D() bool

func (*Object) IsConstantNear

func (obj *Object) IsConstantNear() bool

func (*Object) IsContainer

func (obj *Object) IsContainer() bool

func (*Object) IsDescendantOf

func (obj *Object) IsDescendantOf(ancestor *Object) bool

func (*Object) IsGridDiagram

func (obj *Object) IsGridDiagram() bool

func (*Object) IsMultiple

func (obj *Object) IsMultiple() bool

func (*Object) IsSequenceDiagram

func (obj *Object) IsSequenceDiagram() bool

func (*Object) IsSequenceDiagramActor added in v0.10.1

func (obj *Object) IsSequenceDiagramActor() bool

Actors are the direct children of a v2 diagram or an actor group. Descendants of an actor have timeline semantics rather than introducing another lifeline.

func (*Object) IsSequenceDiagramActorGroup added in v0.10.1

func (obj *Object) IsSequenceDiagramActorGroup() bool

func (*Object) IsSequenceDiagramActorRepeat added in v0.10.1

func (obj *Object) IsSequenceDiagramActorRepeat() bool

func (*Object) IsSequenceDiagramBranch added in v0.10.1

func (obj *Object) IsSequenceDiagramBranch() bool

IsSequenceDiagramBranch reports a named compartment of a branched message frame.

func (*Object) IsSequenceDiagramCheckpoint added in v0.10.1

func (obj *Object) IsSequenceDiagramCheckpoint() bool

func (*Object) IsSequenceDiagramEvent added in v0.10.1

func (obj *Object) IsSequenceDiagramEvent() bool

func (*Object) IsSequenceDiagramGroup

func (obj *Object) IsSequenceDiagramGroup() bool

groups are objects in sequence diagrams that have no messages connected and does not have a note as a child (a note can appear within a group, but it's a child of an actor)

func (*Object) IsSequenceDiagramNote

func (obj *Object) IsSequenceDiagramNote() bool

notes are descendant of actors with no edges and no children

func (*Object) IsSequenceDiagramSpan added in v0.10.1

func (obj *Object) IsSequenceDiagramSpan() bool

func (*Object) IsSequenceDiagramV2 added in v0.10.1

func (obj *Object) IsSequenceDiagramV2() bool

func (*Object) IterDescendants

func (obj *Object) IterDescendants(apply func(parent, child *Object))

func (*Object) LayoutInnerBox added in v0.10.0

func (obj *Object) LayoutInnerBox() *geo.Box

LayoutInnerBox is the usable interior for a container's children.

func (*Object) Level

func (obj *Object) Level() ContainerLevel

func (*Object) MarkLayoutFontSize added in v0.10.0

func (obj *Object) MarkLayoutFontSize()

MarkLayoutFontSize records the font after layout has committed the object.

func (*Object) MoveWithDescendants

func (obj *Object) MoveWithDescendants(dx, dy float64)

func (*Object) MoveWithDescendantsTo

func (obj *Object) MoveWithDescendantsTo(x, y float64)

func (*Object) NearTarget added in v0.10.0

func (obj *Object) NearTarget() (*Object, bool)

NearTarget resolves an object-relative near placement. Historically an absent unquoted board name at the end of a near key resolved to its container.

func (*Object) OuterNearContainer

func (obj *Object) OuterNearContainer() *Object

func (*Object) OuterSequenceDiagram

func (obj *Object) OuterSequenceDiagram() *Object

func (*Object) RemoveChild

func (parent *Object) RemoveChild(child *Object)

func (*Object) SequenceChildren added in v0.10.1

func (o *Object) SequenceChildren() []*Object

SequenceChildren returns a participant or group's children in authored order.

func (*Object) SequenceDiagramActor added in v0.10.1

func (obj *Object) SequenceDiagramActor() *Object

SequenceDiagramActor returns the lifeline owning this actor or timeline item.

func (*Object) SequenceTimelineOwner added in v0.10.1

func (obj *Object) SequenceTimelineOwner() *Object

SequenceTimelineOwner returns the v2 diagram that lays out this timeline item. A constant-near child and its subtree are laid out separately.

func (*Object) ShapeOptionFlag added in v0.10.1

func (obj *Object) ShapeOptionFlag(name string) *bool

ShapeOptionFlag returns the graph field for a registered boolean option. A default-only edge-group can have no allocated sequence configuration.

func (*Object) ShiftDescendants

func (obj *Object) ShiftDescendants(dx, dy float64)

ShiftDescendants moves Object's descendants (not including itself) descendants' edges are also moved by the same dx and dy (the whole route is moved if both ends are a descendant)

func (*Object) SizeToContent

func (obj *Object) SizeToContent(contentWidth, contentHeight, paddingX, paddingY float64)

resizes the object to fit content of the given width and height in its inner box with the given padding. this accounts for the shape of the object, and if there is a desired width or height set for the object

func (*Object) Spacing

func (obj *Object) Spacing() (margin, padding geo.Spacing)

func (*Object) SpacingOpt

func (obj *Object) SpacingOpt(labelPadding, iconPadding float64, maxIconSize bool) (margin, padding geo.Spacing)

func (*Object) StrokeWidth added in v0.10.1

func (obj *Object) StrokeWidth() (int, float64)

StrokeWidth gives the rendered whole and subpixel parts of a shape stroke.

func (*Object) Text

func (obj *Object) Text() *d2target.MText

func (*Object) ToShape

func (obj *Object) ToShape() shape.Shape

func (*Object) TopGridDiagram

func (obj *Object) TopGridDiagram() *Object

TopGridDiagram returns the least nested (outermost) grid diagram

type Reference

type Reference struct {
	Key          *d2ast.KeyPath `json:"key"`
	KeyPathIndex int            `json:"key_path_index"`

	MapKey          *d2ast.Key `json:"-"`
	MapKeyEdgeIndex int        `json:"map_key_edge_index"`
	Scope           *d2ast.Map `json:"-"`
	ScopeObj        *Object    `json:"-"`
	ScopeAST        *d2ast.Map `json:"-"`
	IsVar           bool       `json:"-"`
}

func (Reference) InEdge

func (r Reference) InEdge() bool

func (Reference) MapKeyEdgeDest

func (r Reference) MapKeyEdgeDest() bool

type RouteEdges

type RouteEdges func(context.Context, *Graph, []*Edge) error

type Scalar

type Scalar struct {
	Value  string     `json:"value"`
	MapKey *d2ast.Key `json:"-"`
	// TweenOffset retains subpixel paint and pin positions while keeping Value
	// integral for measurement and layout.
	TweenOffset float64 `json:"tweenOffset,omitempty"`
	// TweenedPin is also true when an interpolated pin lands on a whole pixel.
	TweenedPin bool `json:"tweenedPin,omitempty"`
}

TODO consider having different Scalar types Right now we'll hold any types in Value and just convert, e.g. floats

type SequenceItem added in v0.10.1

type SequenceItem struct {
	Object *Object
	Edge   *Edge
	Frame  *Object
	Order  []uint64
	Gap    *Scalar
	Key    *d2ast.Key
}

SequenceItem is an authored timeline entry. Frame is the innermost frame owning the declaration, even if later keys edit it from a different scope.

func SequenceTimeline added in v0.10.1

func SequenceTimeline(edges []*Edge, events, spans, frames []*Object) []SequenceItem

SequenceTimeline includes empty spans and frames at the declaration where they reserve space. The compiler and layout must agree on every row boundary.

type SequenceOptions added in v0.10.1

type SequenceOptions struct {
	Branched bool `json:"branched,omitempty"`
	Mirrored bool `json:"mirrored,omitempty"`
	Numbered bool `json:"numbered,omitempty"`
}

type SerializedEdge

type SerializedEdge map[string]interface{}

func ToSerializedEdge

func ToSerializedEdge(e *Edge) (SerializedEdge, error)

type SerializedGraph

type SerializedGraph struct {
	Theme     *d2themes.Theme        `json:"theme,omitempty"`
	Root      SerializedObject       `json:"root"`
	Edges     []SerializedEdge       `json:"edges"`
	Objects   []SerializedObject     `json:"objects"`
	RootLevel int                    `json:"rootLevel"`
	Data      map[string]interface{} `json:"data,omitempty"`

	IsPartialLayout bool `json:"isPartialLayout,omitempty"`
}

type SerializedObject

type SerializedObject map[string]interface{}

type Style

type Style struct {
	Opacity       *Scalar `json:"opacity,omitempty"`
	Stroke        *Scalar `json:"stroke,omitempty"`
	Fill          *Scalar `json:"fill,omitempty"`
	FillPattern   *Scalar `json:"fillPattern,omitempty"`
	StrokeWidth   *Scalar `json:"strokeWidth,omitempty"`
	StrokeDash    *Scalar `json:"strokeDash,omitempty"`
	BorderRadius  *Scalar `json:"borderRadius,omitempty"`
	Shadow        *Scalar `json:"shadow,omitempty"`
	ThreeDee      *Scalar `json:"3d,omitempty"`
	Multiple      *Scalar `json:"multiple,omitempty"`
	Font          *Scalar `json:"font,omitempty"`
	FontSize      *Scalar `json:"fontSize,omitempty"`
	FontColor     *Scalar `json:"fontColor,omitempty"`
	Animated      *Scalar `json:"animated,omitempty"`
	Bold          *Scalar `json:"bold,omitempty"`
	Italic        *Scalar `json:"italic,omitempty"`
	Underline     *Scalar `json:"underline,omitempty"`
	Filled        *Scalar `json:"filled,omitempty"`
	DoubleBorder  *Scalar `json:"doubleBorder,omitempty"`
	TextTransform *Scalar `json:"textTransform,omitempty"`
}

func (*Style) Apply

func (s *Style) Apply(key, value string) error

func (Style) NoneTextTransform

func (s Style) NoneTextTransform() bool

NoneTextTransform will return a boolean if the text should not have any transformation applied. This should overwrite theme specific transformations like `CapsLock` from the `terminal` theme.

Jump to

Keyboard shortcuts

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