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
zIndex
Number
z-index for shape, used to adjust the drawing order.
visible
Boolean
visible or hidden
className
String
mark of the object, specified by users
attrs
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
x1
Number
x value for first line point
y1
Number
y value or first line point
x2
Number
x value for second line point
y2
Number
y value or second line point
lineDash
Array
An Array
of numbers which specify distances to alternately draw a line and a gap (in coordinate space units).See Line Style.
strokeStyle
String/CanvasGradient/CanvasPatter
same as stroke
strokeOpacity
Number
the opacity for stroke.
opacity
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
x
Number
center's x coordinate
y
Number
center's y coordinate
r
Number
radius
startAngle
Number
Start angle of the arc, this should be in radian.
endAngle
Number
End angle of the circle, this should be in radian.
stroke
String/CanvasGradient/CanvasPattern
the color or style to use for the lines around shapes.
strokeStyle
String/CanvasGradient/CanvasPatter
same as stroke.
strokeOpacity
Number
the opacity for stroke
.
opacity
Number
the alpha value that is applied to shapes and images before they are drawn onto the canvas.
lineDash
Array
An Array
of numbers which specify distances to alternately draw a line and a gap (in coordinate space units).See Line Style.
Example:
Shape.Circle
Circle constructor.
attrs
: Object, it includes the following attributes:
Name
Type
Description
x
Number
center's x coordinate
y
Number
center's y coordinate
r
Number
radius
fill
String/CanvasGradient/CanvasPattern
the color or style to use inside shapes
fillStyle
String/CanvasGradient/CanvasPattern
same as fill
fillOpacity
Number
the opacity for fill
style
stroke
String/CanvasGradient/CanvasPattern
the color or style to use for the lines around shapes.
strokeStyle
String/CanvasGradient/CanvasPattern
same as stroke
.
strokeOpacity
Number
the opacity for stroke
style.
lineDash
Array
An Array
of numbers which specify distances to alternately draw a line and a gap (in coordinate space units).See Line Style.
opacity
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
points
Array
points array, which constructs the polyline.
smooth
Boolean
Wether to draw a curve line, the default value is false.
stroke
String/CanvasGradient/CanvasPattern
the color or style to use for the lines around shapes.
strokeStyle
String/CanvasGradient/CanvasPattern
same as stroke
.
strokeOpacity
Number
the opacity for stroke
style.
lineJoin
String
determines how two connecting segments.See Line Styl
lineDash
Array
An Array
of numbers which specify distances to alternately draw a line and a gap (in coordinate space units).See Line Style.
opacity
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
points
Array
points array, which constructs the polygon.
fill
String/CanvasGradient/CanvasPattern
the color or style to use inside shapes
fillStyle
String/CanvasGradient/CanvasPattern
same as fill
fillOpacity
Number
the opacity for fill
style
stroke
String/CanvasGradient/CanvasPattern
the color or style to use for the lines around shapes.
strokeStyle
String/CanvasGradient/CanvasPattern
same as stroke
.
strokeOpacity
Number
the opacity for stroke
style.
lineDash
Array
An Array
of numbers which specify distances to alternately draw a line and a gap (in coordinate space units).See Line Style.
opacity
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
x
Number
x coordinate of upper left point of the rectangle.
y
Number
x coordinate of upper left point of the rectangle.
height
Number
the height of rectangle.
width
Number
the width of rectangle.
radius
Number/Array
the border radius for rectangle.
stroke
String/CanvasGradient/CanvasPattern
the color or style to use for the lines around shapes.
strokeStyle
String/CanvasGradient/CanvasPattern
same as stroke
.
strokeOpacity
Number
the opacity for stroke
style.
fill
String/CanvasGradient/CanvasPattern
the color or style to use inside shapes.
fillStyle
String/CanvasGradient/CanvasPattern
same as fill
.
fillOpacity
Number
the opacity for fill
style.
lineDash
Array
An Array
of numbers which specify distances to alternately draw a line and a gap (in coordinate space units).See Line Style.
opacity
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
x
Number
center's x coordinate
y
Number
center's y coordinate
r
Number
radius
r0
Number
the inner radius
startAngle
Number
start angle of sector, it should be a radian.
endAngle
Number
end angle of sector, it should be a radian.
fill
String/CanvasGradient/CanvasPattern
the color or style to use inside shapes
fillStyle
String/CanvasGradient/CanvasPattern
same as fill
fillOpacity
Number
the opacity for fill
style
stroke
String/CanvasGradient/CanvasPattern
the color or style to use for the lines around shapes.
strokeStyle
String/CanvasGradient/CanvasPattern
same as stroke
.
strokeOpacity
Number
the opacity for stroke
style.
lineDash
Array
An Array
of numbers which specify distances to alternately draw a line and a gap (in coordinate space units).See Line Style.
opacity
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
x
Number
x coordinate of the display position
y
Number
y coordinate of the display position
text
String
text content, if you want a text wrapping, just write '\n' in the text, such as 'maximum \n200'.
rotate
Number
the rotate angle, it should be a radian.
fill
String/CanvasGradient/CanvasPattern
the color or style to use inside shapes
fillStyle
String/CanvasGradient/CanvasPattern
same as fill
fillOpacity
Number
the opacity for fill
style
stroke
String/CanvasGradient/CanvasPattern
the color or style to use for the lines around shapes.
strokeStyle
String/CanvasGradient/CanvasPattern
same as stroke
.
strokeOpacity
Number
the opacity for stroke
style.
opacity
Number
the alpha value that is applied to shapes and images before they are drawn onto the canvas.
fontVariant
String
specifies whether or not a text should be displayed in a small-caps font.See Text Style.
Example:
Shape.Custom
Custom shape constructor.
Last updated