Stage
new Konva.Stage(config)
Stage constructor. A stage is used to contain multiple layers
Parameters
| Name | Type | Description |
|---|---|---|
| config | Object | |
| container | String|Element | Container selector or DOM element |
| x (optional) | Number | |
| y (optional) | Number | |
| width (optional) | Number | |
| height (optional) | Number | |
| visible (optional) | Boolean | |
| listening (optional) | Boolean | whether or not the node is listening for events |
| id (optional) | String | unique id |
| name (optional) | String | non-unique name |
| opacity (optional) | Number | determines node opacity. Can be any number between 0 and 1 |
| scale (optional) | Object | set scale |
| scaleX (optional) | Number | set scale x |
| scaleY (optional) | Number | set scale y |
| rotation (optional) | Number | rotation in degrees |
| offset (optional) | Object | offset from center point and rotation point |
| offsetX (optional) | Number | set offset x |
| offsetY (optional) | Number | set offset y |
| draggable (optional) | Boolean | makes the node draggable. When stages are draggable, you can drag and drop the entire stage by dragging any portion of the stage |
| dragDistance (optional) | Number | |
| dragBoundFunc (optional) | function |
Inherited from: Konva.Container
Own Methods
_getOwnerWindow()
The window the stage is rendered in. It is not always the window Konva was imported into: the container may belong to an iframe, or to a window opened with window.open.
setContainer(container)
set container dom element which contains the stage wrapper div element
Parameters:
container(DomElement): can pass in a dom element or id string
clear()
clear all layers
getPointerPosition()
returns ABSOLUTE pointer position which can be a touch position or mouse position pointer position doesn't include any transforms (such as scale) of the stage it is just a plain position of pointer relative to top-left corner of the canvas
Returns: Vector2d|null
getIntersection(pos)
get visible intersection shape. This is the preferred method for determining if a point intersects a shape or not nodes with listening set to false will not be detected
Parameters:
pos(Object)pos.x(Number)pos.y(Number)
Returns: Konva.Node
Example:
var shape = stage.getIntersection({x: 50, y: 50});
getLayers()
returns an array of layers
setPointersPositions(evt)
manually register pointers positions (mouse/touch) in the stage. So you can use stage.getPointerPosition(). Usually you don't need to use that method because all internal events are automatically registered. It may be useful if event is triggered outside of the stage, but you still want to use Konva methods to get pointers position.
Parameters:
evt(Object): Event object
Example:
window.addEventListener('mousemove', (e) => {
stage.setPointersPositions(e);
});
batchDraw()
batch draw
Returns: Konva.Stage this
container()
get/set container DOM element. The container may belong to another window than the one Konva was imported into: an iframe, or a window opened with window.open. The stage then uses the events and the frames of that window.
Returns: DomElement container
Example:
// get container
var container = stage.container();
// set container
var container = document.createElement('div');
body.appendChild(container);
stage.container(container);
// a stage in a popout window
var popout = window.open('', '', 'width=600,height=400');
stage.container(popout.document.body);
Inherited Methods
Konva.Stage also has all methods of its parent classes. Each link below opens the full documentation of the method on the class that defines it.
From Konva.Container
- getChildren(filterFunc)
- hasChildren()
- removeChildren()
- destroyChildren()
- add(children)
- find(selector)
- findOne(selector)
- isAncestorOf(node)
- getAllIntersections(pos)
- clip(clip)
- clipX(x)
- clipY(y)
- clipWidth(width)
- clipHeight(height)
- clipFunc(function)
From Konva.Node
- clearCache()
- cache(config)
- isCached()
- getClientRect(config)
- on(evtStr, handler)
- off(evtStr)
- remove()
- destroy()
- getAttr(attr)
- getAncestors()
- getAttrs()
- setAttrs(config)
- isListening()
- isVisible()
- show()
- hide()
- getAbsoluteZIndex()
- getDepth()
- getRelativePointerPosition()
- getAbsolutePosition(top)
- move(change)
- rotate(theta)
- moveToTop()
- moveUp()
- moveDown()
- moveToBottom()
- getAbsoluteOpacity()
- moveTo(newContainer)
- toObject()
- toJSON()
- getParent()
- findAncestors(selector, includeSelf, stopNode)
- findAncestor(selector, includeSelf, stopNode)
- getLayer()
- getStage()
- fire(eventType, evt, bubble)
- getAbsoluteTransform()
- getAbsoluteScale()
- getAbsoluteRotation()
- getTransform()
- clone(obj)
- toCanvas(config)
- toDataURL(config)
- toImage(config)
- toBlob(config)
- getClassName()
- getType()
- addName(name)
- hasName(name)
- removeName(name)
- setAttr(attr, val)
- draw()
- startDrag()
- stopDrag()
- isDragging()
- isClientRectOnScreen(margin)
- zIndex(index)
- absolutePosition(pos)
- position(pos)
- x(x)
- y(y)
- globalCompositeOperation(type)
- opacity(opacity)
- name(name)
- id(id)
- rotation(rotation)
- scale(scale)
- scaleX(x)
- scaleY(y)
- skew(skew)
- skewX(x)
- skewY(y)
- offsetX(x)
- offsetY(y)
- dragDistance(distance)
- width(width)
- height(height)
- listening(listening)
- preventDefault(preventDefault)
- filters(filters)
- visible(visible)
- transformsEnabled(enabled)
- size(size)
- dragBoundFunc(dragBoundFunc)
- draggable(draggable)
- to(params)
- blurRadius(radius)
- brightness(brightness)
- contrast(contrast)
- embossStrength(level)
- embossWhiteLevel(embossWhiteLevel)
- embossDirection(embossDirection)
- embossBlend(embossBlend)
- enhance(amount)
- hue(hue)
- saturation(saturation)
- luminance(value)
- value(value)
- kaleidoscopePower(power)
- kaleidoscopeAngle(degrees)
- noise(noise)
- pixelSize(pixelSize)
- levels(level)
- red(red)
- green(green)
- blue(blue)
- alpha(alpha)
- threshold(threshold)