Shape
Shape
Shape
new Shape(config)
Shape constructor. Shapes are primitive objects such as rectangles, circles, text, lines, etc.
config
: Object, it contains the following attributes:
Name | Type | Description |
| Number | z-index for shape, used to adjust the drawing order. |
| Boolean | visible or hidden |
| String | mark of the object, specified by users |
| Object | graphical attributes for shape, must be set. |
We provide the following shape classes:
These shapes have general attributes and different shapes have their own attrs
.
Use new Shape[shapeType](config)
to create a specific type of shape.
Example:
Methods
getType()
isDestroyed()
isVisible()
isShape()
attr()
set or get the attributes.
Example:
Use attr('matrix')
to get matrix attribute.
Use attr('clip')
to get clip attribute.
getBBox()
The structure of the bounding box is as follows:
getParent()
show()
hide()
get(name)
set(name, value)
getMatrix()
setMatrix(m)
transform(actions)
Perform matrix transformation on the current object.
The operations supported in actions are 't' (translate), 's' (scale), 'r' (rotate), operations can be combined in any combination order. For example:
translate(x, y)
rotate(radians)
scale(sx, sy)
setTransform(actions)
Do translating, rotating and scaling operations after resetting the matrix.
The actions
parameter is same as the parameter in transform(actions)
.
remove(destroy)
destroy()
Destroy the element itself, if it has a parent, remove it from parent.
Shape.Line
Line constructor.
attrs
: Object, it includes the following attributes:
Name | Type | Description |
| Number | x value for first line point |
| Number | y value or first line point |
| Number | x value for second line point |
| Number | y value or second line point |
| Number | set the thickness of lines in space units. See Line Style. |
| String | determines how the end points of every line are drawn.See Line Style. |
| Array | An |
| String/ | the color or style to use for the lines around shapes. |
|
| same as |
| Number | the opacity for stroke. |
| Number | the alpha value that is applied to shapes and images before they are drawn onto the canvas. |
Example:
Shape.Arc
Arc constructor.
attrs
: Object, it includes the following attributes:
Name | Type | Description |
| Number | center's x coordinate |
| Number | center's y coordinate |
| Number | radius |
| Number | Start angle of the arc, this should be in radian. |
| Number | End angle of the circle, this should be in radian. |
| String/CanvasGradient/CanvasPattern | the color or style to use for the lines around shapes. |
| String/CanvasGradient/CanvasPatter | same as |
| Number | the opacity for |
| Number | the alpha value that is applied to shapes and images before they are drawn onto the canvas. |
| String | determines how the end points of every line are drawn.See Line Style. |
| Array | An |
| Number | sets the thickness of lines in space units.See Line Style. |
Example:
Shape.Circle
Circle constructor.
attrs
: Object, it includes the following attributes:
Name | Type | Description |
| Number | center's x coordinate |
| Number | center's y coordinate |
| Number | radius |
| String/CanvasGradient/CanvasPattern | the color or style to use inside shapes |
| String/CanvasGradient/CanvasPattern | same as |
| Number | the opacity for |
| String/CanvasGradient/CanvasPattern | the color or style to use for the lines around shapes. |
| String/CanvasGradient/CanvasPattern | same as |
| Number | the opacity for |
| Number | sets the thickness of lines in space units. See Line Style. |
| Array | An |
| Number | the alpha value that is applied to shapes and images before they are drawn onto the canvas. |
Example:
Shape.Polyline
Polyline constructor.
attrs
: Object, it includes the following attributes:
Name | Type | Description |
| Array | points array, which constructs the polyline. |
|
| Wether to draw a curve line, the default value is false. |
| String/CanvasGradient/CanvasPattern | the color or style to use for the lines around shapes. |
| String/CanvasGradient/CanvasPattern | same as |
| Number | the opacity for |
| String | determines how the end points of every line are drawn.See Line Style. |
| String | determines how two connecting segments.See Line Styl |
| Number | sets the thickness of lines in space units. See Line Style. |
| Array | An |
| Number | the alpha value that is applied to shapes and images before they are drawn onto the canvas. |
Example:
Shape.Polygon
Polygon constructor.
attrs
: Object, it includes the following attributes:
Name | Type | Description |
| Array | points array, which constructs the polygon. |
| String/CanvasGradient/CanvasPattern | the color or style to use inside shapes |
| String/CanvasGradient/CanvasPattern | same as |
| Number | the opacity for |
| String/CanvasGradient/CanvasPattern | the color or style to use for the lines around shapes. |
| String/CanvasGradient/CanvasPattern | same as |
| Number | the opacity for |
| Number | sets the thickness of lines in space units. See Line Style. |
| Array | An |
| Number | the alpha value that is applied to shapes and images before they are drawn onto the canvas. |
Example:
Shape.Rect
Rect constructor.
attrs
: Object, it includes the following attributes:
Name | Type | Description |
| Number | x coordinate of upper left point of the rectangle. |
| Number | x coordinate of upper left point of the rectangle. |
| Number | the height of rectangle. |
| Number | the width of rectangle. |
| Number/Array | the border radius for rectangle. |
| String/CanvasGradient/CanvasPattern | the color or style to use for the lines around shapes. |
| String/CanvasGradient/CanvasPattern | same as |
| Number | the opacity for |
| String/CanvasGradient/CanvasPattern | the color or style to use inside shapes. |
| String/CanvasGradient/CanvasPattern | same as |
| Number | the opacity for |
| Number | sets the thickness of lines in space units. See Line Style. |
| Array | An |
| Number | the alpha value that is applied to shapes and images before they are drawn onto the canvas. |
Example:
The radius
usage:
Shape.Sector
Sector constructor.
attrs
: Object, it includes the following attributes:
Name | Type | Description |
| Number | center's x coordinate |
| Number | center's y coordinate |
| Number | radius |
| Number | the inner radius |
| Number | start angle of sector, it should be a radian. |
| Number | end angle of sector, it should be a radian. |
| String/CanvasGradient/CanvasPattern | the color or style to use inside shapes |
| String/CanvasGradient/CanvasPattern | same as |
| Number | the opacity for |
| String/CanvasGradient/CanvasPattern | the color or style to use for the lines around shapes. |
| String/CanvasGradient/CanvasPattern | same as |
| Number | the opacity for |
| Number | sets the thickness of lines in space units. See Line Style. |
| Array | An |
| Number | the alpha value that is applied to shapes and images before they are drawn onto the canvas. |
Example:
Shape.Text
Text constructor.
attrs
: Object, it includes the following attributes:
Name | Type | Description |
| Number | x coordinate of the display position |
| Number | y coordinate of the display position |
| String | text content, if you want a text wrapping, just write '\n' in the text, such as 'maximum \n200'. |
| Number | the rotate angle, it should be a radian. |
| String/CanvasGradient/CanvasPattern | the color or style to use inside shapes |
| String/CanvasGradient/CanvasPattern | same as |
| Number | the opacity for |
| String/CanvasGradient/CanvasPattern | the color or style to use for the lines around shapes. |
| String/CanvasGradient/CanvasPattern | same as |
| Number | the opacity for |
| Number | sets the thickness of lines in space units. See Line Style. |
| Number | the alpha value that is applied to shapes and images before they are drawn onto the canvas. |
| String | specifies the horizontal alignment of text in an element. See Text Style. |
| String | sets the vertical alignment of an element.See Text Style. |
| String | specifies the font style for text.See Text Style. |
| String | specifies the font size of text.See Text Style. |
| String | specifies the font family for text.See Text Style. |
| String / Number | specifies the weight of a font.See Text Style. |
| String | specifies whether or not a text should be displayed in a small-caps font.See Text Style. |
| Number | specifies the height of a line. See Text Style. |
Example:
Shape.Custom
Custom shape constructor.
Last updated