shape

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2020 License: MIT Imports: 10 Imported by: 3

Documentation

Overview

Package shape provides various SVG shapes

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultFont    = Font{Height: 12, LineHeight: 16, /* contains filtered or unexported fields */}
	DefaultTextPad = Padding{Left: 6, Top: 4, Bottom: 6, Right: 10}
	DefaultPad     = Padding{Left: 10, Top: 2, Bottom: 7, Right: 10}
)
View Source
var ClassAttributes = map[string]string{
	"actor":                 `stroke="black" stroke-width="2" fill="#ffffff"`,
	"circle":                `stroke="black" stroke-width="2" fill="#ffffff"`,
	"dot":                   `stroke="black"`,
	"exit":                  `stroke="black" stroke-width="2" fill="#ffffff"`,
	"exit-dot":              `stroke="black"`,
	"note":                  `font-family="Arial,Helvetica,sans-serif"`,
	"note-box":              `stroke="#d3d3d3" fill="#ffffcc"`,
	"highlight":             `stroke="red"`,
	"highlight-head":        `stroke="red" fill="#ffffff"`,
	"implements-arrow":      `stroke="black" stroke-dasharray="5,5,5"`,
	"implements-arrow-head": `stroke="black" fill="#ffffff"`,
	"arrow":                 `stroke="black"`,
	"arrow-head":            `stroke="black" fill="#ffffff"`,
	"arrow-tail":            `stroke="black" fill="#777777"`,
	"activity-arrow":        `stroke="black"`,
	"activity-arrow-head":   `stroke="black" fill="#ffffff"`,
	"activity-arrow-tail":   `stroke="black" fill="#777777"`,
	"compose-arrow":         `stroke="black"`,
	"compose-arrow-head":    `stroke="black" fill="#ffffff"`,
	"compose-arrow-tail":    `stroke="black" fill="#777777"`,
	"aggregate-arrow":       `stroke="black"`,
	"aggregate-arrow-head":  `stroke="black" fill="#ffffff"`,
	"aggregate-arrow-tail":  `stroke="black" fill="#ffffff"`,
	"line":                  `stroke="black"`,
	"triangle":              `stroke="black"`,
	"column-line":           `stroke="#d3d3d3"`,
	"record":                `stroke="#d3d3d3" fill="#ffffff"`,
	"record-line":           `stroke="#d3d3d3"`,
	"record-title":          `font-family="Arial,Helvetica,sans-serif"`,
	"rect":                  `stroke="#d3d3d3" fill="#ffffff"`,
	"span-green":            `stroke="#d3d3d3" fill="#ccff99" rx="5" ry="5"`,
	"span-blue":             `stroke="#d3d3d3" fill="#99e6ff" rx="5" ry="5"`,
	"span-red":              `stroke="#d3d3d3" fill="#ff9999" rx="5" ry="5"`,
	"state-title":           `font-family="Arial,Helvetica,sans-serif"`,
	"state":                 `stroke="#d3d3d3" fill="#ffffff" rx="10" ry="10"`,
	"component":             `stroke="#d3d3d3" fill="#ffffff"`,
	"component-title":       `font-family="Arial,Helvetica,sans-serif"`,
	"field":                 `font-family="Arial,Helvetica,sans-serif"`,
	"method":                `font-family="Arial,Helvetica,sans-serif"`,
	"record-label":          `font-family="Arial,Helvetica,sans-serif"`,
	"label":                 `font-family="Arial,Helvetica,sans-serif"`,
	"weekend":               `font-family="Arial,Helvetica,sans-serif" fill="#f3f3f3"`,
	"caption":               `font-family="Arial,Helvetica,sans-serif"`,
	"diamond":               `stroke="#d3d3d3" fill="#333333"`,
	"decision":              `stroke="#d3d3d3" fill="#ffffff"`,
}

ClassAttributes define mapping between classes and svg attributes. Setting attributes that modify size or position is not advised.

Functions

func Move added in v0.8.0

func Move(m Movable, xd, yd int)

Types

type Actor added in v0.8.0

type Actor struct {
	// contains filtered or unexported fields
}

func NewActor added in v0.8.0

func NewActor() *Actor

NewActor returns a new actor with a default height.

func (*Actor) Direction added in v0.8.0

func (a *Actor) Direction() Direction

func (*Actor) Edge added in v0.8.0

func (a *Actor) Edge(start xy.Position) xy.Position

func (*Actor) Height added in v0.8.0

func (a *Actor) Height() int

func (*Actor) Position added in v0.8.0

func (a *Actor) Position() (int, int)

