seqdiagram

package
v0.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 17, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SolidArrowStem  ArrowStem = iota
	DashedArrowStem           = iota
	ThickArrowStem            = iota
)
View Source
const (
	SolidArrowHead     ArrowHead = iota
	OpenArrowHead                = iota
	BarbArrowHead                = iota
	LowerBarbArrowHead           = iota
)
View Source
const (
	LeftNoteAlignment  NoteAlignment = iota
	RightNoteAlignment               = iota
	OverNoteAlignment                = iota
)

Variables

View Source
var DefaultOptions = &ImageOptions{
	Style:    DefaultStyle,
	Embedded: false,
}

The default options

View Source
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

View Source
var EIconNotFound = errors.New("Icon not found")

Error returned if the icon cannot be found

View Source
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.

View Source
var StyleNames = map[string]*DiagramStyles{
	"default": DefaultStyle,
	"tight":   TightStyle,
	"small":   SmallStyle,
}
View Source
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
	InFooter  bool
	Lifeline  bool
	Color     string
	TextColor string
	// contains filtered or unexported fields
}

A participant

var LeftOffsideActor *Actor = &Actor{rank: -1}

Special actors

var RightOffsideActor *Actor = &Actor{rank: -2}

type ActorIcon

type ActorIcon interface {
	// contains filtered or unexported methods
}

An actor icon

func LookupActorIcon

func LookupActorIcon(name string) (ActorIcon, error)

Lookup an actor icon based on it's name. If the actor icon cannot be found, an EIconNotFound error is returned

type Arrow

type Arrow struct {
	Stem ArrowStem
	Head ArrowHead
}

An arrow

type ArrowHead

type ArrowHead int

The supported arrow heads

type ArrowStem

type ArrowStem int

The supported arrow stems

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

func (*AttributeSet) GetBool

func (as *AttributeSet) GetBool(name string, def bool) bool

Gets a boolean value. If the value is undefined, returns the default.

func (*AttributeSet) GetDef

func (as *AttributeSet) GetDef(name string, def string) string

Get an attribute value or a default if it is not 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

func (b *Block) Concurrent() bool

Concurrent returns true if the block is a concurrent block segment.

func (*Block) MaxNestDepth

func (b *Block) MaxNestDepth() int

Returns the maximum number of nested blocks within the segments

func (*Block) ShouldBeFullWidth added in v0.0.4

func (b *Block) ShouldBeFullWidth() bool

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 NewDiagram

func NewDiagram() *Diagram

Creates a new, empty diagram

func ParseDiagram

func ParseDiagram(r io.Reader, filename string) (*Diagram, error)

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

func (d *Diagram) GetOrAddActor(name string) *Actor

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 (d *Diagram) GetOrAddActorWithOptions(name string, label string) *Actor

func (*Diagram) WriteSVG

func (d *Diagram) WriteSVG(w io.Writer) error

Write the diagram as an SVG

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 DividerType

type DividerType int
const (
	DTSpacer DividerType = iota
	DTGap
	DTFrame
	DTLine
)

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 NoteAlignment

type NoteAlignment int

Note alignments

type ProcessingInstruction

type ProcessingInstruction struct {
	Prefix string
	Value  string
}

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
)

type SequenceItem

type SequenceItem interface {
}

A sequence item

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL