...

Package d2target

import "oss.terrastruct.com/d2/d2target"
Overview
Index

Overview ▾

Index ▾

Constants
Variables
func GetIconSize(box *geo.Box, position string) int
func IsShape(s string) bool
type Arrowhead
    func ToArrowhead(arrowheadType string, filled *bool) Arrowhead
    func (arrowhead Arrowhead) Dimensions(strokeWidth float64) (width, height float64)
type Class
type ClassField
    func (cf ClassField) Text(fontSize int) *MText
    func (cf ClassField) VisibilityToken() string
type ClassMethod
    func (cm ClassMethod) Text(fontSize int) *MText
    func (cm ClassMethod) VisibilityToken() string
type Config
type Connection
    func BaseConnection() *Connection
    func (c Connection) CSSStyle() string
    func (connection *Connection) GetArrowheadLabelPosition(isDst bool) *geo.Point
    func (c Connection) GetFontColor() string
    func (c Connection) GetID() string
    func (c *Connection) GetLabelTopLeft() *geo.Point
    func (c Connection) GetZIndex() int
type Diagram
    func NewDiagram() *Diagram
    func (diagram Diagram) BoundingBox() (topLeft, bottomRight Point)
    func (diagram Diagram) Bytes() ([]byte, error)
    func (d *Diagram) GetBoard(boardPath []string) *Diagram
    func (diagram Diagram) GetCorpus() string
    func (diagram Diagram) GetNestedCorpus() string
    func (diagram Diagram) HasShape(condition func(Shape) bool) bool
    func (diagram Diagram) HashID() (string, error)
    func (diagram Diagram) NestedBoundingBox() (topLeft, bottomRight Point)
type MText
    func (text MText) GetColor(isItalic bool) string
type Point
    func NewPoint(x, y int) Point
type SQLColumn
    func (c SQLColumn) ConstraintAbbr() string
    func (c SQLColumn) Texts(fontSize int) []*MText
type SQLTable
type Shape
    func BaseShape() *Shape
    func (s Shape) CSSStyle() string
    func (s Shape) GetFontColor() string
    func (s Shape) GetID() string
    func (s Shape) GetZIndex() int
    func (s *Shape) SetType(t string)
type Text
type TextDimensions
    func NewTextDimensions(w, h int) *TextDimensions
type ThemeOverrides

Package files

class.go d2target.go sqltable.go

Constants

const (
    PrefixPadding = 10
    PrefixWidth   = 20
    CenterPadding = 50
    // 10px of padding top and bottom so text doesn't look squished
    VerticalPadding = 20
)
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.
)
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"
)
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

valid values for arrowhead.shape

var Arrowheads = map[string]struct{}{
    string(NoArrowhead):       {},
    string(ArrowArrowhead):    {},
    string(TriangleArrowhead): {},
    string(DiamondArrowhead):  {},
    string(CircleArrowhead):   {},
    string(CfOne):             {},
    string(CfMany):            {},
    string(CfOneRequired):     {},
    string(CfManyRequired):    {},
}
var BorderOffset = geo.NewVector(5, 5)
var DSL_SHAPE_TO_SHAPE_TYPE = map[string]string{
    "":                   shape.SQUARE_TYPE,
    ShapeRectangle:       shape.SQUARE_TYPE,
    ShapeSquare:          shape.REAL_SQUARE_TYPE,
    ShapePage:            shape.PAGE_TYPE,
    ShapeParallelogram:   shape.PARALLELOGRAM_TYPE,
    ShapeDocument:        shape.DOCUMENT_TYPE,
    ShapeCylinder:        shape.CYLINDER_TYPE,
    ShapeQueue:           shape.QUEUE_TYPE,
    ShapePackage:         shape.PACKAGE_TYPE,
    ShapeStep:            shape.STEP_TYPE,
    ShapeCallout:         shape.CALLOUT_TYPE,
    ShapeStoredData:      shape.STORED_DATA_TYPE,
    ShapePerson:          shape.PERSON_TYPE,
    ShapeDiamond:         shape.DIAMOND_TYPE,
    ShapeOval:            shape.OVAL_TYPE,
    ShapeCircle:          shape.CIRCLE_TYPE,
    ShapeHexagon:         shape.HEXAGON_TYPE,
    ShapeCloud:           shape.CLOUD_TYPE,
    ShapeText:            shape.TEXT_TYPE,
    ShapeCode:            shape.CODE_TYPE,
    ShapeClass:           shape.CLASS_TYPE,
    ShapeSQLTable:        shape.TABLE_TYPE,
    ShapeImage:           shape.IMAGE_TYPE,
    ShapeSequenceDiagram: shape.SQUARE_TYPE,
}
var SHAPE_TYPE_TO_DSL_SHAPE map[string]string
var Shapes = []string{
    ShapeRectangle,
    ShapeSquare,
    ShapePage,
    ShapeParallelogram,
    ShapeDocument,
    ShapeCylinder,
    ShapeQueue,
    ShapePackage,
    ShapeStep,
    ShapeCallout,
    ShapeStoredData,
    ShapePerson,
    ShapeDiamond,
    ShapeOval,
    ShapeCircle,
    ShapeHexagon,
    ShapeCloud,
    ShapeText,
    ShapeCode,
    ShapeClass,
    ShapeSQLTable,
    ShapeImage,
    ShapeSequenceDiagram,
}

func GetIconSize

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

func IsShape

func IsShape(s string) bool

type Arrowhead

type Arrowhead string
const (
    NoArrowhead               Arrowhead = "none"
    ArrowArrowhead            Arrowhead = "arrow"
    UnfilledTriangleArrowhead Arrowhead = "unfilled-triangle"
    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,omitempty"`
    DarkThemeOverrides *ThemeOverrides `json:"darkThemeOverrides,omitempty"`
}

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

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"`
    PrettyLink   string   `json:"prettyLink,omitempty"`
    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

    ContentAspectRatio *float64 `json:"contentAspectRatio,omitempty"`

    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"`
    N2  *string `json:"n2"`
    N3  *string `json:"n3"`
    N4  *string `json:"n4"`
    N5  *string `json:"n5"`
    N6  *string `json:"n6"`
    N7  *string `json:"n7"`
    B1  *string `json:"b1"`
    B2  *string `json:"b2"`
    B3  *string `json:"b3"`
    B4  *string `json:"b4"`
    B5  *string `json:"b5"`
    B6  *string `json:"b6"`
    AA2 *string `json:"aa2"`
    AA4 *string `json:"aa4"`
    AA5 *string `json:"aa5"`
    AB4 *string `json:"ab4"`
    AB5 *string `json:"ab5"`
}