Documentation
¶
Overview ¶
Package go-design provides svg diagram creators
Index ¶
- type ClassDiagram
- type Diagram
- func (diagram *Diagram) AdaptSize() (int, int)
- func (diagram *Diagram) Place(s ...shape.Shape) *shape.Adjuster
- 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 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{})
diamond = 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(diamond).Below(circle)
d.Place(triangle).Below(diamond)
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)
diamond = shape.NewArrow(20, 120, 150, 120)
note = shape.NewNote(`Notes support
multilines`)
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)
diamond.Tail = shape.NewDiamond(0, 0)
d.Place(diamond).Below(withtail)
d.Place(note).Below(diamond)
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) 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 (
cli = "Client"
srv = "Server"
db = "Database"
d = design.NewSequenceDiagram()
)
d.AddColumns(cli, srv, db)
d.Link(cli, srv, "connect()")
d.Link(srv, db, "SELECT").Class = "highlight"
d.Link(db, srv, "Rows")
// Special link
lnk := d.Link(srv, srv, "Transform to view model")
lnk.Class = "highlight"
d.Link(srv, cli, "Send HTML")
d.SaveAs("img/sequence_example.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.