Skip to content

Box

Box shape

Extends

Constructors

new Box()

new Box(): Box

Returns

Box

Overrides

Shape.constructor

Source

shapes.ts:1181

Properties

anchorAngle

anchorAngle: number

Anchor angle (in degree)

Source

shapes.ts:1103


anchorLength

anchorLength: number

Anchor length

Source

shapes.ts:1108


anchorPosition

anchorPosition: number

Anchor position (0~1). 0 is on tail, 1 is on head

Source

shapes.ts:1113


anchored

anchored: boolean

Anchored

Source

shapes.ts:1098


children

children: Obj[]

Inherited from

Shape.children

Source

core/obj.ts:14


connectable

connectable: boolean

Connectable flag

Inherited from

Shape.connectable

Source

shapes.ts:200


constraints

constraints: Constraint[]

Shape’s constraints

Inherited from

Shape.constraints

Source

shapes.ts:295


containable

containable: boolean

Containable flag

Inherited from

Shape.containable

Source

shapes.ts:190


containableFilter

containableFilter: string

Containable filter

Inherited from

Shape.containableFilter

Source

shapes.ts:195


corners

corners: number[]

Corner radius [top-left, top-right, bottom-right, bottom-left] (same with CSS)

Source

shapes.ts:1093


description

description: string

Description of the shape

Inherited from

Shape.description

Source

shapes.ts:150


enable

enable: boolean

Enable flag

Inherited from

Shape.enable

Source

shapes.ts:165


fillColor

fillColor: string

Fill color

Inherited from

Shape.fillColor

Source

shapes.ts:245


fillStyle

fillStyle: string

Fill style

Inherited from

Shape.fillStyle

Source

shapes.ts:250


fontColor

fontColor: string

Font color

Inherited from

Shape.fontColor

Source

shapes.ts:255


fontFamily

fontFamily: string

Font family

Inherited from

Shape.fontFamily

Source

shapes.ts:260


fontSize

fontSize: number

Font size

Inherited from

Shape.fontSize

Source

shapes.ts:265


fontStyle

fontStyle: string

Font style

Inherited from

Shape.fontStyle

Source

shapes.ts:270


fontWeight

fontWeight: number

Font weight

Inherited from

Shape.fontWeight

Source

shapes.ts:275


height

height: number

Shape’s height

Inherited from

Shape.height

Source

shapes.ts:220


horzAlign

horzAlign: HorzAlignEnum

Text horizontal alignment

Source

shapes.ts:1158


id

id: string

Inherited from

Shape.id

Source

core/obj.ts:11


left

left: number

Shape’s left position

Inherited from

Shape.left

Source

shapes.ts:205


lineHeight

lineHeight: number

Text line height

Source

shapes.ts:1168


link: string

Link

Inherited from

Shape.link

Source

shapes.ts:290


movable

movable: MovableEnum

Indicate how this shape can be moved

Inherited from

Shape.movable

Source

shapes.ts:175


name

name: string

Name of the shape

Inherited from

Shape.name

Source

shapes.ts:145


opacity

opacity: number

Opacity

Inherited from

Shape.opacity

Source

shapes.ts:280


padding

padding: number[]

Padding spaces [top, right, bottom, left] (same with CSS)

Source

shapes.ts:1088


paragraphSpacing

paragraphSpacing: number

Text paragraph spacing

Source

shapes.ts:1173


parent

parent: null | Obj

Inherited from

Shape.parent

Source

core/obj.ts:13


properties

properties: Property[]

Shape’s properties

Inherited from

Shape.properties

Source

shapes.ts:300


proto

proto: boolean

The flag to indicate this shape is a prototype or not

Inherited from

Shape.proto

Source

shapes.ts:155


rotatable

rotatable: boolean

Rotatable flag

Inherited from

Shape.rotatable

Source

shapes.ts:185


rotate

rotate: number

Shape’s rotation angle (in degree)

Inherited from

Shape.rotate

Source

shapes.ts:225


roughness

roughness: number

Roughness

Inherited from

Shape.roughness

Source

shapes.ts:285


scripts

scripts: Script[]

Shape’s scripts

Inherited from

Shape.scripts

Source

shapes.ts:305


sizable

sizable: SizableEnum

Indicate how this shape can be resized

Inherited from

Shape.sizable

Source

shapes.ts:180


strokeColor

strokeColor: string

Stroke color

Inherited from

Shape.strokeColor

Source

shapes.ts:230


strokePattern

strokePattern: number[]

Stroke pattern

Inherited from

Shape.strokePattern

Source

shapes.ts:240


strokeWidth

strokeWidth: number

