Documentation ¶
Overview ¶
Package go-design provides svg diagram creators
Index ¶
- type ActivityDiagram
- type ClassDiagram
- type Diagram
- func (diagram *Diagram) AdaptSize() (int, int)
- func (diagram *Diagram) Link(from, to shape.Shape, txt string)
- func (diagram *Diagram) LinkAll(s ...shape.Shape)
- func (diagram *Diagram) Place(s ...shape.Shape) *shape.Adjuster
- func (diagram *Diagram) PlaceGrid(cols, X, Y int, s ...shape.Shape)
- func (d *Diagram) SaveAs(filename string) error
- func (d *Diagram) SetCaption(txt string)
- func (d *Diagram) SetHeight(h int)
- func (d *Diagram) SetWidth(w int)
- func (d *Diagram) WriteSvg(w io.Writer) error
- type Link
- type Relation
- type SequenceDiagram
- func (d *SequenceDiagram) AddColumns(names ...string)
- func (d *SequenceDiagram) AddStruct(obj interface{}) string
- func (d *SequenceDiagram) ClearLinks()
- func (d *SequenceDiagram) Height() int
- func (d *SequenceDiagram) Link(from, to, text string) *Link
- func (d *SequenceDiagram) SaveAs(filename string) error
- func (d *SequenceDiagram) Width() int
- func (d *SequenceDiagram) WriteSvg(w io.Writer) error
- type SvgWriter
- type VRecord
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ActivityDiagram ¶ added in v0.6.0
type ActivityDiagram struct {
Diagram
}
Example ¶
package main import ( design "github.com/gregoryv/go-design" "github.com/gregoryv/go-design/shape" ) func main() { var ( d = design.NewActivityDiagram() start = shape.NewDot(10) push = shape.NewState("Push commit") dec = shape.NewDecision() run = shape.NewState("Run git hook") deploy = shape.NewState("Deploy") endOk = shape.NewExitDot() endFail = shape.NewExitDot() ) d.Place(start).At(80, 20) d.Place(push, run, dec, deploy, endOk).Below(start, 40) d.Place(endFail).RightOf(dec, 80) d.VAlignCenter(start, push, run, dec, deploy, endOk) d.HAlignCenter(dec, endFail) d.LinkAll(start, push, run, dec, deploy, endOk) d.Link(dec, endFail, "Tests failed") d.SaveAs("img/activity_diagram.svg") }
Output:
func NewActivityDiagram ¶ added in v0.6.0
func NewActivityDiagram() *ActivityDiagram
type ClassDiagram ¶
type ClassDiagram struct { Diagram // contains filtered or unexported fields }
Example ¶
package main import ( design "github.com/gregoryv/go-design" "github.com/gregoryv/go-design/shape" ) func main() { var ( d = design.NewClassDiagram() record = d.Struct(shape.Record{}) arrow = d.Struct(shape.Arrow{}) line = d.Struct(shape.Line{}) circle = d.Struct(shape.Circle{}) diaarrow = d.Struct(shape.Diamond{}) triangle = d.Struct(shape.Triangle{}) shapE = d.Interface((*shape.Shape)(nil)) ) d.HideRealizations() var ( fnt = d.Struct(shape.Font{}) style = d.Struct(shape.Style{}) seqdia = d.Struct(design.SequenceDiagram{}) classdia = d.Struct(design.ClassDiagram{}) dia = d.Struct(design.Diagram{}) aligner = d.Struct(shape.Aligner{}) adj = d.Struct(shape.Adjuster{}) ) d.HideRealizations() d.Place(shapE).At(220, 20) d.Place(record).At(20, 120) d.Place(line).Below(shapE, 90) d.VAlignCenter(shapE, line) d.Place(arrow).RightOf(line, 90) d.Place(circle).RightOf(shapE, 280) d.Place(diaarrow).Below(circle) d.Place(triangle).Below(diaarrow) d.HAlignBottom(record, arrow, line) d.Place(fnt).Below(record, 120) d.Place(style).RightOf(fnt, 90) d.VAlignCenter(shapE, line, style) d.VAlignCenter(record, fnt) d.Place(dia).RightOf(style, 90) d.Place(aligner).RightOf(dia, 80) d.HAlignCenter(fnt, style, dia, aligner) d.Place(adj).Below(fnt, 70) d.Place(seqdia).Below(aligner, 90) d.Place(classdia).Below(dia, 90) d.VAlignCenter(dia, classdia) d.HAlignBottom(classdia, seqdia) d.SetCaption("Figure 1. Class diagram of design and design.shape packages") d.SaveAs("img/class_example.svg") }
Output:
func NewClassDiagram ¶
func NewClassDiagram() *ClassDiagram
NewClassDiagram returns a diagram representing structs and interfaces. Relations are reflected from the types and drawn as arrows.
func (*ClassDiagram) HideRealizations ¶
func (d *ClassDiagram) HideRealizations()
HideRealizations hides all methods of structs that implement a visible interface.
func (*ClassDiagram) Interface ¶
func (d *ClassDiagram) Interface(obj interface{}) VRecord
func (*ClassDiagram) SaveAs ¶
func (d *ClassDiagram) SaveAs(filename string) error
SaveAs saves the diagram to filename as SVG
func (*ClassDiagram) Struct ¶
func (d *ClassDiagram) Struct(obj interface{}) VRecord
type Diagram ¶
Diagram is a generic SVG image with box related styling
Example ¶
package main import ( design "github.com/gregoryv/go-design" "github.com/gregoryv/go-design/shape" ) func main() { var ( record = shape.NewRecord("Record") x, y = 130, 80 q1arrow = shape.NewArrow(x, y, x+50, y-10) q2arrow = shape.NewArrow(x, y, x-30, y-10) q3arrow = shape.NewArrow(x, y, x-50, y+20) q4arrow = shape.NewArrow(x, y, x+40, y+20) rightarrow = shape.NewArrow(x, y, x+90, y) leftarrow = shape.NewArrow(x, y, x-50, y) uparrow = shape.NewArrow(x, y, x, y-40) downarrow = shape.NewArrow(x, y, x, y+40) label = shape.NewLabel("Label") withtail = shape.NewArrow(20, 100, 150, 100) diaarrow = shape.NewArrow(20, 120, 150, 120) note = shape.NewNote(`Notes support multilines`) comp = shape.NewComponent("database") srv = shape.NewComponent("service") circle = shape.NewCircle(10) dot = shape.NewDot(10) exit = shape.NewExitDot() rect = shape.NewRect("Rect") state = shape.NewState("Waiting for go routine") d = design.NewDiagram() ) d.Place(record).At(10, 30) for _, arrow := range []*shape.Arrow{ q1arrow, q2arrow, q3arrow, q4arrow, rightarrow, leftarrow, uparrow, downarrow, } { d.Place(arrow) } d.Place(label).RightOf(record, 150) withtail.Tail = shape.NewCircle(3) d.Place(withtail).At(20, 150) diaarrow.Tail = shape.NewDiamond() d.Place(diaarrow).Below(withtail) d.Place(note).Below(diaarrow) d.Place(circle).Below(note) d.Place(dot).RightOf(circle) d.Place(exit).RightOf(dot) d.Place(comp).RightOf(diaarrow) d.Place(rect).Below(circle) d.Place(state).RightOf(rect) d.Place(srv).Below(comp) d.VAlignCenter(comp, srv) d.LinkAll(srv, comp) d.SaveAs("img/diagram_example.svg") }
Output:
func NewDiagram ¶
func NewDiagram() Diagram
NewDiagram returns a diagram with present font and padding values.
TODO: size and padding affects eg. records, but is related to the styling
func (*Diagram) AdaptSize ¶
AdaptSize adapts the diagram size to the shapes inside it so all are visible. Returns the new width and height
func (*Diagram) LinkAll ¶ added in v0.6.0
LinkAll places an arrow between the shapes, s0->s1->...->sn
func (*Diagram) PlaceGrid ¶ added in v0.6.0
PlaceGrid place all the shapes into a grid starting at X,Y position. Row height is adapted to heighest element.
func (*Diagram) SetCaption ¶
type Relation ¶
type Relation struct {
// contains filtered or unexported fields
}
Relation defines a relation between two records
type SequenceDiagram ¶
type SequenceDiagram struct { Diagram ColWidth int VMargin int // top margin for each horizontal lane // contains filtered or unexported fields }
SequenceDiagram defines columns and links between columns.
Example ¶
package main import ( design "github.com/gregoryv/go-design" ) func main() { var ( d = design.NewSequenceDiagram() cli = "Client" srv = "Server" db = "Database" ) d.AddColumns(cli, srv, db) d.Link(cli, srv, "connect()") d.Link(srv, db, "SELECT").Class = "highlight" d.Link(db, srv, "Rows") d.Link(srv, srv, "Transform to view model").Class = "highlight" d.Link(srv, cli, "Send HTML") d.SaveAs("img/sequence_diagram.svg") }
Output:
func NewSequenceDiagram ¶
func NewSequenceDiagram() *SequenceDiagram
NewSequenceDiagram returns a sequence diagram with default column width.
func (*SequenceDiagram) AddColumns ¶
func (d *SequenceDiagram) AddColumns(names ...string)
func (*SequenceDiagram) AddStruct ¶ added in v0.4.0
func (d *SequenceDiagram) AddStruct(obj interface{}) string
func (*SequenceDiagram) ClearLinks ¶
func (d *SequenceDiagram) ClearLinks()
func (*SequenceDiagram) Height ¶
func (d *SequenceDiagram) Height() int
Height returns the total height of the diagram
func (*SequenceDiagram) Link ¶
func (d *SequenceDiagram) Link(from, to, text string) *Link
func (*SequenceDiagram) SaveAs ¶
func (d *SequenceDiagram) SaveAs(filename string) error
func (*SequenceDiagram) Width ¶
func (d *SequenceDiagram) Width() int
Width returns the total width of the diagram
type VRecord ¶
VRecord represents a type struct or interface as a record shape.
func NewInterface ¶
func NewInterface(obj interface{}) VRecord
NewInterface returns a VRecord of the given object, panics if not interface.