d2target

package
v0.0.0-...-e815181 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2023 License: MPL-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PrefixPadding = 10
	PrefixWidth   = 20
	CenterPadding = 50
	// 10px of padding top and bottom so text doesn't look squished
	VerticalPadding = 20
)
View Source
const (
	DEFAULT_ICON_SIZE = 32
	MAX_ICON_SIZE     = 64

	SHADOW_SIZE_X    = 3
	SHADOW_SIZE_Y    = 5
	THREE_DEE_OFFSET = 15
	MULTIPLE_OFFSET  = 10

	INNER_BORDER_OFFSET = 5

	BG_COLOR = color.N7
	FG_COLOR = color.N1

	MIN_ARROWHEAD_STROKE_WIDTH = 2
	ARROWHEAD_PADDING          = 2.
)
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
	ConstraintPadding = 20
	HeaderPadding     = 10

	// Setting table font size sets it for columns
	// The header needs to be a little larger for visual hierarchy
	HeaderFontAdd = 4
)

Variables

View Source
var BorderOffset = geo.NewVector(5, 5)
View Source
var SHAPE_TYPE_TO_DSL_SHAPE map[string]string

Functions

func GetIconSize

func GetIconSize(box *geo.Box, position string) int

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"
	CircleArrowhead        Arrowhead = "circle"
	FilledCircleArrowhead  Arrowhead = "filled-circle"

	// 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"

	DefaultArrowhead Arrowhead = TriangleArrowhead
)

func ToArrowhead

func ToArrowhead(arrowheadType string, filled bool) Arrowhead

func (Arrowhead) Dimensions

func (arrowhead Arrowhead) Dimensions(strokeWidth float64) (width, height float64)

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(fontSize int) *MText

func (ClassField) VisibilityToken

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(fontSize int) *MText

func (ClassMethod) VisibilityToken

func (cm ClassMethod) VisibilityToken() string

type Config

type Config struct {
	Sketch         *bool           `json:"sketch"`
	ThemeID        *int64          `json:"themeID"`
	DarkThemeID    *int64          `json:"darkThemeID"`
	Pad            *int64          `json:"pad"`
	Center         *bool           `json:"center"`
	LayoutEngine   *string         `json:"layoutEngine"`
	ThemeOverrides *ThemeOverrides `json:"themeOverrides"`
}

type Connection

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

	Classes []string `json:"classes,omitempty"`

	Src      string    `json:"src"`
	SrcArrow Arrowhead `json:"srcArrow"`
	SrcLabel *Text     `json:"srcLabel,omitempty"`

	Dst      string    `json:"dst"`
	DstArrow Arrowhead `json:"dstArrow"`
	DstLabel *Text     `json:"dstLabel,omitempty"`

	Opacity      float64 `json:"opacity"`
	StrokeDash   float64 `json:"strokeDash"`
	StrokeWidth  int     `json:"strokeWidth"`
	Stroke       string  `json:"stroke"`
	Fill         string  `json:"fill,omitempty"`
	BorderRadius float64 `json:"borderRadius,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) CSSStyle

func (c Connection) CSSStyle() string

func (*Connection) GetArrowheadLabelPosition

func (connection *Connection) GetArrowheadLabelPosition(isDst bool) *geo.Point

func (Connection) GetFontColor

func (c Connection) GetFontColor() string

func (Connection) GetID

func (c Connection) GetID() string

func (*Connection) GetLabelTopLeft

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

func (Connection) GetZIndex

func (c Connection) GetZIndex() int

type Diagram

type Diagram struct {
	Name   string  `json:"name"`
	Config *Config `json:"config,omitempty"`
	// See docs on the same field in d2graph to understand what it means.
	IsFolderOnly bool                `json:"isFolderOnly"`
	Description  string              `json:"description,omitempty"`
	FontFamily   *d2fonts.FontFamily `json:"fontFamily,omitempty"`

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

	Root Shape `json:"root"`

	Layers    []*Diagram `json:"layers,omitempty"`
	Scenarios []*Diagram `json:"scenarios,omitempty"`
	Steps     []*Diagram `json:"steps,omitempty"`
}

func NewDiagram

func NewDiagram() *Diagram

func (Diagram) BoundingBox

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

func (Diagram) Bytes

func (diagram Diagram) Bytes() ([]byte, error)

func (*Diagram) GetBoard

func (d *Diagram) GetBoard(boardPath string) *Diagram

boardPath comes in the form of "x/layers/z/scenarios/a" or in the form of "layers/z/scenarios/a"

func (Diagram) GetCorpus

func (diagram Diagram) GetCorpus() string

func (Diagram) GetNestedCorpus

func (diagram Diagram) GetNestedCorpus() string

func (Diagram) HasShape

func (diagram Diagram) HasShape(condition func(Shape) bool) bool

func (Diagram) HashID

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

func (Diagram) NestedBoundingBox

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

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(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

func (c SQLColumn) ConstraintAbbr() string

func (SQLColumn) Texts

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

type SQLTable

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

type Shape

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

	Classes []string `json:"classes,omitempty"`

	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"`
	FillPattern string `json:"fillPattern,omitempty"`
	Stroke      string `json:"stroke"`

	Shadow       bool `json:"shadow"`
	ThreeDee     bool `json:"3d"`
	Multiple     bool `json:"multiple"`
	DoubleBorder bool `json:"double-border"`

	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) CSSStyle

func (s Shape) CSSStyle() string

TODO remove this function, just set fields on themeable

func (Shape) GetFontColor

func (s Shape) GetFontColor() string

func (Shape) GetID

func (s Shape) GetID() string

func (Shape) GetZIndex

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"`
	LabelFill   string `json:"labelFill,omitempty"`
}

type TextDimensions

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

func NewTextDimensions

func NewTextDimensions(w, h int) *TextDimensions

type ThemeOverrides

type ThemeOverrides struct {
	N1 *string `json:"n1"`
}

Jump to

Keyboard shortcuts

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