Stroke width

Inherited from

Shape.strokeWidth

Source

shapes.ts:235


tags

tags: string[]

Tags

Inherited from

Shape.tags

Source

shapes.ts:160


text

text: any

Text could a string or document object

Rich text document content grammar (BNF): doc = (paragraph | bulletList | orderedList)* bulletList = listItem* orderedList = listItem* paragraph = (text | hardBreak)* listItem = paragraph text = hardBreak =

Rich text document content (this.text) look like: { “type”: “doc”, “content”: [ { “type”: “paragraph”, “content”: [ { “type”: “text”, “text”: “asdf asdf” }, { “type”: “text”, “marks”: [{ “type”: “strong” }], “text”: “sadflkj” }, … ] } … ] }

Source

shapes.ts:1148


textEditable

textEditable: boolean

Text editable

Source

shapes.ts:1118


top

top: number

Shape’s top position

Inherited from

Shape.top

Source

shapes.ts:210


type

type: string

Inherited from

Shape.type

Source

core/obj.ts:12


vertAlign

vertAlign: VertAlignEnum

Text vertical alignment

Source

shapes.ts:1163


visible

visible: boolean

Visible flag

Inherited from

Shape.visible

Source

shapes.ts:170


width

width: number

Shape’s width

Inherited from

Shape.width

Source

shapes.ts:215


wordWrap

wordWrap: boolean

Word wrap

Source

shapes.ts:1153

Accessors

bottom

get bottom(): number

Returns

number

Source

shapes.ts:455


innerBottom

get innerBottom(): number

Returns

number

Source

shapes.ts:1249


innerHeight

get innerHeight(): number

Returns

number

Source

shapes.ts:1257


innerLeft

get innerLeft(): number

Returns

number

Source

shapes.ts:1237


innerRight

get innerRight(): number

Returns

number

Source

shapes.ts:1241


innerTop

get innerTop(): number

Returns

number

Source

shapes.ts:1245


innerWidth

get innerWidth(): number

Returns

number

Source

shapes.ts:1253


get right(): number

Returns

number

Source

shapes.ts:451

Methods

assignStyles()

assignStyles(canvas): void

Assign styles to memoization canvas.

Parameters

canvas: MemoizationCanvas

Returns

void

Inherited from

Shape.assignStyles

Source

shapes.ts:516


canContain()

canContain(shape): boolean

Determine a given shape can be contained in this shape

Parameters

shape: Shape

Returns

boolean

Inherited from

Shape.canContain

Source

shapes.ts:908


containsPoint()

containsPoint(canvas, point): boolean

Determines whether this shape contains a point in GCS

Parameters

canvas: Canvas

point: number[]

Returns

boolean

Inherited from

Shape.containsPoint

Source

shapes.ts:785


draw()

draw(canvas, showDOM): void

Draw this shape

Render vs Draw

  • Render: computing geometries how to draw the shape
  • Draw: actual drawing the computed geometries of the shape on the canvas

Parameters

canvas: Canvas

showDOM: boolean= false

Returns

void

Inherited from

Shape.draw

Source

shapes.ts:651


drawLink(canvas, showDOM): void

Draw link

Parameters

canvas: Canvas

showDOM: boolean= false

Returns

void

Inherited from

Shape.drawLink

Source

shapes.ts:665


finalize()

finalize(canvas): void

Finalize shape

Parameters

canvas: Canvas

Returns

void

Inherited from

Shape.finalize

Source

shapes.ts:472


find()

find(pred): null | Obj

Find an shape in breath-first order

Parameters

pred

Returns

null | Obj

Inherited from

Shape.find

Source

core/obj.ts:106


findAllByQuery()

findAllByQuery(queryString): Shape[]

Find all shapes matched with the query string

Parameters

queryString: string

Returns

Shape[]

Inherited from

Shape.findAllByQuery

Source

shapes.ts:898


findByQuery()

findByQuery(queryString): null | Shape

Find a shape first matched with the query string

Parameters

queryString: any

Returns

null | Shape

Inherited from

Shape.findByQuery

Source

shapes.ts:885


findDepthFirst()

findDepthFirst(pred): null | Obj

Find an shape in depth-first order

Parameters

pred

Returns

null | Obj

Inherited from

Shape.findDepthFirst

Source

core/obj.ts:119


findParent()

findParent(pred): null | Obj

Find a shape along with the parent-chain

Parameters

pred

Returns

null | Obj

Inherited from

Shape.findParent

Source

core/obj.ts:132


fromJSON()

fromJSON(json): void

Import shape from JSON

Parameters

json: any

Returns

void

Overrides