func (*Actor) SetClass added in v0.8.0

func (a *Actor) SetClass(class string)

func (*Actor) SetHeight added in v0.8.0

func (a *Actor) SetHeight(h int)

func (*Actor) SetX added in v0.8.0

func (a *Actor) SetX(x int)

func (*Actor) SetY added in v0.8.0

func (a *Actor) SetY(y int)

func (*Actor) String added in v0.8.0

func (a *Actor) String() string

func (*Actor) Width added in v0.8.0

func (a *Actor) Width() int

func (*Actor) WriteSvg added in v0.8.0

func (a *Actor) WriteSvg(out io.Writer) error

type Adjuster

type Adjuster struct {
	// contains filtered or unexported fields
}

Adjuster is used to position a shape relative to other shapes or at a specific xy position.

func NewAdjuster

func NewAdjuster(s ...Shape) *Adjuster

NewAdjuster returns an adjuster with default space of 30 pixels.

func (*Adjuster) Above

func (a *Adjuster) Above(o Shape, space ...int)

Above places the wrapped shape above o. Optional space to override default.

func (*Adjuster) At

func (a *Adjuster) At(x, y int)

At sets the x, y coordinates of the wrapped shape

func (*Adjuster) Below

func (a *Adjuster) Below(o Shape, space ...int)

Below places the wrapped shape below o. Optional space to override default.

func (*Adjuster) LeftOf

func (a *Adjuster) LeftOf(o Shape, space ...int)

LeftOf places the wrapped shape to the left of o. Optional space to override default.

func (*Adjuster) RightOf

func (a *Adjuster) RightOf(o Shape, space ...int)

RightOf places the wrapped shape to the right of o. Optional space to override default.

type Aligner

type Aligner struct{}

Aligner type aligns multiple shapes

func (Aligner) HAlignBottom

func (Aligner) HAlignBottom(shapes ...Shape)

HAlignBottom aligns shape[1:] to shape[0] bottom coordinates horizontally

func (Aligner) HAlignCenter

func (Aligner) HAlignCenter(shapes ...Shape)

HAlignCenter aligns shape[1:] to shape[0] center coordinates horizontally

func (Aligner) HAlignTop

func (Aligner) HAlignTop(shapes ...Shape)

HAlignTop aligns shape[1:] to shape[0] top coordinates horizontally

func (Aligner) VAlignCenter

func (Aligner) VAlignCenter(shapes ...Shape)

VAlignCenter aligns shape[1:] to shape[0] center coordinates vertically

func (Aligner) VAlignLeft

func (Aligner) VAlignLeft(shapes ...Shape)

VAlignLeft aligns shape[1:] to shape[0] left coordinates vertically

func (Aligner) VAlignRight

func (Aligner) VAlignRight(shapes ...Shape)

VAlignRight aligns shape[1:] to shape[0] right coordinates vertically

type Alignment

type Alignment int
const (
	Top Alignment = iota
	Left
	Right
	Bottom
	Center
)

type Arrow

type Arrow struct {
	Start xy.Position
	End   xy.Position
	Tail  Shape
	Head  Shape
	// contains filtered or unexported fields
}

func NewArrow

func NewArrow(x1, y1, x2, y2 int) *Arrow

func NewArrowBetween

func NewArrowBetween(a, b Shape) *Arrow

func (*Arrow) DirQ1

func (a *Arrow) DirQ1() bool

DirQ1 returns true if the arrow points to the bottom-right quadrant.

func (*Arrow) DirQ2

func (a *Arrow) DirQ2() bool

DirQ2 returns true if the arrow points to the bottom-left quadrant.

func (*Arrow) DirQ3

func (a *Arrow) DirQ3() bool

DirQ3 returns true if the arrow points to the top-left quadrant.

func (*Arrow) DirQ4

func (a *Arrow) DirQ4() bool

DirQ4 returns true if the arrow points to the top-right quadrant.

func (*Arrow) Direction

func (a *Arrow) Direction() Direction

Direction returns vertical or horizontal direction, Other if at an angle. If Other, use arrow.DirQn() methods to check to which quadrant.

func (*Arrow) Height

func (a *Arrow) Height() int

func (*Arrow) Position

func (a *Arrow) Position() (int, int)

func (*Arrow) SetClass

func (a *Arrow) SetClass(c string)

func (*Arrow) SetX

func (a *Arrow) SetX(x int)

func (*Arrow) SetY

func (a *Arrow) SetY(y int)

func (*Arrow) String

func (a *Arrow) String() string

func (*Arrow) Width

