Malyan
Construction:
( params : Object )
Create a new instance of Malyan whereparams
is a object with several optional parameters listed below. The constructor also accepts no parameters at all.- id:
String | undefined
the id of the canvas HTML tag. Optional; defaults toundefined
. - dom:
HTMLElement
the HTML element of the canvas. Optional; defaults toundefined
. - width:
Number
the width of the canvas . Optional; defaults to300
. - height:
Number
the height of the canvas . Optional; defaults to150
. - ratio:
Number
the pixel ratio of the canvas. Optional; defaults to1
. - autoRatio:
Boolean
if autoRatio istrue
, the value of ratio will be computed by devicePixelRatio. Optional; defaults totrue
. - autoClear:
Boolean
Defines whether the renderer should automatically clear its output before rendering a frame. Optional; defaults totrue
. - background:
String | undefined
the property of canvas style. Optional; defaults toundefined
.
- id:
Members:
- id:
Number
the same as above - dom:
Number
the same as above - width:
Number
the same as above - height:
Number
the same as above - ratio:
Number
the same as above - autoClear:
Boolean
the same as above - background:
String | undefined
the same as above - ctx:
Object
canvas context - config:
Object
construction arguments (width, height, ratio, autoRatio, autoClear, background...) - scene:
Object
a new instance of Scene - tree:
Object
a new instance of Tree - eventManager:
Object
a new instance of EventManager
- id:
Methods:
- getSize:
(): {width: Number, height: Number}
return width and height of canvas. - setSize:
(width: Number, height: Number): null
set width and height of canvas. - getPixelRatio:
(): Number
return current device pixel ratio used. - add:
(object: Object, ...): null
add one or many shapes / groups to the instance. Objects can be added as arguments, new Malyan().add(o1, o2, oN), or as an array depicted above. - render:
(): null
render a scene. - forEach:
(callback: Function): null
traverse objects Deep First by the way of preOrder.
- getSize:
Example:
var canvas = new Malyan({ id: 'canvas', width: 500, height: 500, background: '#fff })
Scene
Extends: Group
Construction:
( params : Object )
Create a new instance of Scene.- root:
Malyan
the instance of Malyan.
- root:
Members:
- root:
Malyan
the same as above
- root:
Methods:
- render:
(): null
render objects.
- render:
Example:
this.scene = new Scene({ name: 'root_group', root: this })
Group
Extends: Shape
Construction:
( params : Object )
Create a new instance of Group.Members: the same as
Shape
Methods:
- render:
(): null
render the children of this group.
- render:
Shape
Extends: BaseObject && EventTarget
Construction:
( params : Object )
Create a new instance of Group whereparams
is a object with several optional parameters listed below. The constructor also accepts no parameters at all.- fill:
Boolean
Defines whether fill the shape. Optional; defaults totrue
. - stroke:
Boolean
Defines whether stroke the shape. Optional; defaults totrue
. - closed:
Boolean
Defines whether close the path of shape. Optional; defaults tofalse
. - fillStyle:
String
The fillStyle property specifies the color, gradient, or pattern to use inside shapes. Optional; defaults to#fff
. - strokeStyle:
String
The strokeStyle property specifies the color, gradient, or pattern to use for the strokes (outlines) around shapes. Optional; defaults to#000
. - lineWidth:
Number
The lineWidth property sets the thickness of lines. Optional; defaults to1
. - opacity:
Number
The opacity property specifies the alpha (transparency) value that is applied to shapes and images before they are drawn onto the canvas. Optional; defaults to1
. - shadowColor:
String
The shadowColor property specifies the color of shadows. Optional; defaults torgba(0, 0, 0, 0)
. - shadowOffsetX:
Number
The shadowOffsetX property specifies the distance that shadows will be offset horizontally. Optional; defaults to0
. - shadowOffsetY:
Number
The shadowOffsetX property specifies the distance that shadows will be offset vertically. Optional; defaults to0
. - shadowBlur:
Number
The shadowBlur property specifies the amount of blur applied to shadows. Optional; defaults to0
. - lineCap:
String
The lineCap("butt" || "round" || "square")
property determines the shape used to draw the end points of lines. Optional; defaults tobutt
. - lineJoin:
String
The lineJoin("bevel" || "round" || "miter")
property determines the shape used to join two line segments where they meet. Optional; defaults tomiter
. - miterLimit:
Number
The miterLimit property sets the miter limit ratio. Optional; defaults to10
. - lineDash:
Array | undefined
Used as arguments of the setLineDash() method of the Canvas 2D API. Sets the line dash pattern used when stroking lines. It uses an array of values that specify alternating lengths of lines and gaps which describe the pattern. Optional; defaults toundefined
. - lineDashOffset:
Number
The lineDashOffset property sets the line dash offset. Optional; defaults to0
. - penetrable:
Boolean
Defines whether target has effect when event occured. likepointer-events: none
in css. Optional; defaults tofalse
. - onBeforeRender:
Function
hook execute before render. Optional; defaults to() => {}
. - onAfterRender:
Function
hook execute after render. Optional; defaults to() => {}
.
- fill:
Members:
- fill:
Boolean
the same as above - stroke:
Boolean
the same as above - closed:
Boolean
the same as above - fillStyle:
String
the same as above - strokeStyle:
String
the same as above - lineWidth:
Number
the same as above - opacity:
Number
the same as above - shadowColor:
String
the same as above - shadowOffsetX:
Number
the same as above - shadowOffsetY:
Number
the same as above - shadowBlur:
Number
the same as above - lineCap:
String
the same as above - lineJoin:
String
the same as above - miterLimit:
Number
the same as above - lineDash:
Array | undefined
the same as above - lineDashOffset:
Number
the same as above - penetrable:
Boolean
the same as above - onBeforeRender:
Function
the same as above - onAfterRender:
Function
the same as above - matrix:
Matrix
a new instance of Matrix, calculated by_translation && _rotation && _scale
- _translation:
Vector
a new instance of Vector, determines the distance of translation - _scale:
Vector
a new instance of Vector, determines the amount of scale - _rotation:
Number
determines the amount of rotation
- fill:
Methods:
- calcFinalMatrix:
(): Matrix
return this shape final matrix. - calcCanvasToPixelCoordinatePoint:
(targetPoint:[Number, Number]): relativePos:[Number, Number]
converts a point in the canvas coordinate system to the pixel coordinate system - calcPixelToCanvasCoordinatePoint:
(targetPoint:[Number, Number]): relativePos:[Number, Number]
converts a point in the pixel coordinate system to the canvas coordinate system - calcPixelToParentCoordinatePoint:
(targetPoint:[Number, Number]): relativePos:[Number, Number]
converts a point in the pixel coordinate system to the parent object coordinate system - calcParentToPixelCoordinatePoint:
(targetPoint:[Number, Number]): relativePos:[Number, Number]
converts a point in the parent object coordinate system to the pixel coordinate system - getRoot:
(): Malyan
return a Malyan instance (new Scene().root). - on:
(type: String, callback: Function): null
add event listener - dispatch:
(type: String, detail: Object): null
trigger event - off:
(type: String, callback: Function): null
remove event listener
- calcFinalMatrix:
Vector
Construction:
( params : Object )
Create a new instance of Vector.- x:
Number
the amount of x-axis. Optional; defaults to0
. - y:
Number
the amount of y-axis. Optional; defaults to0
. - onChange:
Function
callback excute when x or y changed. Optional; defaults toundefined
.
- x:
Members:
- x:
Number
the same as above - y:
Number
the same as above - onChange:
Function
the same as above
- x:
Methods:
- set:
(x: Number, y: Number): null
set the value of x and y - static formatPointIntoVector:
(point: Array | Obeject): Vector
return a Vector instance from a point ([0, 0]
or{x: 0, y: 0}
).
- set:
BaseObject
Construction:
()
Members:
- uuid:
String
unique identifier - children:
Array
- parent:
Object
- uuid:
Methods:
- add:
(object: Object, ...): null
add one or many shapes to the instance. Objects can be added as arguments, new BaseObject().add(o1, o2, oN), or as an array depicted above. - remove:
(object: Object, ...): null
remove one or many shapes to the instance. Objects can be added as arguments, new BaseObject().remove(o1, o2, oN), or as an array depicted above.
- add:
EventTarget
Construction:
()
Members:
- listeners:
Object
- listeners:
Methods:
- addEventListener:
(type: String, callback: Function): null
add event listener - dispatchEvent:
(type: String, event: CustomEvent): null
trigger event - removeEventListener:
(type: String, callback: Function): null
remove event listener
- addEventListener:
shapes
Rect
- Extends: Shape
Construction:
( params : Object )
Create a new instance of Vector.- x:
Number
the x-axis value of left-top vertex. Optional; defaults to0
. - y:
Number
the y-axis value of left-top vertex. Optional; defaults to0
. - width:
Number
the width of rect. Optional; defaults to0
. - height:
Number
the height of rect. Optional; defaults to0
. - center:
Boolean
Defines whether the position of rect is in the center. Optional; defaults totrue
.
- x:
Members:
- x:
Number
the same as above - y:
Number
the same as above - width:
Number
the same as above - height:
Number
the same as above - center:
Boolean
the same as above
- x:
Methods:
- render:
(ctx: CanvasRenderContext): null
render rect. - containPoint:
(ctx: CanvasRenderContext, point: {x: Number, y: Number}): Boolean
whether a point is inside of this rect. - getBoundingClientRect:
(): Object
return this rect bounding client params. (width, height, top, bottom, left, right) - getVertices:
(): Object
return this rect vertices.[[0,0], [1,1],...]
- setCenter:
(): null
let this rect position to be in center.
- render: