Documentation ¶
Index ¶
- Constants
- Variables
- type Action
- type Actor
- type ActorIcon
- type Arrow
- type ArrowHead
- type ArrowStem
- type AttributeSet
- type Block
- type BlockSegment
- type Diagram
- func (d *Diagram) AddSequenceItem(item SequenceItem)
- func (d *Diagram) GetOrAddActor(name string) *Actor
- func (d *Diagram) GetOrAddActorWithOptions(name string, label string) *Actor
- func (d *Diagram) WriteSVG(w io.Writer) error
- func (d *Diagram) WriteSVGWithOptions(w io.Writer, options *ImageOptions) error
- type DiagramStyles
- type Divider
- type DividerType
- type ImageOptions
- type Note
- type NoteAlignment
- type ProcessingInstruction
- type SegmentType
- type SequenceItem
Constants ¶
const ( SolidArrowStem ArrowStem = iota DashedArrowStem = iota ThickArrowStem = iota )
const ( SolidArrowHead ArrowHead = iota OpenArrowHead = iota BarbArrowHead = iota LowerBarbArrowHead = iota )
const ( LeftNoteAlignment NoteAlignment = iota RightNoteAlignment = iota OverNoteAlignment = iota )
Variables ¶
var DefaultOptions = &ImageOptions{ Style: DefaultStyle, Embedded: false, }
The default options
var DefaultStyle = &DiagramStyles{ Margin: graphbox.Point{8, 8}, ActorBox: graphbox.ActorBoxStyle{ Font: standardFont, FontSize: 16, Padding: graphbox.Point{16, 8}, Margin: graphbox.Point{8, 8}, }, ActorIconBox: graphbox.ActorIconBoxStyle{ Font: standardFont, FontSize: 16, Padding: graphbox.Point{16, 8}, Margin: graphbox.Point{8, 8}, IconGap: 4, }, NoteBox: graphbox.NoteBoxStyle{ Font: standardFont, FontSize: 14, Padding: graphbox.Point{8, 4}, Margin: graphbox.Point{8, 8}, }, MultiNoteOverlap: 16, ActivityLine: graphbox.ActivityLineStyle{ Font: standardFont, FontSize: 14, SelfRefWidth: 48, SelfRefHeight: 24, Margin: graphbox.Point{16, 8}, TextGap: 4, }, ArrowHeads: map[ArrowHead]*graphbox.ArrowHeadStyle{ SolidArrowHead: { Xs: []int{-9, 0, -9}, Ys: []int{-5, 0, 5}, BaseStyle: "stroke:black;fill:black;stroke-width:2px;", }, OpenArrowHead: { Xs: []int{-9, 0, -9}, Ys: []int{-5, 0, 5}, BaseStyle: "stroke:black;fill:none;stroke-width:2px;", }, BarbArrowHead: { Xs: []int{-11, 0}, Ys: []int{-7, 0}, BaseStyle: "stroke:black;fill:black;stroke-width:2px;", }, LowerBarbArrowHead: { Xs: []int{-11, 0}, Ys: []int{7, 0}, BaseStyle: "stroke:black;fill:black;stroke-width:2px;", }, }, Title: graphbox.TitleStyle{ Font: standardFont, FontSize: 20, Padding: graphbox.Point{4, 16}, }, Block: graphbox.BlockStyle{ Margin: graphbox.Point{8, 8}, TextPadding: graphbox.Point{4, 4}, MessagePadding: graphbox.Point{4, 4}, GapWidth: 4, PrefixExtraWidth: 4, Font: standardFont, FontSize: 14, MidMargin: 4, }, Divider: map[DividerType]graphbox.DividerStyle{ DTGap: { Font: standardFont, FontSize: 14, Padding: graphbox.Point{16, 8}, Margin: graphbox.Point{8, 8}, TextPadding: graphbox.Point{0, 0}, Shape: graphbox.DSFullRect, }, DTFrame: { Font: standardFont, FontSize: 14, Padding: graphbox.Point{16, 8}, Margin: graphbox.Point{8, 8}, TextPadding: graphbox.Point{0, 0}, Shape: graphbox.DSFramedRect, }, DTLine: { Font: standardFont, FontSize: 14, Padding: graphbox.Point{16, 4}, Margin: graphbox.Point{8, 16}, TextPadding: graphbox.Point{4, 2}, Shape: graphbox.DSFullLine, }, DTSpacer: { Font: standardFont, FontSize: 14, Padding: graphbox.Point{16, 4}, Margin: graphbox.Point{8, 16}, TextPadding: graphbox.Point{0, 0}, Shape: graphbox.DSSpacerRect, }, }, }
The Default style
var EIconNotFound = errors.New("Icon not found")
Error returned if the icon cannot be found
var SmallStyle = &DiagramStyles{ Margin: graphbox.Point{4, 4}, ActorBox: graphbox.ActorBoxStyle{ Font: standardFont, FontSize: 14, Padding: graphbox.Point{12, 6}, Margin: graphbox.Point{8, 8}, }, ActorIconBox: graphbox.ActorIconBoxStyle{ Font: standardFont, FontSize: 14, Padding: graphbox.Point{12, 6}, Margin: graphbox.Point{8, 8}, IconGap: 2, }, NoteBox: graphbox.NoteBoxStyle{ Font: standardFont, FontSize: 12, Padding: graphbox.Point{6, 3}, Margin: graphbox.Point{6, 6}, }, MultiNoteOverlap: 8, ActivityLine: graphbox.ActivityLineStyle{ Font: standardFont, FontSize: 12, Margin: graphbox.Point{8, 8}, TextGap: 4, SelfRefWidth: 32, SelfRefHeight: 12, }, ArrowHeads: map[ArrowHead]*graphbox.ArrowHeadStyle{ SolidArrowHead: { Xs: []int{-7, 0, -7}, Ys: []int{-4, 0, 4}, BaseStyle: "stroke:black;fill:black;stroke-width:2px;", }, OpenArrowHead: { Xs: []int{-7, 0, -7}, Ys: []int{-4, 0, 4}, BaseStyle: "stroke:black;fill:none;stroke-width:2px;", }, BarbArrowHead: { Xs: []int{-9, 0}, Ys: []int{-5, 0}, BaseStyle: "stroke:black;fill:black;stroke-width:2px;", }, LowerBarbArrowHead: { Xs: []int{-9, 0}, Ys: []int{5, 0}, BaseStyle: "stroke:black;fill:black;stroke-width:2px;", }, }, Title: graphbox.TitleStyle{ Font: standardFont, FontSize: 18, Padding: graphbox.Point{2, 8}, }, Block: graphbox.BlockStyle{ Margin: graphbox.Point{5, 5}, TextPadding: graphbox.Point{3, 2}, MessagePadding: graphbox.Point{3, 2}, GapWidth: 3, PrefixExtraWidth: 3, Font: standardFont, FontSize: 12, MidMargin: 2, }, Divider: map[DividerType]graphbox.DividerStyle{ DTGap: { Font: standardFont, FontSize: 12, Padding: graphbox.Point{12, 6}, Margin: graphbox.Point{6, 6}, TextPadding: graphbox.Point{0, 0}, Shape: graphbox.DSFullRect, }, DTFrame: { Font: standardFont, FontSize: 12, Padding: graphbox.Point{12, 6}, Margin: graphbox.Point{6, 6}, TextPadding: graphbox.Point{0, 0}, Shape: graphbox.DSFramedRect, }, DTLine: { Font: standardFont, FontSize: 12, Padding: graphbox.Point{12, 6}, Margin: graphbox.Point{6, 12}, TextPadding: graphbox.Point{2, 1}, Shape: graphbox.DSFullLine, }, DTSpacer: { Font: standardFont, FontSize: 12, Padding: graphbox.Point{12, 6}, Margin: graphbox.Point{6, 12}, TextPadding: graphbox.Point{2, 1}, Shape: graphbox.DSSpacerRect, }, }, }
The small style. This has narrower margins and font sizes and is used to produce smaller diagrams.
var StyleNames = map[string]*DiagramStyles{ "default": DefaultStyle, "tight": TightStyle, "small": SmallStyle, }
var TightStyle = &DiagramStyles{ Margin: graphbox.Point{8, 8}, ActorBox: graphbox.ActorBoxStyle{ Font: standardFont, FontSize: 16, Padding: graphbox.Point{16, 4}, Margin: graphbox.Point{8, 4}, }, ActorIconBox: graphbox.ActorIconBoxStyle{ Font: standardFont, FontSize: 16, Padding: graphbox.Point{16, 8}, Margin: graphbox.Point{8, 4}, IconGap: 4, }, NoteBox: graphbox.NoteBoxStyle{ Font: standardFont, FontSize: 14, Padding: graphbox.Point{8, 4}, Margin: graphbox.Point{8, 4}, }, MultiNoteOverlap: 16, ActivityLine: graphbox.ActivityLineStyle{ Font: standardFont, FontSize: 14, SelfRefWidth: 48, SelfRefHeight: 12, Margin: graphbox.Point{16, 4}, TextGap: 4, }, ArrowHeads: map[ArrowHead]*graphbox.ArrowHeadStyle{ SolidArrowHead: { Xs: []int{-9, 0, -9}, Ys: []int{-5, 0, 5}, BaseStyle: "stroke:black;fill:black;stroke-width:2px;", }, OpenArrowHead: { Xs: []int{-9, 0, -9}, Ys: []int{-5, 0, 5}, BaseStyle: "stroke:black;fill:none;stroke-width:2px;", }, BarbArrowHead: { Xs: []int{-11, 0}, Ys: []int{-7, 0}, BaseStyle: "stroke:black;fill:black;stroke-width:2px;", }, LowerBarbArrowHead: { Xs: []int{-11, 0}, Ys: []int{7, 0}, BaseStyle: "stroke:black;fill:black;stroke-width:2px;", }, }, Title: graphbox.TitleStyle{ Font: standardFont, FontSize: 20, Padding: graphbox.Point{4, 8}, }, Block: graphbox.BlockStyle{ Margin: graphbox.Point{8, 8}, TextPadding: graphbox.Point{4, 4}, MessagePadding: graphbox.Point{4, 4}, GapWidth: 4, PrefixExtraWidth: 4, Font: standardFont, FontSize: 14, MidMargin: 4, }, Divider: map[DividerType]graphbox.DividerStyle{ DTGap: { Font: standardFont, FontSize: 14, Padding: graphbox.Point{16, 8}, Margin: graphbox.Point{8, 8}, TextPadding: graphbox.Point{0, 0}, Shape: graphbox.DSFullRect, }, DTFrame: { Font: standardFont, FontSize: 14, Padding: graphbox.Point{16, 8}, Margin: graphbox.Point{8, 8}, TextPadding: graphbox.Point{0, 0}, Shape: graphbox.DSFramedRect, }, DTLine: { Font: standardFont, FontSize: 14, Padding: graphbox.Point{16, 4}, Margin: graphbox.Point{8, 16}, TextPadding: graphbox.Point{4, 2}, Shape: graphbox.DSFullLine, }, DTSpacer: { Font: standardFont, FontSize: 14, Padding: graphbox.Point{16, 4}, Margin: graphbox.Point{8, 16}, TextPadding: graphbox.Point{0, 0}, Shape: graphbox.DSSpacerRect, }, }, }
The Tight style. Same horizontal dimensions as the normal style but slightly smaller vertical margins
Functions ¶
This section is empty.
Types ¶
type Action ¶
type Action struct { // The originating actor From *Actor // The destination actor To *Actor // The arrow to use Arrow Arrow // The message Message string }
Defines an action
type Actor ¶
type Actor struct { Name string Label string Icon ActorIcon InHeader bool Lifeline bool Color string TextColor string // contains filtered or unexported fields }
A participant
type ActorIcon ¶
type ActorIcon interface {
// contains filtered or unexported methods
}
An actor icon
func LookupActorIcon ¶
Lookup an actor icon based on it's name. If the actor icon cannot be found, an EIconNotFound error is returned
type AttributeSet ¶
type AttributeSet struct { Parent *AttributeSet Attrs map[string]string }
An attribute set
func (*AttributeSet) Get ¶
func (as *AttributeSet) Get(name string) (value string, hasValue bool)
Get an attribute value and if the attribute is defined
type Block ¶
type Block struct {
Segments []*BlockSegment
}
A framed block of sequence items. Each block can have one or more segments, which will appear one after the other.
func (*Block) Concurrent ¶
Concurrent returns true if the block is a concurrent block segment.
func (*Block) MaxNestDepth ¶
Returns the maximum number of nested blocks within the segments
func (*Block) ShouldBeFullWidth ¶ added in v0.0.4
type BlockSegment ¶
type BlockSegment struct { Type SegmentType Prefix string Message string FullWidth bool SubItems []SequenceItem }
A segment within a block
func (*BlockSegment) MaxNestDepth ¶
func (bs *BlockSegment) MaxNestDepth() int
Returns the number of nested blocks
func (*BlockSegment) ShouldBeFullWidth ¶ added in v0.0.4
func (bs *BlockSegment) ShouldBeFullWidth() bool
Returns true if this block should be full width. A block is full width, either if it's full width itself, or if any nested blocks are full width.
type Diagram ¶
type Diagram struct { ProcessingInstructions []*ProcessingInstruction Title string Actors []*Actor Items []SequenceItem }
Top level diagram definition
func ParseDiagram ¶
Parses a diagram from a reader and returns the diagram or an error
func (*Diagram) AddSequenceItem ¶
func (d *Diagram) AddSequenceItem(item SequenceItem)
Adds a new sequence item
func (*Diagram) GetOrAddActor ¶
Returns an actor by name. If the actor is undefined, a new actor is created and added to the end of the slice.
func (*Diagram) GetOrAddActorWithOptions ¶
func (*Diagram) WriteSVGWithOptions ¶
func (d *Diagram) WriteSVGWithOptions(w io.Writer, options *ImageOptions) error
Write the diagram as an SVG using a specific style
type DiagramStyles ¶
type DiagramStyles struct { // Diagram margins Margin graphbox.Point // Styling of the actor box ActorBox graphbox.ActorBoxStyle ActorIconBox graphbox.ActorIconBoxStyle // Styling of the note box NoteBox graphbox.NoteBoxStyle MultiNoteOverlap int // Styling of the activity line ActivityLine graphbox.ActivityLineStyle // Styling of arrow heads ArrowHeads map[ArrowHead]*graphbox.ArrowHeadStyle // Styling of the diagram title Title graphbox.TitleStyle // Block styling Block graphbox.BlockStyle // Styles of dividers Divider map[DividerType]graphbox.DividerStyle }
Diagram styles
type Divider ¶
type Divider struct { // The message Message string // The divider type Type DividerType }
Defines a divider, which spans the diagram.
type ImageOptions ¶
type ImageOptions struct { // The diagram style Style *DiagramStyles // If true, generate attributes to make the SVG suitable for embedding // in other documents (e.g. HTML). Embedded bool }
Options for SVG image generation
type Note ¶
type Note struct { // The note's alignment and position Actor1 *Actor Actor2 *Actor Align NoteAlignment // The message Message string }
Defines a note
type ProcessingInstruction ¶
A processing instruction
type SegmentType ¶
type SegmentType int
The type of segment
const ( // The alt segment AltSegmentType SegmentType = iota // The else segment ElseSegmentType // ParSegmentType is for the "par" blocks ParSegmentType // ParElseSegmentType is for the "parelse" blocks ParElseSegmentType // The opt segment OptSegmentType // The loop segment LoopSegmentType // ConcurrentSegmentType is for the first segment of a concurrent block. ConcurrentSegmentType // ConcurrentWhilstSegmentType is for the subsequent segments (i.e. the "whilst" segments) // of a concurrent block. ConcurrentWhilstSegmentType EmptySegmentType )