...

Package shape

import "oss.terrastruct.com/d2/lib/shape"
Overview
Index

Overview ▾

Index ▾

Package files

shape.go shape_callout.go shape_circle.go shape_class.go shape_cloud.go shape_code.go shape_cylinder.go shape_diamond.go shape_document.go shape_hexagon.go shape_image.go shape_oval.go shape_package.go shape_page.go shape_parallelogram.go shape_person.go shape_queue.go shape_real_square.go shape_square.go shape_step.go shape_stored_data.go shape_table.go shape_text.go

Constants

const (
    SQUARE_TYPE        = "Square"
    REAL_SQUARE_TYPE   = "RealSquare"
    PARALLELOGRAM_TYPE = "Parallelogram"
    DOCUMENT_TYPE      = "Document"
    CYLINDER_TYPE      = "Cylinder"
    QUEUE_TYPE         = "Queue"
    PAGE_TYPE          = "Page"
    PACKAGE_TYPE       = "Package"
    STEP_TYPE          = "Step"
    CALLOUT_TYPE       = "Callout"
    STORED_DATA_TYPE   = "StoredData"
    PERSON_TYPE        = "Person"
    DIAMOND_TYPE       = "Diamond"
    OVAL_TYPE          = "Oval"
    CIRCLE_TYPE        = "Circle"
    HEXAGON_TYPE       = "Hexagon"
    CLOUD_TYPE         = "Cloud"

    TABLE_TYPE = "Table"
    CLASS_TYPE = "Class"
    TEXT_TYPE  = "Text"
    CODE_TYPE  = "Code"
    IMAGE_TYPE = "Image"
)
const CLOUD_SQUARE_INNER_HEIGHT = 0.663
const CLOUD_SQUARE_INNER_WIDTH = 0.663

The percentage values of the cloud's square inner box

const CLOUD_SQUARE_INNER_X = 0.167
const CLOUD_SQUARE_INNER_Y = 0.335
const CLOUD_TALL_ASPECT_BOUNDARY = (1 + CLOUD_TALL_INNER_WIDTH/CLOUD_TALL_INNER_HEIGHT) / 2
const CLOUD_TALL_INNER_HEIGHT = 0.820
const CLOUD_TALL_INNER_WIDTH = 0.549

The percentage values of the cloud's tall inner box

const CLOUD_TALL_INNER_X = 0.228
const CLOUD_TALL_INNER_Y = 0.179
const CLOUD_WIDE_ASPECT_BOUNDARY = (1 + CLOUD_WIDE_INNER_WIDTH/CLOUD_WIDE_INNER_HEIGHT) / 2
const CLOUD_WIDE_INNER_HEIGHT = 0.548
const CLOUD_WIDE_INNER_WIDTH = 0.819

The percentage values of the cloud's wide inner box

const CLOUD_WIDE_INNER_X = 0.085
const CLOUD_WIDE_INNER_Y = 0.409
const OVAL_AR_LIMIT = 3.
const (
    PERSON_AR_LIMIT = 1.5
)
const STEP_WEDGE_WIDTH = 35.0

func LimitAR

func LimitAR(width, height, aspectRatio float64) (float64, float64)

func TraceToShapeBorder

func TraceToShapeBorder(shape Shape, rectBorderPoint, prevPoint *geo.Point) *geo.Point

TraceToShapeBorder takes the point on the rectangular border r here is the point on rectangular border p is the prev point (used to calculate slope) s is the point on the actual shape border that'll be returned

. p . │ . │ . ▼ . ┌────r─────────────────────────┐ . │ │ . │ │ │ . │ │ xxxxxxxx │ . │ ▼ xxxxx xxxx │ . │ sxxx xx │ . │ x xx │ . │ xx xx │ . │ x xx │ . │ xx xxx │ . │ xxxx xxxx │ . └──────xxxxxxxxxxxxxx──────────┘

type Shape

type Shape interface {
    Is(shape string) bool
    GetType() string

    AspectRatio1() bool
    IsRectangular() bool

    GetBox() *geo.Box
    GetInnerBox() *geo.Box
    // cloud shape has different innerBoxes depending on content's aspect ratio
    GetInnerBoxForContent(width, height float64) *geo.Box
    SetInnerBoxAspectRatio(aspectRatio float64)

    // placing a rectangle of the given size and padding inside the shape, return the position relative to the shape's TopLeft
    GetInsidePlacement(width, height, paddingX, paddingY float64) geo.Point

    GetDimensionsToFit(width, height, paddingX, paddingY float64) (float64, float64)
    GetDefaultPadding() (paddingX, paddingY float64)

    // Perimeter returns a slice of geo.Intersectables that together constitute the shape border
    Perimeter() []geo.Intersectable

    GetSVGPathData() []string
}

func NewCallout

func NewCallout(box *geo.Box) Shape

func NewCircle

func NewCircle(box *geo.Box) Shape

func NewClass

func NewClass(box *geo.Box) Shape

func NewCloud

func NewCloud(box *geo.Box) Shape

func NewCode

func NewCode(box *geo.Box) Shape

func NewCylinder

func NewCylinder(box *geo.Box) Shape

func NewDiamond

func NewDiamond(box *geo.Box) Shape

func NewDocument

func NewDocument(box *geo.Box) Shape

func NewHexagon

func NewHexagon(box *geo.Box) Shape

func NewImage

func NewImage(box *geo.Box) Shape

func NewOval

func NewOval(box *geo.Box) Shape

func NewPackage

func NewPackage(box *geo.Box) Shape

func NewPage

func NewPage(box *geo.Box) Shape

func NewParallelogram

func NewParallelogram(box *geo.Box) Shape

func NewPerson

func NewPerson(box *geo.Box) Shape

func NewQueue

func NewQueue(box *geo.Box) Shape

func NewRealSquare

func NewRealSquare(box *geo.Box) Shape

func NewShape

func NewShape(shapeType string, box *geo.Box) Shape

func NewSquare

func NewSquare(box *geo.Box) Shape

func NewStep

func NewStep(box *geo.Box) Shape

func NewStoredData

func NewStoredData(box *geo.Box) Shape

func NewTable

func NewTable(box *geo.Box) Shape

func NewText

func NewText(box *geo.Box) Shape