func (a *Arrow) Width() int

func (*Arrow) WriteSvg

func (a *Arrow) WriteSvg(out io.Writer) error

type Box

type Box interface {
	Position() (int, int)
	Width() int
	Height() int
}

type Circle

type Circle struct {
	Radius int
	// contains filtered or unexported fields
}

func NewCircle

func NewCircle(radius int) *Circle

func (*Circle) Direction

func (c *Circle) Direction() Direction

func (*Circle) Edge

func (c *Circle) Edge(start xy.Position) xy.Position

func (*Circle) Height

func (c *Circle) Height() int

func (*Circle) Position

func (c *Circle) Position() (int, int)

func (*Circle) SetClass

func (c *Circle) SetClass(class string)

func (*Circle) SetX

func (c *Circle) SetX(x int)

func (*Circle) SetY

func (c *Circle) SetY(y int)

func (*Circle) String

func (c *Circle) String() string

func (*Circle) Width

func (c *Circle) Width() int

func (*Circle) WriteSvg

func (c *Circle) WriteSvg(out io.Writer) error

type Component

type Component struct {
	X, Y  int
	Title string

	Font Font
	Pad  Padding
	// contains filtered or unexported fields
}

func NewComponent

func NewComponent(title string) *Component

func (*Component) Direction

func (c *Component) Direction() Direction

func (*Component) Edge

func (c *Component) Edge(start xy.Position) xy.Position

Edge returns intersecting position of a line starting at start and pointing to the components center.

func (*Component) Height

func (c *Component) Height() int

func (*Component) Position

func (c *Component) Position() (int, int)

func (*Component) SetClass

func (c *Component) SetClass(v string)

func (*Component) SetFont

func (c *Component) SetFont(f Font)

func (*Component) SetTextPad

func (c *Component) SetTextPad(pad Padding)

func (*Component) SetX

func (c *Component) SetX(x int)

func (*Component) SetY

func (c *Component) SetY(y int)

func (*Component) String

func (c *Component) String() string

func (*Component) Width

func (c *Component) Width() int

func (*Component) WriteSvg

func (c *Component) WriteSvg(out io.Writer) error

type Diamond

type Diamond struct {
	// contains filtered or unexported fields
}

func NewDecision

func NewDecision() *Diamond

func NewDiamond

func NewDiamond() *Diamond

func (*Diamond) Direction

func (d *Diamond) Direction() Direction

func (*Diamond) Edge

func (d *Diamond) Edge(start xy.Position) xy.Position

func (*Diamond) Height

func (d *Diamond) Height() int

func (*Diamond) Position

func (d *Diamond) Position() (int, int)

func (*Diamond) SetClass

func (d *Diamond) SetClass(c string)

func (*Diamond) SetX

func (d *Diamond) SetX(x int)

func (*Diamond) SetY

func (d *Diamond) SetY(y int)

func (*Diamond) String

func (d *Diamond) String() string

func (*Diamond) Width

func (d *Diamond) Width() int

func (*Diamond) WriteSvg

func (d *Diamond) WriteSvg(out io.Writer) error

type Direction

type Direction int
const (
	Other Direction = iota
	RightDir
	LeftDir
	Up
	Down
)

type Dot

type Dot struct {
	Radius int
	// contains filtered or unexported fields
}

func NewDot

func NewDot() *Dot

func (*Dot) Direction

func (d *Dot) Direction() Direction

func (*Dot) Edge

func (d *Dot) Edge(start xy.Position) xy.Position

func (*Dot) Height

func (d *Dot) Height() int

func (*Dot) Position

func (d *Dot) Position() (int, int)

func (*Dot) SetClass

func (d *Dot) SetClass(class string)

func (*Dot) SetX

func (d *Dot) SetX(x int)

func (*Dot) SetY

func (d *Dot) SetY(y int)

func (*Dot) String

func (d *Dot) String() string

func (*Dot) Width

func (d *Dot) Width() int

func (*Dot) WriteSvg

func (d *Dot) WriteSvg(out io.Writer) error

type Edge

type Edge interface {
	// Edge returns the intersecting position to a shape from start
	// position.
	Edge(start xy.Position) xy.Position
}

type ExitDot

type ExitDot struct {
	Radius int
	// contains filtered or unexported fields
}

func NewExitDot

func NewExitDot() *ExitDot

func (*ExitDot) Direction

func (e *ExitDot) Direction() Direction

func (*ExitDot) Edge

func (e *ExitDot) Edge(start xy.Position) xy.Position

func (*ExitDot) Height

func (e *ExitDot) Height() int