Shape.fromJSON

Source

shapes.ts:1220


getAnchorVector()

getAnchorVector(canvas): number[][]

Return the anchor vector based on this.anchorPosition. The anchor vector provides the start point and end point to derive the base angle. The shape will be rotated as the angle of (base angle + anchor angle) at start point.

(shape)
\ <— anchorLength
o --------------------> o | (anchor vector) | | | vector[0] vector[1]

Parameters

canvas: Canvas

Returns

number[][]

Source

shapes.ts:1414


getBoundingRect()

getBoundingRect(includeAnchorPoints): number[][]

Return a bounding rect.

Parameters

includeAnchorPoints: boolean= false

Returns

number[][]

Inherited from

Shape.getBoundingRect

Source

shapes.ts:712


getCenter()

getCenter(): number[]

Returns the center point

Returns

number[]

Inherited from

Shape.getCenter

Source

shapes.ts:705


getChildrenBoundingRect()

getChildrenBoundingRect(): number[][]

Return a bounding box embracing children shapes

Returns

number[][]

Inherited from

Shape.getChildrenBoundingRect

Source

shapes.ts:738


getEnclosure()

getEnclosure(): number[][]

Return a enclosure

Returns

number[][]

Inherited from

Shape.getEnclosure

Source

shapes.ts:772


getOutline()

getOutline(): number[][]

Return outline polygon.

Returns

number[][]

Inherited from

Shape.getOutline

Source

shapes.ts:640


getProperty()

getProperty(name): any

Get a property object

Parameters

name: string

Returns

any

Inherited from

Shape.getProperty

Source

shapes.ts:920


getPropertyValue()

getPropertyValue(name): any

Get a property value

Parameters

name: string

Returns

any

Inherited from

Shape.getPropertyValue

Source

shapes.ts:930


getRectInDCS()

getRectInDCS(canvas, includeAnchorPoints): number[][]

Return a bounding box in DOM coord.

[Note] If you want to place DOM elements over the canvas, use this method. and don’t forget to apply transform scale to the DOM element.

Parameters

canvas: Canvas

includeAnchorPoints: boolean= false

Returns

number[][]

Inherited from

Shape.getRectInDCS

Source

shapes.ts:751


getScript()

getScript(id): undefined | string

Get a property object

Parameters

id: string

Returns

undefined | string

Inherited from

Shape.getScript

Source

shapes.ts:938


getSeed()

getSeed(): number

Returns

number

Inherited from

Shape.getSeed

Source

shapes.ts:459


getShapeAt()

getShapeAt(canvas, point, exceptions): null | Shape

Pick a shape at specific position (x, y)

Parameters

canvas: Canvas

point: number[]

exceptions: Shape[]= []

Returns

null | Shape

Inherited from

Shape.getShapeAt

Source

shapes.ts:491


getViewRect()

getViewRect(canvas): number[][]

Return a view rect in GCS. View rect is a rect that includes actually drawn area which includes stroke width, arrowheads, etc. So view rect is mostly larger than bounding rect.

Parameters

canvas: Canvas

Returns

number[][]

Inherited from

Shape.getViewRect

Source

shapes.ts:725


inGroup()

inGroup(): null | Obj

Return true if this shape is contained by a group (recursively)

Returns

null | Obj

Inherited from

Shape.inGroup

Source

shapes.ts:509


initialze()

initialze(canvas): void

Initialize shape

Parameters

canvas: Canvas

Returns

void

Inherited from

Shape.initialze

Source

shapes.ts:467


isDescendant()

isDescendant(obj): boolean

Test whether the given shape is a descendant

Parameters

obj: Obj

Returns

boolean

Inherited from

Shape.isDescendant

Source

core/obj.ts:142


localCoordTransform()

localCoordTransform(canvas, point, recursive): number[]

Transform local coord to parent’s coord (LCS —> parent’s LCS) if recursive=true, transform to GCS (Global coord-system).

Parameters

canvas: Canvas

point: number[]

recursive: boolean= false

Returns

number[]

Inherited from

Shape.localCoordTransform

Source

shapes.ts:552


localCoordTransformRev()

localCoordTransformRev(canvas, point, recursive): number[]

Transform parent’s coord to local coord (parent’s LCS —> LCS) if recursive=true, transform GCS (Global coord-system) —> LCS.

Parameters

canvas: Canvas

point: number[]

recursive: boolean= false

Returns

number[]

Inherited from

Shape.localCoordTransformRev

Source

shapes.ts:572


localTransform()

localTransform(canvas, recursive): void

Transform local context to parent’s context

Parameters

canvas: Canvas

recursive: boolean= false

Returns

void

Inherited from

Shape.localTransform

Source

shapes.ts:536


match()

match(query): boolean

Returns true if query matches this shape

Parameters

query: object[]

Returns

boolean

Inherited from

Shape.match

Source

shapes.ts:860


overlapRect()

overlapRect(canvas, rect): boolean

Determines whether this shape overlaps a given rect

Parameters

canvas: Canvas

rect: number[][]

Returns

boolean

Inherited from

Shape.overlapRect

Source

shapes.ts:805


parseQueryString()

parseQueryString(queryString): any[]

Parse the query-string and returns a query object (JSON)

Query syntax: = [”|” ]* = [”&” ]* = | = e.g.) OuterBox, NameText, … = ”@” e.g.) @Box, @Text, @Line, … = ”#” e.g.) #label, #compartment, …

e.g.) parseQuery(“@Box|NameText|@Text&#compartment”) —> [{_type: “Box”},{name: “NameText”},{_type: “Text”, tag:“compartment”}]

Parameters

queryString: string

Returns

any[]

query object

Inherited from

Shape.parseQueryString

Source

shapes.ts:835


preprocess()

preprocess(doc, wordWrap, width, listIndent): void

Preprocess document (handle wordWrap and hardBreak) options: wordWrap: boolean width: number listIndent: number

Preprocessed document content grammar (BNF): doc = (paragraph | bulletList | orderedList)* orderedList [width, height] = listItem* bulletList [width, height] = listItem* listItem [width, height] = paragraph paragraph [width, height] = line* line [width, height] = text* text [width, height] =

Parameters

doc: any

wordWrap: boolean

width: number

listIndent: number

Returns

void

Source

shapes.ts:1308


render()

render(canvas): void

Render this shape

Render vs Draw

  • Render: computing geometries how to draw the shape
  • Draw: actual drawing the computed geometries of the shape on the canvas

Parameters

canvas: MemoizationCanvas

Returns

void

Inherited from

Shape.render

Source

shapes.ts:595


renderDefault()

renderDefault(canvas): void

Default render this shape

Parameters

canvas: MemoizationCanvas

Returns

void

Overrides

Shape.renderDefault

Source

shapes.ts:1261


renderOutline()

renderOutline(canvas): void

Render this shape’s outline

Parameters

canvas: MemoizationCanvas

Returns

void

Inherited from

Shape.renderOutline

Source

shapes.ts:618


renderOutlineDefault()

renderOutlineDefault(): number[][]

Return outline polygon

Returns

number[][]

Overrides

Shape.renderOutlineDefault

Source

shapes.ts:1389


renderText()

renderText(canvas): void

Parameters

canvas: MemoizationCanvas

Returns

void

Source

shapes.ts:1283


resolveRefs()

resolveRefs(idMap, nullIfNotFound): void

Resolve references

Parameters

idMap: Record<string, Obj>

id to object map

nullIfNotFound: boolean= false

assign null if not found

Returns

void

Inherited from

Shape.resolveRefs

Source

core/obj.ts:47


toJSON()

toJSON(recursive, keepRefs): any

Export shape to JSON

Parameters

recursive: boolean= false

keepRefs: boolean= false

Returns

any

Overrides

Shape.toJSON

Source

shapes.ts:1202


traverse()

traverse(fun, parent): void

Traverse all objects in breath-first order

Parameters

fun

parent: null | Obj= null

Returns

void

Inherited from

Shape.traverse

Source

core/obj.ts:60


traverseDepthFirst()

traverseDepthFirst(fun, parent): void

Traverse all shapes in depth-first order

Parameters

fun

parent: null | Obj= null

Returns

void

Inherited from

Shape.traverseDepthFirst

Source

core/obj.ts:74


traverseDepthFirstSequence()

traverseDepthFirstSequence(): Obj[]

Returns an array of shapes in order of traverse sequence.

Returns

Obj[]

Inherited from

Shape.traverseDepthFirstSequence

Source

core/obj.ts:97


traverseSequence()

traverseSequence(): Obj[]

Returns an array of shapes in order of traverse sequence.

Returns

Obj[]

Inherited from

Shape.traverseSequence

Source

core/obj.ts:88


update()

update(canvas): void

Update shape

Parameters

canvas: Canvas

Returns

void

Inherited from

Shape.update

Source

shapes.ts:482


wordWrapTextSize()

wordWrapTextSize(canvas, wordWrap, width): number[]

Compute size of text with word-wrap and new line chars

Parameters

canvas: Canvas

wordWrap: boolean

width: number

Returns

number[]

Source

shapes.ts:1313