Documentation ¶
Index ¶
- Constants
- Variables
- func MeasureFontRect(font Font, size int, text string, x, y int, gravity Gravity) (Rect, Point)
- type ActivityArrowStem
- type ActivityLine
- type ActivityLineStyle
- type ActorBox
- type ActorBoxPos
- type ActorBoxStyle
- type ActorIconBox
- type ActorIconBoxStyle
- type AddSizeConstraint
- type ArrowHeadStyle
- type Block
- type BlockStyle
- type BoxFrame
- type Constraint
- type ConstraintApplier
- type ConstraintChanger
- type CylinderIcon
- type Divider
- type DividerShape
- type DividerStyle
- type DrawContext
- type Font
- type GraphboxItem
- type Graphic
- func (g *Graphic) AddLeftToCol(col, newLeft int)
- func (g *Graphic) AddTopToRow(row, newTop int)
- func (g *Graphic) Cols() int
- func (g *Graphic) DrawSVG(w io.Writer)
- func (g *Graphic) EnsureLeftIsAtleast(col, newLeft int)
- func (g *Graphic) EnsureTopIsAtLeast(row, newTop int)
- func (g *Graphic) GridPointRect(fr, fc, tr, tc int) (int, int)
- func (g *Graphic) PointAt(r, c int) (Point, bool)
- func (g *Graphic) Put(r, c int, item GraphboxItem) bool
- func (g *Graphic) Rows() int
- type Gravity
- type Icon
- type LifeLine
- type LifeLineStyle
- type NoteBox
- type NoteBoxPos
- type NoteBoxStyle
- type PathIcon
- type PathIconData
- type Point
- type Rect
- type SizeConstraint
- type Spacer
- type StickPersonIcon
- type SvgStyle
- type TTFFont
- type TextAlign
- type TextBox
- type Title
- type TitleStyle
- type TotalSizeConstraint
Constants ¶
const ( // SolidArrowStem draws a solid arrow stem SolidArrowStem ActivityArrowStem = iota // DashedArrowStem draws a dashed arrow stem DashedArrowStem = iota // ThickArrowStem draws a thick arrow stem ThickArrowStem = iota )
const ( LeftActorBox ActorBoxPos = (iota << 8) MiddleActorBox = (iota << 8) RightActorBox = (iota << 8) )
These flags are for the horizontal position
const ( CenterNotePos NoteBoxPos = iota LeftNotePos = iota RightNotePos = iota )
const ( LeftTextAlign TextAlign = iota MiddleTextAlign = iota RightTextAlign = iota )
const (
LINE_GAP = 2
)
Variables ¶
var CloudPathData = PathIconData{
Width: 365.0,
Height: 185.0,
TargetIconSize: 44.0,
IconPadding: -18.0,
Path: `
m299.75 60.587c-4.108 0-8.123 0.411-12.001 1.188-11.95-35.875-46.03-61.775-86.23-61.775-33.761
0-63.196 18.27-78.847 45.363-0.919-0.036-1.84-0.07-2.769-0.07-23.494 0-44.202 11.816-56.409
29.777-3.263-0.617-6.627-0.953-10.071-0.953-29.503 0-53.42 23.702-53.42 52.943 0 29.24 23.917
52.94 53.421 52.94h66.435 0.045 0.045 81.525 0.045 0.047 98.145 0.046c33.28 0 60.25-26.73
60.25-59.71 0-32.972-26.97-59.703-60.25-59.703z
`,
}
CloudPathData represents the path data for the cloud icon. The image was adapted from the one at https://freesvg.org/simple-white-cloud-icon-vector-graphics
Functions ¶
func MeasureFontRect ¶
Given a font, font size, points and gravity, returns a rectangle which will contain the text centered. The point and gravity describes the location of the rect. The second point is where the text is to start given that it is to be rendered to fill the rectangle with default anchoring and alignment
Types ¶
type ActivityArrowStem ¶
type ActivityArrowStem int
ActivityArrowStem is the type of arrow stem to use for activity arrows
type ActivityLine ¶
type ActivityLine struct { TC int // contains filtered or unexported fields }
ActivityLine is an activity line graphical object
func NewActivityLine ¶
func NewActivityLine(toCol int, selfRef bool, text string, style ActivityLineStyle) *ActivityLine
NewActivityLine constructs a new ActivityLine
func (*ActivityLine) Constraint ¶
func (al *ActivityLine) Constraint(r, c int, applier ConstraintApplier)
Constraint returns the constraints of the graphics object
func (*ActivityLine) Draw ¶
func (al *ActivityLine) Draw(ctx DrawContext, point Point)
Draw draws the graphics object
type ActivityLineStyle ¶
type ActivityLineStyle struct { Font Font FontSize int Margin Point TextGap int SelfRefWidth int SelfRefHeight int //ArrowHead ActivityArrowHead ArrowHead *ArrowHeadStyle ArrowStem ActivityArrowStem }
ActivityLineStyle defines the style to use for an activity line
type ActorBox ¶
type ActorBox struct {
// contains filtered or unexported fields
}
ActorBox represents an a actor
func NewActorBox ¶
func NewActorBox(text string, style ActorBoxStyle, pos ActorBoxPos) *ActorBox
NewActorBox returns a new actor
func (*ActorBox) Constraint ¶
func (tr *ActorBox) Constraint(r, c int, applier ConstraintApplier)
func (*ActorBox) Draw ¶
func (r *ActorBox) Draw(ctx DrawContext, point Point)
type ActorBoxPos ¶
type ActorBoxPos int
ActorBoxPos is used to manage the flags representing the actor boxes position
const ( TopActorBox ActorBoxPos = iota BottomActorBox = iota )
These flags are for the vertical position
type ActorBoxStyle ¶
type ActorBoxStyle struct { Font Font FontSize int Padding Point Margin Point Color string TextColor string }
ActorBoxStyle defines styling options for the actor boxes
type ActorIconBox ¶
type ActorIconBox struct { Icon Icon // contains filtered or unexported fields }
ActorIconBox represents an actor icon
func NewActorIconBox ¶
func NewActorIconBox(text string, icon Icon, style ActorIconBoxStyle, pos ActorBoxPos) *ActorIconBox
NewActorIconBox constructs a new actor icon
func (*ActorIconBox) Constraint ¶
func (tr *ActorIconBox) Constraint(r, c int, applier ConstraintApplier)
func (*ActorIconBox) Draw ¶
func (tr *ActorIconBox) Draw(ctx DrawContext, point Point)
type ActorIconBoxStyle ¶
type ActorIconBoxStyle struct { Font Font FontSize int Padding Point Margin Point IconGap int Color string TextColor string }
ActorIconBoxStyle defines styling options for an actor icon
type AddSizeConstraint ¶
Adds a size constraint which requests a minimum gap between points
func (AddSizeConstraint) Apply ¶
func (sc AddSizeConstraint) Apply(cm ConstraintChanger)
type ArrowHeadStyle ¶
type ArrowHeadStyle struct { // Points from the origin Xs []int Ys []int // Base style for the arrow head BaseStyle string }
ArrowHeadStyle defines style information for the arrow heads
type Block ¶
type Block struct { TR int TC int MarginMup int IsLast bool ShowPrefix bool ShowMessage bool Style BlockStyle // contains filtered or unexported fields }
A block
func (*Block) Constraint ¶
func (block *Block) Constraint(r, c int, applier ConstraintApplier)
func (*Block) Draw ¶
func (block *Block) Draw(ctx DrawContext, point Point)
type BlockStyle ¶
type BlockStyle struct { Margin Point Font Font FontSize int TextPadding Point MessagePadding Point PrefixExtraWidth int GapWidth int MidMargin int }
A block stype
type BoxFrame ¶
type BoxFrame struct { // The outer rectangle. This encompasses margins, etc. OuterRect Rect // The inner rectangle. InnerRect Rect }
A box frame
type Constraint ¶
type Constraint interface {
Apply(cm ConstraintChanger)
}
type ConstraintApplier ¶
type ConstraintApplier struct {
// contains filtered or unexported fields
}
func (ConstraintApplier) Apply ¶
func (ca ConstraintApplier) Apply(constraint Constraint)
func (ConstraintApplier) Cols ¶
func (ca ConstraintApplier) Cols() int
type ConstraintChanger ¶
type ConstraintChanger interface { // Number of columns in constraint changer Cols() int // Calculate the current size between the two grid points GridPointRect(fr, fc, tr, tc int) (int, int) // Ensure that the left side of this column has this much space. // Provide space if needed. EnsureLeftIsAtleast(col, newLeft int) // Ensure that the top side of this row has this much space. // Provide space if needed. EnsureTopIsAtLeast(row, newTop int) AddLeftToCol(col, newLeft int) AddTopToRow(row, newTop int) }
type CylinderIcon ¶
type CylinderIcon int
func (CylinderIcon) Draw ¶
func (ci CylinderIcon) Draw(ctx DrawContext, x int, y int, lineStyle *SvgStyle)
func (CylinderIcon) Size ¶
func (ci CylinderIcon) Size() (width int, height int)
type Divider ¶
type Divider struct { TC int // contains filtered or unexported fields }
Divider is a divider graphics object. This spans the entire diagram.
func NewDivider ¶
func NewDivider(toCol int, text string, style DividerStyle) *Divider
NewDivider creates a new divider
func (*Divider) Constraint ¶
func (div *Divider) Constraint(r, c int, applier ConstraintApplier)
Constraint returns the constraints of the graphics object
func (*Divider) Draw ¶
func (div *Divider) Draw(ctx DrawContext, point Point)
Draw draws the graphics object
type DividerShape ¶
type DividerShape int
DividerShape determines which shape to use for the divider
const ( // DSFullRect is a rectangle which will span the entire graphic from end to end. // The text will be centered in front of it. DSFullRect DividerShape = iota // DSFramedRect is like FullRect but using a framed rectangle DSFramedRect // DSSpacerRect is like FullRect but "transparent". If there is any text, it will be // blocked out. DSSpacerRect // DSFullLine is a line which will span the entire grapic. The text will be // centered in front of it. DSFullLine )
type DividerStyle ¶
type DividerStyle struct { Font Font FontSize int Padding Point Margin Point TextPadding Point Overlap int Shape DividerShape }
DividerStyle defines the style of the divider
type DrawContext ¶
A drawing context
type GraphboxItem ¶
type GraphboxItem interface { // Defines a constraint. It is provided with the coordinates // of the item. Constraint(r, c int, applier ConstraintApplier) // Call to draw this box Draw(ctx DrawContext, point Point) }
type Graphic ¶
type Graphic struct { // The margin between items Margin Point // Show the grid ShowGrid bool // If true, generate a 'viewport' attribute with the image size and // use percentages for the original image size Viewport bool // contains filtered or unexported fields }
A graphbox diagram. This diagram is made up of uniform points. Each item on the diagram has the option of describing a constraint such as the amount of spacing around the point it requires.
func NewGraphic ¶
func (*Graphic) AddLeftToCol ¶
func (*Graphic) AddTopToRow ¶
func (*Graphic) EnsureLeftIsAtleast ¶
func (*Graphic) EnsureTopIsAtLeast ¶
func (*Graphic) GridPointRect ¶
Implementation of ConstrantModifier.
While updating constraints:
- The first column is used to maintain Y deltas
- The first row is used to maintain X deltas
TODO: Instead of using loops, add cheats like only using the first row/column
type Icon ¶
type Icon interface { // Return the size of the icon Size() (width int, height int) // Draw the icon onto the draw context centered at x and y Draw(ctx DrawContext, x int, y int, lineStyle *SvgStyle) }
An icon which can be added to actors
type LifeLine ¶
type LifeLine struct {
TR, TC int
Style LifeLineStyle
}
The object lifeline
func (*LifeLine) Constraint ¶
func (ll *LifeLine) Constraint(r, c int, applier ConstraintApplier)
func (*LifeLine) Draw ¶
func (ll *LifeLine) Draw(ctx DrawContext, point Point)
type LifeLineStyle ¶
type LifeLineStyle struct {
Color string
}
type NoteBox ¶
type NoteBox struct {
// contains filtered or unexported fields
}
Draws an object instance
func NewNoteBox ¶
func NewNoteBox(text string, style NoteBoxStyle, pos NoteBoxPos) *NoteBox
func (*NoteBox) Constraint ¶
func (tr *NoteBox) Constraint(r, c int, applier ConstraintApplier)
func (*NoteBox) Draw ¶
func (r *NoteBox) Draw(ctx DrawContext, point Point)
type NoteBoxPos ¶
type NoteBoxPos int
type NoteBoxStyle ¶
type NoteBoxStyle struct { Font Font FontSize int Padding Point Margin Point Position NoteBoxPos }
Styling options for the actor rect
type PathIcon ¶ added in v0.0.3
type PathIcon struct {
Data PathIconData
}
type PathIconData ¶ added in v0.0.3
type Rect ¶
A rectangle
type SizeConstraint ¶
Apply a size constraint which requests a minimum gap between points
func (SizeConstraint) Apply ¶
func (sc SizeConstraint) Apply(cm ConstraintChanger)
type Spacer ¶
type Spacer struct {
Margin Point
}
func (*Spacer) Constraint ¶
func (sp *Spacer) Constraint(r, c int, applier ConstraintApplier)
func (*Spacer) Draw ¶
func (sp *Spacer) Draw(ctx DrawContext, point Point)
type StickPersonIcon ¶
type StickPersonIcon int
func (StickPersonIcon) Draw ¶
func (spi StickPersonIcon) Draw(ctx DrawContext, x int, y int, lineStyle *SvgStyle)
func (StickPersonIcon) Size ¶
func (spi StickPersonIcon) Size() (width int, height int)
type SvgStyle ¶
A SVG style
func StyleFromString ¶
Converts a style in a CSS base string to a SvgStyle
type TTFFont ¶
type TTFFont struct {
// contains filtered or unexported fields
}
A true-type font
func NewTTFFontFromByteSlice ¶
Loads a TTF font from a byte slice
type TextBox ¶
A block of prose
func NewTextBox ¶
Returns a new text box
func (*TextBox) BoundingRect ¶
Given a font, font size, points and gravity, returns a rectangle which will contain the text centered. The point and gravity describes the location of the rect. The second point is where the text is to start given that it is to be rendered to fill the rectangle with default anchoring and alignment
type Title ¶
type Title struct { TC int // contains filtered or unexported fields }
A title
func (*Title) Constraint ¶
func (al *Title) Constraint(r, c int, applier ConstraintApplier)
func (*Title) Draw ¶
func (al *Title) Draw(ctx DrawContext, point Point)
type TitleStyle ¶
type TotalSizeConstraint ¶
Ensures that the total size between the two points is big enough for the rectangle. If not, resize the grid points uniformally.
func (TotalSizeConstraint) Apply ¶
func (sc TotalSizeConstraint) Apply(cm ConstraintChanger)