func (*ExitDot) Position

func (e *ExitDot) Position() (int, int)

func (*ExitDot) SetClass

func (e *ExitDot) SetClass(class string)

func (*ExitDot) SetX

func (e *ExitDot) SetX(x int)

func (*ExitDot) SetY

func (e *ExitDot) SetY(y int)

func (*ExitDot) String

func (e *ExitDot) String() string

func (*ExitDot) Width

func (e *ExitDot) Width() int

func (*ExitDot) WriteSvg

func (e *ExitDot) WriteSvg(out io.Writer) error

type Font

type Font struct {
	Height     int
	LineHeight int
	// contains filtered or unexported fields
}

func (Font) TextWidth

func (f Font) TextWidth(txt string) int

type HasFont

type HasFont interface {
	SetFont(Font)
}

type HasTextPad

type HasTextPad interface {
	SetTextPad(Padding)
}

type Label

type Label struct {
	Text string
	Font Font
	Pad  Padding
	// contains filtered or unexported fields
}

func NewLabel

func NewLabel(text string) *Label

func (*Label) Direction

func (l *Label) Direction() Direction

func (*Label) Edge

func (l *Label) Edge(start xy.Position) xy.Position

func (*Label) Height

func (l *Label) Height() int

func (*Label) Position

func (l *Label) Position() (int, int)

func (*Label) SetClass

func (l *Label) SetClass(c string)

func (*Label) SetX

func (l *Label) SetX(x int)

func (*Label) SetY

func (l *Label) SetY(y int)

func (*Label) String

func (l *Label) String() string

func (*Label) Width

func (l *Label) Width() int

func (*Label) WriteSvg

func (l *Label) WriteSvg(w io.Writer) error

type Line

type Line struct {
	Start xy.Position
	End   xy.Position
	// contains filtered or unexported fields
}

func NewLine

func NewLine(x1, y1 int, x2, y2 int) *Line

func (*Line) Direction

func (l *Line) Direction() Direction

func (*Line) Height

func (l *Line) Height() int

func (*Line) Position

func (l *Line) Position() (int, int)

func (*Line) SetClass

func (l *Line) SetClass(c string)

func (*Line) SetX

func (l *Line) SetX(x int)

func (*Line) SetY

func (l *Line) SetY(y int)

func (*Line) String

func (l *Line) String() string

func (*Line) Width

func (l *Line) Width() int

func (*Line) WriteSvg

func (l *Line) WriteSvg(w io.Writer) error

type Movable added in v0.8.0

type Movable interface {
	Position() (int, int)
	SetX(int)
	SetY(int)
}

type Note

type Note struct {
	Text string

	Font
	Pad Padding
	// contains filtered or unexported fields
}

func NewNote

func NewNote(text string) *Note

func (*Note) Direction

func (n *Note) Direction() Direction

func (*Note) Edge added in v0.8.0

func (n *Note) Edge(start xy.Position) xy.Position

func (*Note) Height

func (n *Note) Height() int

func (*Note) Position

func (n *Note) Position() (int, int)

func (*Note) SetClass

func (n *Note) SetClass(c string)

func (*Note) SetX

func (n *Note) SetX(x int)

func (*Note) SetY

func (n *Note) SetY(y int)

func (*Note) String

func (n *Note) String() string

func (*Note) Width

func (n *Note) Width() int

func (*Note) WriteSvg

func (n *Note) WriteSvg(out io.Writer) error

type Padding

type Padding struct {
	Left, Top, Right, Bottom int
}

type Record

type Record struct {
	X, Y    int
	Title   string
	Fields  []string
	Methods []string

	Font Font
	Pad  Padding
	// contains filtered or unexported fields
}

func NewInterfaceRecord

func NewInterfaceRecord(obj interface{}) *Record

func NewRecord

func NewRecord(title string) *Record

func NewStructRecord

func NewStructRecord(obj interface{}) *Record

NewStructRecord returns a record shape based on a Go struct type. Reflection is used.

func (*Record) Direction

func (r *Record) Direction() Direction

func (*Record) Edge

func (r *Record) Edge(start xy.Position) xy.Position

Edge returns intersecting position of a line starting at start and pointing to the records center.

func (*Record) Height

func (r *Record) Height() int

func (*Record) HideFields

func (r *Record) HideFields()

func (*Record) HideMethod

func (r *Record) HideMethod(m string) (found bool)

func (*Record) HideMethods

func (r *Record) HideMethods()

func (*Record) Position

func (r *Record) Position() (int, int)

func (*Record) SetClass

func (r *Record) SetClass(c string)

