Documentation
¶
Overview ¶
Example (Animated) ¶
c := Ctx()
c.Scon("x", "y").Animated()
fmt.Println(c.d2())
Output: x -> y: {style.animated: true}
Example (BoldItalicUnderline) ¶
c := Ctx()
c.Node("x").Underline()
c.Node("y").Italic()
c.Scon("x", "y").Label("hi").Bold()
fmt.Println(c.d2())
Output: x: {style.underline: true} y: {style.italic: true} x -> y: hi {style.bold: true}
Example (BorderRadius) ¶
c := Ctx()
c.Node("x").BorderRadius(3)
c.Node("y").BorderRadius(8)
c.Scon("x", "y").Label("hi")
fmt.Println(c.d2())
Output: x: {style.border-radius: 3} y: {style.border-radius: 8} x -> y: hi
Example (Class) ¶
c := Ctx()
c.Class("MyClass").
Field("field", "[]string").
Field("method(a uint64)", "(x, y int)").
Field(`# peekn(n int)`, "(s string, eof bool)")
fmt.Println(c.d2())
Output: MyClass: { shape: class field: "[]string" method(a uint64): (x, y int) \# peekn(n int): (s string, eof bool) }
Example (Code) ¶
c := Ctx()
c.Code("markdown", "md", `# Hi cdor
- Go+
- Go
`)
c.Code("latex", "latex", `\lim_{h \rightarrow 0 } \frac{f(x+h)-f(x)}{h}`)
fmt.Println(c.d2())
Output: markdown: |md # Hi cdor - Go+ - Go | latex: |latex \\lim_{h \\rightarrow 0 } \\frac{f(x+h)-f(x)}{h} |
Example (Connection) ¶
c := Ctx()
c.Con("x", "y").Stroke("red")
c.Con("x", "y").Stroke("blue")
fmt.Println(c.d2())
Output: x <-> y: {style.stroke: red} x <-> y: {style.stroke: blue}
Example (Connection_arrow) ¶
c := Ctx()
c.Con("x", "y").
Stroke("red").
SrcHeadLabel("from").SrcHeadShape(c.HeadArrow()).
DstHeadLabel("to").DstHeadShape(c.HeadDiamond()).DstHeadFilled()
fmt.Println(c.d2())
Output: x <-> y: { style.stroke: red target-arrowhead.style.filled: true source-arrowhead.label: from source-arrowhead.shape: arrow target-arrowhead.label: to target-arrowhead.shape: diamond }
Example (Container) ¶
c := Ctx()
c.Node("server.process")
c.Node("im a parent.im a child")
c.Con("apartment.Bedroom.Bathroom", "office.Spare Room.Bathroom").Label("Portal")
fmt.Println(c.d2())
Output: server.process im a parent.im a child apartment.Bedroom.Bathroom <-> office.Spare Room.Bathroom: Portal
Example (D2) ¶
c := Ctx()
c.D2(`x -> y: hi`)
c.Direction(c.Right())
c.Con("Go+", "Go").Label("cdor")
fmt.Println(c.d2())
Output: x -> y: hi direction: right Go+ <-> Go: cdor
Example (DoubleBorder) ¶
c := Ctx()
c.Node("x").DoubleBorder()
c.Circle("y").DoubleBorder()
c.Scon("x", "y").Label("hi")
fmt.Println(c.d2())
Output: x: {style.double-border: true} y: { shape: circle style.double-border: true } x -> y: hi
Example (Fillpattern) ¶
c := Ctx()
c.Direction(c.Right())
c.FillPattern(c.Dots())
c.Node("x").FillPattern(c.Lines())
c.Node("y").FillPattern(c.Grain())
c.Scon("x", "y").Label("hi")
fmt.Println(c.d2())
Output: direction: right style.fill-pattern: dots x: {style.fill-pattern: lines} y: {style.fill-pattern: grain} x -> y: hi
Example (Font) ¶
c := Ctx()
c.Node("x").Font("mono").FontSize(8)
c.Node("y").Font("mono").FontSize(55).FontColor("#f4a261")
c.Scon("x", "y").Label("hi").Font("mono").FontSize(28).FontColor("red")
fmt.Println(c.d2())
Output: x: { style.font-size: 8 style.font: mono } y: { style.font-size: 55 style.font-color: "#f4a261" style.font: mono } x -> y: hi { style.font-size: 28 style.font-color: red style.font: mono }
Example (Grid) ¶
c := Ctx()
c.GridRows(2).GridCols(4).GridGap(0)
c.Node("Element")
c.Node("Atomic Number")
c.Node("Atomic Mass")
c.Node("Melting Point")
c.Node("Hydrogen")
c.Node(`"1"`)
c.Node(`"1.008"`)
c.Node(`"-259.16"`)
c.Node("Carbon")
c.Node(`"6"`)
c.Node(`"12.011"`)
c.Node(`"3500"`)
c.Node("Oxygen")
c.Node(`"8"`)
c.Node(`"15.999"`)
c.Node(`"-218.79"`)
fmt.Println(c.d2())
Output: grid-rows: 2 grid-columns: 4 grid-gap: 0 Element Atomic Number Atomic Mass Melting Point Hydrogen "1" "1.008" "-259.16" Carbon "6" "12.011" "3500" Oxygen "8" "15.999" "-218.79"
Example (Hello) ¶
c := Ctx()
c.Direction(c.Right())
c.Con("Go+", "Go").Label("cdor")
fmt.Println(c.d2())
Output: direction: right Go+ <-> Go: cdor
Example (Icon) ¶
c := Ctx()
c.Node("github").Icon("https://icons.terrastruct.com/dev/github.svg")
c.Image("gg").Icon("https://icons.terrastruct.com/dev/github.svg")
fmt.Println(c.d2())
Output: github: {icon: https://icons.terrastruct.com/dev/github.svg} gg: { icon: https://icons.terrastruct.com/dev/github.svg shape: image }
Example (Id) ¶
c := Ctx()
c.Node("imAShape")
c.Node("im_a_shape")
c.Node("im a shape")
c.Node("i'm a shape")
c.Node("a-shape")
fmt.Println(c.d2())
Output: imAShape im_a_shape im a shape i'm a shape a-shape
Example (Is3d) ¶
c := Ctx()
c.Node("x").Is3d()
c.Scon("x", "y").Label("hi")
fmt.Println(c.d2())
Output: x: {style.3d: true} x -> y: hi
Example (Json) ¶
c := Ctx()
json := `[13, {"37": 37}]`
c.Json(json)
fmt.Println(c.d2())
Output: direction: right 0: { shape: sql_table 13: " " } 1: { shape: sql_table 37: 37 } 0.1 -> 1
Example (Label) ¶
c := Ctx()
c.Node("pg").Label("PostgreSQL")
c.Node("Cloud").Label("my cloud")
fmt.Println(c.d2())
Output: pg: PostgreSQL Cloud: my cloud
Example (Link) ¶
c := Ctx()
c.Node("cdor").Link("https://github.com/zrcoder/cdor")
fmt.Println(c.d2())
Output: cdor: {link: https://github.com/zrcoder/cdor}
Example (Multiple) ¶
c := Ctx()
c.Node("x").Multiple()
c.Scon("x", "y").Label("hi")
fmt.Println(c.d2())
Output: x: {style.multiple: true} x -> y: hi
Example (Nested_containers) ¶
c := Ctx()
c.Node("clouds").
Children(
c.Node("aws").Cons(
c.Con("load_balancer", "api"),
c.Con("api", "db"),
),
c.Node("gcloud").Cons(
c.Con("auth", "db"),
),
).
Cons(
c.Con("gcloud", "aws"),
)
fmt.Println(c.d2())
Output: clouds: { aws: { load_balancer <-> api api <-> db } gcloud: { auth <-> db } gcloud <-> aws }
Example (Node_json) ¶
json := `{
"fruit":"Apple"
}`
c := Ctx()
c.Node("ttt").Json(json)
fmt.Println(c.d2())
Output: ttt: { 0: { shape: sql_table fruit: Apple } }
Example (Opacity) ¶
c := Ctx()
c.Direction(c.Right())
c.Node("x").Opacity(0)
c.Node("y").Opacity(0.7)
c.Scon("x", "y").Opacity(0.4)
fmt.Println(c.d2())
Output: direction: right x: {style.opacity: 0.0} y: {style.opacity: 0.7} x -> y: {style.opacity: 0.4}
Example (Same_name_sub_containers) ¶
c := Ctx()
c.Node("christmas").Fill("#ACE1AF")
c.Con("christmas.presents", "birthdays.presents").Label("regift")
fmt.Println(c.d2())
Output: christmas: {style.fill: "#ACE1AF"} christmas.presents <-> birthdays.presents: regift
Example (Sequence) ¶
c := Ctx()
c.Sequence()
c.Scon("alice", "bob").Label("What does it mean\nto be well-adjusted?")
c.Scon("bob", "alice").Label("The ability to play bridge or\ngolf as if they were games.")
fmt.Println(c.d2())
Output: shape: sequence_diagram alice -> bob: "What does it mean\nto be well-adjusted?" bob -> alice: "The ability to play bridge or\ngolf as if they were games."
Example (Shadow) ¶
c := Ctx()
c.Node("x").Shadow()
c.Scon("x", "y").Label("hi")
fmt.Println(c.d2())
Output: x: {style.shadow: true} x -> y: hi
Example (Shape) ¶
c := Ctx()
c.Cloud("cloud")
fmt.Println(c.d2())
Output: cloud: {shape: cloud}
Example (Sql_table) ¶
c := Ctx()
c.SqlTable("table").
Field("id", "int", "primary_key").
Field("last_updated", "timestamp with time zone")
fmt.Println(c.d2())
Output: table: { shape: sql_table id: int id.constraint: primary_key last_updated: timestamp with time zone }
Example (StrokeDash) ¶
c := Ctx()
c.Node("x").StrokeDash(5)
c.Scon("x", "y").Label("hi").StrokeDash(3)
fmt.Println(c.d2())
Output: x: {style.stroke-dash: 5} x -> y: hi {style.stroke-dash: 3}
Example (StrokeWidth) ¶
c := Ctx()
c.Direction(c.Right())
c.Node("x").StrokeWidth(1)
c.Scon("x", "y").StrokeWidth(8)
fmt.Println(c.d2())
Output: direction: right x: {style.stroke-width: 1} x -> y: {style.stroke-width: 8}
Example (Tooltip) ¶
c := Ctx()
c.Node("x").Tooltip("Hello,\nWorld!")
fmt.Println(c.d2())
Output: x: {tooltip: "Hello,\nWorld!"}
Index ¶
- Constants
- func Gopt_App_Main(app IMain, workers ...IWorker)
- type App
- type Cdor
- func (c *Cdor) ApplyConfig(cfg *config) *Cdor
- func (c *Cdor) ApplyOption(opt *option) *Cdor
- func (c *Cdor) Aubergine() int
- func (c *Cdor) ButteredToast() int
- func (c *Cdor) Callout(id string) *node
- func (c Cdor) Center(b ...bool) *config
- func (c *Cdor) Cfg() *config
- func (c *Cdor) Circle(id string) *node
- func (c *Cdor) Class(id string) *node
- func (c *Cdor) Clear()
- func (c *Cdor) Cloud(id string) *node
- func (c *Cdor) Code(id, tag, code string) *node
- func (c *Cdor) ColorblindClear() int
- func (c *Cdor) Con(src, dst string) *connection
- func (c *Cdor) ConOpt() *conOption
- func (c *Cdor) Cool() int
- func (c *Cdor) Cylinder(id string) *node
- func (c *Cdor) D2(d2script string) *Cdor
- func (c *Cdor) DarkFlagshipTerrastruct() int
- func (c *Cdor) DarkMauve() int
- func (c Cdor) DarkTheme(theme int) *config
- func (c Cdor) DarkThemeOverrides(ov *ThemeOverrides) *config
- func (c *Cdor) Diamond(id string) *node
- func (c Cdor) Direction(dir string) *config
- func (c *Cdor) Document(id string) *node
- func (c *Cdor) Dots() string
- func (c *Cdor) Down() string
- func (c *Cdor) EarthTones() int
- func (c Cdor) ElkLayout(b ...bool) *config
- func (c *Cdor) EvergladeGreen() int
- func (c *Cdor) FillPattern(pattern string) *Cdor
- func (c *Cdor) Flagship() int
- func (c *Cdor) Gen() (svg []byte, err error)
- func (c *Cdor) Grain() string
- func (c *Cdor) GrapeSoda() int
- func (c *Cdor) GridCols(cols int) *Cdor
- func (c *Cdor) GridGap(gap int) *Cdor
- func (c *Cdor) GridRows(rows int) *Cdor
- func (c *Cdor) HeadArrow() string
- func (c *Cdor) HeadCfMany() string
- func (c *Cdor) HeadCfManyRequired() string
- func (c *Cdor) HeadCfOne() string
- func (c *Cdor) HeadCfOneRequired() string
- func (c *Cdor) HeadDiamond() string
- func (c *Cdor) HeadNone() string
- func (c *Cdor) HeadTriangle() string
- func (c *Cdor) Hexagon(id string) *node
- func (c *Cdor) HorizontalGap(gap int) *Cdor
- func (c *Cdor) Image(id string) *node
- func (c *Cdor) Json(json string) *Cdor
- func (c *Cdor) Jsonn(id, json string) *node
- func (c *Cdor) Latex(id, content string) *node
- func (c *Cdor) Left() string
- func (c *Cdor) Lines() string
- func (c *Cdor) Markdown(id, content string) *node
- func (c *Cdor) MdCode(code string, id ...string) *node
- func (c *Cdor) MixedBerryBlue() int
- func (c *Cdor) Neutral() int
- func (c *Cdor) NeutralGrey() int
- func (c *Cdor) Node(id string) *node
- func (c *Cdor) Obj(x any) *Cdor
- func (c *Cdor) Objn(id string, obj any) *node
- func (c *Cdor) Opt() *option
- func (c *Cdor) OrangeCreamsicle() int
- func (c *Cdor) Origami() int
- func (c *Cdor) Oval(id string) *node
- func (c Cdor) Pad(pad int) *config
- func (c *Cdor) Page(id string) *node
- func (c *Cdor) Parallelogram(id string) *node
- func (c *Cdor) Person(id string) *node
- func (c *Cdor) Pkg(id string) *node
- func (c *Cdor) Queue(id string) *node
- func (c *Cdor) Rectangle(id string) *node
- func (c *Cdor) Right() string
- func (c *Cdor) SaveFile(filename string) error
- func (c *Cdor) Scon(src, dst string) *connection
- func (c Cdor) Sequence() *config
- func (c *Cdor) Sequencen(id string) *node
- func (c *Cdor) ShirleyTemple() int
- func (c Cdor) Sketch(b ...bool) *config
- func (c *Cdor) SqlTable(id string) *node
- func (c *Cdor) Square(id string) *node
- func (c *Cdor) Step(id string) *node
- func (c *Cdor) StoredData(id string) *node
- func (c *Cdor) Terminal() int
- func (c *Cdor) TerminalGrayscale() int
- func (c *Cdor) Text(id, content string) *node
- func (c Cdor) Theme(theme int) *config
- func (c Cdor) ThemeOverrides(ov *ThemeOverrides) *config
- func (c *Cdor) Toml(toml string) *Cdor
- func (c *Cdor) Tomln(id, toml string) *node
- func (c *Cdor) Up() string
- func (c *Cdor) VanillaNitroCola() int
- func (c *Cdor) VerticalGap(gap int) *Cdor
- func (c *Cdor) Yaml(yaml string) *Cdor
- func (c *Cdor) Yamln(id, yaml string) *node
- type IMain
- type IWorker
- type Mgr
- func (a *Mgr) ApplyConfig(cfg *config, diagrams ...string)
- func (a *Mgr) ApplyOption(opt *option, diagrams ...string)
- func (c Mgr) Center(b ...bool) *config
- func (c Mgr) DarkTheme(theme int) *config
- func (c Mgr) DarkThemeOverrides(ov *ThemeOverrides) *config
- func (c Mgr) Direction(dir string) *config
- func (c Mgr) ElkLayout(b ...bool) *config
- func (a *Mgr) Merge(diagrams ...string) *Cdor
- func (c Mgr) Pad(pad int) *config
- func (m *Mgr) RangeCdors(action func(string, *Cdor, error) error, diagrams ...string)
- func (a *Mgr) SaveFiles(dir string, diagrams ...string) (err error)
- func (c Mgr) Sequence() *config
- func (c Mgr) Sketch(b ...bool) *config
- func (c Mgr) Theme(theme int) *config
- func (c Mgr) ThemeOverrides(ov *ThemeOverrides) *config
- type ThemeOverrides
Examples ¶
- Package (Animated)
- Package (BoldItalicUnderline)
- Package (BorderRadius)
- Package (Class)
- Package (Code)
- Package (Connection)
- Package (Connection_arrow)
- Package (Container)
- Package (D2)
- Package (DoubleBorder)
- Package (Fillpattern)
- Package (Font)
- Package (Grid)
- Package (Hello)
- Package (Icon)
- Package (Id)
- Package (Is3d)
- Package (Json)
- Package (Label)
- Package (Link)
- Package (Multiple)
- Package (Nested_containers)
- Package (Node_json)
- Package (Opacity)
- Package (Same_name_sub_containers)
- Package (Sequence)
- Package (Shadow)
- Package (Shape)
- Package (Sql_table)
- Package (StrokeDash)
- Package (StrokeWidth)
- Package (Tooltip)
Constants ¶
const GopPackage = true
Variables ¶
This section is empty.
Functions ¶
func Gopt_App_Main ¶
Types ¶
type Cdor ¶
type Cdor struct {
// contains filtered or unexported fields
}
func (*Cdor) ApplyConfig ¶ added in v0.0.5
ApplyConfig applys the diagram's config
func (*Cdor) ApplyOption ¶ added in v0.0.5
ApplyOption applys the diagram's global option
func (*Cdor) ButteredToast ¶ added in v0.1.1
func (Cdor) Center ¶ added in v0.0.3
func (c Cdor) Center(b ...bool) *config
Center sets if the diagram is centered
func (*Cdor) ColorblindClear ¶ added in v0.1.1
func (*Cdor) ConOpt ¶ added in v0.0.5
func (c *Cdor) ConOpt() *conOption
ConOpt creates a default connection option
func (*Cdor) DarkFlagshipTerrastruct ¶ added in v0.1.1
func (Cdor) DarkTheme ¶ added in v0.0.3
func (c Cdor) DarkTheme(theme int) *config
DarkTheme sets the diagram's dark theme id
func (Cdor) DarkThemeOverrides ¶ added in v0.0.3
func (c Cdor) DarkThemeOverrides(ov *ThemeOverrides) *config
DarkThemeOverrides sets the diagram's dark theme over rides
func (Cdor) Direction ¶ added in v0.0.3
func (c Cdor) Direction(dir string) *config
Direction sets the diagram's direction
func (*Cdor) EarthTones ¶ added in v0.1.1
func (Cdor) ElkLayout ¶ added in v0.0.3
func (c Cdor) ElkLayout(b ...bool) *config
ElkLayout sets if the diagram is elk layouted
func (*Cdor) EvergladeGreen ¶ added in v0.1.1
func (*Cdor) FillPattern ¶ added in v0.1.0
FillPattern sets the global fill pattern
func (*Cdor) HeadCfMany ¶ added in v0.1.2
func (*Cdor) HeadCfManyRequired ¶ added in v0.1.2
func (*Cdor) HeadCfOneRequired ¶ added in v0.1.2
func (*Cdor) HeadDiamond ¶ added in v0.1.2
func (*Cdor) HeadTriangle ¶ added in v0.1.2
func (*Cdor) HorizontalGap ¶ added in v0.0.7
HorizontalGap sets the global horizontal gap
func (*Cdor) MixedBerryBlue ¶ added in v0.1.1
func (*Cdor) NeutralGrey ¶ added in v0.1.1
func (*Cdor) OrangeCreamsicle ¶ added in v0.1.1
func (*Cdor) Parallelogram ¶ added in v0.1.1
Parallelogram creates a parallelogram node
func (Cdor) Sequence ¶ added in v0.0.4
func (c Cdor) Sequence() *config
Sequence sets the diagram as a sequence
func (*Cdor) ShirleyTemple ¶ added in v0.1.1
func (Cdor) Sketch ¶ added in v0.0.3
func (c Cdor) Sketch(b ...bool) *config
Sketch sets if the diagram is sketch style
func (*Cdor) StoredData ¶ added in v0.1.1
StoredData creates a stored_data node
func (*Cdor) TerminalGrayscale ¶ added in v0.1.1
func (Cdor) Theme ¶ added in v0.0.3
func (c Cdor) Theme(theme int) *config
Theme sets the diagram's theme id
func (Cdor) ThemeOverrides ¶ added in v0.0.3
func (c Cdor) ThemeOverrides(ov *ThemeOverrides) *config
ThemeOverrides sets the diagram's theme over rides
func (*Cdor) VanillaNitroCola ¶ added in v0.1.1
func (*Cdor) VerticalGap ¶ added in v0.0.7
VertivalGap sets the global vertical gap
type IWorker ¶ added in v0.0.4
type IWorker interface {
// contains filtered or unexported methods
}
type Mgr ¶ added in v0.1.0
type Mgr struct {
Cdor
// contains filtered or unexported fields
}
func (*Mgr) ApplyConfig ¶ added in v0.1.0
func (*Mgr) ApplyOption ¶ added in v0.1.0
func (Mgr) Center ¶ added in v0.1.0
func (c Mgr) Center(b ...bool) *config
Center sets if the diagram is centered
func (Mgr) DarkTheme ¶ added in v0.1.0
func (c Mgr) DarkTheme(theme int) *config
DarkTheme sets the diagram's dark theme id
func (Mgr) DarkThemeOverrides ¶ added in v0.1.0
func (c Mgr) DarkThemeOverrides(ov *ThemeOverrides) *config
DarkThemeOverrides sets the diagram's dark theme over rides
func (Mgr) Direction ¶ added in v0.1.0
func (c Mgr) Direction(dir string) *config
Direction sets the diagram's direction
func (Mgr) ElkLayout ¶ added in v0.1.0
func (c Mgr) ElkLayout(b ...bool) *config
ElkLayout sets if the diagram is elk layouted
func (*Mgr) RangeCdors ¶ added in v0.1.0
func (Mgr) Sequence ¶ added in v0.1.0
func (c Mgr) Sequence() *config
Sequence sets the diagram as a sequence
func (Mgr) Sketch ¶ added in v0.1.0
func (c Mgr) Sketch(b ...bool) *config
Sketch sets if the diagram is sketch style
func (Mgr) Theme ¶ added in v0.1.0
func (c Mgr) Theme(theme int) *config
Theme sets the diagram's theme id
func (Mgr) ThemeOverrides ¶ added in v0.1.0
func (c Mgr) ThemeOverrides(ov *ThemeOverrides) *config
ThemeOverrides sets the diagram's theme over rides
type ThemeOverrides ¶ added in v0.0.3
type ThemeOverrides = d2target.ThemeOverrides