package d2graph
Import Path
oss.terrastruct.com/d2/d2graph (on go.dev )
Dependency Relation
imports 27 packages , and imported by 11 packages
Package-Level Type Names (total 14)
/* sort by: alphabet | popularity */
type Edge (struct)
Fields (total 38 )
Attributes Attributes
Attributes .Classes []string
These names are attached to the rendered elements in SVG
so that users can target them however they like outside of D2
Attributes .Constraint []string
Attributes .Direction Scalar
Attributes .GridColumns *Scalar
Attributes .GridGap *Scalar
Attributes .GridRows *Scalar
Attributes .HeightAttr *Scalar
Attributes .HorizontalGap *Scalar
Attributes .Icon *url .URL
Attributes .IconPosition *Scalar
Attributes .Label Scalar
Attributes .LabelDimensions d2target .TextDimensions
Attributes .Language string
Attributes .Left *Scalar
Attributes .Link *Scalar
Attributes .NearKey *d2ast .KeyPath
TODO consider separate Attributes struct for shape-specific and edge-specific
Shapes only
Attributes .Shape Scalar
TODO: default to ShapeRectangle instead of empty string
Attributes .Style Style
Attributes .Tooltip *Scalar
Attributes .Top *Scalar
Attributes .VerticalGap *Scalar
Attributes .WidthAttr *Scalar
Dst *Object
DstArrow bool
TODO alixander (Mon Sep 12 2022): deprecate SrcArrow and DstArrow and just use SrcArrowhead and DstArrowhead
DstArrowhead *Attributes
DstTableColumnIndex *int
Index int
IsCurve bool
LabelPercentage *float64
LabelPosition *string
References []EdgeReference
Route []*geo .Point
Src *Object
SrcArrow bool
SrcArrowhead *Attributes
SrcTableColumnIndex *int
ZIndex int
Methods (total 13 )
(*Edge) AbsID () string
(*Edge) 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!
(*Edge) ArrowString () string
(*Edge) ContainedBy (obj *Object ) bool
(*Edge) GetAstEdge () *d2ast .Edge
(*Edge) GetGroup () *Object
(*Edge) GetStroke (dashGapSize interface{}) string
(*Edge) Move (dx, dy float64 )
(*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)
(*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
(*Edge) Text () *d2target .MText
(*Edge) ToArrowhead () d2target .Arrowhead
(*Edge) TraceToShape (points []*geo .Point , startIndex, endIndex int ) (newStart, newEnd int )
As Outputs Of (at least 4 )
func (*Object ).Connect (srcID, dstID []d2ast .String , srcArrow, dstArrow bool , label string ) (*Edge , error )
func (*Object ).FindEdges (mk *d2ast .Key ) ([]*Edge , bool )
func (*Object ).HasEdge (mk *d2ast .Key ) (*Edge , bool )
func oss.terrastruct.com/d2/d2layouts.ExtractSubgraph (container *Object , includeSelf bool ) (nestedGraph *Graph , externalEdges []*Edge , externalEdgeIDs []d2layouts .edgeIDs )
As Inputs Of (at least 4 )
func CompareSerializedEdge (edge, other *Edge ) error
func ToSerializedEdge (e *Edge ) (SerializedEdge , error )
func (*Object ).ContainsAnyEdge (edges []*Edge ) bool
func oss.terrastruct.com/d2/d2layouts.DefaultRouter (ctx context .Context , graph *Graph , edges []*Edge ) error
type Graph (struct)
Fields (total 15 )
AST *d2ast .Map
BaseAST *d2ast .Map
BaseAST is the AST of the original graph without inherited fields and edges
Data map[string ]interface{}
Currently this holds data embedded from source code configuration variables
Plugins only have access to exported graph, so this data structure allows
carrying arbitrary metadata that any plugin might handle
Edges []*Edge
FS fs .FS
IsFolderOnly bool
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.
Layers []*Graph
Name string
Objects []*Object
Parent *Graph
Root *Object
RootLevel int
Object.Level uses the location of a nested graph
Scenarios []*Graph
Steps []*Graph
Theme *d2themes .Theme
Methods (total 11 )
(*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
(*Graph) ExtractAsNestedGraph (obj *Object ) *Graph
(*Graph) GetBoard (name string ) *Graph
(*Graph) IDA () []string
(*Graph) InjectNestedGraph (tempGraph *Graph , parent *Object )
(*Graph) PrintString () string
(*Graph) RootBoard () *Graph
(*Graph) SetDimensions (mtexts []*d2target .MText , ruler *textmeasure .Ruler , fontFamily *d2fonts .FontFamily ) error
(*Graph) SortEdgesByAST ()
(*Graph) SortObjectsByAST ()
(*Graph) Texts () []*d2target .MText
As Outputs Of (at least 7 )
func NewGraph () *Graph
func (*Graph).ExtractAsNestedGraph (obj *Object ) *Graph
func (*Graph).GetBoard (name string ) *Graph
func (*Graph).RootBoard () *Graph
func oss.terrastruct.com/d2/d2compiler.Compile (p string , r io .Reader , opts *d2compiler .CompileOptions ) (*Graph , *d2target .Config , error )
func oss.terrastruct.com/d2/d2layouts.ExtractSubgraph (container *Object , includeSelf bool ) (nestedGraph *Graph , externalEdges []*Edge , externalEdgeIDs []d2layouts .edgeIDs )
func oss.terrastruct.com/d2/d2lib.Compile (ctx context .Context , input string , compileOpts *d2lib .CompileOptions , renderOpts *d2svg .RenderOpts ) (*d2target .Diagram , *Graph , error )
As Inputs Of (at least 19 )
func CompareSerializedGraph (g, other *Graph ) error
func DeserializeGraph (bytes []byte , g *Graph ) error
func SerializeGraph (g *Graph ) ([]byte , error )
func (*Graph).InjectNestedGraph (tempGraph *Graph , parent *Object )
func oss.terrastruct.com/d2/d2exporter.Export (ctx context .Context , g *Graph , fontFamily *d2fonts .FontFamily ) (*d2target .Diagram , error )
func oss.terrastruct.com/d2/d2layouts.DefaultRouter (ctx context .Context , graph *Graph , edges []*Edge ) error
func oss.terrastruct.com/d2/d2layouts.FitToGraph (container *Object , nestedGraph *Graph , padding geo .Spacing )
func oss.terrastruct.com/d2/d2layouts.InjectNested (container *Object , nestedGraph *Graph , isRoot bool )
func oss.terrastruct.com/d2/d2layouts.LayoutNested (ctx context .Context , g *Graph , graphInfo d2layouts .GraphInfo , coreLayout LayoutGraph , edgeRouter RouteEdges ) error
func oss.terrastruct.com/d2/d2layouts.PositionNested (container *Object , nestedGraph *Graph )
func oss.terrastruct.com/d2/d2layouts.SaveOrder (g *Graph ) (restoreOrder func())
func oss.terrastruct.com/d2/d2layouts/d2dagrelayout.DefaultLayout (ctx context .Context , g *Graph ) (err error )
func oss.terrastruct.com/d2/d2layouts/d2dagrelayout.Layout (ctx context .Context , g *Graph , opts *d2dagrelayout .ConfigurableOpts ) (err error )
func oss.terrastruct.com/d2/d2layouts/d2elklayout.DefaultLayout (ctx context .Context , g *Graph ) (err error )
func oss.terrastruct.com/d2/d2layouts/d2elklayout.Layout (ctx context .Context , g *Graph , opts *d2elklayout .ConfigurableOpts ) (err error )
func oss.terrastruct.com/d2/d2layouts/d2grid.Layout (ctx context .Context , g *Graph ) error
func oss.terrastruct.com/d2/d2layouts/d2near.Layout (ctx context .Context , g *Graph , constantNearGraphs []*Graph ) error
func oss.terrastruct.com/d2/d2layouts/d2near.Layout (ctx context .Context , g *Graph , constantNearGraphs []*Graph ) error
func oss.terrastruct.com/d2/d2layouts/d2sequence.Layout (ctx context .Context , g *Graph , layout LayoutGraph ) error
type Object (struct)
TODO maybe rename to Shape
Fields (total 40 )
Attributes Attributes
Attributes .Classes []string
These names are attached to the rendered elements in SVG
so that users can target them however they like outside of D2
Attributes .Constraint []string
Attributes .Direction Scalar
Attributes .GridColumns *Scalar
Attributes .GridGap *Scalar
Attributes .GridRows *Scalar
Attributes .HeightAttr *Scalar
Attributes .HorizontalGap *Scalar
Attributes .Icon *url .URL
Attributes .Label Scalar
Attributes .LabelDimensions d2target .TextDimensions
Attributes .Language string
Attributes .Left *Scalar
Attributes .Link *Scalar
Attributes .NearKey *d2ast .KeyPath
TODO consider separate Attributes struct for shape-specific and edge-specific
Shapes only
Attributes .Shape Scalar
TODO: default to ShapeRectangle instead of empty string
Attributes .Style Style
Attributes .Tooltip *Scalar
Attributes .Top *Scalar
Attributes .VerticalGap *Scalar
Attributes .WidthAttr *Scalar
Box *geo .Box
Box .Height float64
Box .TopLeft *geo .Point
Box .Width float64
Children map[string ]*Object
ChildrenArray []*Object
Class *d2target .Class
ContentAspectRatio *float64
Graph *Graph
ID string
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
IDVal string
IconPosition *string
LabelPosition *string
Map *d2ast .Map
Parent *Object
References []Reference
SQLTable *d2target .SQLTable
ZIndex int
Methods (total 56 )
(*Object) AbsID () string
(*Object) AbsIDArray () []string
(*Object) AppendReferences (ida []string , ref Reference , unresolvedObj *Object )
(*Object) 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!
( Object) Center () *geo .Point
(*Object) ClosestGridCell () *Object
(*Object) ClosestGridDiagram () *Object
(*Object) Connect (srcID, dstID []d2ast .String , srcArrow, dstArrow bool , label string ) (*Edge , error )
(*Object) ContainedBy (obj *Object ) bool
( Object) Contains (p *geo .Point ) bool
(*Object) ContainsAnyEdge (edges []*Edge ) bool
(*Object) ContainsAnyObject (objects []*Object ) bool
( Object) Copy () *geo .Box
(*Object) EnsureChild (ida []d2ast .String ) *Object
EnsureChild grabs the child by ids or creates it if it does not exist including all
intermediate nodes.
(*Object) FindEdges (mk *d2ast .Key ) ([]*Edge , bool )
TODO: remove edges []edge and scope each edge inside Object.
(*Object) GetDefaultSize (mtexts []*d2target .MText , ruler *textmeasure .Ruler , fontFamily *d2fonts .FontFamily , labelDims d2target .TextDimensions , withLabelPadding bool ) (*d2target .TextDimensions , error )
(*Object) GetFill () string
(*Object) GetIconTopLeft () *geo .Point
(*Object) GetLabelSize (mtexts []*d2target .MText , ruler *textmeasure .Ruler , fontFamily *d2fonts .FontFamily ) (*d2target .TextDimensions , error )
(*Object) GetLabelTopLeft () *geo .Point
(*Object) GetMargin () geo .Spacing
(*Object) GetModifierElementAdjustments () (dx, dy float64 )
GetModifierElementAdjustments returns width/height adjustments to account for shapes with 3d or multiple
(*Object) GetStroke (dashGapSize interface{}) string
(*Object) HasChild (ids []string ) (*Object , bool )
(*Object) HasEdge (mk *d2ast .Key ) (*Edge , bool )
(*Object) HasIcon () bool
(*Object) HasLabel () bool
(*Object) HasOutsideBottomLabel () bool
( Object) Intersections (s geo .Segment ) []*geo .Point
( Object) Intersects (s geo .Segment , buffer float64 ) bool
Intersects returns true if the segment comes within buffer of the box
(*Object) Is3D () bool
(*Object) IsConstantNear () bool
(*Object) IsContainer () bool
(*Object) IsDescendantOf (ancestor *Object ) bool
(*Object) IsGridDiagram () bool
(*Object) IsMultiple () bool
(*Object) IsSequenceDiagram () bool
(*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)
(*Object) IsSequenceDiagramNote () bool
notes are descendant of actors with no edges and no children
(*Object) IterDescendants (apply func(parent, child *Object ))
(*Object) Level () ContainerLevel
(*Object) MoveWithDescendants (dx, dy float64 )
(*Object) MoveWithDescendantsTo (x, y float64 )
(*Object) OuterNearContainer () *Object
(*Object) OuterSequenceDiagram () *Object
( Object) Overlaps (b2 geo .Box ) bool
(*Object) RemoveChild (child *Object )
(*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)
(*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
(*Object) Spacing () (margin, padding geo .Spacing )
(*Object) SpacingOpt (labelPadding, iconPadding float64 , maxIconSize bool ) (margin, padding geo .Spacing )
(*Object) Text () *d2target .MText
(*Object) ToArrowhead () d2target .Arrowhead
(*Object) ToShape () shape .Shape
( Object) ToString () string
(*Object) TopGridDiagram () *Object
TopGridDiagram returns the least nested (outermost) grid diagram
Implements (at least one exported )
Object : oss.terrastruct.com/d2/lib/geo.Intersectable
As Outputs Of (at least 10 )
func ResolveUnderscoreKey (ida []string , obj *Object ) (resolvedObj *Object , resolvedIDA []string , _ error )
func (*Edge ).GetGroup () *Object
func (*Object).ClosestGridCell () *Object
func (*Object).ClosestGridDiagram () *Object
func (*Object).EnsureChild (ida []d2ast .String ) *Object
func (*Object).HasChild (ids []string ) (*Object , bool )
func (*Object).OuterNearContainer () *Object
func (*Object).OuterSequenceDiagram () *Object
func (*Object).TopGridDiagram () *Object
func oss.terrastruct.com/d2/d2layouts/d2grid.GenLayout (objects []*Object , cutIndices []int ) [][]*Object
As Inputs Of (at least 18 )
func CompareSerializedObject (obj, other *Object ) error
func ResolveUnderscoreKey (ida []string , obj *Object ) (resolvedObj *Object , resolvedIDA []string , _ error )
func (*Edge ).ContainedBy (obj *Object ) bool
func (*Graph ).ExtractAsNestedGraph (obj *Object ) *Graph
func (*Graph ).InjectNestedGraph (tempGraph *Graph , parent *Object )
func (*Object).AppendReferences (ida []string , ref Reference , unresolvedObj *Object )
func (*Object).ContainedBy (obj *Object ) bool
func (*Object).ContainsAnyObject (objects []*Object ) bool
func (*Object).IsDescendantOf (ancestor *Object ) bool
func (*Object).RemoveChild (child *Object )
func oss.terrastruct.com/d2/d2layouts.ExtractSubgraph (container *Object , includeSelf bool ) (nestedGraph *Graph , externalEdges []*Edge , externalEdgeIDs []d2layouts .edgeIDs )
func oss.terrastruct.com/d2/d2layouts.FitToGraph (container *Object , nestedGraph *Graph , padding geo .Spacing )
func oss.terrastruct.com/d2/d2layouts.InjectNested (container *Object , nestedGraph *Graph , isRoot bool )
func oss.terrastruct.com/d2/d2layouts.NestedGraphInfo (obj *Object ) (gi d2layouts .GraphInfo )
func oss.terrastruct.com/d2/d2layouts.PositionNested (container *Object , nestedGraph *Graph )
func oss.terrastruct.com/d2/d2layouts.SaveChildrenOrder (container *Object ) (restoreOrder func())
func oss.terrastruct.com/d2/d2layouts/d2grid.GenLayout (objects []*Object , cutIndices []int ) [][]*Object
func oss.terrastruct.com/d2/d2layouts/d2sequence.IsLifelineEnd (obj *Object ) bool
Package-Level Functions (total 11)
Package-Level Constants (total 4)
The pages are generated with Golds v0.8.2 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .