d2target

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2023 License: MPL-2.0 Imports: 12 Imported by: 22

Documentation

Index

Constants

View Source
const (
	PrefixPadding = 10
	PrefixWidth   = 20
)
View Source
const (
	DEFAULT_ICON_SIZE = 32
	MAX_ICON_SIZE     = 64
)
View Source
const (
	ShapeRectangle       = "rectangle"
	ShapeSquare          = "square"
	ShapePage            = "page"
	ShapeParallelogram   = "parallelogram"
	ShapeDocument        = "document"
	ShapeCylinder        = "cylinder"
	ShapeQueue           = "queue"
	ShapePackage         = "package"
	ShapeStep            = "step"
	ShapeCallout         = "callout"
	ShapeStoredData      = "stored_data"
	ShapePerson          = "person"
	ShapeDiamond         = "diamond"
	ShapeOval            = "oval"
	ShapeCircle          = "circle"
	ShapeHexagon         = "hexagon"
	ShapeCloud           = "cloud"
	ShapeText            = "text"
	ShapeCode            = "code"
	ShapeClass           = "class"
	ShapeSQLTable        = "sql_table"
	ShapeImage           = "image"
	ShapeSequenceDiagram = "sequence_diagram"
)
View Source
const (
	NamePadding   = 10
	TypePadding   = 20
	HeaderPadding = 20
)

Variables

View Source
var SHAPE_TYPE_TO_DSL_SHAPE map[string]string

Functions

func IsShape

func IsShape(s string) bool

Types

type Arrowhead

type Arrowhead string
const (
	NoArrowhead            Arrowhead = "none"
	ArrowArrowhead         Arrowhead = "arrow"
	TriangleArrowhead      Arrowhead = "triangle"
	DiamondArrowhead       Arrowhead = "diamond"
	FilledDiamondArrowhead Arrowhead = "filled-diamond"

	// For fat arrows
	LineArrowhead Arrowhead = "line"

	// Crows feet notation
	CfOne          Arrowhead = "cf-one"
	CfMany         Arrowhead = "cf-many"
	CfOneRequired  Arrowhead = "cf-one-required"
	CfManyRequired Arrowhead = "cf-many-required"
)

func ToArrowhead

func ToArrowhead(arrowheadType string, filled bool) Arrowhead

type Class

type Class struct {
	Fields  []ClassField  `json:"fields"`
	Methods []ClassMethod `json:"methods"`
}

type ClassField

type ClassField struct {
	Name       string `json:"name"`
	Type       string `json:"type"`
	Visibility string `json:"visibility"`
}

func (ClassField) Text

func (cf ClassField) Text() *MText

func (ClassField) VisibilityToken added in v0.1.3

func (cf ClassField) VisibilityToken() string

type ClassMethod

type ClassMethod struct {
	Name       string `json:"name"`
	Return     string `json:"return"`
	Visibility string `json:"visibility"`
}

func (ClassMethod) Text

func (cm ClassMethod) Text() *MText

func (ClassMethod) VisibilityToken added in v0.1.3

func (cm ClassMethod) VisibilityToken() string

type Connection

type Connection struct {
	ID string `json:"id"`

	Src      string    `json:"src"`
	SrcArrow Arrowhead `json:"srcArrow"`
	SrcLabel string    `json:"srcLabel"`

	Dst      string    `json:"dst"`
	DstArrow Arrowhead `json:"dstArrow"`
	DstLabel string    `json:"dstLabel"`

	Opacity     float64 `json:"opacity"`
	StrokeDash  float64 `json:"strokeDash"`
	StrokeWidth int     `json:"strokeWidth"`
	Stroke      string  `json:"stroke"`
	Fill        string  `json:"fill,omitempty"`

	Text
	LabelPosition   string  `json:"labelPosition"`
	LabelPercentage float64 `json:"labelPercentage"`

	Route   []*geo.Point `json:"route"`
	IsCurve bool         `json:"isCurve,omitempty"`

	Animated bool     `json:"animated"`
	Tooltip  string   `json:"tooltip"`
	Icon     *url.URL `json:"icon"`

	ZIndex int `json:"zIndex"`
}

func BaseConnection

func BaseConnection() *Connection

func (Connection) GetID added in v0.1.0

func (c Connection) GetID() string

func (*Connection) GetLabelTopLeft

func (c *Connection) GetLabelTopLeft() *geo.Point

func (Connection) GetZIndex added in v0.1.0

func (c Connection) GetZIndex() int

type Diagram

type Diagram struct {
	Name        string              `json:"name"`
	Description string              `json:"description,omitempty"`
	FontFamily  *d2fonts.FontFamily `json:"fontFamily,omitempty"`

	Shapes      []Shape      `json:"shapes"`
	Connections []Connection `json:"connections"`
}

func NewDiagram

func NewDiagram() *Diagram

func (Diagram) BoundingBox

func (diagram Diagram) BoundingBox() (topLeft, bottomRight Point)

func (Diagram) HashID added in v0.1.0

func (diagram Diagram) HashID() (string, error)

type MText

type MText struct {
	Text     string `json:"text"`
	FontSize int    `json:"fontSize"`
	IsBold   bool   `json:"isBold"`
	IsItalic bool   `json:"isItalic"`
	Language string `json:"language"`
	Shape    string `json:"shape"`

	Dimensions TextDimensions `json:"dimensions,omitempty"`
}

func (MText) GetColor

func (text MText) GetColor(theme *d2themes.Theme, isItalic bool) string

type Point

type Point struct {
	X int `json:"x"`
	Y int `json:"y"`
}

func NewPoint

func NewPoint(x, y int) Point

type SQLColumn

type SQLColumn struct {
	Name       Text   `json:"name"`
	Type       Text   `json:"type"`
	Constraint string `json:"constraint"`
	Reference  string `json:"reference"`
}

func (SQLColumn) ConstraintAbbr added in v0.1.3

func (c SQLColumn) ConstraintAbbr() string

func (SQLColumn) Texts added in v0.1.3

func (c SQLColumn) Texts() []*MText

type SQLTable

type SQLTable struct {
	Columns []SQLColumn `json:"columns"`
}

type Shape

type Shape struct {
	ID   string `json:"id"`
	Type string `json:"type"`

	Pos    Point `json:"pos"`
	Width  int   `json:"width"`
	Height int   `json:"height"`

	Opacity     float64 `json:"opacity"`
	StrokeDash  float64 `json:"strokeDash"`
	StrokeWidth int     `json:"strokeWidth"`

	BorderRadius int `json:"borderRadius"`

	Fill   string `json:"fill"`
	Stroke string `json:"stroke"`

	Shadow   bool `json:"shadow"`
	ThreeDee bool `json:"3d"`
	Multiple bool `json:"multiple"`

	Tooltip      string   `json:"tooltip"`
	Link         string   `json:"link"`
	Icon         *url.URL `json:"icon"`
	IconPosition string   `json:"iconPosition"`

	// Whether the shape should allow shapes behind it to bleed through
	// Currently just used for sequence diagram groups
	Blend bool `json:"blend"`

	Class
	SQLTable

	Text

	LabelPosition string `json:"labelPosition,omitempty"`

	ZIndex int `json:"zIndex"`
	Level  int `json:"level"`

	// These are used for special shapes, sql_table and class
	PrimaryAccentColor   string `json:"primaryAccentColor,omitempty"`
	SecondaryAccentColor string `json:"secondaryAccentColor,omitempty"`
	NeutralAccentColor   string `json:"neutralAccentColor,omitempty"`
}

func BaseShape

func BaseShape() *Shape

func (Shape) GetID added in v0.1.0

func (s Shape) GetID() string

func (*Shape) GetIconSize

func (s *Shape) GetIconSize(box *geo.Box) int

func (Shape) GetZIndex added in v0.1.0

func (s Shape) GetZIndex() int

func (*Shape) SetType

func (s *Shape) SetType(t string)

type Text

type Text struct {
	Label      string `json:"label"`
	FontSize   int    `json:"fontSize"`
	FontFamily string `json:"fontFamily"`
	Language   string `json:"language"`
	Color      string `json:"color"`

	Italic    bool `json:"italic"`
	Bold      bool `json:"bold"`
	Underline bool `json:"underline"`

	LabelWidth  int `json:"labelWidth"`
	LabelHeight int `json:"labelHeight"`
}

type TextDimensions

type TextDimensions struct {
	Width  int `json:"width"`
	Height int `json:"height"`
}

func NewTextDimensions

func NewTextDimensions(w, h int) *TextDimensions

Jump to

Keyboard shortcuts

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