func (*Record) SetFont

func (r *Record) SetFont(f Font)

func (*Record) SetTextPad

func (r *Record) SetTextPad(pad Padding)

func (*Record) SetX

func (r *Record) SetX(x int)

func (*Record) SetY

func (r *Record) SetY(y int)

func (*Record) String

func (r *Record) String() string

func (*Record) Width

func (r *Record) Width() int

func (*Record) WriteSvg

func (r *Record) WriteSvg(out io.Writer) error

type Rect

type Rect struct {
	X, Y  int
	Title string

	Font Font
	Pad  Padding
	// contains filtered or unexported fields
}

func NewRect

func NewRect(title string) *Rect

func (*Rect) Direction

func (r *Rect) Direction() Direction

func (*Rect) Edge

func (r *Rect) Edge(start xy.Position) xy.Position

Edge returns intersecting position of a line starting at start and pointing to the rect center.

func (*Rect) Height

func (r *Rect) Height() int

func (*Rect) Position

func (r *Rect) Position() (int, int)

func (*Rect) SetClass

func (r *Rect) SetClass(c string)

func (*Rect) SetFont

func (r *Rect) SetFont(f Font)

func (*Rect) SetHeight added in v0.8.0

func (r *Rect) SetHeight(h int)

func (*Rect) SetTextPad

func (r *Rect) SetTextPad(pad Padding)

func (*Rect) SetWidth added in v0.8.0

func (r *Rect) SetWidth(w int)

func (*Rect) SetX

func (r *Rect) SetX(x int)

func (*Rect) SetY

func (r *Rect) SetY(y int)

func (*Rect) String

func (r *Rect) String() string

func (*Rect) Width

func (r *Rect) Width() int

func (*Rect) WriteSvg

func (r *Rect) WriteSvg(out io.Writer) error

type Shape

type Shape interface {
	// Position returns the xy position of the top left corner.
	Position() (x int, y int)
	SetX(int)
	SetY(int)
	Width() int
	Height() int
	// Direction returns in which direction the shape is drawn.
	// The direction and position is needed when aligning shapes.
	Direction() Direction
	SetClass(string)
	WriteSvg(io.Writer) error
}

type State

type State struct {
	X, Y  int
	Title string

	Font Font
	Pad  Padding
	// contains filtered or unexported fields
}

func NewState

func NewState(title string) *State

func (*State) Direction

func (r *State) Direction() Direction

func (*State) Edge

func (r *State) Edge(start xy.Position) xy.Position

Edge returns intersecting position of a line starting at start and pointing to the rect center.

func (*State) Height

func (r *State) Height() int

func (*State) Position

func (r *State) Position() (int, int)

func (*State) SetClass

func (r *State) SetClass(c string)

func (*State) SetFont

func (r *State) SetFont(f Font)

func (*State) SetTextPad

func (r *State) SetTextPad(pad Padding)

func (*State) SetX

func (r *State) SetX(x int)

func (*State) SetY

func (r *State) SetY(y int)

func (*State) String

func (r *State) String() string

func (*State) Width

func (r *State) Width() int

func (*State) WriteSvg

func (r *State) WriteSvg(out io.Writer) error

type Style

type Style struct {
	Font
	TextPad Padding // Surrounding text
	Pad     Padding // E.g. records
	// contains filtered or unexported fields
}

func NewStyle

func NewStyle(w io.Writer) Style

func (*Style) SetOutput

func (s *Style) SetOutput(w io.Writer)

func (*Style) Write

func (s *Style) Write(p []byte) (int, error)

Write adds a style attribute based on class. Limited to 1 class only and assumes the entire classname attribute is found.

type Triangle

type Triangle struct {
	// contains filtered or unexported fields
}

func NewTriangle

func NewTriangle() *Triangle

func (*Triangle) Direction

func (t *Triangle) Direction() Direction

func (*Triangle) Height

func (t *Triangle) Height() int

func (*Triangle) Position

func (t *Triangle) Position() (int, int)

func (*Triangle) SetClass

func (t *Triangle) SetClass(c string)

func (*Triangle) SetX

func (t *Triangle) SetX(x int)

func (*Triangle) SetY

func (t *Triangle) SetY(y int)

func (*Triangle) String

func (t *Triangle) String() string

func (*Triangle) Width

func (t *Triangle) Width() int

func (*Triangle) WriteSvg

func (t *Triangle) WriteSvg(out io.Writer) error

Directories

Path Synopsis
Package design provides svg diagram creators
Package design provides svg diagram creators

Jump to

Keyboard shortcuts

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